summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2012-10-10 15:05:42 -0700
committerDianne Hackborn <hackbod@google.com>2012-10-10 15:05:42 -0700
commitcaefa9b5f03b595b81729407e4123fee18a4342c (patch)
treeb50a80299e37718720dd500c532fbbc6555a9c47
parent553074f0fc2aa46f44797b72f1457146697645b6 (diff)
downloadpackages_apps_settings-caefa9b5f03b595b81729407e4123fee18a4342c.zip
packages_apps_settings-caefa9b5f03b595b81729407e4123fee18a4342c.tar.gz
packages_apps_settings-caefa9b5f03b595b81729407e4123fee18a4342c.tar.bz2
Fix issue #7318666: hide developer options from user build
Change-Id: I4c5a66bd5f4d3fc36d439228a7a276d694291606
-rw-r--r--res/values/strings.xml8
-rw-r--r--src/com/android/settings/DevelopmentSettings.java11
-rw-r--r--src/com/android/settings/DeviceInfoSettings.java49
-rw-r--r--src/com/android/settings/Settings.java40
4 files changed, 97 insertions, 11 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f66ca3a..2e5adc0 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -26,7 +26,13 @@
<!-- Device Info --> <skip />
<!-- Device Info screen. Used for a status item's value when the proper value is not known -->
<string name="device_info_default">Unknown</string>
-
+ <!-- [CHAR LIMIT=NONE] Device Info screen. Countdown for user taps to enable development settings -->
+ <string name="show_dev_countdown">You are now <xliff:g id="step_count">%1$d</xliff:g> steps away from being a developer.</string>
+ <!-- [CHAR LIMIT=NONE] Device Info screen. Confirmation that developer settings are enabled -->
+ <string name="show_dev_on">You are now a developer!</string>
+ <!-- [CHAR LIMIT=NONE] Device Info screen. Okay we get it, stop pressing, you already have it on -->
+ <string name="show_dev_already">No need, you are already a developer.</string>
+
<!-- Category headings in left-pane header menu --> <skip />
<!-- Settings main menu category heading. Wireless and networks (Wi-Fi, Bluetooth, data usage...). [CHAR LIMIT=40] -->
<string name="header_category_wireless_networks">WIRELESS &amp; NETWORKS</string>
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.