2015-04-03 21:54:41 +00:00
|
|
|
/*
|
2015-10-03 20:47:05 +00:00
|
|
|
* Copyright 2013-2015 microG Project Team
|
2015-04-03 21:54:41 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.microg.gms.ui;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
2017-02-22 03:20:46 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2016-11-15 23:52:49 +00:00
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.support.v4.app.Fragment;
|
2015-04-03 21:54:41 +00:00
|
|
|
|
|
|
|
import com.google.android.gms.R;
|
|
|
|
|
2016-11-15 23:52:49 +00:00
|
|
|
import org.microg.gms.gcm.GcmDatabase;
|
|
|
|
import org.microg.gms.gcm.GcmPrefs;
|
2017-02-08 13:13:34 +00:00
|
|
|
import org.microg.gms.snet.SafetyNetPrefs;
|
2017-02-22 03:20:46 +00:00
|
|
|
import org.microg.nlp.Preferences;
|
2016-11-15 23:52:49 +00:00
|
|
|
import org.microg.tools.ui.AbstractDashboardActivity;
|
|
|
|
import org.microg.tools.ui.ResourceSettingsFragment;
|
2016-01-12 22:27:43 +00:00
|
|
|
|
2017-02-22 03:20:46 +00:00
|
|
|
import static org.microg.gms.checkin.TriggerReceiver.PREF_ENABLE_CHECKIN;
|
|
|
|
|
2016-11-15 23:52:49 +00:00
|
|
|
public class SettingsActivity extends AbstractDashboardActivity {
|
2016-01-12 22:27:43 +00:00
|
|
|
|
2016-11-15 23:52:49 +00:00
|
|
|
public SettingsActivity() {
|
|
|
|
preferencesResource = R.xml.preferences_start;
|
|
|
|
addCondition(Conditions.GCM_BATTERY_OPTIMIZATIONS);
|
|
|
|
addCondition(Conditions.PERMISSIONS);
|
|
|
|
}
|
2016-01-12 22:27:43 +00:00
|
|
|
|
2015-04-03 21:54:41 +00:00
|
|
|
@Override
|
2016-11-15 23:52:49 +00:00
|
|
|
protected Fragment getFragment() {
|
|
|
|
return new FragmentImpl();
|
2015-04-03 21:54:41 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 23:52:49 +00:00
|
|
|
public static class FragmentImpl extends ResourceSettingsFragment {
|
2015-04-03 21:54:41 +00:00
|
|
|
|
2016-11-15 23:52:49 +00:00
|
|
|
public static final String PREF_ABOUT = "pref_about";
|
|
|
|
public static final String PREF_GCM = "pref_gcm";
|
2017-02-08 13:13:34 +00:00
|
|
|
public static final String PREF_SNET = "pref_snet";
|
2017-02-22 03:20:46 +00:00
|
|
|
public static final String PREF_UNIFIEDNLP = "pref_unifiednlp";
|
|
|
|
public static final String PREF_CHECKIN = "pref_checkin";
|
2016-01-12 22:27:43 +00:00
|
|
|
|
2016-11-15 23:52:49 +00:00
|
|
|
public FragmentImpl() {
|
|
|
|
preferencesResource = R.xml.preferences_start;
|
2016-01-12 22:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-11-15 23:52:49 +00:00
|
|
|
public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
|
|
|
|
super.onCreatePreferencesFix(savedInstanceState, rootKey);
|
2017-02-08 13:13:34 +00:00
|
|
|
updateDetails();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
updateDetails();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateDetails() {
|
|
|
|
findPreference(PREF_ABOUT).setSummary(getString(R.string.about_version_str, AboutFragment.getSelfVersion(getContext())));
|
2016-11-15 23:52:49 +00:00
|
|
|
if (GcmPrefs.get(getContext()).isGcmEnabled()) {
|
2016-11-20 18:37:13 +00:00
|
|
|
GcmDatabase database = new GcmDatabase(getContext());
|
|
|
|
int regCount = database.getRegistrationList().size();
|
|
|
|
database.close();
|
2017-02-22 03:20:46 +00:00
|
|
|
findPreference(PREF_GCM).setSummary(getString(R.string.v7_preference_on) + " / " + getResources().getQuantityString(R.plurals.gcm_registered_apps_counter, regCount, regCount));
|
2016-11-15 23:52:49 +00:00
|
|
|
} else {
|
2017-02-08 13:13:34 +00:00
|
|
|
findPreference(PREF_GCM).setSummary(R.string.v7_preference_off);
|
2016-01-12 22:27:43 +00:00
|
|
|
}
|
2017-02-08 13:13:34 +00:00
|
|
|
findPreference(PREF_SNET).setSummary(SafetyNetPrefs.get(getContext()).isEnabled() ? R.string.service_status_enabled : R.string.service_status_disabled);
|
2017-02-22 03:20:46 +00:00
|
|
|
|
|
|
|
Preferences unifiedNlPrefs = new Preferences(getContext());
|
|
|
|
int backendCount = Preferences.splitBackendString(unifiedNlPrefs.getLocationBackends()).length;
|
|
|
|
backendCount += Preferences.splitBackendString(unifiedNlPrefs.getGeocoderBackends()).length;
|
|
|
|
findPreference(PREF_UNIFIEDNLP).setSummary(getResources().getQuantityString(R.plurals.pref_unifiednlp_summary, backendCount, backendCount));
|
|
|
|
|
|
|
|
boolean checkinEnabled = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean(PREF_ENABLE_CHECKIN, false);
|
|
|
|
findPreference(PREF_CHECKIN).setSummary(checkinEnabled ? R.string.service_status_enabled : R.string.service_status_disabled);
|
2015-04-03 21:54:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|