2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings;
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.PackageManager;
38 import android.content.pm.PackageManager.NameNotFoundException;
39 import android.content.pm.ResolveInfo;
40 import android.content.res.Resources;
41 import android.hardware.usb.IUsbManager;
42 import android.hardware.usb.UsbManager;
43 import android.net.wifi.WifiManager;
44 import android.os.AsyncTask;
45 import android.os.BatteryManager;
46 import android.os.Build;
47 import android.os.Bundle;
48 import android.os.IBinder;
49 import android.os.Parcel;
50 import android.os.RemoteException;
51 import android.os.ServiceManager;
52 import android.os.StrictMode;
53 import android.os.SystemProperties;
54 import android.os.UserHandle;
55 import android.os.UserManager;
56 import android.preference.ListPreference;
57 import android.preference.Preference;
58 import android.preference.Preference.OnPreferenceChangeListener;
59 import android.preference.PreferenceGroup;
60 import android.preference.PreferenceScreen;
61 import android.preference.SwitchPreference;
62 import android.provider.SearchIndexableResource;
63 import android.provider.Settings;
64 import android.text.TextUtils;
65 import android.util.Log;
66 import android.view.HardwareRenderer;
67 import android.view.IWindowManager;
68 import android.view.LayoutInflater;
69 import android.view.View;
70 import android.view.ViewGroup;
71 import android.view.accessibility.AccessibilityManager;
72 import android.widget.Switch;
73 import android.widget.TextView;
75 import com.android.internal.logging.MetricsLogger;
76 import com.android.settings.fuelgauge.InactiveApps;
77 import com.android.settings.search.BaseSearchIndexProvider;
78 import com.android.settings.search.Indexable;
79 import com.android.settings.widget.SwitchBar;
81 import java.util.ArrayList;
82 import java.util.Arrays;
83 import java.util.HashSet;
84 import java.util.List;
87 * Displays preferences for application developers.
89 public class DevelopmentSettings extends SettingsPreferenceFragment
90 implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
91 OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable {
92 private static final String TAG = "DevelopmentSettings";
95 * Preference file were development settings prefs are stored.
97 public static final String PREF_FILE = "development";
100 * Whether to show the development settings to the user. Default is false.
102 public static final String PREF_SHOW = "show";
104 private static final ComponentName SYSUI_TUNER = new ComponentName("com.android.systemui",
105 "com.android.systemui.tuner.TunerActivity");
107 private static final String ENABLE_ADB = "enable_adb";
108 private static final String CLEAR_ADB_KEYS = "clear_adb_keys";
109 private static final String ENABLE_TERMINAL = "enable_terminal";
110 private static final String KEEP_SCREEN_ON = "keep_screen_on";
111 private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log";
112 private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable";
113 private static final String HDCP_CHECKING_KEY = "hdcp_checking";
114 private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking";
115 private static final String LOCAL_BACKUP_PASSWORD = "local_backup_password";
116 private static final String HARDWARE_UI_PROPERTY = "persist.sys.ui.hw";
117 private static final String MSAA_PROPERTY = "debug.egl.force_msaa";
118 private static final String BUGREPORT = "bugreport";
119 private static final String BUGREPORT_IN_POWER_KEY = "bugreport_in_power";
120 private static final String OPENGL_TRACES_PROPERTY = "debug.egl.trace";
121 private static final String TUNER_UI_KEY = "tuner_ui";
123 private static final String DEBUG_APP_KEY = "debug_app";
124 private static final String WAIT_FOR_DEBUGGER_KEY = "wait_for_debugger";
125 private static final String MOCK_LOCATION_APP_KEY = "mock_location_app";
126 private static final String VERIFY_APPS_OVER_USB_KEY = "verify_apps_over_usb";
127 private static final String DEBUG_VIEW_ATTRIBUTES = "debug_view_attributes";
128 private static final String STRICT_MODE_KEY = "strict_mode";
129 private static final String POINTER_LOCATION_KEY = "pointer_location";
130 private static final String SHOW_TOUCHES_KEY = "show_touches";
131 private static final String SHOW_SCREEN_UPDATES_KEY = "show_screen_updates";
132 private static final String DISABLE_OVERLAYS_KEY = "disable_overlays";
133 private static final String SIMULATE_COLOR_SPACE = "simulate_color_space";
134 private static final String USB_AUDIO_KEY = "usb_audio";
135 private static final String SHOW_CPU_USAGE_KEY = "show_cpu_usage";
136 private static final String FORCE_HARDWARE_UI_KEY = "force_hw_ui";
137 private static final String FORCE_MSAA_KEY = "force_msaa";
138 private static final String TRACK_FRAME_TIME_KEY = "track_frame_time";
139 private static final String SHOW_NON_RECTANGULAR_CLIP_KEY = "show_non_rect_clip";
140 private static final String SHOW_HW_SCREEN_UPDATES_KEY = "show_hw_screen_udpates";
141 private static final String SHOW_HW_LAYERS_UPDATES_KEY = "show_hw_layers_udpates";
142 private static final String DEBUG_HW_OVERDRAW_KEY = "debug_hw_overdraw";
143 private static final String DEBUG_LAYOUT_KEY = "debug_layout";
144 private static final String FORCE_RTL_LAYOUT_KEY = "force_rtl_layout_all_locales";
145 private static final String WINDOW_ANIMATION_SCALE_KEY = "window_animation_scale";
146 private static final String TRANSITION_ANIMATION_SCALE_KEY = "transition_animation_scale";
147 private static final String ANIMATOR_DURATION_SCALE_KEY = "animator_duration_scale";
148 private static final String OVERLAY_DISPLAY_DEVICES_KEY = "overlay_display_devices";
149 private static final String ENABLE_MULTI_WINDOW_KEY = "enable_multi_window";
150 private static final String DEBUG_DEBUGGING_CATEGORY_KEY = "debug_debugging_category";
151 private static final String SELECT_LOGD_SIZE_KEY = "select_logd_size";
152 private static final String SELECT_LOGD_SIZE_PROPERTY = "persist.logd.size";
153 private static final String SELECT_LOGD_DEFAULT_SIZE_PROPERTY = "ro.logd.size";
155 private static final String WIFI_DISPLAY_CERTIFICATION_KEY = "wifi_display_certification";
156 private static final String WIFI_VERBOSE_LOGGING_KEY = "wifi_verbose_logging";
157 private static final String WIFI_AGGRESSIVE_HANDOVER_KEY = "wifi_aggressive_handover";
158 private static final String WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY = "wifi_allow_scan_with_traffic";
159 private static final String USB_CONFIGURATION_KEY = "select_usb_configuration";
160 private static final String WIFI_LEGACY_DHCP_CLIENT_KEY = "legacy_dhcp_client";
161 private static final String MOBILE_DATA_ALWAYS_ON = "mobile_data_always_on";
163 private static final String INACTIVE_APPS_KEY = "inactive_apps";
165 private static final String OPENGL_TRACES_KEY = "enable_opengl_traces";
167 private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY
168 = "immediately_destroy_activities";
169 private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit";
171 private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs";
173 private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
175 private static final String TERMINAL_APP_PACKAGE = "com.android.terminal";
177 private static final int RESULT_DEBUG_APP = 1000;
178 private static final int RESULT_MOCK_LOCATION_APP = 1001;
180 private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
182 private static final int REQUEST_CODE_ENABLE_OEM_UNLOCK = 0;
184 private static String DEFAULT_LOG_RING_BUFFER_SIZE_IN_BYTES = "262144"; // 256K
186 private static final int[] MOCK_LOCATION_APP_OPS = new int[] {AppOpsManager.OP_MOCK_LOCATION};
188 private static final String MULTI_WINDOW_SYSTEM_PROPERTY = "persist.sys.debug.multi_window";
189 private IWindowManager mWindowManager;
190 private IBackupManager mBackupManager;
191 private DevicePolicyManager mDpm;
192 private UserManager mUm;
193 private WifiManager mWifiManager;
195 private SwitchBar mSwitchBar;
196 private boolean mLastEnabledState;
197 private boolean mHaveDebugSettings;
198 private boolean mDontPokeProperties;
200 private SwitchPreference mEnableAdb;
201 private Preference mClearAdbKeys;
202 private SwitchPreference mEnableTerminal;
203 private Preference mBugreport;
204 private SwitchPreference mBugreportInPower;
205 private SwitchPreference mKeepScreenOn;
206 private SwitchPreference mBtHciSnoopLog;
207 private SwitchPreference mEnableOemUnlock;
208 private SwitchPreference mDebugViewAttributes;
210 private PreferenceScreen mPassword;
211 private String mDebugApp;
212 private Preference mDebugAppPref;
214 private String mMockLocationApp;
215 private Preference mMockLocationAppPref;
217 private SwitchPreference mWaitForDebugger;
218 private SwitchPreference mVerifyAppsOverUsb;
219 private SwitchPreference mWifiDisplayCertification;
220 private SwitchPreference mWifiVerboseLogging;
221 private SwitchPreference mWifiAggressiveHandover;
222 private SwitchPreference mLegacyDhcpClient;
223 private SwitchPreference mMobileDataAlwaysOn;
225 private SwitchPreference mWifiAllowScansWithTraffic;
226 private SwitchPreference mStrictMode;
227 private SwitchPreference mPointerLocation;
228 private SwitchPreference mShowTouches;
229 private SwitchPreference mShowScreenUpdates;
230 private SwitchPreference mDisableOverlays;
231 private SwitchPreference mEnableMultiWindow;
232 private SwitchPreference mShowCpuUsage;
233 private SwitchPreference mForceHardwareUi;
234 private SwitchPreference mForceMsaa;
235 private SwitchPreference mShowHwScreenUpdates;
236 private SwitchPreference mShowHwLayersUpdates;
237 private SwitchPreference mDebugLayout;
238 private SwitchPreference mForceRtlLayout;
239 private ListPreference mDebugHwOverdraw;
240 private ListPreference mLogdSize;
241 private ListPreference mUsbConfiguration;
242 private ListPreference mTrackFrameTime;
243 private ListPreference mShowNonRectClip;
244 private ListPreference mWindowAnimationScale;
245 private ListPreference mTransitionAnimationScale;
246 private ListPreference mAnimatorDurationScale;
247 private ListPreference mOverlayDisplayDevices;
248 private ListPreference mOpenGLTraces;
250 private ListPreference mSimulateColorSpace;
252 private SwitchPreference mUSBAudio;
253 private SwitchPreference mImmediatelyDestroyActivities;
255 private ListPreference mAppProcessLimit;
257 private SwitchPreference mShowAllANRs;
259 private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>();
261 private final ArrayList<SwitchPreference> mResetSwitchPrefs
262 = new ArrayList<SwitchPreference>();
264 private final HashSet<Preference> mDisabledPrefs = new HashSet<Preference>();
265 // To track whether a confirmation dialog was clicked.
266 private boolean mDialogClicked;
267 private Dialog mEnableDialog;
268 private Dialog mAdbDialog;
270 private Dialog mAdbKeysDialog;
271 private boolean mUnavailable;
273 private SwitchPreference mTunerUiPref;
276 protected int getMetricsCategory() {
277 return MetricsLogger.DEVELOPMENT;
281 public void onCreate(Bundle icicle) {
282 super.onCreate(icicle);
284 mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
285 mBackupManager = IBackupManager.Stub.asInterface(
286 ServiceManager.getService(Context.BACKUP_SERVICE));
287 mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
288 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
290 mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
292 if (android.os.Process.myUserHandle().getIdentifier() != UserHandle.USER_OWNER
293 || mUm.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES)) {
295 setPreferenceScreen(new PreferenceScreen(getActivity(), null));
299 addPreferencesFromResource(R.xml.development_prefs);
301 final PreferenceGroup debugDebuggingCategory = (PreferenceGroup)
302 findPreference(DEBUG_DEBUGGING_CATEGORY_KEY);
303 mEnableAdb = findAndInitSwitchPref(ENABLE_ADB);
304 mClearAdbKeys = findPreference(CLEAR_ADB_KEYS);
305 if (!SystemProperties.getBoolean("ro.adb.secure", false)) {
306 if (debugDebuggingCategory != null) {
307 debugDebuggingCategory.removePreference(mClearAdbKeys);
310 mAllPrefs.add(mClearAdbKeys);
311 mEnableTerminal = findAndInitSwitchPref(ENABLE_TERMINAL);
312 if (!isPackageInstalled(getActivity(), TERMINAL_APP_PACKAGE)) {
313 debugDebuggingCategory.removePreference(mEnableTerminal);
314 mEnableTerminal = null;
317 mBugreport = findPreference(BUGREPORT);
318 mBugreportInPower = findAndInitSwitchPref(BUGREPORT_IN_POWER_KEY);
319 mKeepScreenOn = findAndInitSwitchPref(KEEP_SCREEN_ON);
320 mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG);
321 mEnableOemUnlock = findAndInitSwitchPref(ENABLE_OEM_UNLOCK);
322 if (!showEnableOemUnlockPreference()) {
323 removePreference(mEnableOemUnlock);
324 mEnableOemUnlock = null;
327 mDebugViewAttributes = findAndInitSwitchPref(DEBUG_VIEW_ATTRIBUTES);
328 mPassword = (PreferenceScreen) findPreference(LOCAL_BACKUP_PASSWORD);
329 mAllPrefs.add(mPassword);
332 if (!android.os.Process.myUserHandle().equals(UserHandle.OWNER)) {
333 disableForUser(mEnableAdb);
334 disableForUser(mClearAdbKeys);
335 disableForUser(mEnableTerminal);
336 disableForUser(mPassword);
339 mDebugAppPref = findPreference(DEBUG_APP_KEY);
340 mAllPrefs.add(mDebugAppPref);
341 mWaitForDebugger = findAndInitSwitchPref(WAIT_FOR_DEBUGGER_KEY);
343 mMockLocationAppPref = findPreference(MOCK_LOCATION_APP_KEY);
344 mAllPrefs.add(mMockLocationAppPref);
346 mVerifyAppsOverUsb = findAndInitSwitchPref(VERIFY_APPS_OVER_USB_KEY);
347 if (!showVerifierSetting()) {
348 if (debugDebuggingCategory != null) {
349 debugDebuggingCategory.removePreference(mVerifyAppsOverUsb);
351 mVerifyAppsOverUsb.setEnabled(false);
354 mStrictMode = findAndInitSwitchPref(STRICT_MODE_KEY);
355 mPointerLocation = findAndInitSwitchPref(POINTER_LOCATION_KEY);
356 mShowTouches = findAndInitSwitchPref(SHOW_TOUCHES_KEY);
357 mShowScreenUpdates = findAndInitSwitchPref(SHOW_SCREEN_UPDATES_KEY);
358 mDisableOverlays = findAndInitSwitchPref(DISABLE_OVERLAYS_KEY);
359 mShowCpuUsage = findAndInitSwitchPref(SHOW_CPU_USAGE_KEY);
360 mForceHardwareUi = findAndInitSwitchPref(FORCE_HARDWARE_UI_KEY);
361 mForceMsaa = findAndInitSwitchPref(FORCE_MSAA_KEY);
362 mTrackFrameTime = addListPreference(TRACK_FRAME_TIME_KEY);
363 mShowNonRectClip = addListPreference(SHOW_NON_RECTANGULAR_CLIP_KEY);
364 mShowHwScreenUpdates = findAndInitSwitchPref(SHOW_HW_SCREEN_UPDATES_KEY);
365 mShowHwLayersUpdates = findAndInitSwitchPref(SHOW_HW_LAYERS_UPDATES_KEY);
366 mDebugLayout = findAndInitSwitchPref(DEBUG_LAYOUT_KEY);
367 mForceRtlLayout = findAndInitSwitchPref(FORCE_RTL_LAYOUT_KEY);
368 mDebugHwOverdraw = addListPreference(DEBUG_HW_OVERDRAW_KEY);
369 mWifiDisplayCertification = findAndInitSwitchPref(WIFI_DISPLAY_CERTIFICATION_KEY);
370 mWifiVerboseLogging = findAndInitSwitchPref(WIFI_VERBOSE_LOGGING_KEY);
371 mWifiAggressiveHandover = findAndInitSwitchPref(WIFI_AGGRESSIVE_HANDOVER_KEY);
372 mWifiAllowScansWithTraffic = findAndInitSwitchPref(WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY);
373 mLegacyDhcpClient = findAndInitSwitchPref(WIFI_LEGACY_DHCP_CLIENT_KEY);
374 mMobileDataAlwaysOn = findAndInitSwitchPref(MOBILE_DATA_ALWAYS_ON);
375 mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY);
376 mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY);
378 mWindowAnimationScale = addListPreference(WINDOW_ANIMATION_SCALE_KEY);
379 mTransitionAnimationScale = addListPreference(TRANSITION_ANIMATION_SCALE_KEY);
380 mAnimatorDurationScale = addListPreference(ANIMATOR_DURATION_SCALE_KEY);
381 mOverlayDisplayDevices = addListPreference(OVERLAY_DISPLAY_DEVICES_KEY);
382 mEnableMultiWindow = findAndInitSwitchPref(ENABLE_MULTI_WINDOW_KEY);
383 if (!showEnableMultiWindowPreference()) {
384 final PreferenceGroup drawingGroup =
385 (PreferenceGroup)findPreference("debug_drawing_category");
386 if (drawingGroup != null) {
387 drawingGroup.removePreference(mEnableMultiWindow);
389 mEnableMultiWindow.setEnabled(false);
391 removePreference(mEnableMultiWindow);
392 mEnableMultiWindow = null;
394 mOpenGLTraces = addListPreference(OPENGL_TRACES_KEY);
395 mSimulateColorSpace = addListPreference(SIMULATE_COLOR_SPACE);
396 mUSBAudio = findAndInitSwitchPref(USB_AUDIO_KEY);
398 mImmediatelyDestroyActivities = (SwitchPreference) findPreference(
399 IMMEDIATELY_DESTROY_ACTIVITIES_KEY);
400 mAllPrefs.add(mImmediatelyDestroyActivities);
401 mResetSwitchPrefs.add(mImmediatelyDestroyActivities);
403 mAppProcessLimit = addListPreference(APP_PROCESS_LIMIT_KEY);
405 mShowAllANRs = (SwitchPreference) findPreference(
407 mAllPrefs.add(mShowAllANRs);
408 mResetSwitchPrefs.add(mShowAllANRs);
410 mTunerUiPref = findAndInitSwitchPref(TUNER_UI_KEY);
412 Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY);
413 if (hdcpChecking != null) {
414 mAllPrefs.add(hdcpChecking);
415 removePreferenceForProduction(hdcpChecking);
419 private ListPreference addListPreference(String prefKey) {
420 ListPreference pref = (ListPreference) findPreference(prefKey);
422 pref.setOnPreferenceChangeListener(this);
426 private void disableForUser(Preference pref) {
428 pref.setEnabled(false);
429 mDisabledPrefs.add(pref);
433 private SwitchPreference findAndInitSwitchPref(String key) {
434 SwitchPreference pref = (SwitchPreference) findPreference(key);
436 throw new IllegalArgumentException("Cannot find preference with key = " + key);
439 mResetSwitchPrefs.add(pref);
444 public void onActivityCreated(Bundle savedInstanceState) {
445 super.onActivityCreated(savedInstanceState);
447 final SettingsActivity activity = (SettingsActivity) getActivity();
449 mSwitchBar = activity.getSwitchBar();
451 mSwitchBar.setEnabled(false);
455 mSwitchBar.addOnSwitchChangeListener(this);
458 private boolean removePreferenceForProduction(Preference preference) {
459 if ("user".equals(Build.TYPE)) {
460 removePreference(preference);
466 private void removePreference(Preference preference) {
467 getPreferenceScreen().removePreference(preference);
468 mAllPrefs.remove(preference);
469 mResetSwitchPrefs.remove(preference);
472 private void setPrefsEnabledState(boolean enabled) {
473 for (int i = 0; i < mAllPrefs.size(); i++) {
474 Preference pref = mAllPrefs.get(i);
475 pref.setEnabled(enabled && !mDisabledPrefs.contains(pref));
481 public void onResume() {
485 // Show error message
486 TextView emptyView = (TextView) getView().findViewById(android.R.id.empty);
487 getListView().setEmptyView(emptyView);
488 if (emptyView != null) {
489 emptyView.setText(R.string.development_settings_not_available);
494 if (mDpm.getMaximumTimeToLock(null) > 0) {
495 // A DeviceAdmin has specified a maximum time until the device
496 // will lock... in this case we can't allow the user to turn
497 // on "stay awake when plugged in" because that would defeat the
499 mDisabledPrefs.add(mKeepScreenOn);
501 mDisabledPrefs.remove(mKeepScreenOn);
504 final ContentResolver cr = getActivity().getContentResolver();
505 mLastEnabledState = Settings.Global.getInt(cr,
506 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
507 mSwitchBar.setChecked(mLastEnabledState);
508 setPrefsEnabledState(mLastEnabledState);
510 if (mHaveDebugSettings && !mLastEnabledState) {
511 // Overall debugging is disabled, but there are some debug
512 // settings that are enabled. This is an invalid state. Switch
513 // to debug settings being enabled, so the user knows there is
514 // stuff enabled and can turn it all off if they want.
515 Settings.Global.putInt(getActivity().getContentResolver(),
516 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
517 mLastEnabledState = true;
518 mSwitchBar.setChecked(mLastEnabledState);
519 setPrefsEnabledState(mLastEnabledState);
525 public View onCreateView(LayoutInflater inflater, ViewGroup container,
526 Bundle savedInstanceState) {
527 IntentFilter filter = new IntentFilter();
528 filter.addAction(UsbManager.ACTION_USB_STATE);
529 getActivity().registerReceiver(mUsbReceiver, filter);
530 return super.onCreateView(inflater, container, savedInstanceState);
534 public void onDestroyView() {
535 super.onDestroyView();
540 mSwitchBar.removeOnSwitchChangeListener(this);
542 getActivity().unregisterReceiver(mUsbReceiver);
545 void updateSwitchPreference(SwitchPreference switchPreference, boolean value) {
546 switchPreference.setChecked(value);
547 mHaveDebugSettings |= value;
550 private void updateAllOptions() {
551 final Context context = getActivity();
552 final ContentResolver cr = context.getContentResolver();
553 mHaveDebugSettings = false;
554 updateSwitchPreference(mEnableAdb, Settings.Global.getInt(cr,
555 Settings.Global.ADB_ENABLED, 0) != 0);
556 if (mEnableTerminal != null) {
557 updateSwitchPreference(mEnableTerminal,
558 context.getPackageManager().getApplicationEnabledSetting(TERMINAL_APP_PACKAGE)
559 == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
561 updateSwitchPreference(mBugreportInPower, Settings.Secure.getInt(cr,
562 Settings.Secure.BUGREPORT_IN_POWER_MENU, 0) != 0);
563 updateSwitchPreference(mKeepScreenOn, Settings.Global.getInt(cr,
564 Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
565 updateSwitchPreference(mBtHciSnoopLog, Settings.Secure.getInt(cr,
566 Settings.Secure.BLUETOOTH_HCI_LOG, 0) != 0);
567 if (mEnableOemUnlock != null) {
568 updateSwitchPreference(mEnableOemUnlock, Utils.isOemUnlockEnabled(getActivity()));
570 updateSwitchPreference(mDebugViewAttributes, Settings.Global.getInt(cr,
571 Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0);
573 updatePasswordSummary();
574 updateDebuggerOptions();
575 updateMockLocation();
576 updateStrictModeVisualOptions();
577 updatePointerLocationOptions();
578 updateShowTouchesOptions();
579 updateFlingerOptions();
580 updateCpuUsageOptions();
581 updateHardwareUiOptions();
583 updateTrackFrameTimeOptions();
584 updateShowNonRectClipOptions();
585 updateShowHwScreenUpdatesOptions();
586 updateShowHwLayersUpdatesOptions();
587 updateDebugHwOverdrawOptions();
588 updateDebugLayoutOptions();
589 updateAnimationScaleOptions();
590 updateOverlayDisplayDevicesOptions();
591 if (mEnableMultiWindow != null) {
592 updateSwitchPreference(mEnableMultiWindow,
593 SystemProperties.getBoolean(MULTI_WINDOW_SYSTEM_PROPERTY, false));
595 updateOpenGLTracesOptions();
596 updateImmediatelyDestroyActivitiesOptions();
597 updateAppProcessLimitOptions();
598 updateShowAllANRsOptions();
599 updateVerifyAppsOverUsbOptions();
600 updateBugreportOptions();
601 updateForceRtlOptions();
602 updateLogdSizeValues();
603 updateWifiDisplayCertificationOptions();
604 updateWifiVerboseLoggingOptions();
605 updateWifiAggressiveHandoverOptions();
606 updateWifiAllowScansWithTrafficOptions();
607 updateLegacyDhcpClientOptions();
608 updateMobileDataAlwaysOnOptions();
609 updateSimulateColorSpace();
610 updateUSBAudioOptions();
614 private void resetDangerousOptions() {
615 mDontPokeProperties = true;
616 for (int i=0; i< mResetSwitchPrefs.size(); i++) {
617 SwitchPreference cb = mResetSwitchPrefs.get(i);
618 if (cb.isChecked()) {
619 cb.setChecked(false);
620 onPreferenceTreeClick(null, cb);
623 resetDebuggerOptions();
624 writeLogdSizeOption(null);
625 writeAnimationScaleOption(0, mWindowAnimationScale, null);
626 writeAnimationScaleOption(1, mTransitionAnimationScale, null);
627 writeAnimationScaleOption(2, mAnimatorDurationScale, null);
628 // Only poke the color space setting if we control it.
629 if (usingDevelopmentColorSpace()) {
630 writeSimulateColorSpace(-1);
632 writeOverlayDisplayDevicesOptions(null);
633 writeAppProcessLimitOptions(null);
634 mHaveDebugSettings = false;
636 mDontPokeProperties = false;
637 pokeSystemProperties();
640 private void updateHdcpValues() {
641 ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
642 if (hdcpChecking != null) {
643 String currentValue = SystemProperties.get(HDCP_CHECKING_PROPERTY);
644 String[] values = getResources().getStringArray(R.array.hdcp_checking_values);
645 String[] summaries = getResources().getStringArray(R.array.hdcp_checking_summaries);
646 int index = 1; // Defaults to drm-only. Needs to match with R.array.hdcp_checking_values
647 for (int i = 0; i < values.length; i++) {
648 if (currentValue.equals(values[i])) {
653 hdcpChecking.setValue(values[index]);
654 hdcpChecking.setSummary(summaries[index]);
655 hdcpChecking.setOnPreferenceChangeListener(this);
659 private void updatePasswordSummary() {
661 if (mBackupManager.hasBackupPassword()) {
662 mPassword.setSummary(R.string.local_backup_password_summary_change);
664 mPassword.setSummary(R.string.local_backup_password_summary_none);
666 } catch (RemoteException e) {
667 // Not much we can do here
671 private void writeBtHciSnoopLogOptions() {
672 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
673 adapter.configHciSnoopLog(mBtHciSnoopLog.isChecked());
674 Settings.Secure.putInt(getActivity().getContentResolver(),
675 Settings.Secure.BLUETOOTH_HCI_LOG,
676 mBtHciSnoopLog.isChecked() ? 1 : 0);
679 private void writeDebuggerOptions() {
681 ActivityManagerNative.getDefault().setDebugApp(
682 mDebugApp, mWaitForDebugger.isChecked(), true);
683 } catch (RemoteException ex) {
687 private void writeMockLocation() {
688 AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
690 // Disable the app op of the previous mock location app if such.
691 List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
692 if (packageOps != null) {
693 // Should be one but in case we are in a bad state due to use of command line tools.
694 for (PackageOps packageOp : packageOps) {
695 if (packageOp.getOps().get(0).getMode() != AppOpsManager.MODE_ERRORED) {
696 String oldMockLocationApp = packageOp.getPackageName();
698 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
699 oldMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
700 appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid,
701 oldMockLocationApp, AppOpsManager.MODE_ERRORED);
702 } catch (NameNotFoundException e) {
709 // Enable the app op of the new mock location app if such.
710 if (!TextUtils.isEmpty(mMockLocationApp)) {
712 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
713 mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
714 appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid,
715 mMockLocationApp, AppOpsManager.MODE_ALLOWED);
716 } catch (NameNotFoundException e) {
722 private static void resetDebuggerOptions() {
724 ActivityManagerNative.getDefault().setDebugApp(
726 } catch (RemoteException ex) {
730 private void updateDebuggerOptions() {
731 mDebugApp = Settings.Global.getString(
732 getActivity().getContentResolver(), Settings.Global.DEBUG_APP);
733 updateSwitchPreference(mWaitForDebugger, Settings.Global.getInt(
734 getActivity().getContentResolver(), Settings.Global.WAIT_FOR_DEBUGGER, 0) != 0);
735 if (mDebugApp != null && mDebugApp.length() > 0) {
738 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mDebugApp,
739 PackageManager.GET_DISABLED_COMPONENTS);
740 CharSequence lab = getActivity().getPackageManager().getApplicationLabel(ai);
741 label = lab != null ? lab.toString() : mDebugApp;
742 } catch (PackageManager.NameNotFoundException e) {
745 mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_set, label));
746 mWaitForDebugger.setEnabled(true);
747 mHaveDebugSettings = true;
749 mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_not_set));
750 mWaitForDebugger.setEnabled(false);
754 private void updateMockLocation() {
755 AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
757 List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
758 if (packageOps != null) {
759 for (PackageOps packageOp : packageOps) {
760 if (packageOp.getOps().get(0).getMode() == AppOpsManager.MODE_ALLOWED) {
761 mMockLocationApp = packageOps.get(0).getPackageName();
767 if (!TextUtils.isEmpty(mMockLocationApp)) {
768 String label = mMockLocationApp;
770 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
771 mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
772 CharSequence appLabel = getPackageManager().getApplicationLabel(ai);
773 if (appLabel != null) {
774 label = appLabel.toString();
776 } catch (PackageManager.NameNotFoundException e) {
780 mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_set, label));
781 mHaveDebugSettings = true;
783 mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_not_set));
787 private void updateVerifyAppsOverUsbOptions() {
788 updateSwitchPreference(mVerifyAppsOverUsb, Settings.Global.getInt(getActivity().getContentResolver(),
789 Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0);
790 mVerifyAppsOverUsb.setEnabled(enableVerifierSetting());
793 private void writeVerifyAppsOverUsbOptions() {
794 Settings.Global.putInt(getActivity().getContentResolver(),
795 Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, mVerifyAppsOverUsb.isChecked() ? 1 : 0);
798 private boolean enableVerifierSetting() {
799 final ContentResolver cr = getActivity().getContentResolver();
800 if (Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, 0) == 0) {
803 if (Settings.Global.getInt(cr, Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) == 0) {
806 final PackageManager pm = getActivity().getPackageManager();
807 final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
808 verification.setType(PACKAGE_MIME_TYPE);
809 verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
810 final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(verification, 0);
811 if (receivers.size() == 0) {
818 private boolean showVerifierSetting() {
819 return Settings.Global.getInt(getActivity().getContentResolver(),
820 Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0;
823 private static boolean showEnableOemUnlockPreference() {
824 return !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("");
827 private static boolean showEnableMultiWindowPreference() {
828 return !"user".equals(Build.TYPE);
831 private void setEnableMultiWindow(boolean value) {
832 SystemProperties.set(MULTI_WINDOW_SYSTEM_PROPERTY, String.valueOf(value));
833 pokeSystemProperties();
836 private void updateBugreportOptions() {
837 final ComponentName bugreportStorageProviderComponentName =
838 new ComponentName("com.android.shell",
839 "com.android.shell.BugreportStorageProvider");
840 if ("user".equals(Build.TYPE)) {
841 final ContentResolver resolver = getActivity().getContentResolver();
842 final boolean adbEnabled = Settings.Global.getInt(
843 resolver, Settings.Global.ADB_ENABLED, 0) != 0;
845 mBugreport.setEnabled(true);
846 mBugreportInPower.setEnabled(true);
847 getPackageManager().setComponentEnabledSetting(
848 bugreportStorageProviderComponentName,
849 PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
851 mBugreport.setEnabled(false);
852 mBugreportInPower.setEnabled(false);
853 mBugreportInPower.setChecked(false);
854 Settings.Secure.putInt(resolver, Settings.Secure.BUGREPORT_IN_POWER_MENU, 0);
855 getPackageManager().setComponentEnabledSetting(
856 bugreportStorageProviderComponentName,
857 PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
860 mBugreportInPower.setEnabled(true);
861 getPackageManager().setComponentEnabledSetting(
862 bugreportStorageProviderComponentName,
863 PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
867 // Returns the current state of the system property that controls
868 // strictmode flashes. One of:
869 // 0: not explicitly set one way or another
872 private static int currentStrictModeActiveIndex() {
873 if (TextUtils.isEmpty(SystemProperties.get(StrictMode.VISUAL_PROPERTY))) {
876 boolean enabled = SystemProperties.getBoolean(StrictMode.VISUAL_PROPERTY, false);
877 return enabled ? 1 : 2;
880 private void writeStrictModeVisualOptions() {
882 mWindowManager.setStrictModeVisualIndicatorPreference(mStrictMode.isChecked()
884 } catch (RemoteException e) {
888 private void updateStrictModeVisualOptions() {
889 updateSwitchPreference(mStrictMode, currentStrictModeActiveIndex() == 1);
892 private void writePointerLocationOptions() {
893 Settings.System.putInt(getActivity().getContentResolver(),
894 Settings.System.POINTER_LOCATION, mPointerLocation.isChecked() ? 1 : 0);
897 private void updatePointerLocationOptions() {
898 updateSwitchPreference(mPointerLocation,
899 Settings.System.getInt(getActivity().getContentResolver(),
900 Settings.System.POINTER_LOCATION, 0) != 0);
903 private void writeShowTouchesOptions() {
904 Settings.System.putInt(getActivity().getContentResolver(),
905 Settings.System.SHOW_TOUCHES, mShowTouches.isChecked() ? 1 : 0);
908 private void updateShowTouchesOptions() {
909 updateSwitchPreference(mShowTouches,
910 Settings.System.getInt(getActivity().getContentResolver(),
911 Settings.System.SHOW_TOUCHES, 0) != 0);
914 private void updateFlingerOptions() {
915 // magic communication with surface flinger.
917 IBinder flinger = ServiceManager.getService("SurfaceFlinger");
918 if (flinger != null) {
919 Parcel data = Parcel.obtain();
920 Parcel reply = Parcel.obtain();
921 data.writeInterfaceToken("android.ui.ISurfaceComposer");
922 flinger.transact(1010, data, reply, 0);
923 @SuppressWarnings("unused")
924 int showCpu = reply.readInt();
925 @SuppressWarnings("unused")
926 int enableGL = reply.readInt();
927 int showUpdates = reply.readInt();
928 updateSwitchPreference(mShowScreenUpdates, showUpdates != 0);
929 @SuppressWarnings("unused")
930 int showBackground = reply.readInt();
931 int disableOverlays = reply.readInt();
932 updateSwitchPreference(mDisableOverlays, disableOverlays != 0);
936 } catch (RemoteException ex) {
940 private void writeShowUpdatesOption() {
942 IBinder flinger = ServiceManager.getService("SurfaceFlinger");
943 if (flinger != null) {
944 Parcel data = Parcel.obtain();
945 data.writeInterfaceToken("android.ui.ISurfaceComposer");
946 final int showUpdates = mShowScreenUpdates.isChecked() ? 1 : 0;
947 data.writeInt(showUpdates);
948 flinger.transact(1002, data, null, 0);
951 updateFlingerOptions();
953 } catch (RemoteException ex) {
957 private void writeDisableOverlaysOption() {
959 IBinder flinger = ServiceManager.getService("SurfaceFlinger");
960 if (flinger != null) {
961 Parcel data = Parcel.obtain();
962 data.writeInterfaceToken("android.ui.ISurfaceComposer");
963 final int disableOverlays = mDisableOverlays.isChecked() ? 1 : 0;
964 data.writeInt(disableOverlays);
965 flinger.transact(1008, data, null, 0);
968 updateFlingerOptions();
970 } catch (RemoteException ex) {
974 private void updateHardwareUiOptions() {
975 updateSwitchPreference(mForceHardwareUi, SystemProperties.getBoolean(HARDWARE_UI_PROPERTY, false));
978 private void writeHardwareUiOptions() {
979 SystemProperties.set(HARDWARE_UI_PROPERTY, mForceHardwareUi.isChecked() ? "true" : "false");
980 pokeSystemProperties();
983 private void updateMsaaOptions() {
984 updateSwitchPreference(mForceMsaa, SystemProperties.getBoolean(MSAA_PROPERTY, false));
987 private void writeMsaaOptions() {
988 SystemProperties.set(MSAA_PROPERTY, mForceMsaa.isChecked() ? "true" : "false");
989 pokeSystemProperties();
992 private void updateTrackFrameTimeOptions() {
993 String value = SystemProperties.get(HardwareRenderer.PROFILE_PROPERTY);
998 CharSequence[] values = mTrackFrameTime.getEntryValues();
999 for (int i = 0; i < values.length; i++) {
1000 if (value.contentEquals(values[i])) {
1001 mTrackFrameTime.setValueIndex(i);
1002 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[i]);
1006 mTrackFrameTime.setValueIndex(0);
1007 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[0]);
1010 private void writeTrackFrameTimeOptions(Object newValue) {
1011 SystemProperties.set(HardwareRenderer.PROFILE_PROPERTY,
1012 newValue == null ? "" : newValue.toString());
1013 pokeSystemProperties();
1014 updateTrackFrameTimeOptions();
1017 private void updateShowNonRectClipOptions() {
1018 String value = SystemProperties.get(
1019 HardwareRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY);
1020 if (value == null) {
1024 CharSequence[] values = mShowNonRectClip.getEntryValues();
1025 for (int i = 0; i < values.length; i++) {
1026 if (value.contentEquals(values[i])) {
1027 mShowNonRectClip.setValueIndex(i);
1028 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[i]);
1032 mShowNonRectClip.setValueIndex(0);
1033 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[0]);
1036 private void writeShowNonRectClipOptions(Object newValue) {
1037 SystemProperties.set(HardwareRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY,
1038 newValue == null ? "" : newValue.toString());
1039 pokeSystemProperties();
1040 updateShowNonRectClipOptions();
1043 private void updateShowHwScreenUpdatesOptions() {
1044 updateSwitchPreference(mShowHwScreenUpdates,
1045 SystemProperties.getBoolean(HardwareRenderer.DEBUG_DIRTY_REGIONS_PROPERTY, false));
1048 private void writeShowHwScreenUpdatesOptions() {
1049 SystemProperties.set(HardwareRenderer.DEBUG_DIRTY_REGIONS_PROPERTY,
1050 mShowHwScreenUpdates.isChecked() ? "true" : null);
1051 pokeSystemProperties();
1054 private void updateShowHwLayersUpdatesOptions() {
1055 updateSwitchPreference(mShowHwLayersUpdates, SystemProperties.getBoolean(
1056 HardwareRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY, false));
1059 private void writeShowHwLayersUpdatesOptions() {
1060 SystemProperties.set(HardwareRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY,
1061 mShowHwLayersUpdates.isChecked() ? "true" : null);
1062 pokeSystemProperties();
1065 private void updateDebugHwOverdrawOptions() {
1066 String value = SystemProperties.get(HardwareRenderer.DEBUG_OVERDRAW_PROPERTY);
1067 if (value == null) {
1071 CharSequence[] values = mDebugHwOverdraw.getEntryValues();
1072 for (int i = 0; i < values.length; i++) {
1073 if (value.contentEquals(values[i])) {
1074 mDebugHwOverdraw.setValueIndex(i);
1075 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[i]);
1079 mDebugHwOverdraw.setValueIndex(0);
1080 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[0]);
1083 private void writeDebugHwOverdrawOptions(Object newValue) {
1084 SystemProperties.set(HardwareRenderer.DEBUG_OVERDRAW_PROPERTY,
1085 newValue == null ? "" : newValue.toString());
1086 pokeSystemProperties();
1087 updateDebugHwOverdrawOptions();
1090 private void updateDebugLayoutOptions() {
1091 updateSwitchPreference(mDebugLayout,
1092 SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false));
1095 private void writeDebugLayoutOptions() {
1096 SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY,
1097 mDebugLayout.isChecked() ? "true" : "false");
1098 pokeSystemProperties();
1101 private void updateSimulateColorSpace() {
1102 final ContentResolver cr = getContentResolver();
1103 final boolean enabled = Settings.Secure.getInt(
1104 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0;
1106 final String mode = Integer.toString(Settings.Secure.getInt(
1107 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
1108 AccessibilityManager.DALTONIZER_DISABLED));
1109 mSimulateColorSpace.setValue(mode);
1110 final int index = mSimulateColorSpace.findIndexOfValue(mode);
1112 // We're using a mode controlled by accessibility preferences.
1113 mSimulateColorSpace.setSummary(getString(R.string.daltonizer_type_overridden,
1114 getString(R.string.accessibility_display_daltonizer_preference_title)));
1116 mSimulateColorSpace.setSummary("%s");
1119 mSimulateColorSpace.setValue(
1120 Integer.toString(AccessibilityManager.DALTONIZER_DISABLED));
1125 * @return <code>true</code> if the color space preference is currently
1126 * controlled by development settings
1128 private boolean usingDevelopmentColorSpace() {
1129 final ContentResolver cr = getContentResolver();
1130 final boolean enabled = Settings.Secure.getInt(
1131 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0;
1133 final String mode = Integer.toString(Settings.Secure.getInt(
1134 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
1135 AccessibilityManager.DALTONIZER_DISABLED));
1136 final int index = mSimulateColorSpace.findIndexOfValue(mode);
1138 // We're using a mode controlled by developer preferences.
1145 private void writeSimulateColorSpace(Object value) {
1146 final ContentResolver cr = getContentResolver();
1147 final int newMode = Integer.parseInt(value.toString());
1149 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0);
1151 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 1);
1152 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, newMode);
1156 private void updateTweakUi() {
1157 updateSwitchPreference(mTunerUiPref, getActivity().getPackageManager()
1158 .getComponentEnabledSetting(SYSUI_TUNER)
1159 == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
1160 mTunerUiPref.setOnPreferenceChangeListener(this);
1163 private void writeTweakUi(Object newValue) {
1164 Boolean enabled = (Boolean) newValue;
1165 getActivity().getPackageManager().setComponentEnabledSetting(SYSUI_TUNER,
1166 enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1167 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1168 PackageManager.DONT_KILL_APP);
1171 private void updateUSBAudioOptions() {
1172 updateSwitchPreference(mUSBAudio, Settings.Secure.getInt(getContentResolver(),
1173 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 0) != 0);
1176 private void writeUSBAudioOptions() {
1177 Settings.Secure.putInt(getContentResolver(),
1178 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED,
1179 mUSBAudio.isChecked() ? 1 : 0);
1182 private void updateForceRtlOptions() {
1183 updateSwitchPreference(mForceRtlLayout,
1184 Settings.Global.getInt(getActivity().getContentResolver(),
1185 Settings.Global.DEVELOPMENT_FORCE_RTL, 0) != 0);
1188 private void writeForceRtlOptions() {
1189 boolean value = mForceRtlLayout.isChecked();
1190 Settings.Global.putInt(getActivity().getContentResolver(),
1191 Settings.Global.DEVELOPMENT_FORCE_RTL, value ? 1 : 0);
1192 SystemProperties.set(Settings.Global.DEVELOPMENT_FORCE_RTL, value ? "1" : "0");
1193 LocalePicker.updateLocale(getActivity().getResources().getConfiguration().locale);
1196 private void updateWifiDisplayCertificationOptions() {
1197 updateSwitchPreference(mWifiDisplayCertification, Settings.Global.getInt(
1198 getActivity().getContentResolver(),
1199 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, 0) != 0);
1202 private void writeWifiDisplayCertificationOptions() {
1203 Settings.Global.putInt(getActivity().getContentResolver(),
1204 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON,
1205 mWifiDisplayCertification.isChecked() ? 1 : 0);
1208 private void updateWifiVerboseLoggingOptions() {
1209 boolean enabled = mWifiManager.getVerboseLoggingLevel() > 0;
1210 updateSwitchPreference(mWifiVerboseLogging, enabled);
1213 private void writeWifiVerboseLoggingOptions() {
1214 mWifiManager.enableVerboseLogging(mWifiVerboseLogging.isChecked() ? 1 : 0);
1217 private void updateWifiAggressiveHandoverOptions() {
1218 boolean enabled = mWifiManager.getAggressiveHandover() > 0;
1219 updateSwitchPreference(mWifiAggressiveHandover, enabled);
1222 private void writeWifiAggressiveHandoverOptions() {
1223 mWifiManager.enableAggressiveHandover(mWifiAggressiveHandover.isChecked() ? 1 : 0);
1226 private void updateWifiAllowScansWithTrafficOptions() {
1227 boolean enabled = mWifiManager.getAllowScansWithTraffic() > 0;
1228 updateSwitchPreference(mWifiAllowScansWithTraffic, enabled);
1231 private void writeWifiAllowScansWithTrafficOptions() {
1232 mWifiManager.setAllowScansWithTraffic(mWifiAllowScansWithTraffic.isChecked() ? 1 : 0);
1235 private void updateLegacyDhcpClientOptions() {
1236 updateSwitchPreference(mLegacyDhcpClient, Settings.Global.getInt(
1237 getActivity().getContentResolver(),
1238 Settings.Global.LEGACY_DHCP_CLIENT, 0) != 0);
1241 private void writeLegacyDhcpClientOptions() {
1242 Settings.Global.putInt(getActivity().getContentResolver(),
1243 Settings.Global.LEGACY_DHCP_CLIENT,
1244 mLegacyDhcpClient.isChecked() ? 1 : 0);
1247 private void updateMobileDataAlwaysOnOptions() {
1248 updateSwitchPreference(mMobileDataAlwaysOn, Settings.Global.getInt(
1249 getActivity().getContentResolver(),
1250 Settings.Global.MOBILE_DATA_ALWAYS_ON, 0) != 0);
1253 private void writeMobileDataAlwaysOnOptions() {
1254 Settings.Global.putInt(getActivity().getContentResolver(),
1255 Settings.Global.MOBILE_DATA_ALWAYS_ON,
1256 mMobileDataAlwaysOn.isChecked() ? 1 : 0);
1259 private void updateLogdSizeValues() {
1260 if (mLogdSize != null) {
1261 String currentValue = SystemProperties.get(SELECT_LOGD_SIZE_PROPERTY);
1262 if (currentValue == null) {
1263 currentValue = SystemProperties.get(SELECT_LOGD_DEFAULT_SIZE_PROPERTY);
1264 if (currentValue == null) {
1265 currentValue = "256K";
1268 String[] values = getResources().getStringArray(R.array.select_logd_size_values);
1269 String[] titles = getResources().getStringArray(R.array.select_logd_size_titles);
1270 if (SystemProperties.get("ro.config.low_ram").equals("true")) {
1271 mLogdSize.setEntries(R.array.select_logd_size_lowram_titles);
1272 titles = getResources().getStringArray(R.array.select_logd_size_lowram_titles);
1274 String[] summaries = getResources().getStringArray(R.array.select_logd_size_summaries);
1275 int index = 1; // punt to second entry if not found
1276 for (int i = 0; i < titles.length; i++) {
1277 if (currentValue.equals(values[i])
1278 || currentValue.equals(titles[i])) {
1283 mLogdSize.setValue(values[index]);
1284 mLogdSize.setSummary(summaries[index]);
1285 mLogdSize.setOnPreferenceChangeListener(this);
1289 private void writeLogdSizeOption(Object newValue) {
1290 String currentValue = SystemProperties.get(SELECT_LOGD_DEFAULT_SIZE_PROPERTY);
1291 if (currentValue != null) {
1292 DEFAULT_LOG_RING_BUFFER_SIZE_IN_BYTES = currentValue;
1294 final String size = (newValue != null) ?
1295 newValue.toString() : DEFAULT_LOG_RING_BUFFER_SIZE_IN_BYTES;
1296 SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, size);
1297 pokeSystemProperties();
1299 Process p = Runtime.getRuntime().exec("logcat -b all -G " + size);
1301 Log.i(TAG, "Logcat ring buffer sizes set to: " + size);
1302 } catch (Exception e) {
1303 Log.w(TAG, "Cannot set logcat ring buffer sizes", e);
1305 updateLogdSizeValues();
1308 private void updateUsbConfigurationValues() {
1309 if (mUsbConfiguration != null) {
1310 UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
1312 String[] values = getResources().getStringArray(R.array.usb_configuration_values);
1313 String[] titles = getResources().getStringArray(R.array.usb_configuration_titles);
1315 for (int i = 0; i < titles.length; i++) {
1316 if (manager.isFunctionEnabled(values[i])) {
1321 mUsbConfiguration.setValue(values[index]);
1322 mUsbConfiguration.setSummary(titles[index]);
1323 mUsbConfiguration.setOnPreferenceChangeListener(this);
1327 private void writeUsbConfigurationOption(Object newValue) {
1328 UsbManager manager = (UsbManager)getActivity().getSystemService(Context.USB_SERVICE);
1329 manager.setCurrentFunction(newValue.toString());
1332 private void updateCpuUsageOptions() {
1333 updateSwitchPreference(mShowCpuUsage,
1334 Settings.Global.getInt(getActivity().getContentResolver(),
1335 Settings.Global.SHOW_PROCESSES, 0) != 0);
1338 private void writeCpuUsageOptions() {
1339 boolean value = mShowCpuUsage.isChecked();
1340 Settings.Global.putInt(getActivity().getContentResolver(),
1341 Settings.Global.SHOW_PROCESSES, value ? 1 : 0);
1342 Intent service = (new Intent())
1343 .setClassName("com.android.systemui", "com.android.systemui.LoadAverageService");
1345 getActivity().startService(service);
1347 getActivity().stopService(service);
1351 private void writeImmediatelyDestroyActivitiesOptions() {
1353 ActivityManagerNative.getDefault().setAlwaysFinish(
1354 mImmediatelyDestroyActivities.isChecked());
1355 } catch (RemoteException ex) {
1359 private void updateImmediatelyDestroyActivitiesOptions() {
1360 updateSwitchPreference(mImmediatelyDestroyActivities, Settings.Global.getInt(
1361 getActivity().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) != 0);
1364 private void updateAnimationScaleValue(int which, ListPreference pref) {
1366 float scale = mWindowManager.getAnimationScale(which);
1368 mHaveDebugSettings = true;
1370 CharSequence[] values = pref.getEntryValues();
1371 for (int i=0; i<values.length; i++) {
1372 float val = Float.parseFloat(values[i].toString());
1374 pref.setValueIndex(i);
1375 pref.setSummary(pref.getEntries()[i]);
1379 pref.setValueIndex(values.length-1);
1380 pref.setSummary(pref.getEntries()[0]);
1381 } catch (RemoteException e) {
1385 private void updateAnimationScaleOptions() {
1386 updateAnimationScaleValue(0, mWindowAnimationScale);
1387 updateAnimationScaleValue(1, mTransitionAnimationScale);
1388 updateAnimationScaleValue(2, mAnimatorDurationScale);
1391 private void writeAnimationScaleOption(int which, ListPreference pref, Object newValue) {
1393 float scale = newValue != null ? Float.parseFloat(newValue.toString()) : 1;
1394 mWindowManager.setAnimationScale(which, scale);
1395 updateAnimationScaleValue(which, pref);
1396 } catch (RemoteException e) {
1400 private void updateOverlayDisplayDevicesOptions() {
1401 String value = Settings.Global.getString(getActivity().getContentResolver(),
1402 Settings.Global.OVERLAY_DISPLAY_DEVICES);
1403 if (value == null) {
1407 CharSequence[] values = mOverlayDisplayDevices.getEntryValues();
1408 for (int i = 0; i < values.length; i++) {
1409 if (value.contentEquals(values[i])) {
1410 mOverlayDisplayDevices.setValueIndex(i);
1411 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[i]);
1415 mOverlayDisplayDevices.setValueIndex(0);
1416 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[0]);
1419 private void writeOverlayDisplayDevicesOptions(Object newValue) {
1420 Settings.Global.putString(getActivity().getContentResolver(),
1421 Settings.Global.OVERLAY_DISPLAY_DEVICES, (String)newValue);
1422 updateOverlayDisplayDevicesOptions();
1425 private void updateOpenGLTracesOptions() {
1426 String value = SystemProperties.get(OPENGL_TRACES_PROPERTY);
1427 if (value == null) {
1431 CharSequence[] values = mOpenGLTraces.getEntryValues();
1432 for (int i = 0; i < values.length; i++) {
1433 if (value.contentEquals(values[i])) {
1434 mOpenGLTraces.setValueIndex(i);
1435 mOpenGLTraces.setSummary(mOpenGLTraces.getEntries()[i]);
1439 mOpenGLTraces.setValueIndex(0);
1440 mOpenGLTraces.setSummary(mOpenGLTraces.getEntries()[0]);
1443 private void writeOpenGLTracesOptions(Object newValue) {
1444 SystemProperties.set(OPENGL_TRACES_PROPERTY, newValue == null ? "" : newValue.toString());
1445 pokeSystemProperties();
1446 updateOpenGLTracesOptions();
1449 private void updateAppProcessLimitOptions() {
1451 int limit = ActivityManagerNative.getDefault().getProcessLimit();
1452 CharSequence[] values = mAppProcessLimit.getEntryValues();
1453 for (int i=0; i<values.length; i++) {
1454 int val = Integer.parseInt(values[i].toString());
1457 mHaveDebugSettings = true;
1459 mAppProcessLimit.setValueIndex(i);
1460 mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[i]);
1464 mAppProcessLimit.setValueIndex(0);
1465 mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[0]);
1466 } catch (RemoteException e) {
1470 private void writeAppProcessLimitOptions(Object newValue) {
1472 int limit = newValue != null ? Integer.parseInt(newValue.toString()) : -1;
1473 ActivityManagerNative.getDefault().setProcessLimit(limit);
1474 updateAppProcessLimitOptions();
1475 } catch (RemoteException e) {
1479 private void writeShowAllANRsOptions() {
1480 Settings.Secure.putInt(getActivity().getContentResolver(),
1481 Settings.Secure.ANR_SHOW_BACKGROUND,
1482 mShowAllANRs.isChecked() ? 1 : 0);
1485 private void updateShowAllANRsOptions() {
1486 updateSwitchPreference(mShowAllANRs, Settings.Secure.getInt(
1487 getActivity().getContentResolver(), Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0);
1490 private void confirmEnableOemUnlock() {
1491 DialogInterface.OnClickListener onConfirmListener = new DialogInterface.OnClickListener() {
1493 public void onClick(DialogInterface dialog, int which) {
1494 Utils.setOemUnlockEnabled(getActivity(), true);
1499 new AlertDialog.Builder(getActivity())
1500 .setTitle(R.string.confirm_enable_oem_unlock_title)
1501 .setMessage(R.string.confirm_enable_oem_unlock_text)
1502 .setPositiveButton(R.string.enable_text, onConfirmListener)
1503 .setNegativeButton(android.R.string.cancel, null)
1508 private void confirmEnableMultiWindowMode() {
1509 DialogInterface.OnClickListener onConfirmListener = new DialogInterface.OnClickListener() {
1511 public void onClick(DialogInterface dialog, int which) {
1512 setEnableMultiWindow((which == DialogInterface.BUTTON_POSITIVE) ? true : false);
1517 new AlertDialog.Builder(getActivity())
1518 .setTitle(R.string.confirm_enable_multi_window_title)
1519 .setMessage(R.string.confirm_enable_multi_window_text)
1520 .setPositiveButton(R.string.enable_text, onConfirmListener)
1521 .setNegativeButton(android.R.string.cancel, onConfirmListener)
1527 public void onSwitchChanged(Switch switchView, boolean isChecked) {
1528 if (switchView != mSwitchBar.getSwitch()) {
1531 if (isChecked != mLastEnabledState) {
1533 mDialogClicked = false;
1534 if (mEnableDialog != null) dismissDialogs();
1535 mEnableDialog = new AlertDialog.Builder(getActivity()).setMessage(
1536 getActivity().getResources().getString(
1537 R.string.dev_settings_warning_message))
1538 .setTitle(R.string.dev_settings_warning_title)
1539 .setPositiveButton(android.R.string.yes, this)
1540 .setNegativeButton(android.R.string.no, this)
1542 mEnableDialog.setOnDismissListener(this);
1544 resetDangerousOptions();
1545 Settings.Global.putInt(getActivity().getContentResolver(),
1546 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
1547 mLastEnabledState = isChecked;
1548 setPrefsEnabledState(mLastEnabledState);
1554 public void onActivityResult(int requestCode, int resultCode, Intent data) {
1555 if (requestCode == RESULT_DEBUG_APP) {
1556 if (resultCode == Activity.RESULT_OK) {
1557 mDebugApp = data.getAction();
1558 writeDebuggerOptions();
1559 updateDebuggerOptions();
1561 } else if (requestCode == RESULT_MOCK_LOCATION_APP) {
1562 if (resultCode == Activity.RESULT_OK) {
1563 mMockLocationApp = data.getAction();
1564 writeMockLocation();
1565 updateMockLocation();
1567 } else if (requestCode == REQUEST_CODE_ENABLE_OEM_UNLOCK) {
1568 if (resultCode == Activity.RESULT_OK) {
1569 if (mEnableOemUnlock.isChecked()) {
1570 confirmEnableOemUnlock();
1572 Utils.setOemUnlockEnabled(getActivity(), false);
1576 super.onActivityResult(requestCode, resultCode, data);
1581 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
1582 if (Utils.isMonkeyRunning()) {
1586 if (preference == mEnableAdb) {
1587 if (mEnableAdb.isChecked()) {
1588 mDialogClicked = false;
1589 if (mAdbDialog != null) dismissDialogs();
1590 mAdbDialog = new AlertDialog.Builder(getActivity()).setMessage(
1591 getActivity().getResources().getString(R.string.adb_warning_message))
1592 .setTitle(R.string.adb_warning_title)
1593 .setPositiveButton(android.R.string.yes, this)
1594 .setNegativeButton(android.R.string.no, this)
1596 mAdbDialog.setOnDismissListener(this);
1598 Settings.Global.putInt(getActivity().getContentResolver(),
1599 Settings.Global.ADB_ENABLED, 0);
1600 mVerifyAppsOverUsb.setEnabled(false);
1601 mVerifyAppsOverUsb.setChecked(false);
1602 updateBugreportOptions();
1604 } else if (preference == mClearAdbKeys) {
1605 if (mAdbKeysDialog != null) dismissDialogs();
1606 mAdbKeysDialog = new AlertDialog.Builder(getActivity())
1607 .setMessage(R.string.adb_keys_warning_message)
1608 .setPositiveButton(android.R.string.ok, this)
1609 .setNegativeButton(android.R.string.cancel, null)
1611 } else if (preference == mEnableTerminal) {
1612 final PackageManager pm = getActivity().getPackageManager();
1613 pm.setApplicationEnabledSetting(TERMINAL_APP_PACKAGE,
1614 mEnableTerminal.isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1615 : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
1616 } else if (preference == mBugreportInPower) {
1617 Settings.Secure.putInt(getActivity().getContentResolver(),
1618 Settings.Secure.BUGREPORT_IN_POWER_MENU,
1619 mBugreportInPower.isChecked() ? 1 : 0);
1620 } else if (preference == mKeepScreenOn) {
1621 Settings.Global.putInt(getActivity().getContentResolver(),
1622 Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
1623 mKeepScreenOn.isChecked() ?
1624 (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
1625 } else if (preference == mBtHciSnoopLog) {
1626 writeBtHciSnoopLogOptions();
1627 } else if (preference == mEnableOemUnlock) {
1628 if (!showKeyguardConfirmation(getResources(), REQUEST_CODE_ENABLE_OEM_UNLOCK)) {
1629 if (mEnableOemUnlock.isChecked()) {
1630 confirmEnableOemUnlock();
1632 Utils.setOemUnlockEnabled(getActivity(), false);
1635 } else if (preference == mMockLocationAppPref) {
1636 Intent intent = new Intent(getActivity(), AppPicker.class);
1637 intent.putExtra(AppPicker.EXTRA_REQUESTIING_PERMISSION,
1638 Manifest.permission.ACCESS_MOCK_LOCATION);
1639 startActivityForResult(intent, RESULT_MOCK_LOCATION_APP);
1640 } else if (preference == mDebugViewAttributes) {
1641 Settings.Global.putInt(getActivity().getContentResolver(),
1642 Settings.Global.DEBUG_VIEW_ATTRIBUTES,
1643 mDebugViewAttributes.isChecked() ? 1 : 0);
1644 } else if (preference == mDebugAppPref) {
1645 Intent intent = new Intent(getActivity(), AppPicker.class);
1646 intent.putExtra(AppPicker.EXTRA_DEBUGGABLE, true);
1647 startActivityForResult(intent, RESULT_DEBUG_APP);
1648 } else if (preference == mWaitForDebugger) {
1649 writeDebuggerOptions();
1650 } else if (preference == mVerifyAppsOverUsb) {
1651 writeVerifyAppsOverUsbOptions();
1652 } else if (preference == mStrictMode) {
1653 writeStrictModeVisualOptions();
1654 } else if (preference == mPointerLocation) {
1655 writePointerLocationOptions();
1656 } else if (preference == mShowTouches) {
1657 writeShowTouchesOptions();
1658 } else if (preference == mShowScreenUpdates) {
1659 writeShowUpdatesOption();
1660 } else if (preference == mDisableOverlays) {
1661 writeDisableOverlaysOption();
1662 } else if (preference == mEnableMultiWindow) {
1663 if (mEnableMultiWindow.isChecked()) {
1664 confirmEnableMultiWindowMode();
1666 setEnableMultiWindow(false);
1668 } else if (preference == mShowCpuUsage) {
1669 writeCpuUsageOptions();
1670 } else if (preference == mImmediatelyDestroyActivities) {
1671 writeImmediatelyDestroyActivitiesOptions();
1672 } else if (preference == mShowAllANRs) {
1673 writeShowAllANRsOptions();
1674 } else if (preference == mForceHardwareUi) {
1675 writeHardwareUiOptions();
1676 } else if (preference == mForceMsaa) {
1678 } else if (preference == mShowHwScreenUpdates) {
1679 writeShowHwScreenUpdatesOptions();
1680 } else if (preference == mShowHwLayersUpdates) {
1681 writeShowHwLayersUpdatesOptions();
1682 } else if (preference == mDebugLayout) {
1683 writeDebugLayoutOptions();
1684 } else if (preference == mForceRtlLayout) {
1685 writeForceRtlOptions();
1686 } else if (preference == mWifiDisplayCertification) {
1687 writeWifiDisplayCertificationOptions();
1688 } else if (preference == mWifiVerboseLogging) {
1689 writeWifiVerboseLoggingOptions();
1690 } else if (preference == mWifiAggressiveHandover) {
1691 writeWifiAggressiveHandoverOptions();
1692 } else if (preference == mWifiAllowScansWithTraffic) {
1693 writeWifiAllowScansWithTrafficOptions();
1694 } else if (preference == mLegacyDhcpClient) {
1695 writeLegacyDhcpClientOptions();
1696 } else if (preference == mMobileDataAlwaysOn) {
1697 writeMobileDataAlwaysOnOptions();
1698 } else if (preference == mUSBAudio) {
1699 writeUSBAudioOptions();
1700 } else if (INACTIVE_APPS_KEY.equals(preference.getKey())) {
1701 startInactiveAppsFragment();
1703 return super.onPreferenceTreeClick(preferenceScreen, preference);
1709 private void startInactiveAppsFragment() {
1710 ((SettingsActivity) getActivity()).startPreferencePanel(
1711 InactiveApps.class.getName(),
1712 null, R.string.inactive_apps_title, null, null, 0);
1715 private boolean showKeyguardConfirmation(Resources resources, int requestCode) {
1716 return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
1717 requestCode, resources.getString(R.string.oem_unlock_enable));
1721 public boolean onPreferenceChange(Preference preference, Object newValue) {
1722 if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
1723 SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString());
1725 pokeSystemProperties();
1727 } else if (preference == mLogdSize) {
1728 writeLogdSizeOption(newValue);
1730 } else if (preference == mUsbConfiguration) {
1731 writeUsbConfigurationOption(newValue);
1733 } else if (preference == mWindowAnimationScale) {
1734 writeAnimationScaleOption(0, mWindowAnimationScale, newValue);
1736 } else if (preference == mTransitionAnimationScale) {
1737 writeAnimationScaleOption(1, mTransitionAnimationScale, newValue);
1739 } else if (preference == mAnimatorDurationScale) {
1740 writeAnimationScaleOption(2, mAnimatorDurationScale, newValue);
1742 } else if (preference == mOverlayDisplayDevices) {
1743 writeOverlayDisplayDevicesOptions(newValue);
1745 } else if (preference == mOpenGLTraces) {
1746 writeOpenGLTracesOptions(newValue);
1748 } else if (preference == mTrackFrameTime) {
1749 writeTrackFrameTimeOptions(newValue);
1751 } else if (preference == mDebugHwOverdraw) {
1752 writeDebugHwOverdrawOptions(newValue);
1754 } else if (preference == mShowNonRectClip) {
1755 writeShowNonRectClipOptions(newValue);
1757 } else if (preference == mAppProcessLimit) {
1758 writeAppProcessLimitOptions(newValue);
1760 } else if (preference == mSimulateColorSpace) {
1761 writeSimulateColorSpace(newValue);
1763 } else if (preference == mTunerUiPref) {
1764 writeTweakUi(newValue);
1770 private void dismissDialogs() {
1771 if (mAdbDialog != null) {
1772 mAdbDialog.dismiss();
1775 if (mAdbKeysDialog != null) {
1776 mAdbKeysDialog.dismiss();
1777 mAdbKeysDialog = null;
1779 if (mEnableDialog != null) {
1780 mEnableDialog.dismiss();
1781 mEnableDialog = null;
1785 public void onClick(DialogInterface dialog, int which) {
1786 if (dialog == mAdbDialog) {
1787 if (which == DialogInterface.BUTTON_POSITIVE) {
1788 mDialogClicked = true;
1789 Settings.Global.putInt(getActivity().getContentResolver(),
1790 Settings.Global.ADB_ENABLED, 1);
1791 mVerifyAppsOverUsb.setEnabled(true);
1792 updateVerifyAppsOverUsbOptions();
1793 updateBugreportOptions();
1796 mEnableAdb.setChecked(false);
1798 } else if (dialog == mAdbKeysDialog) {
1799 if (which == DialogInterface.BUTTON_POSITIVE) {
1801 IBinder b = ServiceManager.getService(Context.USB_SERVICE);
1802 IUsbManager service = IUsbManager.Stub.asInterface(b);
1803 service.clearUsbDebuggingKeys();
1804 } catch (RemoteException e) {
1805 Log.e(TAG, "Unable to clear adb keys", e);
1808 } else if (dialog == mEnableDialog) {
1809 if (which == DialogInterface.BUTTON_POSITIVE) {
1810 mDialogClicked = true;
1811 Settings.Global.putInt(getActivity().getContentResolver(),
1812 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
1813 mLastEnabledState = true;
1814 setPrefsEnabledState(mLastEnabledState);
1817 mSwitchBar.setChecked(false);
1822 public void onDismiss(DialogInterface dialog) {
1823 // Assuming that onClick gets called first
1824 if (dialog == mAdbDialog) {
1825 if (!mDialogClicked) {
1826 mEnableAdb.setChecked(false);
1829 } else if (dialog == mEnableDialog) {
1830 if (!mDialogClicked) {
1831 mSwitchBar.setChecked(false);
1833 mEnableDialog = null;
1838 public void onDestroy() {
1843 void pokeSystemProperties() {
1844 if (!mDontPokeProperties) {
1845 //noinspection unchecked
1846 (new SystemPropPoker()).execute();
1850 private BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
1852 public void onReceive(Context context, Intent intent) {
1853 updateUsbConfigurationValues();
1857 static class SystemPropPoker extends AsyncTask<Void, Void, Void> {
1859 protected Void doInBackground(Void... params) {
1862 services = ServiceManager.listServices();
1863 } catch (RemoteException e) {
1866 for (String service : services) {
1867 IBinder obj = ServiceManager.checkService(service);
1869 Parcel data = Parcel.obtain();
1871 obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0);
1872 } catch (RemoteException e) {
1873 } catch (Exception e) {
1874 Log.i(TAG, "Someone wrote a bad service '" + service
1875 + "' that doesn't like to be poked: " + e);
1884 private static boolean isPackageInstalled(Context context, String packageName) {
1886 return context.getPackageManager().getPackageInfo(packageName, 0) != null;
1887 } catch (NameNotFoundException e) {
1895 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
1896 new BaseSearchIndexProvider() {
1898 private boolean isShowingDeveloperOptions(Context context) {
1899 return context.getSharedPreferences(DevelopmentSettings.PREF_FILE,
1900 Context.MODE_PRIVATE).getBoolean(
1901 DevelopmentSettings.PREF_SHOW,
1902 android.os.Build.TYPE.equals("eng"));
1906 public List<SearchIndexableResource> getXmlResourcesToIndex(
1907 Context context, boolean enabled) {
1909 if (!isShowingDeveloperOptions(context)) {
1913 final SearchIndexableResource sir = new SearchIndexableResource(context);
1914 sir.xmlResId = R.xml.development_prefs;
1915 return Arrays.asList(sir);
1919 public List<String> getNonIndexableKeys(Context context) {
1920 if (!isShowingDeveloperOptions(context)) {
1924 final List<String> keys = new ArrayList<String>();
1925 if (!showEnableOemUnlockPreference()) {
1926 keys.add(ENABLE_OEM_UNLOCK);
1928 if (!showEnableMultiWindowPreference()) {
1929 keys.add(ENABLE_MULTI_WINDOW_KEY);