diff options
author | Dianne Hackborn <hackbod@google.com> | 2012-10-10 15:53:57 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-10-10 15:53:57 -0700 |
commit | af0cea0a2148f8915a57c50a571636911feed9d3 (patch) | |
tree | 02f12bb27711ce957d2c9a1c2d02ce36c6c214ed /src | |
parent | 33080be20a58d340f860feed444167edb527d689 (diff) | |
parent | caefa9b5f03b595b81729407e4123fee18a4342c (diff) | |
download | packages_apps_settings-af0cea0a2148f8915a57c50a571636911feed9d3.zip packages_apps_settings-af0cea0a2148f8915a57c50a571636911feed9d3.tar.gz packages_apps_settings-af0cea0a2148f8915a57c50a571636911feed9d3.tar.bz2 |
Merge "Fix issue #7318666: hide developer options from user build" into jb-mr1-dev
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/DevelopmentSettings.java | 11 | ||||
-rw-r--r-- | src/com/android/settings/DeviceInfoSettings.java | 49 | ||||
-rw-r--r-- | src/com/android/settings/Settings.java | 40 |
3 files changed, 90 insertions, 10 deletions
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java index 6468f94..6a8caec 100644 --- a/src/com/android/settings/DevelopmentSettings.java +++ b/src/com/android/settings/DevelopmentSettings.java @@ -74,6 +74,16 @@ public class DevelopmentSettings extends PreferenceFragment implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener, OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener { + /** + * Preference file were development settings prefs are stored. + */ + public static final String PREF_FILE = "development"; + + /** + * Whether to show the development settings to the user. Default is false. + */ + public static final String PREF_SHOW = "show"; + private static final String ENABLE_ADB = "enable_adb"; private static final String KEEP_SCREEN_ON = "keep_screen_on"; private static final String ALLOW_MOCK_LOCATION = "allow_mock_location"; @@ -350,6 +360,7 @@ public class DevelopmentSettings extends PreferenceFragment Settings.Global.putInt(getActivity().getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1); mLastEnabledState = true; + mEnabledSwitch.setChecked(mLastEnabledState); setPrefsEnabledState(mLastEnabledState); } } diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java index 5f35871..f113da1 100644 --- a/src/com/android/settings/DeviceInfoSettings.java +++ b/src/com/android/settings/DeviceInfoSettings.java @@ -17,10 +17,8 @@ package com.android.settings; import android.app.Activity; -import android.content.ComponentName; +import android.content.Context; import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; import android.os.Build; import android.os.Bundle; import android.os.SELinux; @@ -30,13 +28,12 @@ import android.os.UserHandle; import android.preference.Preference; import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; -import android.provider.Settings; import android.util.Log; +import android.widget.Toast; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -68,6 +65,8 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment { private static final String PROPERTY_EQUIPMENT_ID = "ro.ril.fccid"; long[] mHits = new long[3]; + int mDevHitCountdown; + Toast mDevHitToast; @Override public void onCreate(Bundle icicle) { @@ -82,6 +81,7 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment { setValueSummary(KEY_EQUIPMENT_ID, PROPERTY_EQUIPMENT_ID); setStringSummary(KEY_DEVICE_MODEL, Build.MODEL); setStringSummary(KEY_BUILD_NUMBER, Build.DISPLAY); + findPreference(KEY_BUILD_NUMBER).setEnabled(true); findPreference(KEY_KERNEL_VERSION).setSummary(getFormattedKernelVersion()); if (!SELinux.isSELinuxEnabled()) { @@ -148,6 +148,15 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment { } @Override + public void onResume() { + super.onResume(); + mDevHitCountdown = getActivity().getSharedPreferences(DevelopmentSettings.PREF_FILE, + Context.MODE_PRIVATE).getBoolean(DevelopmentSettings.PREF_SHOW, + android.os.Build.TYPE.equals("eng")) ? -1 : 7; + mDevHitToast = null; + } + + @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { if (preference.getKey().equals(KEY_FIRMWARE_VERSION)) { System.arraycopy(mHits, 1, mHits, 0, mHits.length-1); @@ -162,6 +171,36 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment { Log.e(LOG_TAG, "Unable to start activity " + intent.toString()); } } + } else if (preference.getKey().equals(KEY_BUILD_NUMBER)) { + if (mDevHitCountdown > 0) { + mDevHitCountdown--; + if (mDevHitCountdown == 0) { + getActivity().getSharedPreferences(DevelopmentSettings.PREF_FILE, + Context.MODE_PRIVATE).edit().putBoolean( + DevelopmentSettings.PREF_SHOW, true).apply(); + if (mDevHitToast != null) { + mDevHitToast.cancel(); + } + mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_on, + Toast.LENGTH_LONG); + mDevHitToast.show(); + } else if (mDevHitCountdown > 0) { + if (mDevHitToast != null) { + mDevHitToast.cancel(); + } + mDevHitToast = Toast.makeText(getActivity(), getResources().getString( + R.string.show_dev_countdown, mDevHitCountdown), + Toast.LENGTH_SHORT); + mDevHitToast.show(); + } + } else if (mDevHitCountdown < 0) { + if (mDevHitToast != null) { + mDevHitToast.cancel(); + } + mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_already, + Toast.LENGTH_LONG); + mDevHitToast.show(); + } } return super.onPreferenceTreeClick(preferenceScreen, preference); } diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index b52c2e2..4314f2d 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -34,6 +34,7 @@ import android.accounts.OnAccountsUpdateListener; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; @@ -121,6 +122,9 @@ public class Settings extends PreferenceActivity R.id.accessibility_settings }; + private SharedPreferences mDevelopmentPreferences; + private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener; + // TODO: Update Call Settings based on airplane mode state. protected HashMap<Integer, Integer> mHeaderIndexMap = new HashMap<Integer, Integer>(); @@ -139,6 +143,9 @@ public class Settings extends PreferenceActivity mAuthenticatorHelper.updateAuthDescriptions(this); mAuthenticatorHelper.onAccountsUpdated(this, null); + mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, + Context.MODE_PRIVATE); + getMetaData(); mInLocalHeaderSwitch = true; super.onCreate(savedInstanceState); @@ -195,6 +202,15 @@ public class Settings extends PreferenceActivity public void onResume() { super.onResume(); + mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + invalidateHeaders(); + } + }; + mDevelopmentPreferences.registerOnSharedPreferenceChangeListener( + mDevelopmentPreferencesListener); + ListAdapter listAdapter = getListAdapter(); if (listAdapter instanceof HeaderAdapter) { ((HeaderAdapter) listAdapter).resume(); @@ -210,6 +226,10 @@ public class Settings extends PreferenceActivity if (listAdapter instanceof HeaderAdapter) { ((HeaderAdapter) listAdapter).pause(); } + + mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener( + mDevelopmentPreferencesListener); + mDevelopmentPreferencesListener = null; } @Override @@ -390,7 +410,12 @@ public class Settings extends PreferenceActivity } private void updateHeaderList(List<Header> target) { + final boolean showDev = mDevelopmentPreferences.getBoolean( + DevelopmentSettings.PREF_SHOW, + android.os.Build.TYPE.equals("eng")); int i = 0; + + mHeaderIndexMap.clear(); while (i < target.size()) { Header header = target.get(i); // Ids are integers, so downcasting @@ -400,12 +425,12 @@ public class Settings extends PreferenceActivity } else if (id == R.id.wifi_settings) { // Remove WiFi Settings if WiFi service is not available. if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) { - target.remove(header); + target.remove(i); } } else if (id == R.id.bluetooth_settings) { // Remove Bluetooth Settings if Bluetooth service is not available. if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) { - target.remove(header); + target.remove(i); } } else if (id == R.id.data_usage_settings) { // Remove data usage when kernel module not enabled @@ -413,7 +438,7 @@ public class Settings extends PreferenceActivity .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)); try { if (!netManager.isBandwidthControlEnabled()) { - target.remove(header); + target.remove(i); } } catch (RemoteException e) { // ignored @@ -425,12 +450,17 @@ public class Settings extends PreferenceActivity if (!UserHandle.MU_ENABLED || !UserManager.supportsMultipleUsers() || Utils.isMonkeyRunning()) { - target.remove(header); + target.remove(i); + } + } else if (id == R.id.development_settings) { + if (!showDev) { + target.remove(i); } } + if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) { - target.remove(header); + target.remove(i); } // Increment if the current one wasn't removed by the Utils code. |