summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/SecuritySettings.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/settings/SecuritySettings.java')
-rw-r--r--src/com/android/settings/SecuritySettings.java117
1 files changed, 33 insertions, 84 deletions
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 6858fd3..166fa44 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -18,11 +18,11 @@ package com.android.settings;
import android.app.Activity;
-import android.app.AlertDialog;
+import android.content.ContentQueryMap;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.database.Cursor;
import android.location.LocationManager;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
@@ -34,13 +34,15 @@ import android.provider.Settings;
import android.util.Config;
import android.util.Log;
+import java.util.Observable;
+import java.util.Observer;
+
import com.android.internal.widget.LockPatternUtils;
/**
* Gesture lock pattern settings.
*/
-public class SecuritySettings extends PreferenceActivity
- implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
+public class SecuritySettings extends PreferenceActivity {
// Lock Settings
@@ -64,10 +66,16 @@ public class SecuritySettings extends PreferenceActivity
private CheckBoxPreference mNetwork;
private CheckBoxPreference mGps;
- private LocationManager mLocationManager;
-
- // To track whether Agree was clicked in the Network location warning dialog
- private boolean mOkClicked;
+
+ // These provide support for receiving notification when Location Manager settings change.
+ // This is necessary because the Network Location Provider can change settings
+ // if the user does not confirm enabling the provider.
+ private ContentQueryMap mContentQueryMap;
+ private final class SettingsObserver implements Observer {
+ public void update(Observable o, Object arg) {
+ updateToggles();
+ }
+ }
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -77,14 +85,18 @@ public class SecuritySettings extends PreferenceActivity
mLockPatternUtils = new LockPatternUtils(getContentResolver());
createPreferenceHierarchy();
-
- // Get the available location providers
- mLocationManager = (LocationManager)
- getSystemService(Context.LOCATION_SERVICE);
mNetwork = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_NETWORK);
mGps = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_GPS);
updateToggles();
+
+ // listen for Location Manager settings changes
+ Cursor settingsCursor = getContentResolver().query(Settings.Secure.CONTENT_URI, null,
+ "(" + Settings.System.NAME + "=?)",
+ new String[]{Settings.Secure.LOCATION_PROVIDERS_ALLOWED},
+ null);
+ mContentQueryMap = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, null);
+ mContentQueryMap.addObserver(new SettingsObserver());
}
private PreferenceScreen createPreferenceHierarchy() {
@@ -128,7 +140,7 @@ public class SecuritySettings extends PreferenceActivity
simLockPreferences.setTitle(R.string.sim_lock_settings_category);
// Intent to launch SIM lock settings
intent = new Intent();
- intent.setClassName("com.android.settings", "com.android.settings.SimLockSettings");
+ intent.setClassName("com.android.settings", "com.android.settings.IccLockSettings");
simLockPreferences.setIntent(intent);
PreferenceCategory simLockCat = new PreferenceCategory(this);
@@ -189,87 +201,24 @@ public class SecuritySettings extends PreferenceActivity
Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
mShowPassword.isChecked() ? 1 : 0);
} else if (preference == mNetwork) {
- //normally called on the toggle click
- if (mNetwork.isChecked()) {
- // Show a warning to the user that location data will be shared
- mOkClicked = false;
- new AlertDialog.Builder(this).setMessage(
- getResources().getString(R.string.location_warning_message))
- .setTitle(R.string.location_warning_title)
- .setIcon(android.R.drawable.ic_dialog_alert)
- .setPositiveButton(R.string.agree, this)
- .setNegativeButton(R.string.disagree, this)
- .show()
- .setOnDismissListener(this);
- } else {
- updateProviders();
- }
+ Settings.Secure.setLocationProviderEnabled(getContentResolver(),
+ LocationManager.NETWORK_PROVIDER, mNetwork.isChecked());
} else if (preference == mGps) {
- updateProviders();
+ Settings.Secure.setLocationProviderEnabled(getContentResolver(),
+ LocationManager.GPS_PROVIDER, mGps.isChecked());
}
return false;
}
- public void onClick(DialogInterface dialog, int which) {
- if (which == DialogInterface.BUTTON_POSITIVE) {
- updateProviders();
- mOkClicked = true;
- } else {
- // Reset the toggle
- mNetwork.setChecked(false);
- }
- }
-
- public void onDismiss(DialogInterface dialog) {
- // Assuming that onClick gets called first
- if (!mOkClicked) {
- mNetwork.setChecked(false);
- }
- }
-
/*
* Creates toggles for each available location provider
*/
private void updateToggles() {
- String providers = getAllowedProviders();
- mNetwork.setChecked(providers.contains(LocationManager.NETWORK_PROVIDER));
- mGps.setChecked(providers.contains(LocationManager.GPS_PROVIDER));
- }
-
- private void updateProviders() {
- String preferredProviders = "";
- if (mNetwork.isChecked()) {
- preferredProviders += LocationManager.NETWORK_PROVIDER;
- }
- if (mGps.isChecked()) {
- preferredProviders += "," + LocationManager.GPS_PROVIDER;
- }
- setProviders(preferredProviders);
- }
-
- private void setProviders(String providers) {
- // Update the secure setting LOCATION_PROVIDERS_ALLOWED
- Settings.Secure.putString(getContentResolver(),
- Settings.Secure.LOCATION_PROVIDERS_ALLOWED, providers);
- if (Config.LOGV) {
- Log.v("Location Accuracy", "Setting LOCATION_PROVIDERS_ALLOWED = " + providers);
- }
- // Inform the location manager about the changes
- mLocationManager.updateProviders();
- }
-
- /**
- * @return string containing a list of providers that have been enabled for use
- */
- private String getAllowedProviders() {
- String allowedProviders =
- Settings.Secure.getString(getContentResolver(),
- Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
- if (allowedProviders == null) {
- allowedProviders = "";
- }
- return allowedProviders;
+ mNetwork.setChecked(Settings.Secure.isLocationProviderEnabled(
+ getContentResolver(), LocationManager.NETWORK_PROVIDER));
+ mGps.setChecked(Settings.Secure.isLocationProviderEnabled(
+ getContentResolver(), LocationManager.GPS_PROVIDER));
}
private boolean isToggled(Preference pref) {