OSDN Git Service

Add an entry in developer options for location tools.
[android-x86/packages-apps-Settings.git] / src / com / android / settings / DevelopmentSettings.java
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.android.settings;
18
19 import android.Manifest;
20 import android.app.Activity;
21 import android.app.ActivityManagerNative;
22 import android.app.AlertDialog;
23 import android.app.AppOpsManager;
24 import android.app.AppOpsManager.PackageOps;
25 import android.app.Dialog;
26 import android.app.admin.DevicePolicyManager;
27 import android.app.backup.IBackupManager;
28 import android.bluetooth.BluetoothAdapter;
29 import android.content.BroadcastReceiver;
30 import android.content.ComponentName;
31 import android.content.ContentResolver;
32 import android.content.Context;
33 import android.content.DialogInterface;
34 import android.content.Intent;
35 import android.content.IntentFilter;
36 import android.content.pm.ApplicationInfo;
37 import android.content.pm.IShortcutService;
38 import android.content.pm.PackageManager;
39 import android.content.pm.PackageManager.NameNotFoundException;
40 import android.content.pm.ResolveInfo;
41 import android.content.res.Resources;
42 import android.hardware.usb.IUsbManager;
43 import android.hardware.usb.UsbManager;
44 import android.net.wifi.WifiManager;
45 import android.os.AsyncTask;
46 import android.os.BatteryManager;
47 import android.os.Build;
48 import android.os.Bundle;
49 import android.os.IBinder;
50 import android.os.Parcel;
51 import android.os.RemoteException;
52 import android.os.ServiceManager;
53 import android.os.StrictMode;
54 import android.os.SystemProperties;
55 import android.os.UserHandle;
56 import android.service.persistentdata.PersistentDataBlockManager;
57 import android.os.UserManager;
58 import android.os.storage.IMountService;
59 import android.provider.SearchIndexableResource;
60 import android.provider.Settings;
61 import android.support.v14.preference.SwitchPreference;
62 import android.support.v7.preference.ListPreference;
63 import android.support.v7.preference.Preference;
64 import android.support.v7.preference.Preference.OnPreferenceChangeListener;
65 import android.support.v7.preference.PreferenceGroup;
66 import android.support.v7.preference.PreferenceScreen;
67 import android.text.TextUtils;
68 import android.util.Log;
69 import android.view.ThreadedRenderer;
70 import android.view.IWindowManager;
71 import android.view.LayoutInflater;
72 import android.view.View;
73 import android.view.ViewGroup;
74 import android.view.accessibility.AccessibilityManager;
75 import android.webkit.IWebViewUpdateService;
76 import android.webkit.WebViewProviderInfo;
77 import android.widget.Switch;
78 import android.widget.Toast;
79
80 import com.android.internal.app.LocalePicker;
81 import com.android.internal.logging.MetricsProto.MetricsEvent;
82 import com.android.settings.applications.BackgroundCheckSummary;
83 import com.android.settings.fuelgauge.InactiveApps;
84 import com.android.settings.search.BaseSearchIndexProvider;
85 import com.android.settings.search.Indexable;
86 import com.android.settings.widget.SwitchBar;
87 import com.android.settingslib.RestrictedLockUtils;
88 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
89 import com.android.settingslib.RestrictedSwitchPreference;
90
91 import java.util.ArrayList;
92 import java.util.Arrays;
93 import java.util.HashSet;
94 import java.util.List;
95
96 /*
97  * Displays preferences for application developers.
98  */
99 public class DevelopmentSettings extends RestrictedSettingsFragment
100         implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
101                 OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable {
102     private static final String TAG = "DevelopmentSettings";
103
104     /**
105      * Preference file were development settings prefs are stored.
106      */
107     public static final String PREF_FILE = "development";
108
109     /**
110      * Whether to show the development settings to the user.  Default is false.
111      */
112     public static final String PREF_SHOW = "show";
113
114     private static final String ENABLE_ADB = "enable_adb";
115     private static final String CLEAR_ADB_KEYS = "clear_adb_keys";
116     private static final String ENABLE_TERMINAL = "enable_terminal";
117     private static final String KEEP_SCREEN_ON = "keep_screen_on";
118     private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log";
119     private static final String WEBVIEW_PROVIDER_KEY = "select_webview_provider";
120     private static final String WEBVIEW_MULTIPROCESS_KEY = "enable_webview_multiprocess";
121     private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable";
122     private static final String HDCP_CHECKING_KEY = "hdcp_checking";
123     private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking";
124     private static final String LOCAL_BACKUP_PASSWORD = "local_backup_password";
125     private static final String HARDWARE_UI_PROPERTY = "persist.sys.ui.hw";
126     private static final String MSAA_PROPERTY = "debug.egl.force_msaa";
127     private static final String BUGREPORT = "bugreport";
128     private static final String BUGREPORT_IN_POWER_KEY = "bugreport_in_power";
129     private static final String OPENGL_TRACES_PROPERTY = "debug.egl.trace";
130     private static final String TUNER_UI_KEY = "tuner_ui";
131     private static final String COLOR_TEMPERATURE_PROPERTY = "persist.sys.debug.color_temp";
132
133     private static final String DEBUG_APP_KEY = "debug_app";
134     private static final String WAIT_FOR_DEBUGGER_KEY = "wait_for_debugger";
135     private static final String MOCK_LOCATION_APP_KEY = "mock_location_app";
136     private static final String VERIFY_APPS_OVER_USB_KEY = "verify_apps_over_usb";
137     private static final String DEBUG_VIEW_ATTRIBUTES =  "debug_view_attributes";
138     private static final String FORCE_ALLOW_ON_EXTERNAL_KEY = "force_allow_on_external";
139     private static final String STRICT_MODE_KEY = "strict_mode";
140     private static final String POINTER_LOCATION_KEY = "pointer_location";
141     private static final String SHOW_TOUCHES_KEY = "show_touches";
142     private static final String SHOW_SCREEN_UPDATES_KEY = "show_screen_updates";
143     private static final String DISABLE_OVERLAYS_KEY = "disable_overlays";
144     private static final String SIMULATE_COLOR_SPACE = "simulate_color_space";
145     private static final String USB_AUDIO_KEY = "usb_audio";
146     private static final String SHOW_CPU_USAGE_KEY = "show_cpu_usage";
147     private static final String FORCE_HARDWARE_UI_KEY = "force_hw_ui";
148     private static final String FORCE_MSAA_KEY = "force_msaa";
149     private static final String TRACK_FRAME_TIME_KEY = "track_frame_time";
150     private static final String SHOW_NON_RECTANGULAR_CLIP_KEY = "show_non_rect_clip";
151     private static final String SHOW_HW_SCREEN_UPDATES_KEY = "show_hw_screen_udpates";
152     private static final String SHOW_HW_LAYERS_UPDATES_KEY = "show_hw_layers_udpates";
153     private static final String DEBUG_HW_OVERDRAW_KEY = "debug_hw_overdraw";
154     private static final String DEBUG_LAYOUT_KEY = "debug_layout";
155     private static final String FORCE_RTL_LAYOUT_KEY = "force_rtl_layout_all_locales";
156     private static final String WINDOW_ANIMATION_SCALE_KEY = "window_animation_scale";
157     private static final String TRANSITION_ANIMATION_SCALE_KEY = "transition_animation_scale";
158     private static final String ANIMATOR_DURATION_SCALE_KEY = "animator_duration_scale";
159     private static final String OVERLAY_DISPLAY_DEVICES_KEY = "overlay_display_devices";
160     private static final String DEBUG_DEBUGGING_CATEGORY_KEY = "debug_debugging_category";
161     private static final String SELECT_LOGD_SIZE_KEY = "select_logd_size";
162     private static final String SELECT_LOGD_SIZE_PROPERTY = "persist.logd.size";
163     private static final String SELECT_LOGD_TAG_PROPERTY = "persist.log.tag";
164     // Tricky, isLoggable only checks for first character, assumes silence
165     private static final String SELECT_LOGD_TAG_SILENCE = "Settings";
166     private static final String SELECT_LOGD_SNET_TAG_PROPERTY = "persist.log.tag.snet_event_log";
167     private static final String SELECT_LOGD_RUNTIME_SNET_TAG_PROPERTY = "log.tag.snet_event_log";
168     private static final String SELECT_LOGD_DEFAULT_SIZE_PROPERTY = "ro.logd.size";
169     private static final String SELECT_LOGD_DEFAULT_SIZE_VALUE = "262144";
170     private static final String SELECT_LOGD_SVELTE_DEFAULT_SIZE_VALUE = "65536";
171     // 32768 is merely a menu marker, 64K is our lowest log buffer size we replace it with.
172     private static final String SELECT_LOGD_MINIMUM_SIZE_VALUE = "65536";
173     private static final String SELECT_LOGD_OFF_SIZE_MARKER_VALUE = "32768";
174
175     private static final String WIFI_DISPLAY_CERTIFICATION_KEY = "wifi_display_certification";
176     private static final String WIFI_VERBOSE_LOGGING_KEY = "wifi_verbose_logging";
177     private static final String WIFI_AGGRESSIVE_HANDOVER_KEY = "wifi_aggressive_handover";
178     private static final String WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY = "wifi_allow_scan_with_traffic";
179     private static final String USB_CONFIGURATION_KEY = "select_usb_configuration";
180     private static final String MOBILE_DATA_ALWAYS_ON = "mobile_data_always_on";
181     private static final String KEY_COLOR_MODE = "color_mode";
182     private static final String FORCE_RESIZABLE_KEY = "force_resizable_activities";
183     private static final String COLOR_TEMPERATURE_KEY = "color_temperature";
184
185     private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY =
186                                     "bluetooth_disable_absolute_volume";
187     private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY =
188                                     "persist.bluetooth.disableabsvol";
189
190     private static final String INACTIVE_APPS_KEY = "inactive_apps";
191
192     private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY
193             = "immediately_destroy_activities";
194     private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit";
195
196     private static final String BACKGROUND_CHECK_KEY = "background_check";
197
198     private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs";
199
200     private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
201
202     private static final String TERMINAL_APP_PACKAGE = "com.android.terminal";
203
204     private static final String KEY_CONVERT_FBE = "convert_to_file_encryption";
205
206     private static final String OTA_DISABLE_AUTOMATIC_UPDATE_KEY = "ota_disable_automatic_update";
207
208     private static final String LOCATION_DOGFOOD_TOOLS_KEY = "location_dogfood_tools";
209
210     private static final int RESULT_DEBUG_APP = 1000;
211     private static final int RESULT_MOCK_LOCATION_APP = 1001;
212
213     private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
214     private static final String FLASH_LOCKED_PROP = "ro.boot.flash.locked";
215
216     private static final String SHORTCUT_MANAGER_RESET_KEY = "reset_shortcut_manager_throttling";
217
218     private static final int REQUEST_CODE_ENABLE_OEM_UNLOCK = 0;
219
220     private static final int[] MOCK_LOCATION_APP_OPS = new int[] {AppOpsManager.OP_MOCK_LOCATION};
221
222     private IWindowManager mWindowManager;
223     private IBackupManager mBackupManager;
224     private IWebViewUpdateService mWebViewUpdateService;
225     private DevicePolicyManager mDpm;
226     private UserManager mUm;
227     private WifiManager mWifiManager;
228     private PersistentDataBlockManager mOemUnlockManager;
229
230     private SwitchBar mSwitchBar;
231     private boolean mLastEnabledState;
232     private boolean mHaveDebugSettings;
233     private boolean mDontPokeProperties;
234
235     private SwitchPreference mEnableAdb;
236     private Preference mClearAdbKeys;
237     private SwitchPreference mEnableTerminal;
238     private Preference mBugreport;
239     private SwitchPreference mBugreportInPower;
240     private RestrictedSwitchPreference mKeepScreenOn;
241     private SwitchPreference mBtHciSnoopLog;
242     private SwitchPreference mEnableOemUnlock;
243     private SwitchPreference mDebugViewAttributes;
244     private SwitchPreference mForceAllowOnExternal;
245
246     private PreferenceScreen mPassword;
247     private String mDebugApp;
248     private Preference mDebugAppPref;
249
250     private String mMockLocationApp;
251     private Preference mMockLocationAppPref;
252     private Preference mLocationDogfoodTools;
253
254     private SwitchPreference mWaitForDebugger;
255     private SwitchPreference mVerifyAppsOverUsb;
256     private SwitchPreference mWifiDisplayCertification;
257     private SwitchPreference mWifiVerboseLogging;
258     private SwitchPreference mWifiAggressiveHandover;
259     private SwitchPreference mMobileDataAlwaysOn;
260     private SwitchPreference mBluetoothDisableAbsVolume;
261     private SwitchPreference mOtaDisableAutomaticUpdate;
262
263     private SwitchPreference mWifiAllowScansWithTraffic;
264     private SwitchPreference mStrictMode;
265     private SwitchPreference mPointerLocation;
266     private SwitchPreference mShowTouches;
267     private SwitchPreference mShowScreenUpdates;
268     private SwitchPreference mDisableOverlays;
269     private SwitchPreference mShowCpuUsage;
270     private SwitchPreference mForceHardwareUi;
271     private SwitchPreference mForceMsaa;
272     private SwitchPreference mShowHwScreenUpdates;
273     private SwitchPreference mShowHwLayersUpdates;
274     private SwitchPreference mDebugLayout;
275     private SwitchPreference mForceRtlLayout;
276     private ListPreference mDebugHwOverdraw;
277     private ListPreference mLogdSize;
278     private ListPreference mUsbConfiguration;
279     private ListPreference mTrackFrameTime;
280     private ListPreference mShowNonRectClip;
281     private ListPreference mWindowAnimationScale;
282     private ListPreference mTransitionAnimationScale;
283     private ListPreference mAnimatorDurationScale;
284     private ListPreference mOverlayDisplayDevices;
285
286     private SwitchPreference mWebViewMultiprocess;
287     private ListPreference mWebViewProvider;
288
289     private ListPreference mSimulateColorSpace;
290
291     private SwitchPreference mUSBAudio;
292     private SwitchPreference mImmediatelyDestroyActivities;
293
294     private ListPreference mAppProcessLimit;
295
296     private SwitchPreference mShowAllANRs;
297
298     private ColorModePreference mColorModePreference;
299
300     private SwitchPreference mForceResizable;
301
302     private SwitchPreference mColorTemperaturePreference;
303
304     private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>();
305
306     private final ArrayList<SwitchPreference> mResetSwitchPrefs
307             = new ArrayList<SwitchPreference>();
308
309     private final HashSet<Preference> mDisabledPrefs = new HashSet<Preference>();
310     // To track whether a confirmation dialog was clicked.
311     private boolean mDialogClicked;
312     private Dialog mEnableDialog;
313     private Dialog mAdbDialog;
314
315     private Dialog mAdbKeysDialog;
316     private boolean mUnavailable;
317
318     public DevelopmentSettings() {
319         super(UserManager.DISALLOW_DEBUGGING_FEATURES);
320     }
321
322     @Override
323     protected int getMetricsCategory() {
324         return MetricsEvent.DEVELOPMENT;
325     }
326
327     @Override
328     public void onCreate(Bundle icicle) {
329         super.onCreate(icicle);
330
331         mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
332         mBackupManager = IBackupManager.Stub.asInterface(
333                 ServiceManager.getService(Context.BACKUP_SERVICE));
334         mWebViewUpdateService  =
335             IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate"));
336         mOemUnlockManager = (PersistentDataBlockManager)getActivity()
337                 .getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
338
339         mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
340         mUm = (UserManager) getSystemService(Context.USER_SERVICE);
341
342         mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
343
344         setIfOnlyAvailableForAdmins(true);
345         if (isUiRestricted() || !Utils.isDeviceProvisioned(getActivity())) {
346             // Block access to developer options if the user is not the owner, if user policy
347             // restricts it, or if the device has not been provisioned
348             mUnavailable = true;
349             setPreferenceScreen(new PreferenceScreen(getPrefContext(), null));
350             return;
351         }
352
353         addPreferencesFromResource(R.xml.development_prefs);
354
355         final PreferenceGroup debugDebuggingCategory = (PreferenceGroup)
356                 findPreference(DEBUG_DEBUGGING_CATEGORY_KEY);
357         mEnableAdb = findAndInitSwitchPref(ENABLE_ADB);
358         mClearAdbKeys = findPreference(CLEAR_ADB_KEYS);
359         if (!SystemProperties.getBoolean("ro.adb.secure", false)) {
360             if (debugDebuggingCategory != null) {
361                 debugDebuggingCategory.removePreference(mClearAdbKeys);
362             }
363         }
364         mAllPrefs.add(mClearAdbKeys);
365         mEnableTerminal = findAndInitSwitchPref(ENABLE_TERMINAL);
366         if (!isPackageInstalled(getActivity(), TERMINAL_APP_PACKAGE)) {
367             debugDebuggingCategory.removePreference(mEnableTerminal);
368             mEnableTerminal = null;
369         }
370
371         mBugreport = findPreference(BUGREPORT);
372         mBugreportInPower = findAndInitSwitchPref(BUGREPORT_IN_POWER_KEY);
373         mKeepScreenOn = (RestrictedSwitchPreference) findAndInitSwitchPref(KEEP_SCREEN_ON);
374         mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG);
375         mEnableOemUnlock = findAndInitSwitchPref(ENABLE_OEM_UNLOCK);
376         if (!showEnableOemUnlockPreference()) {
377             removePreference(mEnableOemUnlock);
378             mEnableOemUnlock = null;
379         }
380
381         mDebugViewAttributes = findAndInitSwitchPref(DEBUG_VIEW_ATTRIBUTES);
382         mForceAllowOnExternal = findAndInitSwitchPref(FORCE_ALLOW_ON_EXTERNAL_KEY);
383         mPassword = (PreferenceScreen) findPreference(LOCAL_BACKUP_PASSWORD);
384         mAllPrefs.add(mPassword);
385
386         if (!mUm.isAdminUser()) {
387             disableForUser(mEnableAdb);
388             disableForUser(mClearAdbKeys);
389             disableForUser(mEnableTerminal);
390             disableForUser(mPassword);
391         }
392
393         mDebugAppPref = findPreference(DEBUG_APP_KEY);
394         mAllPrefs.add(mDebugAppPref);
395         mWaitForDebugger = findAndInitSwitchPref(WAIT_FOR_DEBUGGER_KEY);
396
397         mMockLocationAppPref = findPreference(MOCK_LOCATION_APP_KEY);
398         mAllPrefs.add(mMockLocationAppPref);
399
400         mLocationDogfoodTools = findPreference(LOCATION_DOGFOOD_TOOLS_KEY);
401         mAllPrefs.add(mLocationDogfoodTools);
402
403         mVerifyAppsOverUsb = findAndInitSwitchPref(VERIFY_APPS_OVER_USB_KEY);
404         if (!showVerifierSetting()) {
405             if (debugDebuggingCategory != null) {
406                 debugDebuggingCategory.removePreference(mVerifyAppsOverUsb);
407             } else {
408                 mVerifyAppsOverUsb.setEnabled(false);
409             }
410         }
411         mStrictMode = findAndInitSwitchPref(STRICT_MODE_KEY);
412         mPointerLocation = findAndInitSwitchPref(POINTER_LOCATION_KEY);
413         mShowTouches = findAndInitSwitchPref(SHOW_TOUCHES_KEY);
414         mShowScreenUpdates = findAndInitSwitchPref(SHOW_SCREEN_UPDATES_KEY);
415         mDisableOverlays = findAndInitSwitchPref(DISABLE_OVERLAYS_KEY);
416         mShowCpuUsage = findAndInitSwitchPref(SHOW_CPU_USAGE_KEY);
417         mForceHardwareUi = findAndInitSwitchPref(FORCE_HARDWARE_UI_KEY);
418         mForceMsaa = findAndInitSwitchPref(FORCE_MSAA_KEY);
419         mTrackFrameTime = addListPreference(TRACK_FRAME_TIME_KEY);
420         mShowNonRectClip = addListPreference(SHOW_NON_RECTANGULAR_CLIP_KEY);
421         mShowHwScreenUpdates = findAndInitSwitchPref(SHOW_HW_SCREEN_UPDATES_KEY);
422         mShowHwLayersUpdates = findAndInitSwitchPref(SHOW_HW_LAYERS_UPDATES_KEY);
423         mDebugLayout = findAndInitSwitchPref(DEBUG_LAYOUT_KEY);
424         mForceRtlLayout = findAndInitSwitchPref(FORCE_RTL_LAYOUT_KEY);
425         mDebugHwOverdraw = addListPreference(DEBUG_HW_OVERDRAW_KEY);
426         mWifiDisplayCertification = findAndInitSwitchPref(WIFI_DISPLAY_CERTIFICATION_KEY);
427         mWifiVerboseLogging = findAndInitSwitchPref(WIFI_VERBOSE_LOGGING_KEY);
428         mWifiAggressiveHandover = findAndInitSwitchPref(WIFI_AGGRESSIVE_HANDOVER_KEY);
429         mWifiAllowScansWithTraffic = findAndInitSwitchPref(WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY);
430         mMobileDataAlwaysOn = findAndInitSwitchPref(MOBILE_DATA_ALWAYS_ON);
431         mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY);
432         mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY);
433         mWebViewProvider = addListPreference(WEBVIEW_PROVIDER_KEY);
434         mWebViewMultiprocess = findAndInitSwitchPref(WEBVIEW_MULTIPROCESS_KEY);
435         mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY);
436
437         mWindowAnimationScale = addListPreference(WINDOW_ANIMATION_SCALE_KEY);
438         mTransitionAnimationScale = addListPreference(TRANSITION_ANIMATION_SCALE_KEY);
439         mAnimatorDurationScale = addListPreference(ANIMATOR_DURATION_SCALE_KEY);
440         mOverlayDisplayDevices = addListPreference(OVERLAY_DISPLAY_DEVICES_KEY);
441         mSimulateColorSpace = addListPreference(SIMULATE_COLOR_SPACE);
442         mUSBAudio = findAndInitSwitchPref(USB_AUDIO_KEY);
443         mForceResizable = findAndInitSwitchPref(FORCE_RESIZABLE_KEY);
444
445         mImmediatelyDestroyActivities = (SwitchPreference) findPreference(
446                 IMMEDIATELY_DESTROY_ACTIVITIES_KEY);
447         mAllPrefs.add(mImmediatelyDestroyActivities);
448         mResetSwitchPrefs.add(mImmediatelyDestroyActivities);
449
450         mAppProcessLimit = addListPreference(APP_PROCESS_LIMIT_KEY);
451
452         mShowAllANRs = (SwitchPreference) findPreference(
453                 SHOW_ALL_ANRS_KEY);
454         mAllPrefs.add(mShowAllANRs);
455         mResetSwitchPrefs.add(mShowAllANRs);
456
457         Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY);
458         if (hdcpChecking != null) {
459             mAllPrefs.add(hdcpChecking);
460             removePreferenceForProduction(hdcpChecking);
461         }
462
463         PreferenceScreen convertFbePreference =
464             (PreferenceScreen) findPreference(KEY_CONVERT_FBE);
465
466         try {
467             IBinder service = ServiceManager.getService("mount");
468             IMountService mountService = IMountService.Stub.asInterface(service);
469             if (!mountService.isConvertibleToFBE()) {
470                 removePreference(KEY_CONVERT_FBE);
471             } else if ("file".equals(SystemProperties.get("ro.crypto.type", "none"))) {
472                 convertFbePreference.setEnabled(false);
473                 convertFbePreference.setSummary(getResources()
474                                    .getString(R.string.convert_to_file_encryption_done));
475             }
476         } catch(RemoteException e) {
477             removePreference(KEY_CONVERT_FBE);
478         }
479
480         mOtaDisableAutomaticUpdate = findAndInitSwitchPref(OTA_DISABLE_AUTOMATIC_UPDATE_KEY);
481
482         mColorModePreference = (ColorModePreference) findPreference(KEY_COLOR_MODE);
483         mColorModePreference.updateCurrentAndSupported();
484         if (mColorModePreference.getTransformsCount() < 2) {
485             removePreference(KEY_COLOR_MODE);
486             mColorModePreference = null;
487         }
488         updateWebViewProviderOptions();
489
490         mColorTemperaturePreference = (SwitchPreference) findPreference(COLOR_TEMPERATURE_KEY);
491         if (getResources().getBoolean(R.bool.config_enableColorTemperature)) {
492             mAllPrefs.add(mColorTemperaturePreference);
493             mResetSwitchPrefs.add(mColorTemperaturePreference);
494         } else {
495             removePreference(COLOR_TEMPERATURE_KEY);
496             mColorTemperaturePreference = null;
497         }
498     }
499
500     private ListPreference addListPreference(String prefKey) {
501         ListPreference pref = (ListPreference) findPreference(prefKey);
502         mAllPrefs.add(pref);
503         pref.setOnPreferenceChangeListener(this);
504         return pref;
505     }
506
507     private void disableForUser(Preference pref) {
508         if (pref != null) {
509             pref.setEnabled(false);
510             mDisabledPrefs.add(pref);
511         }
512     }
513
514     private SwitchPreference findAndInitSwitchPref(String key) {
515         SwitchPreference pref = (SwitchPreference) findPreference(key);
516         if (pref == null) {
517             throw new IllegalArgumentException("Cannot find preference with key = " + key);
518         }
519         mAllPrefs.add(pref);
520         mResetSwitchPrefs.add(pref);
521         return pref;
522     }
523
524     @Override
525     public void onActivityCreated(Bundle savedInstanceState) {
526         super.onActivityCreated(savedInstanceState);
527
528         final SettingsActivity activity = (SettingsActivity) getActivity();
529
530         mSwitchBar = activity.getSwitchBar();
531        if (mUnavailable) {
532             mSwitchBar.setEnabled(false);
533             return;
534         }
535
536         mSwitchBar.addOnSwitchChangeListener(this);
537     }
538
539     private boolean removePreferenceForProduction(Preference preference) {
540         if ("user".equals(Build.TYPE)) {
541             removePreference(preference);
542             return true;
543         }
544         return false;
545     }
546
547     private void removePreference(Preference preference) {
548         getPreferenceScreen().removePreference(preference);
549         mAllPrefs.remove(preference);
550         mResetSwitchPrefs.remove(preference);
551     }
552
553     private void setPrefsEnabledState(boolean enabled) {
554         for (int i = 0; i < mAllPrefs.size(); i++) {
555             Preference pref = mAllPrefs.get(i);
556             pref.setEnabled(enabled && !mDisabledPrefs.contains(pref));
557         }
558         updateAllOptions();
559     }
560
561     @Override
562     public void onResume() {
563         super.onResume();
564
565         if (mUnavailable) {
566             // Show error message
567             if (!isUiRestrictedByOnlyAdmin()) {
568                 getEmptyTextView().setText(R.string.development_settings_not_available);
569             }
570             getPreferenceScreen().removeAll();
571             return;
572         }
573
574         // A DeviceAdmin has specified a maximum time until the device
575         // will lock...  in this case we can't allow the user to turn
576         // on "stay awake when plugged in" because that would defeat the
577         // restriction.
578         final EnforcedAdmin admin = RestrictedLockUtils.checkIfMaximumTimeToLockIsSet(
579                 getActivity());
580         mKeepScreenOn.setDisabledByAdmin(admin);
581         if (admin == null) {
582             mDisabledPrefs.remove(mKeepScreenOn);
583         } else {
584             mDisabledPrefs.add(mKeepScreenOn);
585         }
586
587         final ContentResolver cr = getActivity().getContentResolver();
588         mLastEnabledState = Settings.Global.getInt(cr,
589                 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
590         mSwitchBar.setChecked(mLastEnabledState);
591         setPrefsEnabledState(mLastEnabledState);
592
593         if (mHaveDebugSettings && !mLastEnabledState) {
594             // Overall debugging is disabled, but there are some debug
595             // settings that are enabled.  This is an invalid state.  Switch
596             // to debug settings being enabled, so the user knows there is
597             // stuff enabled and can turn it all off if they want.
598             Settings.Global.putInt(getActivity().getContentResolver(),
599                     Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
600             mLastEnabledState = true;
601             mSwitchBar.setChecked(mLastEnabledState);
602             setPrefsEnabledState(mLastEnabledState);
603         }
604         mSwitchBar.show();
605
606         if (mColorModePreference != null) {
607             mColorModePreference.startListening();
608             mColorModePreference.updateCurrentAndSupported();
609         }
610     }
611
612     @Override
613     public void onPause() {
614         super.onPause();
615         if (mColorModePreference != null) {
616             mColorModePreference.stopListening();
617         }
618     }
619
620     @Override
621     public View onCreateView(LayoutInflater inflater, ViewGroup container,
622             Bundle savedInstanceState) {
623         IntentFilter filter = new IntentFilter();
624         filter.addAction(UsbManager.ACTION_USB_STATE);
625         if (getActivity().registerReceiver(mUsbReceiver, filter) == null) {
626             updateUsbConfigurationValues();
627         }
628         return super.onCreateView(inflater, container, savedInstanceState);
629     }
630
631     @Override
632     public void onDestroyView() {
633         super.onDestroyView();
634
635         if (mUnavailable) {
636             return;
637         }
638         mSwitchBar.removeOnSwitchChangeListener(this);
639         mSwitchBar.hide();
640         getActivity().unregisterReceiver(mUsbReceiver);
641     }
642
643     void updateSwitchPreference(SwitchPreference switchPreference, boolean value) {
644         switchPreference.setChecked(value);
645         mHaveDebugSettings |= value;
646     }
647
648     private void updateAllOptions() {
649         final Context context = getActivity();
650         final ContentResolver cr = context.getContentResolver();
651         mHaveDebugSettings = false;
652         updateSwitchPreference(mEnableAdb, Settings.Global.getInt(cr,
653                 Settings.Global.ADB_ENABLED, 0) != 0);
654         if (mEnableTerminal != null) {
655             updateSwitchPreference(mEnableTerminal,
656                     context.getPackageManager().getApplicationEnabledSetting(TERMINAL_APP_PACKAGE)
657                             == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
658         }
659         updateSwitchPreference(mBugreportInPower, Settings.Secure.getInt(cr,
660                 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0);
661         updateSwitchPreference(mKeepScreenOn, Settings.Global.getInt(cr,
662                 Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
663         updateSwitchPreference(mBtHciSnoopLog, Settings.Secure.getInt(cr,
664                 Settings.Secure.BLUETOOTH_HCI_LOG, 0) != 0);
665         if (mEnableOemUnlock != null) {
666             updateSwitchPreference(mEnableOemUnlock, Utils.isOemUnlockEnabled(getActivity()));
667         }
668         updateSwitchPreference(mDebugViewAttributes, Settings.Global.getInt(cr,
669                 Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0);
670         updateSwitchPreference(mForceAllowOnExternal, Settings.Global.getInt(cr,
671                 Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0);
672         updateHdcpValues();
673         updatePasswordSummary();
674         updateDebuggerOptions();
675         updateMockLocation();
676         updateStrictModeVisualOptions();
677         updatePointerLocationOptions();
678         updateShowTouchesOptions();
679         updateFlingerOptions();
680         updateCpuUsageOptions();
681         updateHardwareUiOptions();
682         updateMsaaOptions();
683         updateTrackFrameTimeOptions();
684         updateShowNonRectClipOptions();
685         updateShowHwScreenUpdatesOptions();
686         updateShowHwLayersUpdatesOptions();
687         updateDebugHwOverdrawOptions();
688         updateDebugLayoutOptions();
689         updateAnimationScaleOptions();
690         updateOverlayDisplayDevicesOptions();
691         updateImmediatelyDestroyActivitiesOptions();
692         updateAppProcessLimitOptions();
693         updateShowAllANRsOptions();
694         updateVerifyAppsOverUsbOptions();
695         updateOtaDisableAutomaticUpdateOptions();
696         updateBugreportOptions();
697         updateForceRtlOptions();
698         updateLogdSizeValues();
699         updateWifiDisplayCertificationOptions();
700         updateWifiVerboseLoggingOptions();
701         updateWifiAggressiveHandoverOptions();
702         updateWifiAllowScansWithTrafficOptions();
703         updateMobileDataAlwaysOnOptions();
704         updateSimulateColorSpace();
705         updateUSBAudioOptions();
706         updateForceResizableOptions();
707         updateWebViewMultiprocessOptions();
708         updateWebViewProviderOptions();
709         updateOemUnlockOptions();
710         if (mColorTemperaturePreference != null) {
711             updateColorTemperature();
712         }
713         updateBluetoothDisableAbsVolumeOptions();
714     }
715
716     private void resetDangerousOptions() {
717         mDontPokeProperties = true;
718         for (int i=0; i< mResetSwitchPrefs.size(); i++) {
719             SwitchPreference cb = mResetSwitchPrefs.get(i);
720             if (cb.isChecked()) {
721                 cb.setChecked(false);
722                 onPreferenceTreeClick(cb);
723             }
724         }
725         resetDebuggerOptions();
726         writeLogdSizeOption(null);
727         writeAnimationScaleOption(0, mWindowAnimationScale, null);
728         writeAnimationScaleOption(1, mTransitionAnimationScale, null);
729         writeAnimationScaleOption(2, mAnimatorDurationScale, null);
730         // Only poke the color space setting if we control it.
731         if (usingDevelopmentColorSpace()) {
732             writeSimulateColorSpace(-1);
733         }
734         writeOverlayDisplayDevicesOptions(null);
735         writeAppProcessLimitOptions(null);
736         mHaveDebugSettings = false;
737         updateAllOptions();
738         mDontPokeProperties = false;
739         pokeSystemProperties();
740     }
741
742     private void updateWebViewProviderOptions() {
743         try {
744             WebViewProviderInfo[] providers = mWebViewUpdateService.getValidWebViewPackages();
745             if (providers == null) {
746                 Log.e(TAG, "No WebView providers available");
747                 return;
748             }
749             ArrayList<String> options = new ArrayList<String>();
750             ArrayList<String> values = new ArrayList<String>();
751             for(int n = 0; n < providers.length; n++) {
752                 if (isPackageEnabled(providers[n].packageName)) {
753                     options.add(providers[n].description);
754                     values.add(providers[n].packageName);
755                 }
756             }
757             mWebViewProvider.setEntries(options.toArray(new String[options.size()]));
758             mWebViewProvider.setEntryValues(values.toArray(new String[values.size()]));
759
760             String value = mWebViewUpdateService.getCurrentWebViewPackageName();
761             if (value == null) {
762                 value = "";
763             }
764
765             for (int i = 0; i < values.size(); i++) {
766                 if (value.contentEquals(values.get(i))) {
767                     mWebViewProvider.setValueIndex(i);
768                     return;
769                 }
770             }
771         } catch(RemoteException e) {
772         }
773     }
774
775     private void updateWebViewMultiprocessOptions() {
776         updateSwitchPreference(mWebViewMultiprocess,
777                 Settings.Global.getInt(getActivity().getContentResolver(),
778                         Settings.Global.WEBVIEW_MULTIPROCESS, 0) != 0);
779     }
780
781     private void writeWebViewMultiprocessOptions() {
782         boolean value = mWebViewMultiprocess.isChecked();
783         Settings.Global.putInt(getActivity().getContentResolver(),
784                 Settings.Global.WEBVIEW_MULTIPROCESS, value ? 1 : 0);
785
786         try {
787             String wv_package = mWebViewUpdateService.getCurrentWebViewPackageName();
788             ActivityManagerNative.getDefault().killPackageDependents(
789                     wv_package, UserHandle.USER_ALL);
790         } catch(RemoteException e) {
791         }
792     }
793
794     private void updateHdcpValues() {
795         ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
796         if (hdcpChecking != null) {
797             String currentValue = SystemProperties.get(HDCP_CHECKING_PROPERTY);
798             String[] values = getResources().getStringArray(R.array.hdcp_checking_values);
799             String[] summaries = getResources().getStringArray(R.array.hdcp_checking_summaries);
800             int index = 1; // Defaults to drm-only. Needs to match with R.array.hdcp_checking_values
801             for (int i = 0; i < values.length; i++) {
802                 if (currentValue.equals(values[i])) {
803                     index = i;
804                     break;
805                 }
806             }
807             hdcpChecking.setValue(values[index]);
808             hdcpChecking.setSummary(summaries[index]);
809             hdcpChecking.setOnPreferenceChangeListener(this);
810         }
811     }
812
813     private void updatePasswordSummary() {
814         try {
815             if (mBackupManager.hasBackupPassword()) {
816                 mPassword.setSummary(R.string.local_backup_password_summary_change);
817             } else {
818                 mPassword.setSummary(R.string.local_backup_password_summary_none);
819             }
820         } catch (RemoteException e) {
821             // Not much we can do here
822         }
823     }
824
825     private void writeBtHciSnoopLogOptions() {
826         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
827         adapter.configHciSnoopLog(mBtHciSnoopLog.isChecked());
828         Settings.Secure.putInt(getActivity().getContentResolver(),
829                 Settings.Secure.BLUETOOTH_HCI_LOG,
830                 mBtHciSnoopLog.isChecked() ? 1 : 0);
831     }
832
833     private boolean writeWebViewProviderOptions(Object newValue) {
834         try {
835             String updatedProvider = mWebViewUpdateService.changeProviderAndSetting(
836                     newValue == null ? "" : newValue.toString());
837             updateWebViewProviderOptions();
838             return newValue != null && newValue.equals(updatedProvider);
839         } catch(RemoteException e) {
840         }
841         return false;
842     }
843
844     private void writeDebuggerOptions() {
845         try {
846             ActivityManagerNative.getDefault().setDebugApp(
847                 mDebugApp, mWaitForDebugger.isChecked(), true);
848         } catch (RemoteException ex) {
849         }
850     }
851
852     private void writeMockLocation() {
853         AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
854
855         // Disable the app op of the previous mock location app if such.
856         List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
857         if (packageOps != null) {
858             // Should be one but in case we are in a bad state due to use of command line tools.
859             for (PackageOps packageOp : packageOps) {
860                 if (packageOp.getOps().get(0).getMode() != AppOpsManager.MODE_ERRORED) {
861                     String oldMockLocationApp = packageOp.getPackageName();
862                     try {
863                         ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
864                                 oldMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
865                         appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid,
866                                 oldMockLocationApp, AppOpsManager.MODE_ERRORED);
867                     } catch (NameNotFoundException e) {
868                         /* ignore */
869                     }
870                 }
871             }
872         }
873
874         // Enable the app op of the new mock location app if such.
875         if (!TextUtils.isEmpty(mMockLocationApp)) {
876             try {
877                 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
878                         mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
879                 appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid,
880                         mMockLocationApp, AppOpsManager.MODE_ALLOWED);
881             } catch (NameNotFoundException e) {
882                 /* ignore */
883             }
884         }
885     }
886
887     private static void resetDebuggerOptions() {
888         try {
889             ActivityManagerNative.getDefault().setDebugApp(
890                     null, false, true);
891         } catch (RemoteException ex) {
892         }
893     }
894
895     private void updateDebuggerOptions() {
896         mDebugApp = Settings.Global.getString(
897                 getActivity().getContentResolver(), Settings.Global.DEBUG_APP);
898         updateSwitchPreference(mWaitForDebugger, Settings.Global.getInt(
899                 getActivity().getContentResolver(), Settings.Global.WAIT_FOR_DEBUGGER, 0) != 0);
900         if (mDebugApp != null && mDebugApp.length() > 0) {
901             String label;
902             try {
903                 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mDebugApp,
904                         PackageManager.GET_DISABLED_COMPONENTS);
905                 CharSequence lab = getActivity().getPackageManager().getApplicationLabel(ai);
906                 label = lab != null ? lab.toString() : mDebugApp;
907             } catch (PackageManager.NameNotFoundException e) {
908                 label = mDebugApp;
909             }
910             mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_set, label));
911             mWaitForDebugger.setEnabled(true);
912             mHaveDebugSettings = true;
913         } else {
914             mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_not_set));
915             mWaitForDebugger.setEnabled(false);
916         }
917     }
918
919     private void updateMockLocation() {
920         AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
921
922         List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
923         if (packageOps != null) {
924             for (PackageOps packageOp : packageOps) {
925                 if (packageOp.getOps().get(0).getMode() == AppOpsManager.MODE_ALLOWED) {
926                     mMockLocationApp = packageOps.get(0).getPackageName();
927                     break;
928                 }
929             }
930         }
931
932         if (!TextUtils.isEmpty(mMockLocationApp)) {
933             String label = mMockLocationApp;
934             try {
935                 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
936                         mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
937                 CharSequence appLabel = getPackageManager().getApplicationLabel(ai);
938                 if (appLabel != null) {
939                     label = appLabel.toString();
940                 }
941             } catch (PackageManager.NameNotFoundException e) {
942                 /* ignore */
943             }
944
945             mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_set, label));
946             mHaveDebugSettings = true;
947         } else {
948             mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_not_set));
949         }
950     }
951
952     private void updateVerifyAppsOverUsbOptions() {
953         updateSwitchPreference(mVerifyAppsOverUsb, Settings.Global.getInt(getActivity().getContentResolver(),
954                 Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0);
955         mVerifyAppsOverUsb.setEnabled(enableVerifierSetting());
956     }
957
958     private void writeVerifyAppsOverUsbOptions() {
959         Settings.Global.putInt(getActivity().getContentResolver(),
960                 Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB,
961                 mVerifyAppsOverUsb.isChecked() ? 1 : 0);
962     }
963
964     private void updateOtaDisableAutomaticUpdateOptions() {
965         // We use the "disabled status" in code, but show the opposite text
966         // "Automatic system updates" on screen. So a value 0 indicates the
967         // automatic update is enabled.
968         updateSwitchPreference(mOtaDisableAutomaticUpdate, Settings.Global.getInt(
969                 getActivity().getContentResolver(),
970                 Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, 0) != 1);
971     }
972
973     private void writeOtaDisableAutomaticUpdateOptions() {
974         // We use the "disabled status" in code, but show the opposite text
975         // "Automatic system updates" on screen. So a value 0 indicates the
976         // automatic update is enabled.
977         Settings.Global.putInt(getActivity().getContentResolver(),
978                 Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE,
979                 mOtaDisableAutomaticUpdate.isChecked() ? 0 : 1);
980     }
981
982     private boolean enableVerifierSetting() {
983         final ContentResolver cr = getActivity().getContentResolver();
984         if (Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, 0) == 0) {
985             return false;
986         }
987         if (Settings.Global.getInt(cr, Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) == 0) {
988             return false;
989         } else {
990             final PackageManager pm = getActivity().getPackageManager();
991             final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
992             verification.setType(PACKAGE_MIME_TYPE);
993             verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
994             final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(verification, 0);
995             if (receivers.size() == 0) {
996                 return false;
997             }
998         }
999         return true;
1000     }
1001
1002     private boolean showVerifierSetting() {
1003         return Settings.Global.getInt(getActivity().getContentResolver(),
1004                 Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0;
1005     }
1006
1007     private static boolean showEnableOemUnlockPreference() {
1008         return !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("");
1009     }
1010
1011     private boolean enableOemUnlockPreference() {
1012         int flashLockState = PersistentDataBlockManager.FLASH_LOCK_UNKNOWN;
1013         if (mOemUnlockManager != null) {
1014             flashLockState = mOemUnlockManager.getFlashLockState();
1015         }
1016
1017         return flashLockState != PersistentDataBlockManager.FLASH_LOCK_UNLOCKED;
1018     }
1019
1020     private void updateOemUnlockOptions() {
1021         if (mEnableOemUnlock != null) {
1022             mEnableOemUnlock.setEnabled(enableOemUnlockPreference());
1023         }
1024     }
1025
1026     private void updateBugreportOptions() {
1027         mBugreport.setEnabled(true);
1028         mBugreportInPower.setEnabled(true);
1029         setBugreportStorageProviderStatus();
1030     }
1031
1032     private void setBugreportStorageProviderStatus() {
1033         final ComponentName componentName = new ComponentName("com.android.shell",
1034                 "com.android.shell.BugreportStorageProvider");
1035         final boolean enabled = mBugreportInPower.isChecked();
1036         getPackageManager().setComponentEnabledSetting(componentName,
1037                 enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1038                         : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
1039                 0);
1040     }
1041
1042     // Returns the current state of the system property that controls
1043     // strictmode flashes.  One of:
1044     //    0: not explicitly set one way or another
1045     //    1: on
1046     //    2: off
1047     private static int currentStrictModeActiveIndex() {
1048         if (TextUtils.isEmpty(SystemProperties.get(StrictMode.VISUAL_PROPERTY))) {
1049             return 0;
1050         }
1051         boolean enabled = SystemProperties.getBoolean(StrictMode.VISUAL_PROPERTY, false);
1052         return enabled ? 1 : 2;
1053     }
1054
1055     private void writeStrictModeVisualOptions() {
1056         try {
1057             mWindowManager.setStrictModeVisualIndicatorPreference(mStrictMode.isChecked()
1058                     ? "1" : "");
1059         } catch (RemoteException e) {
1060         }
1061     }
1062
1063     private void updateStrictModeVisualOptions() {
1064         updateSwitchPreference(mStrictMode, currentStrictModeActiveIndex() == 1);
1065     }
1066
1067     private void writePointerLocationOptions() {
1068         Settings.System.putInt(getActivity().getContentResolver(),
1069                 Settings.System.POINTER_LOCATION, mPointerLocation.isChecked() ? 1 : 0);
1070     }
1071
1072     private void updatePointerLocationOptions() {
1073         updateSwitchPreference(mPointerLocation,
1074                 Settings.System.getInt(getActivity().getContentResolver(),
1075                         Settings.System.POINTER_LOCATION, 0) != 0);
1076     }
1077
1078     private void writeShowTouchesOptions() {
1079         Settings.System.putInt(getActivity().getContentResolver(),
1080                 Settings.System.SHOW_TOUCHES, mShowTouches.isChecked() ? 1 : 0);
1081     }
1082
1083     private void updateShowTouchesOptions() {
1084         updateSwitchPreference(mShowTouches,
1085                 Settings.System.getInt(getActivity().getContentResolver(),
1086                         Settings.System.SHOW_TOUCHES, 0) != 0);
1087     }
1088
1089     private void updateFlingerOptions() {
1090         // magic communication with surface flinger.
1091         try {
1092             IBinder flinger = ServiceManager.getService("SurfaceFlinger");
1093             if (flinger != null) {
1094                 Parcel data = Parcel.obtain();
1095                 Parcel reply = Parcel.obtain();
1096                 data.writeInterfaceToken("android.ui.ISurfaceComposer");
1097                 flinger.transact(1010, data, reply, 0);
1098                 @SuppressWarnings("unused")
1099                 int showCpu = reply.readInt();
1100                 @SuppressWarnings("unused")
1101                 int enableGL = reply.readInt();
1102                 int showUpdates = reply.readInt();
1103                 updateSwitchPreference(mShowScreenUpdates, showUpdates != 0);
1104                 @SuppressWarnings("unused")
1105                 int showBackground = reply.readInt();
1106                 int disableOverlays = reply.readInt();
1107                 updateSwitchPreference(mDisableOverlays, disableOverlays != 0);
1108                 reply.recycle();
1109                 data.recycle();
1110             }
1111         } catch (RemoteException ex) {
1112         }
1113     }
1114
1115     private void writeShowUpdatesOption() {
1116         try {
1117             IBinder flinger = ServiceManager.getService("SurfaceFlinger");
1118             if (flinger != null) {
1119                 Parcel data = Parcel.obtain();
1120                 data.writeInterfaceToken("android.ui.ISurfaceComposer");
1121                 final int showUpdates = mShowScreenUpdates.isChecked() ? 1 : 0;
1122                 data.writeInt(showUpdates);
1123                 flinger.transact(1002, data, null, 0);
1124                 data.recycle();
1125
1126                 updateFlingerOptions();
1127             }
1128         } catch (RemoteException ex) {
1129         }
1130     }
1131
1132     private void writeDisableOverlaysOption() {
1133         try {
1134             IBinder flinger = ServiceManager.getService("SurfaceFlinger");
1135             if (flinger != null) {
1136                 Parcel data = Parcel.obtain();
1137                 data.writeInterfaceToken("android.ui.ISurfaceComposer");
1138                 final int disableOverlays = mDisableOverlays.isChecked() ? 1 : 0;
1139                 data.writeInt(disableOverlays);
1140                 flinger.transact(1008, data, null, 0);
1141                 data.recycle();
1142
1143                 updateFlingerOptions();
1144             }
1145         } catch (RemoteException ex) {
1146         }
1147     }
1148
1149     private void updateHardwareUiOptions() {
1150         updateSwitchPreference(mForceHardwareUi,
1151                 SystemProperties.getBoolean(HARDWARE_UI_PROPERTY, false));
1152     }
1153
1154     private void writeHardwareUiOptions() {
1155         SystemProperties.set(HARDWARE_UI_PROPERTY, mForceHardwareUi.isChecked() ? "true" : "false");
1156         pokeSystemProperties();
1157     }
1158
1159     private void updateMsaaOptions() {
1160         updateSwitchPreference(mForceMsaa, SystemProperties.getBoolean(MSAA_PROPERTY, false));
1161     }
1162
1163     private void writeMsaaOptions() {
1164         SystemProperties.set(MSAA_PROPERTY, mForceMsaa.isChecked() ? "true" : "false");
1165         pokeSystemProperties();
1166     }
1167
1168     private void updateTrackFrameTimeOptions() {
1169         String value = SystemProperties.get(ThreadedRenderer.PROFILE_PROPERTY);
1170         if (value == null) {
1171             value = "";
1172         }
1173
1174         CharSequence[] values = mTrackFrameTime.getEntryValues();
1175         for (int i = 0; i < values.length; i++) {
1176             if (value.contentEquals(values[i])) {
1177                 mTrackFrameTime.setValueIndex(i);
1178                 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[i]);
1179                 return;
1180             }
1181         }
1182         mTrackFrameTime.setValueIndex(0);
1183         mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[0]);
1184     }
1185
1186     private void writeTrackFrameTimeOptions(Object newValue) {
1187         SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY,
1188                 newValue == null ? "" : newValue.toString());
1189         pokeSystemProperties();
1190         updateTrackFrameTimeOptions();
1191     }
1192
1193     private void updateShowNonRectClipOptions() {
1194         String value = SystemProperties.get(
1195                 ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY);
1196         if (value == null) {
1197             value = "hide";
1198         }
1199
1200         CharSequence[] values = mShowNonRectClip.getEntryValues();
1201         for (int i = 0; i < values.length; i++) {
1202             if (value.contentEquals(values[i])) {
1203                 mShowNonRectClip.setValueIndex(i);
1204                 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[i]);
1205                 return;
1206             }
1207         }
1208         mShowNonRectClip.setValueIndex(0);
1209         mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[0]);
1210     }
1211
1212     private void writeShowNonRectClipOptions(Object newValue) {
1213         SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY,
1214                 newValue == null ? "" : newValue.toString());
1215         pokeSystemProperties();
1216         updateShowNonRectClipOptions();
1217     }
1218
1219     private void updateShowHwScreenUpdatesOptions() {
1220         updateSwitchPreference(mShowHwScreenUpdates,
1221                 SystemProperties.getBoolean(ThreadedRenderer.DEBUG_DIRTY_REGIONS_PROPERTY, false));
1222     }
1223
1224     private void writeShowHwScreenUpdatesOptions() {
1225         SystemProperties.set(ThreadedRenderer.DEBUG_DIRTY_REGIONS_PROPERTY,
1226                 mShowHwScreenUpdates.isChecked() ? "true" : null);
1227         pokeSystemProperties();
1228     }
1229
1230     private void updateShowHwLayersUpdatesOptions() {
1231         updateSwitchPreference(mShowHwLayersUpdates, SystemProperties.getBoolean(
1232                 ThreadedRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY, false));
1233     }
1234
1235     private void writeShowHwLayersUpdatesOptions() {
1236         SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY,
1237                 mShowHwLayersUpdates.isChecked() ? "true" : null);
1238         pokeSystemProperties();
1239     }
1240
1241     private void updateDebugHwOverdrawOptions() {
1242         String value = SystemProperties.get(ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY);
1243         if (value == null) {
1244             value = "";
1245         }
1246
1247         CharSequence[] values = mDebugHwOverdraw.getEntryValues();
1248         for (int i = 0; i < values.length; i++) {
1249             if (value.contentEquals(values[i])) {
1250                 mDebugHwOverdraw.setValueIndex(i);
1251                 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[i]);
1252                 return;
1253             }
1254         }
1255         mDebugHwOverdraw.setValueIndex(0);
1256         mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[0]);
1257     }
1258
1259     private void writeDebugHwOverdrawOptions(Object newValue) {
1260         SystemProperties.set(ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY,
1261                 newValue == null ? "" : newValue.toString());
1262         pokeSystemProperties();
1263         updateDebugHwOverdrawOptions();
1264     }
1265
1266     private void updateDebugLayoutOptions() {
1267         updateSwitchPreference(mDebugLayout,
1268                 SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false));
1269     }
1270
1271     private void writeDebugLayoutOptions() {
1272         SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY,
1273                 mDebugLayout.isChecked() ? "true" : "false");
1274         pokeSystemProperties();
1275     }
1276
1277     private void updateSimulateColorSpace() {
1278         final ContentResolver cr = getContentResolver();
1279         final boolean enabled = Settings.Secure.getInt(
1280                 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0;
1281         if (enabled) {
1282             final String mode = Integer.toString(Settings.Secure.getInt(
1283                     cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
1284                     AccessibilityManager.DALTONIZER_DISABLED));
1285             mSimulateColorSpace.setValue(mode);
1286             final int index = mSimulateColorSpace.findIndexOfValue(mode);
1287             if (index < 0) {
1288                 // We're using a mode controlled by accessibility preferences.
1289                 mSimulateColorSpace.setSummary(getString(R.string.daltonizer_type_overridden,
1290                         getString(R.string.accessibility_display_daltonizer_preference_title)));
1291             } else {
1292                 mSimulateColorSpace.setSummary("%s");
1293             }
1294         } else {
1295             mSimulateColorSpace.setValue(
1296                     Integer.toString(AccessibilityManager.DALTONIZER_DISABLED));
1297         }
1298     }
1299
1300     /**
1301      * @return <code>true</code> if the color space preference is currently
1302      *         controlled by development settings
1303      */
1304     private boolean usingDevelopmentColorSpace() {
1305         final ContentResolver cr = getContentResolver();
1306         final boolean enabled = Settings.Secure.getInt(
1307                 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0;
1308         if (enabled) {
1309             final String mode = Integer.toString(Settings.Secure.getInt(
1310                     cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
1311                     AccessibilityManager.DALTONIZER_DISABLED));
1312             final int index = mSimulateColorSpace.findIndexOfValue(mode);
1313             if (index >= 0) {
1314                 // We're using a mode controlled by developer preferences.
1315                 return true;
1316             }
1317         }
1318         return false;
1319     }
1320
1321     private void writeSimulateColorSpace(Object value) {
1322         final ContentResolver cr = getContentResolver();
1323         final int newMode = Integer.parseInt(value.toString());
1324         if (newMode < 0) {
1325             Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0);
1326         } else {
1327             Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 1);
1328             Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, newMode);
1329         }
1330     }
1331
1332     private void updateColorTemperature() {
1333         updateSwitchPreference(mColorTemperaturePreference,
1334                 SystemProperties.getBoolean(COLOR_TEMPERATURE_PROPERTY, false));
1335     }
1336
1337     private void writeColorTemperature() {
1338         SystemProperties.set(COLOR_TEMPERATURE_PROPERTY,
1339                 mColorTemperaturePreference.isChecked() ? "1" : "0");
1340         pokeSystemProperties();
1341         Toast.makeText(getActivity(), R.string.color_temperature_toast, Toast.LENGTH_LONG).show();
1342     }
1343
1344     private void updateUSBAudioOptions() {
1345         updateSwitchPreference(mUSBAudio, Settings.Secure.getInt(getContentResolver(),
1346                 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 0) != 0);
1347     }
1348
1349     private void writeUSBAudioOptions() {
1350         Settings.Secure.putInt(getContentResolver(),
1351                 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED,
1352                 mUSBAudio.isChecked() ? 1 : 0);
1353     }
1354
1355     private void updateForceResizableOptions() {
1356         updateSwitchPreference(mForceResizable, Settings.Global.getInt(getContentResolver(),
1357                 Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0);
1358     }
1359
1360     private void writeForceResizableOptions() {
1361         Settings.Global.putInt(getContentResolver(),
1362                 Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES,
1363                 mForceResizable.isChecked() ? 1 : 0);
1364     }
1365
1366     private void updateForceRtlOptions() {
1367         updateSwitchPreference(mForceRtlLayout,
1368                 Settings.Global.getInt(getActivity().getContentResolver(),
1369                         Settings.Global.DEVELOPMENT_FORCE_RTL, 0) != 0);
1370     }
1371
1372     private void writeForceRtlOptions() {
1373         boolean value = mForceRtlLayout.isChecked();
1374         Settings.Global.putInt(getActivity().getContentResolver(),
1375                 Settings.Global.DEVELOPMENT_FORCE_RTL, value ? 1 : 0);
1376         SystemProperties.set(Settings.Global.DEVELOPMENT_FORCE_RTL, value ? "1" : "0");
1377         LocalePicker.updateLocale(getActivity().getResources().getConfiguration().locale);
1378     }
1379
1380     private void updateWifiDisplayCertificationOptions() {
1381         updateSwitchPreference(mWifiDisplayCertification, Settings.Global.getInt(
1382                 getActivity().getContentResolver(),
1383                 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, 0) != 0);
1384     }
1385
1386     private void writeWifiDisplayCertificationOptions() {
1387         Settings.Global.putInt(getActivity().getContentResolver(),
1388                 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON,
1389                 mWifiDisplayCertification.isChecked() ? 1 : 0);
1390     }
1391
1392     private void updateWifiVerboseLoggingOptions() {
1393         boolean enabled = mWifiManager.getVerboseLoggingLevel() > 0;
1394         updateSwitchPreference(mWifiVerboseLogging, enabled);
1395     }
1396
1397     private void writeWifiVerboseLoggingOptions() {
1398         mWifiManager.enableVerboseLogging(mWifiVerboseLogging.isChecked() ? 1 : 0);
1399     }
1400
1401     private void updateWifiAggressiveHandoverOptions() {
1402         boolean enabled = mWifiManager.getAggressiveHandover() > 0;
1403         updateSwitchPreference(mWifiAggressiveHandover, enabled);
1404     }
1405
1406     private void writeWifiAggressiveHandoverOptions() {
1407         mWifiManager.enableAggressiveHandover(mWifiAggressiveHandover.isChecked() ? 1 : 0);
1408     }
1409
1410     private void updateWifiAllowScansWithTrafficOptions() {
1411         boolean enabled = mWifiManager.getAllowScansWithTraffic() > 0;
1412         updateSwitchPreference(mWifiAllowScansWithTraffic, enabled);
1413     }
1414
1415     private void writeWifiAllowScansWithTrafficOptions() {
1416         mWifiManager.setAllowScansWithTraffic(mWifiAllowScansWithTraffic.isChecked() ? 1 : 0);
1417     }
1418
1419     private void updateBluetoothDisableAbsVolumeOptions() {
1420         updateSwitchPreference(mBluetoothDisableAbsVolume,
1421                 SystemProperties.getBoolean(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY, false));
1422     }
1423
1424     private void writeBluetoothDisableAbsVolumeOptions() {
1425         SystemProperties.set(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY,
1426                 mBluetoothDisableAbsVolume.isChecked() ? "true" : "false");
1427     }
1428
1429     private void updateMobileDataAlwaysOnOptions() {
1430         updateSwitchPreference(mMobileDataAlwaysOn, Settings.Global.getInt(
1431                 getActivity().getContentResolver(),
1432                 Settings.Global.MOBILE_DATA_ALWAYS_ON, 0) != 0);
1433     }
1434
1435     private void writeMobileDataAlwaysOnOptions() {
1436         Settings.Global.putInt(getActivity().getContentResolver(),
1437                 Settings.Global.MOBILE_DATA_ALWAYS_ON,
1438                 mMobileDataAlwaysOn.isChecked() ? 1 : 0);
1439     }
1440
1441     private String defaultLogdSizeValue() {
1442         String defaultValue = SystemProperties.get(SELECT_LOGD_DEFAULT_SIZE_PROPERTY);
1443         if ((defaultValue == null) || (defaultValue.length() == 0)) {
1444             if (SystemProperties.get("ro.config.low_ram").equals("true")) {
1445                 defaultValue = SELECT_LOGD_SVELTE_DEFAULT_SIZE_VALUE;
1446             } else {
1447                 defaultValue = SELECT_LOGD_DEFAULT_SIZE_VALUE;
1448             }
1449         }
1450         return defaultValue;
1451     }
1452
1453     private void updateLogdSizeValues() {
1454         if (mLogdSize != null) {
1455             String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY);
1456             String currentValue = SystemProperties.get(SELECT_LOGD_SIZE_PROPERTY);
1457             if ((currentTag != null) && currentTag.startsWith(SELECT_LOGD_TAG_SILENCE)) {
1458                 currentValue = SELECT_LOGD_OFF_SIZE_MARKER_VALUE;
1459             }
1460             if ((currentValue == null) || (currentValue.length() == 0)) {
1461                 currentValue = defaultLogdSizeValue();
1462             }
1463             String[] values = getResources().getStringArray(R.array.select_logd_size_values);
1464             String[] titles = getResources().getStringArray(R.array.select_logd_size_titles);
1465             int index = 2; // punt to second entry if not found
1466             if (SystemProperties.get("ro.config.low_ram").equals("true")) {
1467                 mLogdSize.setEntries(R.array.select_logd_size_lowram_titles);
1468                 titles = getResources().getStringArray(R.array.select_logd_size_lowram_titles);
1469                 index = 1;
1470             }
1471             String[] summaries = getResources().getStringArray(R.array.select_logd_size_summaries);
1472             for (int i = 0; i < titles.length; i++) {
1473                 if (currentValue.equals(values[i])
1474                         || currentValue.equals(titles[i])) {
1475                     index = i;
1476                     break;
1477                 }
1478             }
1479             mLogdSize.setValue(values[index]);
1480             mLogdSize.setSummary(summaries[index]);
1481             mLogdSize.setOnPreferenceChangeListener(this);
1482         }
1483     }
1484
1485     private void writeLogdSizeOption(Object newValue) {
1486         boolean disable = (newValue != null) &&
1487             (newValue.toString().equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE));
1488         String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY);
1489         if (currentTag == null) {
1490             currentTag = "";
1491         }
1492         // filter clean and unstack all references to our setting
1493         String newTag = currentTag.replaceAll(
1494                 ",+" + SELECT_LOGD_TAG_SILENCE, "").replaceFirst(
1495                 "^" + SELECT_LOGD_TAG_SILENCE + ",*", "").replaceAll(
1496                 ",+", ",").replaceFirst(
1497                 ",+$", "");
1498         if (disable) {
1499             newValue = SELECT_LOGD_MINIMUM_SIZE_VALUE;
1500             // Make sure snet_event_log get through first, but do not override
1501             String snetValue = SystemProperties.get(SELECT_LOGD_SNET_TAG_PROPERTY);
1502             if ((snetValue == null) || (snetValue.length() == 0)) {
1503                 snetValue = SystemProperties.get(SELECT_LOGD_RUNTIME_SNET_TAG_PROPERTY);
1504                 if ((snetValue == null) || (snetValue.length() == 0)) {
1505                     SystemProperties.set(SELECT_LOGD_SNET_TAG_PROPERTY, "I");
1506                 }
1507             }
1508             // Silence all log sources, security logs notwithstanding
1509             if (newTag.length() != 0) {
1510                 newTag = "," + newTag;
1511             }
1512             // Stack settings, stack to help preserve original value
1513             newTag = SELECT_LOGD_TAG_SILENCE + newTag;
1514         }
1515         if (!newTag.equals(currentTag)) {
1516             SystemProperties.set(SELECT_LOGD_TAG_PROPERTY, newTag);
1517         }
1518         String defaultValue = defaultLogdSizeValue();
1519         final String size = ((newValue != null) && (newValue.toString().length() != 0)) ?
1520             newValue.toString() : defaultValue;
1521         SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, defaultValue.equals(size) ? "" : size);
1522         SystemProperties.set("ctl.start", "logd-reinit");
1523         pokeSystemProperties();
1524         updateLogdSizeValues();
1525     }
1526
1527     private void updateUsbConfigurationValues() {
1528         if (mUsbConfiguration != null) {
1529             UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
1530
1531             String[] values = getResources().getStringArray(R.array.usb_configuration_values);
1532             String[] titles = getResources().getStringArray(R.array.usb_configuration_titles);
1533             int index = 0;
1534             for (int i = 0; i < titles.length; i++) {
1535                 if (manager.isFunctionEnabled(values[i])) {
1536                     index = i;
1537                     break;
1538                 }
1539             }
1540             mUsbConfiguration.setValue(values[index]);
1541             mUsbConfiguration.setSummary(titles[index]);
1542             mUsbConfiguration.setOnPreferenceChangeListener(this);
1543         }
1544     }
1545
1546     private void writeUsbConfigurationOption(Object newValue) {
1547         UsbManager manager = (UsbManager)getActivity().getSystemService(Context.USB_SERVICE);
1548         String function = newValue.toString();
1549         manager.setCurrentFunction(function);
1550         if (function.equals("none")) {
1551             manager.setUsbDataUnlocked(false);
1552         } else {
1553             manager.setUsbDataUnlocked(true);
1554         }
1555     }
1556
1557     private void updateCpuUsageOptions() {
1558         updateSwitchPreference(mShowCpuUsage,
1559                 Settings.Global.getInt(getActivity().getContentResolver(),
1560                         Settings.Global.SHOW_PROCESSES, 0) != 0);
1561     }
1562
1563     private void writeCpuUsageOptions() {
1564         boolean value = mShowCpuUsage.isChecked();
1565         Settings.Global.putInt(getActivity().getContentResolver(),
1566                 Settings.Global.SHOW_PROCESSES, value ? 1 : 0);
1567         Intent service = (new Intent())
1568                 .setClassName("com.android.systemui", "com.android.systemui.LoadAverageService");
1569         if (value) {
1570             getActivity().startService(service);
1571         } else {
1572             getActivity().stopService(service);
1573         }
1574     }
1575
1576     private void writeImmediatelyDestroyActivitiesOptions() {
1577         try {
1578             ActivityManagerNative.getDefault().setAlwaysFinish(
1579                     mImmediatelyDestroyActivities.isChecked());
1580         } catch (RemoteException ex) {
1581         }
1582     }
1583
1584     private void updateImmediatelyDestroyActivitiesOptions() {
1585         updateSwitchPreference(mImmediatelyDestroyActivities, Settings.Global.getInt(
1586                 getActivity().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) != 0);
1587     }
1588
1589     private void updateAnimationScaleValue(int which, ListPreference pref) {
1590         try {
1591             float scale = mWindowManager.getAnimationScale(which);
1592             if (scale != 1) {
1593                 mHaveDebugSettings = true;
1594             }
1595             CharSequence[] values = pref.getEntryValues();
1596             for (int i=0; i<values.length; i++) {
1597                 float val = Float.parseFloat(values[i].toString());
1598                 if (scale <= val) {
1599                     pref.setValueIndex(i);
1600                     pref.setSummary(pref.getEntries()[i]);
1601                     return;
1602                 }
1603             }
1604             pref.setValueIndex(values.length-1);
1605             pref.setSummary(pref.getEntries()[0]);
1606         } catch (RemoteException e) {
1607         }
1608     }
1609
1610     private void updateAnimationScaleOptions() {
1611         updateAnimationScaleValue(0, mWindowAnimationScale);
1612         updateAnimationScaleValue(1, mTransitionAnimationScale);
1613         updateAnimationScaleValue(2, mAnimatorDurationScale);
1614     }
1615
1616     private void writeAnimationScaleOption(int which, ListPreference pref, Object newValue) {
1617         try {
1618             float scale = newValue != null ? Float.parseFloat(newValue.toString()) : 1;
1619             mWindowManager.setAnimationScale(which, scale);
1620             updateAnimationScaleValue(which, pref);
1621         } catch (RemoteException e) {
1622         }
1623     }
1624
1625     private void updateOverlayDisplayDevicesOptions() {
1626         String value = Settings.Global.getString(getActivity().getContentResolver(),
1627                 Settings.Global.OVERLAY_DISPLAY_DEVICES);
1628         if (value == null) {
1629             value = "";
1630         }
1631
1632         CharSequence[] values = mOverlayDisplayDevices.getEntryValues();
1633         for (int i = 0; i < values.length; i++) {
1634             if (value.contentEquals(values[i])) {
1635                 mOverlayDisplayDevices.setValueIndex(i);
1636                 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[i]);
1637                 return;
1638             }
1639         }
1640         mOverlayDisplayDevices.setValueIndex(0);
1641         mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[0]);
1642     }
1643
1644     private void writeOverlayDisplayDevicesOptions(Object newValue) {
1645         Settings.Global.putString(getActivity().getContentResolver(),
1646                 Settings.Global.OVERLAY_DISPLAY_DEVICES, (String) newValue);
1647         updateOverlayDisplayDevicesOptions();
1648     }
1649
1650     private void updateAppProcessLimitOptions() {
1651         try {
1652             int limit = ActivityManagerNative.getDefault().getProcessLimit();
1653             CharSequence[] values = mAppProcessLimit.getEntryValues();
1654             for (int i=0; i<values.length; i++) {
1655                 int val = Integer.parseInt(values[i].toString());
1656                 if (val >= limit) {
1657                     if (i != 0) {
1658                         mHaveDebugSettings = true;
1659                     }
1660                     mAppProcessLimit.setValueIndex(i);
1661                     mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[i]);
1662                     return;
1663                 }
1664             }
1665             mAppProcessLimit.setValueIndex(0);
1666             mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[0]);
1667         } catch (RemoteException e) {
1668         }
1669     }
1670
1671     private void writeAppProcessLimitOptions(Object newValue) {
1672         try {
1673             int limit = newValue != null ? Integer.parseInt(newValue.toString()) : -1;
1674             ActivityManagerNative.getDefault().setProcessLimit(limit);
1675             updateAppProcessLimitOptions();
1676         } catch (RemoteException e) {
1677         }
1678     }
1679
1680     private void writeShowAllANRsOptions() {
1681         Settings.Secure.putInt(getActivity().getContentResolver(),
1682                 Settings.Secure.ANR_SHOW_BACKGROUND,
1683                 mShowAllANRs.isChecked() ? 1 : 0);
1684     }
1685
1686     private void updateShowAllANRsOptions() {
1687         updateSwitchPreference(mShowAllANRs, Settings.Secure.getInt(
1688                 getActivity().getContentResolver(), Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0);
1689     }
1690
1691     private void confirmEnableOemUnlock() {
1692         DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
1693             @Override
1694             public void onClick(DialogInterface dialog, int which) {
1695                 if (which == DialogInterface.BUTTON_POSITIVE) {
1696                     Utils.setOemUnlockEnabled(getActivity(), true);
1697                 }
1698             }
1699         };
1700
1701         DialogInterface.OnDismissListener onDismissListener = new DialogInterface.OnDismissListener() {
1702             @Override
1703             public void onDismiss(DialogInterface dialog) {
1704                 if (getActivity() == null) {
1705                     return;
1706                 }
1707                 updateAllOptions();
1708             }
1709         };
1710
1711         new AlertDialog.Builder(getActivity())
1712                 .setTitle(R.string.confirm_enable_oem_unlock_title)
1713                 .setMessage(R.string.confirm_enable_oem_unlock_text)
1714                 .setPositiveButton(R.string.enable_text, onClickListener)
1715                 .setNegativeButton(android.R.string.cancel, null)
1716                 .setOnDismissListener(onDismissListener)
1717                 .create()
1718                 .show();
1719     }
1720
1721     @Override
1722     public void onSwitchChanged(Switch switchView, boolean isChecked) {
1723         if (switchView != mSwitchBar.getSwitch()) {
1724             return;
1725         }
1726         if (isChecked != mLastEnabledState) {
1727             if (isChecked) {
1728                 mDialogClicked = false;
1729                 if (mEnableDialog != null) dismissDialogs();
1730                 mEnableDialog = new AlertDialog.Builder(getActivity()).setMessage(
1731                         getActivity().getResources().getString(
1732                                 R.string.dev_settings_warning_message))
1733                         .setTitle(R.string.dev_settings_warning_title)
1734                         .setPositiveButton(android.R.string.yes, this)
1735                         .setNegativeButton(android.R.string.no, this)
1736                         .show();
1737                 mEnableDialog.setOnDismissListener(this);
1738             } else {
1739                 resetDangerousOptions();
1740                 Settings.Global.putInt(getActivity().getContentResolver(),
1741                         Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
1742                 mLastEnabledState = isChecked;
1743                 setPrefsEnabledState(mLastEnabledState);
1744             }
1745         }
1746     }
1747
1748     @Override
1749     public void onActivityResult(int requestCode, int resultCode, Intent data) {
1750         if (requestCode == RESULT_DEBUG_APP) {
1751             if (resultCode == Activity.RESULT_OK) {
1752                 mDebugApp = data.getAction();
1753                 writeDebuggerOptions();
1754                 updateDebuggerOptions();
1755             }
1756         } else if (requestCode == RESULT_MOCK_LOCATION_APP) {
1757             if (resultCode == Activity.RESULT_OK) {
1758                 mMockLocationApp = data.getAction();
1759                 writeMockLocation();
1760                 updateMockLocation();
1761             }
1762         } else if (requestCode == REQUEST_CODE_ENABLE_OEM_UNLOCK) {
1763             if (resultCode == Activity.RESULT_OK) {
1764                 if (mEnableOemUnlock.isChecked()) {
1765                     confirmEnableOemUnlock();
1766                 } else {
1767                     Utils.setOemUnlockEnabled(getActivity(), false);
1768                 }
1769             }
1770         } else {
1771             super.onActivityResult(requestCode, resultCode, data);
1772         }
1773     }
1774
1775     @Override
1776     public boolean onPreferenceTreeClick(Preference preference) {
1777         if (Utils.isMonkeyRunning()) {
1778             return false;
1779         }
1780
1781         if (preference == mEnableAdb) {
1782             if (mEnableAdb.isChecked()) {
1783                 mDialogClicked = false;
1784                 if (mAdbDialog != null) dismissDialogs();
1785                 mAdbDialog = new AlertDialog.Builder(getActivity()).setMessage(
1786                         getActivity().getResources().getString(R.string.adb_warning_message))
1787                         .setTitle(R.string.adb_warning_title)
1788                         .setPositiveButton(android.R.string.yes, this)
1789                         .setNegativeButton(android.R.string.no, this)
1790                         .show();
1791                 mAdbDialog.setOnDismissListener(this);
1792             } else {
1793                 Settings.Global.putInt(getActivity().getContentResolver(),
1794                         Settings.Global.ADB_ENABLED, 0);
1795                 mVerifyAppsOverUsb.setEnabled(false);
1796                 mVerifyAppsOverUsb.setChecked(false);
1797                 updateBugreportOptions();
1798             }
1799         } else if (preference == mClearAdbKeys) {
1800             if (mAdbKeysDialog != null) dismissDialogs();
1801             mAdbKeysDialog = new AlertDialog.Builder(getActivity())
1802                         .setMessage(R.string.adb_keys_warning_message)
1803                         .setPositiveButton(android.R.string.ok, this)
1804                         .setNegativeButton(android.R.string.cancel, null)
1805                         .show();
1806         } else if (preference == mEnableTerminal) {
1807             final PackageManager pm = getActivity().getPackageManager();
1808             pm.setApplicationEnabledSetting(TERMINAL_APP_PACKAGE,
1809                     mEnableTerminal.isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1810                             : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
1811         } else if (preference == mBugreportInPower) {
1812             Settings.Secure.putInt(getActivity().getContentResolver(),
1813                     Settings.Global.BUGREPORT_IN_POWER_MENU,
1814                     mBugreportInPower.isChecked() ? 1 : 0);
1815             setBugreportStorageProviderStatus();
1816         } else if (preference == mKeepScreenOn) {
1817             Settings.Global.putInt(getActivity().getContentResolver(),
1818                     Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
1819                     mKeepScreenOn.isChecked() ?
1820                             (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
1821         } else if (preference == mBtHciSnoopLog) {
1822             writeBtHciSnoopLogOptions();
1823         } else if (preference == mEnableOemUnlock && mEnableOemUnlock.isEnabled()) {
1824             if (mEnableOemUnlock.isChecked()) {
1825                 if (!showKeyguardConfirmation(getResources(), REQUEST_CODE_ENABLE_OEM_UNLOCK)) {
1826                     confirmEnableOemUnlock();
1827                 }
1828             } else {
1829                 Utils.setOemUnlockEnabled(getActivity(), false);
1830             }
1831         } else if (preference == mMockLocationAppPref) {
1832             Intent intent = new Intent(getActivity(), AppPicker.class);
1833             intent.putExtra(AppPicker.EXTRA_REQUESTIING_PERMISSION,
1834                     Manifest.permission.ACCESS_MOCK_LOCATION);
1835             startActivityForResult(intent, RESULT_MOCK_LOCATION_APP);
1836         } else if (preference == mDebugViewAttributes) {
1837             Settings.Global.putInt(getActivity().getContentResolver(),
1838                     Settings.Global.DEBUG_VIEW_ATTRIBUTES,
1839                     mDebugViewAttributes.isChecked() ? 1 : 0);
1840         } else if (preference == mForceAllowOnExternal) {
1841             Settings.Global.putInt(getActivity().getContentResolver(),
1842                     Settings.Global.FORCE_ALLOW_ON_EXTERNAL,
1843                     mForceAllowOnExternal.isChecked() ? 1 : 0);
1844         } else if (preference == mDebugAppPref) {
1845             Intent intent = new Intent(getActivity(), AppPicker.class);
1846             intent.putExtra(AppPicker.EXTRA_DEBUGGABLE, true);
1847             startActivityForResult(intent, RESULT_DEBUG_APP);
1848         } else if (preference == mWaitForDebugger) {
1849             writeDebuggerOptions();
1850         } else if (preference == mVerifyAppsOverUsb) {
1851             writeVerifyAppsOverUsbOptions();
1852         } else if (preference == mOtaDisableAutomaticUpdate) {
1853             writeOtaDisableAutomaticUpdateOptions();
1854         } else if (preference == mStrictMode) {
1855             writeStrictModeVisualOptions();
1856         } else if (preference == mPointerLocation) {
1857             writePointerLocationOptions();
1858         } else if (preference == mShowTouches) {
1859             writeShowTouchesOptions();
1860         } else if (preference == mShowScreenUpdates) {
1861             writeShowUpdatesOption();
1862         } else if (preference == mDisableOverlays) {
1863             writeDisableOverlaysOption();
1864         } else if (preference == mShowCpuUsage) {
1865             writeCpuUsageOptions();
1866         } else if (preference == mImmediatelyDestroyActivities) {
1867             writeImmediatelyDestroyActivitiesOptions();
1868         } else if (preference == mShowAllANRs) {
1869             writeShowAllANRsOptions();
1870         } else if (preference == mForceHardwareUi) {
1871             writeHardwareUiOptions();
1872         } else if (preference == mForceMsaa) {
1873             writeMsaaOptions();
1874         } else if (preference == mShowHwScreenUpdates) {
1875             writeShowHwScreenUpdatesOptions();
1876         } else if (preference == mShowHwLayersUpdates) {
1877             writeShowHwLayersUpdatesOptions();
1878         } else if (preference == mDebugLayout) {
1879             writeDebugLayoutOptions();
1880         } else if (preference == mForceRtlLayout) {
1881             writeForceRtlOptions();
1882         } else if (preference == mWifiDisplayCertification) {
1883             writeWifiDisplayCertificationOptions();
1884         } else if (preference == mWifiVerboseLogging) {
1885             writeWifiVerboseLoggingOptions();
1886         } else if (preference == mWifiAggressiveHandover) {
1887             writeWifiAggressiveHandoverOptions();
1888         } else if (preference == mWifiAllowScansWithTraffic) {
1889             writeWifiAllowScansWithTrafficOptions();
1890         } else if (preference == mMobileDataAlwaysOn) {
1891             writeMobileDataAlwaysOnOptions();
1892         } else if (preference == mColorTemperaturePreference) {
1893             writeColorTemperature();
1894         } else if (preference == mUSBAudio) {
1895             writeUSBAudioOptions();
1896         } else if (preference == mForceResizable) {
1897             writeForceResizableOptions();
1898         } else if (INACTIVE_APPS_KEY.equals(preference.getKey())) {
1899             startInactiveAppsFragment();
1900         } else if (BACKGROUND_CHECK_KEY.equals(preference.getKey())) {
1901             startBackgroundCheckFragment();
1902         } else if (preference == mBluetoothDisableAbsVolume) {
1903             writeBluetoothDisableAbsVolumeOptions();
1904         } else if (preference == mWebViewMultiprocess) {
1905             writeWebViewMultiprocessOptions();
1906         } else if (SHORTCUT_MANAGER_RESET_KEY.equals(preference.getKey())) {
1907             confirmResetShortcutManagerThrottling();
1908         } else {
1909             return super.onPreferenceTreeClick(preference);
1910         }
1911
1912         return false;
1913     }
1914
1915     private void startInactiveAppsFragment() {
1916         ((SettingsActivity) getActivity()).startPreferencePanel(
1917                 InactiveApps.class.getName(),
1918                 null, R.string.inactive_apps_title, null, null, 0);
1919     }
1920
1921     private void startBackgroundCheckFragment() {
1922         ((SettingsActivity) getActivity()).startPreferencePanel(
1923                 BackgroundCheckSummary.class.getName(),
1924                 null, R.string.background_check_title, null, null, 0);
1925     }
1926
1927     private boolean showKeyguardConfirmation(Resources resources, int requestCode) {
1928         return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
1929                 requestCode, resources.getString(R.string.oem_unlock_enable));
1930     }
1931
1932     private boolean isPackageEnabled(String packageName) {
1933         try {
1934             return getActivity().getPackageManager().getApplicationInfo(packageName, 0).enabled;
1935         } catch (NameNotFoundException e) {
1936             // Thrown by PackageManager.getApplicationInfo if the package does not exist
1937         }
1938         return false;
1939     }
1940
1941     @Override
1942     public boolean onPreferenceChange(Preference preference, Object newValue) {
1943         if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
1944             SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString());
1945             updateHdcpValues();
1946             pokeSystemProperties();
1947             return true;
1948         } else if (preference == mWebViewProvider) {
1949             if (newValue == null) {
1950                 Log.e(TAG, "Tried to set a null WebView provider");
1951                 return false;
1952             }
1953             if (writeWebViewProviderOptions(newValue)) {
1954                 return true;
1955             } else {
1956                 // The user chose a package that became invalid since the list was last updated,
1957                 // show a Toast to explain the situation.
1958                 Toast toast = Toast.makeText(getActivity(),
1959                         R.string.select_webview_provider_toast_text, Toast.LENGTH_SHORT);
1960                 toast.show();
1961             }
1962             return false;
1963         } else if (preference == mLogdSize) {
1964             writeLogdSizeOption(newValue);
1965             return true;
1966         } else if (preference == mUsbConfiguration) {
1967             writeUsbConfigurationOption(newValue);
1968             return true;
1969         } else if (preference == mWindowAnimationScale) {
1970             writeAnimationScaleOption(0, mWindowAnimationScale, newValue);
1971             return true;
1972         } else if (preference == mTransitionAnimationScale) {
1973             writeAnimationScaleOption(1, mTransitionAnimationScale, newValue);
1974             return true;
1975         } else if (preference == mAnimatorDurationScale) {
1976             writeAnimationScaleOption(2, mAnimatorDurationScale, newValue);
1977             return true;
1978         } else if (preference == mOverlayDisplayDevices) {
1979             writeOverlayDisplayDevicesOptions(newValue);
1980             return true;
1981         } else if (preference == mTrackFrameTime) {
1982             writeTrackFrameTimeOptions(newValue);
1983             return true;
1984         } else if (preference == mDebugHwOverdraw) {
1985             writeDebugHwOverdrawOptions(newValue);
1986             return true;
1987         } else if (preference == mShowNonRectClip) {
1988             writeShowNonRectClipOptions(newValue);
1989             return true;
1990         } else if (preference == mAppProcessLimit) {
1991             writeAppProcessLimitOptions(newValue);
1992             return true;
1993         } else if (preference == mSimulateColorSpace) {
1994             writeSimulateColorSpace(newValue);
1995             return true;
1996         }
1997         return false;
1998     }
1999
2000     private void dismissDialogs() {
2001         if (mAdbDialog != null) {
2002             mAdbDialog.dismiss();
2003             mAdbDialog = null;
2004         }
2005         if (mAdbKeysDialog != null) {
2006             mAdbKeysDialog.dismiss();
2007             mAdbKeysDialog = null;
2008         }
2009         if (mEnableDialog != null) {
2010             mEnableDialog.dismiss();
2011             mEnableDialog = null;
2012         }
2013     }
2014
2015     public void onClick(DialogInterface dialog, int which) {
2016         if (dialog == mAdbDialog) {
2017             if (which == DialogInterface.BUTTON_POSITIVE) {
2018                 mDialogClicked = true;
2019                 Settings.Global.putInt(getActivity().getContentResolver(),
2020                         Settings.Global.ADB_ENABLED, 1);
2021                 mVerifyAppsOverUsb.setEnabled(true);
2022                 updateVerifyAppsOverUsbOptions();
2023                 updateBugreportOptions();
2024             } else {
2025                 // Reset the toggle
2026                 mEnableAdb.setChecked(false);
2027             }
2028         } else if (dialog == mAdbKeysDialog) {
2029             if (which == DialogInterface.BUTTON_POSITIVE) {
2030                 try {
2031                     IBinder b = ServiceManager.getService(Context.USB_SERVICE);
2032                     IUsbManager service = IUsbManager.Stub.asInterface(b);
2033                     service.clearUsbDebuggingKeys();
2034                 } catch (RemoteException e) {
2035                     Log.e(TAG, "Unable to clear adb keys", e);
2036                 }
2037             }
2038         } else if (dialog == mEnableDialog) {
2039             if (which == DialogInterface.BUTTON_POSITIVE) {
2040                 mDialogClicked = true;
2041                 Settings.Global.putInt(getActivity().getContentResolver(),
2042                         Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
2043                 mLastEnabledState = true;
2044                 setPrefsEnabledState(mLastEnabledState);
2045             } else {
2046                 // Reset the toggle
2047                 mSwitchBar.setChecked(false);
2048             }
2049         }
2050     }
2051
2052     public void onDismiss(DialogInterface dialog) {
2053         // Assuming that onClick gets called first
2054         if (dialog == mAdbDialog) {
2055             if (!mDialogClicked) {
2056                 mEnableAdb.setChecked(false);
2057             }
2058             mAdbDialog = null;
2059         } else if (dialog == mEnableDialog) {
2060             if (!mDialogClicked) {
2061                 mSwitchBar.setChecked(false);
2062             }
2063             mEnableDialog = null;
2064         }
2065     }
2066
2067     @Override
2068     public void onDestroy() {
2069         dismissDialogs();
2070         super.onDestroy();
2071     }
2072
2073     void pokeSystemProperties() {
2074         if (!mDontPokeProperties) {
2075             //noinspection unchecked
2076             (new SystemPropPoker()).execute();
2077         }
2078     }
2079
2080     private BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
2081         @Override
2082         public void onReceive(Context context, Intent intent) {
2083             updateUsbConfigurationValues();
2084         }
2085     };
2086
2087     static class SystemPropPoker extends AsyncTask<Void, Void, Void> {
2088         @Override
2089         protected Void doInBackground(Void... params) {
2090             String[] services = ServiceManager.listServices();
2091             for (String service : services) {
2092                 IBinder obj = ServiceManager.checkService(service);
2093                 if (obj != null) {
2094                     Parcel data = Parcel.obtain();
2095                     try {
2096                         obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0);
2097                     } catch (RemoteException e) {
2098                     } catch (Exception e) {
2099                         Log.i(TAG, "Someone wrote a bad service '" + service
2100                                 + "' that doesn't like to be poked: " + e);
2101                     }
2102                     data.recycle();
2103                 }
2104             }
2105             return null;
2106         }
2107     }
2108
2109     private static boolean isPackageInstalled(Context context, String packageName) {
2110         try {
2111             return context.getPackageManager().getPackageInfo(packageName, 0) != null;
2112         } catch (NameNotFoundException e) {
2113             return false;
2114         }
2115     }
2116
2117
2118     /**
2119      * For Search.
2120      */
2121     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
2122             new BaseSearchIndexProvider() {
2123
2124                 private boolean isShowingDeveloperOptions(Context context) {
2125                     return context.getSharedPreferences(DevelopmentSettings.PREF_FILE,
2126                             Context.MODE_PRIVATE).getBoolean(
2127                                     DevelopmentSettings.PREF_SHOW,
2128                                     android.os.Build.TYPE.equals("eng"));
2129                 }
2130
2131                 @Override
2132                 public List<SearchIndexableResource> getXmlResourcesToIndex(
2133                         Context context, boolean enabled) {
2134
2135                     if (!isShowingDeveloperOptions(context)) {
2136                         return null;
2137                     }
2138
2139                     final SearchIndexableResource sir = new SearchIndexableResource(context);
2140                     sir.xmlResId = R.xml.development_prefs;
2141                     return Arrays.asList(sir);
2142                 }
2143
2144                 @Override
2145                 public List<String> getNonIndexableKeys(Context context) {
2146                     if (!isShowingDeveloperOptions(context)) {
2147                         return null;
2148                     }
2149
2150                     final List<String> keys = new ArrayList<String>();
2151                     if (!showEnableOemUnlockPreference()) {
2152                         keys.add(ENABLE_OEM_UNLOCK);
2153                     }
2154                     return keys;
2155                 }
2156             };
2157
2158     private void confirmResetShortcutManagerThrottling() {
2159         final IShortcutService service = IShortcutService.Stub.asInterface(
2160                 ServiceManager.getService(Context.SHORTCUT_SERVICE));
2161
2162         DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
2163             @Override
2164             public void onClick(DialogInterface dialog, int which) {
2165                 if (which == DialogInterface.BUTTON_POSITIVE) {
2166                     try {
2167                         service.resetThrottling();
2168                     } catch (RemoteException e) {
2169                     }
2170                 }
2171             }
2172         };
2173
2174         new AlertDialog.Builder(getActivity())
2175                 .setTitle(R.string.confirm_reset_shortcut_manager_throttling_title)
2176                 .setMessage(R.string.confirm_reset_shortcut_manager_throttling_message)
2177                 .setPositiveButton(R.string.okay, onClickListener)
2178                 .setNegativeButton(android.R.string.cancel, null)
2179                 .create()
2180                 .show();
2181
2182     }
2183 }