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.java200
1 files changed, 60 insertions, 140 deletions
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index dc4c42b..057e5de 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -19,15 +19,11 @@ package com.android.settings;
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
-import com.android.internal.widget.LockPatternUtils;
-
+import android.app.AlertDialog;
import android.app.admin.DevicePolicyManager;
-import android.content.ContentQueryMap;
-import android.content.ContentResolver;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
-import android.database.Cursor;
-import android.location.LocationManager;
import android.os.Bundle;
import android.os.Vibrator;
import android.preference.CheckBoxPreference;
@@ -41,15 +37,15 @@ import android.security.KeyStore;
import android.telephony.TelephonyManager;
import android.util.Log;
+import com.android.internal.widget.LockPatternUtils;
+
import java.util.ArrayList;
-import java.util.Observable;
-import java.util.Observer;
/**
* Gesture lock pattern settings.
*/
public class SecuritySettings extends SettingsPreferenceFragment
- implements OnPreferenceChangeListener {
+ implements OnPreferenceChangeListener, DialogInterface.OnClickListener {
// Lock Settings
private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change";
@@ -60,47 +56,28 @@ public class SecuritySettings extends SettingsPreferenceFragment
private static final String KEY_LOCK_AFTER_TIMEOUT = "lock_after_timeout";
private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
- // Location Settings
- private static final String KEY_LOCATION_CATEGORY = "location_category";
- private static final String KEY_LOCATION_NETWORK = "location_network";
- private static final String KEY_LOCATION_GPS = "location_gps";
- private static final String KEY_ASSISTED_GPS = "assisted_gps";
- private static final String KEY_USE_LOCATION = "location_use_for_services";
-
// Misc Settings
private static final String KEY_SIM_LOCK = "sim_lock";
private static final String KEY_SHOW_PASSWORD = "show_password";
- private static final String KEY_ENABLE_CREDENTIALS = "enable_credentials";
private static final String KEY_RESET_CREDENTIALS = "reset_credentials";
-
- private static final String TAG = "SecuritySettings";
-
- private CheckBoxPreference mNetwork;
- private CheckBoxPreference mGps;
- private CheckBoxPreference mAssistedGps;
- private CheckBoxPreference mUseLocation;
+ private static final String KEY_TOGGLE_INSTALL_APPLICATIONS = "toggle_install_applications";
DevicePolicyManager mDPM;
- // 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 ChooseLockSettingsHelper mChooseLockSettingsHelper;
private LockPatternUtils mLockPatternUtils;
private ListPreference mLockAfter;
- private Observer mSettingsObserver;
-
private CheckBoxPreference mVisiblePattern;
private CheckBoxPreference mTactileFeedback;
private CheckBoxPreference mShowPassword;
- private CheckBoxPreference mEnableCredentials;
private Preference mResetCredentials;
+ private CheckBoxPreference mToggleAppInstallation;
+ private DialogInterface mWarnInstallApps;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -112,25 +89,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
}
- @Override
- public void onStart() {
- super.onStart();
- // 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);
- }
-
- @Override
- public void onStop() {
- super.onStop();
- if (mSettingsObserver != null) {
- mContentQueryMap.deleteObserver(mSettingsObserver);
- }
- }
-
private PreferenceScreen createPreferenceHierarchy() {
PreferenceScreen root = getPreferenceScreen();
if (root != null) {
@@ -139,32 +97,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
addPreferencesFromResource(R.xml.security_settings);
root = getPreferenceScreen();
- mNetwork = (CheckBoxPreference) root.findPreference(KEY_LOCATION_NETWORK);
- mGps = (CheckBoxPreference) root.findPreference(KEY_LOCATION_GPS);
- mAssistedGps = (CheckBoxPreference) root.findPreference(KEY_ASSISTED_GPS);
- if (GoogleLocationSettingHelper.isAvailable(getActivity())) {
- // GSF present, Add setting for 'Use My Location'
- PreferenceGroup locationCat =
- (PreferenceGroup) root.findPreference(KEY_LOCATION_CATEGORY);
- CheckBoxPreference useLocation = new CheckBoxPreference(getActivity());
- useLocation.setKey(KEY_USE_LOCATION);
- useLocation.setTitle(R.string.use_location_title);
- useLocation.setSummaryOn(R.string.use_location_summary_enabled);
- useLocation.setSummaryOff(R.string.use_location_summary_disabled);
- useLocation.setChecked(
- GoogleLocationSettingHelper.getUseLocationForServices(getActivity())
- == GoogleLocationSettingHelper.USE_LOCATION_FOR_SERVICES_ON);
- useLocation.setPersistent(false);
- useLocation.setOnPreferenceChangeListener(this);
- locationCat.addPreference(useLocation);
- mUseLocation = useLocation;
- }
-
- // Change the summary for wifi-only devices
- if (Utils.isWifiOnly()) {
- mNetwork.setSummaryOn(R.string.location_neighborhood_level_wifi);
- }
-
// Add options for lock/unlock screen
int resid = 0;
if (!mLockPatternUtils.isSecure()) {
@@ -239,13 +171,52 @@ public class SecuritySettings extends SettingsPreferenceFragment
mShowPassword = (CheckBoxPreference) root.findPreference(KEY_SHOW_PASSWORD);
// Credential storage
- mEnableCredentials = (CheckBoxPreference) root.findPreference(KEY_ENABLE_CREDENTIALS);
- mEnableCredentials.setOnPreferenceChangeListener(this);
mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS);
+ mToggleAppInstallation = (CheckBoxPreference) findPreference(
+ KEY_TOGGLE_INSTALL_APPLICATIONS);
+ mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
+
return root;
}
+ private boolean isNonMarketAppsAllowed() {
+ return Settings.Secure.getInt(getContentResolver(),
+ Settings.Secure.INSTALL_NON_MARKET_APPS, 0) > 0;
+ }
+
+ private void setNonMarketAppsAllowed(boolean enabled) {
+ // Change the system setting
+ Settings.Secure.putInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS,
+ enabled ? 1 : 0);
+ }
+
+ private void warnAppInstallation() {
+ // TODO: DialogFragment?
+ mWarnInstallApps = new AlertDialog.Builder(getActivity()).setTitle(
+ getResources().getString(R.string.error_title))
+ .setIcon(com.android.internal.R.drawable.ic_dialog_alert)
+ .setMessage(getResources().getString(R.string.install_all_warning))
+ .setPositiveButton(android.R.string.yes, this)
+ .setNegativeButton(android.R.string.no, null)
+ .show();
+ }
+
+ public void onClick(DialogInterface dialog, int which) {
+ if (dialog == mWarnInstallApps && which == DialogInterface.BUTTON_POSITIVE) {
+ setNonMarketAppsAllowed(true);
+ mToggleAppInstallation.setChecked(true);
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ if (mWarnInstallApps != null) {
+ mWarnInstallApps.dismiss();
+ }
+ }
+
private void setupLockAfterPreference() {
// Compatible with pre-Froyo
long currentTimeout = Settings.Secure.getLong(getContentResolver(),
@@ -315,16 +286,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
// Make sure we reload the preference hierarchy since some of these settings
// depend on others...
createPreferenceHierarchy();
- updateLocationToggles();
-
- if (mSettingsObserver == null) {
- mSettingsObserver = new Observer() {
- public void update(Observable o, Object arg) {
- updateLocationToggles();
- }
- };
- mContentQueryMap.addObserver(mSettingsObserver);
- }
final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
if (mVisiblePattern != null) {
@@ -337,15 +298,12 @@ public class SecuritySettings extends SettingsPreferenceFragment
mShowPassword.setChecked(Settings.System.getInt(getContentResolver(),
Settings.System.TEXT_SHOW_PASSWORD, 1) != 0);
- int state = KeyStore.getInstance().test();
- mEnableCredentials.setChecked(state == KeyStore.NO_ERROR);
- mEnableCredentials.setEnabled(state != KeyStore.UNINITIALIZED);
- mResetCredentials.setEnabled(state != KeyStore.UNINITIALIZED);
+ KeyStore.State state = KeyStore.getInstance().state();
+ mResetCredentials.setEnabled(state != KeyStore.State.UNINITIALIZED);
}
@Override
- public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
- Preference preference) {
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
final String key = preference.getKey();
final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
@@ -361,19 +319,13 @@ public class SecuritySettings extends SettingsPreferenceFragment
} else if (preference == mShowPassword) {
Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
mShowPassword.isChecked() ? 1 : 0);
- } else if (preference == mNetwork) {
- Settings.Secure.setLocationProviderEnabled(getContentResolver(),
- LocationManager.NETWORK_PROVIDER, mNetwork.isChecked());
- } else if (preference == mGps) {
- boolean enabled = mGps.isChecked();
- Settings.Secure.setLocationProviderEnabled(getContentResolver(),
- LocationManager.GPS_PROVIDER, enabled);
- if (mAssistedGps != null) {
- mAssistedGps.setEnabled(enabled);
+ } else if (preference == mToggleAppInstallation) {
+ if (mToggleAppInstallation.isChecked()) {
+ mToggleAppInstallation.setChecked(false);
+ warnAppInstallation();
+ } else {
+ setNonMarketAppsAllowed(false);
}
- } else if (preference == mAssistedGps) {
- Settings.Secure.putInt(getContentResolver(), Settings.Secure.ASSISTED_GPS_ENABLED,
- mAssistedGps.isChecked() ? 1 : 0);
} else {
// If we didn't handle it, let preferences handle it.
return super.onPreferenceTreeClick(preferenceScreen, preference);
@@ -382,29 +334,12 @@ public class SecuritySettings extends SettingsPreferenceFragment
return true;
}
- /*
- * Creates toggles for each available location provider
- */
- private void updateLocationToggles() {
- ContentResolver res = getContentResolver();
- boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled(
- res, LocationManager.GPS_PROVIDER);
- mNetwork.setChecked(Settings.Secure.isLocationProviderEnabled(
- res, LocationManager.NETWORK_PROVIDER));
- mGps.setChecked(gpsEnabled);
- if (mAssistedGps != null) {
- mAssistedGps.setChecked(Settings.Secure.getInt(res,
- Settings.Secure.ASSISTED_GPS_ENABLED, 2) == 1);
- mAssistedGps.setEnabled(gpsEnabled);
- }
- }
-
private boolean isToggled(Preference pref) {
return ((CheckBoxPreference) pref).isChecked();
}
/**
- * @see #confirmPatternThenDisableAndClear
+ * see confirmPatternThenDisableAndClear
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
@@ -422,21 +357,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
Log.e("SecuritySettings", "could not persist lockAfter timeout setting", e);
}
updateLockAfterPreferenceSummary();
- } else if (preference == mUseLocation) {
- boolean newValue = (value == null ? false : (Boolean) value);
- GoogleLocationSettingHelper.setUseLocationForServices(getActivity(), newValue);
- // We don't want to change the value immediately here, since the user may click
- // disagree in the dialog that pops up. When the activity we just launched exits, this
- // activity will be restated and the new value re-read, so the checkbox will get its
- // new value then.
- return false;
- } else if (preference == mEnableCredentials) {
- if (value != null && (Boolean) value) {
- getActivity().startActivity(new Intent(CredentialStorage.ACTION_UNLOCK));
- return false;
- } else {
- KeyStore.getInstance().lock();
- }
}
return true;
}