2 * Copyright (C) 2008 The Android Open Source Project
3 * Copyright (C) 2013-2014 The CyanogenMod Project
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package com.android.settings;
20 import android.Manifest;
21 import android.app.Activity;
22 import android.app.ActivityManagerNative;
23 import android.app.AlertDialog;
24 import android.app.AppOpsManager;
25 import android.app.AppOpsManager.PackageOps;
26 import android.app.Dialog;
27 import android.app.admin.DevicePolicyManager;
28 import android.app.backup.IBackupManager;
29 import android.bluetooth.BluetoothAdapter;
30 import android.content.BroadcastReceiver;
31 import android.content.ComponentName;
32 import android.content.ContentResolver;
33 import android.content.Context;
34 import android.content.DialogInterface;
35 import android.content.Intent;
36 import android.content.IntentFilter;
37 import android.content.pm.ApplicationInfo;
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.net.NetworkUtils;
43 import android.net.wifi.IWifiManager;
44 import android.net.wifi.WifiInfo;
45 import android.hardware.usb.IUsbManager;
46 import android.hardware.usb.UsbManager;
47 import android.net.wifi.WifiManager;
48 import android.os.AsyncTask;
49 import android.os.BatteryManager;
50 import android.os.Build;
51 import android.os.Bundle;
52 import android.os.IBinder;
53 import android.os.Parcel;
54 import android.os.RemoteException;
55 import android.os.ServiceManager;
56 import android.os.StrictMode;
57 import android.os.SystemProperties;
58 import android.os.UserHandle;
59 import android.os.UserManager;
60 import android.preference.ListPreference;
61 import android.preference.Preference;
62 import android.preference.Preference.OnPreferenceChangeListener;
63 import android.preference.PreferenceGroup;
64 import android.preference.PreferenceScreen;
65 import android.preference.SwitchPreference;
66 import android.provider.SearchIndexableResource;
67 import android.provider.Settings;
68 import android.text.TextUtils;
69 import android.util.Log;
70 import android.view.HardwareRenderer;
71 import android.view.IWindowManager;
72 import android.view.LayoutInflater;
73 import android.view.View;
74 import android.view.ViewGroup;
75 import android.view.accessibility.AccessibilityManager;
76 import android.widget.Switch;
77 import android.widget.TextView;
79 import com.android.internal.logging.MetricsLogger;
80 import com.android.settings.fuelgauge.InactiveApps;
81 import com.android.settings.search.BaseSearchIndexProvider;
82 import com.android.settings.search.Indexable;
83 import com.android.settings.widget.SwitchBar;
85 import java.util.ArrayList;
86 import java.util.Arrays;
87 import java.util.HashSet;
88 import java.util.List;
91 * Displays preferences for application developers.
93 public class DevelopmentSettings extends SettingsPreferenceFragment
94 implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
95 OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable {
96 private static final String TAG = "DevelopmentSettings";
99 * Preference file were development settings prefs are stored.
101 public static final String PREF_FILE = "development";
104 * Whether to show the development settings to the user. Default is false.
106 public static final String PREF_SHOW = "show";
108 private static final String ENABLE_ADB = "enable_adb";
109 private static final String ADB_NOTIFY = "adb_notify";
110 private static final String ADB_TCPIP = "adb_over_network";
111 private static final String CLEAR_ADB_KEYS = "clear_adb_keys";
112 private static final String ENABLE_TERMINAL = "enable_terminal";
113 private static final String KEEP_SCREEN_ON_MODES = "keep_screen_on_modes";
114 private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log";
115 private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable";
116 private static final String HDCP_CHECKING_KEY = "hdcp_checking";
117 private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking";
118 private static final String LOCAL_BACKUP_PASSWORD = "local_backup_password";
119 private static final String HARDWARE_UI_PROPERTY = "persist.sys.ui.hw";
120 private static final String MSAA_PROPERTY = "debug.egl.force_msaa";
121 private static final String BUGREPORT = "bugreport";
122 private static final String BUGREPORT_IN_POWER_KEY = "bugreport_in_power";
123 private static final String OPENGL_TRACES_PROPERTY = "debug.egl.trace";
124 private static final String TUNER_UI_KEY = "tuner_ui";
126 private static final String DEBUG_APP_KEY = "debug_app";
127 private static final String WAIT_FOR_DEBUGGER_KEY = "wait_for_debugger";
128 private static final String MOCK_LOCATION_APP_KEY = "mock_location_app";
129 private static final String VERIFY_APPS_OVER_USB_KEY = "verify_apps_over_usb";
130 private static final String DEBUG_VIEW_ATTRIBUTES = "debug_view_attributes";
131 private static final String STRICT_MODE_KEY = "strict_mode";
132 private static final String POINTER_LOCATION_KEY = "pointer_location";
133 private static final String SHOW_TOUCHES_KEY = "show_touches";
134 private static final String SHOW_SCREEN_UPDATES_KEY = "show_screen_updates";
135 private static final String DISABLE_OVERLAYS_KEY = "disable_overlays";
136 private static final String SIMULATE_COLOR_SPACE = "simulate_color_space";
137 private static final String USB_AUDIO_KEY = "usb_audio";
138 private static final String SHOW_CPU_USAGE_KEY = "show_cpu_usage";
139 private static final String FORCE_HARDWARE_UI_KEY = "force_hw_ui";
140 private static final String FORCE_MSAA_KEY = "force_msaa";
141 private static final String TRACK_FRAME_TIME_KEY = "track_frame_time";
142 private static final String SHOW_NON_RECTANGULAR_CLIP_KEY = "show_non_rect_clip";
143 private static final String SHOW_HW_SCREEN_UPDATES_KEY = "show_hw_screen_udpates";
144 private static final String SHOW_HW_LAYERS_UPDATES_KEY = "show_hw_layers_udpates";
145 private static final String DEBUG_HW_OVERDRAW_KEY = "debug_hw_overdraw";
146 private static final String DEBUG_LAYOUT_KEY = "debug_layout";
147 private static final String FORCE_RTL_LAYOUT_KEY = "force_rtl_layout_all_locales";
148 private static final String WINDOW_ANIMATION_SCALE_KEY = "window_animation_scale";
149 private static final String TRANSITION_ANIMATION_SCALE_KEY = "transition_animation_scale";
150 private static final String ANIMATOR_DURATION_SCALE_KEY = "animator_duration_scale";
151 private static final String OVERLAY_DISPLAY_DEVICES_KEY = "overlay_display_devices";
152 private static final String ENABLE_MULTI_WINDOW_KEY = "enable_multi_window";
153 private static final String DEBUG_DEBUGGING_CATEGORY_KEY = "debug_debugging_category";
154 private static final String SELECT_LOGD_SIZE_KEY = "select_logd_size";
155 private static final String SELECT_LOGD_SIZE_PROPERTY = "persist.logd.size";
156 private static final String SELECT_LOGD_DEFAULT_SIZE_PROPERTY = "ro.logd.size";
158 private static final String WIFI_DISPLAY_CERTIFICATION_KEY = "wifi_display_certification";
159 private static final String WIFI_VERBOSE_LOGGING_KEY = "wifi_verbose_logging";
160 private static final String WIFI_AGGRESSIVE_HANDOVER_KEY = "wifi_aggressive_handover";
161 private static final String WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY = "wifi_allow_scan_with_traffic";
162 private static final String USB_CONFIGURATION_KEY = "select_usb_configuration";
163 private static final String WIFI_LEGACY_DHCP_CLIENT_KEY = "legacy_dhcp_client";
164 private static final String MOBILE_DATA_ALWAYS_ON = "mobile_data_always_on";
166 private static final String INACTIVE_APPS_KEY = "inactive_apps";
168 private static final String OPENGL_TRACES_KEY = "enable_opengl_traces";
170 private static final String ROOT_ACCESS_KEY = "root_access";
171 private static final String ROOT_ACCESS_PROPERTY = "persist.sys.root_access";
173 private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY
174 = "immediately_destroy_activities";
175 private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit";
177 private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs";
179 private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
181 private static final String TERMINAL_APP_PACKAGE = "com.android.terminal";
183 private static final String DEVELOPMENT_TOOLS = "development_tools";
185 private static final int RESULT_DEBUG_APP = 1000;
186 private static final int RESULT_MOCK_LOCATION_APP = 1001;
188 private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
190 private static final int REQUEST_CODE_ENABLE_OEM_UNLOCK = 0;
192 private static String DEFAULT_LOG_RING_BUFFER_SIZE_IN_BYTES = "262144"; // 256K
194 private static final int[] MOCK_LOCATION_APP_OPS = new int[] {AppOpsManager.OP_MOCK_LOCATION};
196 private static final String MULTI_WINDOW_SYSTEM_PROPERTY = "persist.sys.debug.multi_window";
197 private IWindowManager mWindowManager;
198 private IBackupManager mBackupManager;
199 private DevicePolicyManager mDpm;
200 private UserManager mUm;
201 private WifiManager mWifiManager;
203 private SwitchBar mSwitchBar;
204 private boolean mLastEnabledState;
205 private boolean mHaveDebugSettings;
206 private boolean mDontPokeProperties;
208 private SwitchPreference mEnableAdb;
209 private SwitchPreference mAdbNotify;
210 private SwitchPreference mAdbOverNetwork;
211 private Preference mClearAdbKeys;
212 private SwitchPreference mEnableTerminal;
213 private Preference mBugreport;
214 private SwitchPreference mBugreportInPower;
215 private ListPreference mKeepScreenOn;
216 private SwitchPreference mBtHciSnoopLog;
217 private SwitchPreference mEnableOemUnlock;
218 private SwitchPreference mDebugViewAttributes;
220 private PreferenceScreen mPassword;
221 private String mDebugApp;
222 private Preference mDebugAppPref;
224 private String mMockLocationApp;
225 private Preference mMockLocationAppPref;
227 private SwitchPreference mWaitForDebugger;
228 private SwitchPreference mVerifyAppsOverUsb;
229 private SwitchPreference mWifiDisplayCertification;
230 private SwitchPreference mWifiVerboseLogging;
231 private SwitchPreference mWifiAggressiveHandover;
232 private SwitchPreference mLegacyDhcpClient;
233 private SwitchPreference mMobileDataAlwaysOn;
235 private SwitchPreference mWifiAllowScansWithTraffic;
236 private SwitchPreference mStrictMode;
237 private SwitchPreference mPointerLocation;
238 private SwitchPreference mShowTouches;
239 private SwitchPreference mShowScreenUpdates;
240 private SwitchPreference mDisableOverlays;
241 private SwitchPreference mEnableMultiWindow;
242 private SwitchPreference mShowCpuUsage;
243 private SwitchPreference mForceHardwareUi;
244 private SwitchPreference mForceMsaa;
245 private SwitchPreference mShowHwScreenUpdates;
246 private SwitchPreference mShowHwLayersUpdates;
247 private SwitchPreference mDebugLayout;
248 private SwitchPreference mForceRtlLayout;
249 private ListPreference mDebugHwOverdraw;
250 private ListPreference mLogdSize;
251 private ListPreference mUsbConfiguration;
252 private ListPreference mTrackFrameTime;
253 private ListPreference mShowNonRectClip;
254 private ListPreference mWindowAnimationScale;
255 private ListPreference mTransitionAnimationScale;
256 private ListPreference mAnimatorDurationScale;
257 private ListPreference mOverlayDisplayDevices;
258 private ListPreference mOpenGLTraces;
260 private ListPreference mSimulateColorSpace;
262 private SwitchPreference mUSBAudio;
263 private SwitchPreference mImmediatelyDestroyActivities;
265 private ListPreference mAppProcessLimit;
267 private SwitchPreference mShowAllANRs;
269 private ListPreference mRootAccess;
270 private Object mSelectedRootValue;
271 private PreferenceScreen mDevelopmentTools;
273 private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>();
275 private final ArrayList<SwitchPreference> mResetSwitchPrefs
276 = new ArrayList<SwitchPreference>();
278 private final HashSet<Preference> mDisabledPrefs = new HashSet<Preference>();
279 // To track whether a confirmation dialog was clicked.
280 private boolean mDialogClicked;
281 private Dialog mEnableDialog;
282 private Dialog mAdbDialog;
283 private Dialog mAdbTcpDialog;
284 private Dialog mAdbKeysDialog;
285 private boolean mUnavailable;
286 private Dialog mRootDialog;
289 protected int getMetricsCategory() {
290 return MetricsLogger.DEVELOPMENT;
294 public void onCreate(Bundle icicle) {
295 super.onCreate(icicle);
297 mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
298 mBackupManager = IBackupManager.Stub.asInterface(
299 ServiceManager.getService(Context.BACKUP_SERVICE));
300 mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
301 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
303 mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
305 if (android.os.Process.myUserHandle().getIdentifier() != UserHandle.USER_OWNER
306 || mUm.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES)) {
308 setPreferenceScreen(new PreferenceScreen(getActivity(), null));
312 addPreferencesFromResource(R.xml.development_prefs);
314 final PreferenceGroup debugDebuggingCategory = (PreferenceGroup)
315 findPreference(DEBUG_DEBUGGING_CATEGORY_KEY);
316 mEnableAdb = findAndInitSwitchPref(ENABLE_ADB);
318 mAdbNotify = findAndInitSwitchPref(ADB_NOTIFY);
319 mAllPrefs.add(mAdbNotify);
320 mAdbOverNetwork = findAndInitSwitchPref(ADB_TCPIP);
322 mClearAdbKeys = findPreference(CLEAR_ADB_KEYS);
323 if (!SystemProperties.getBoolean("ro.adb.secure", false)) {
324 if (debugDebuggingCategory != null) {
325 debugDebuggingCategory.removePreference(mClearAdbKeys);
328 mAllPrefs.add(mClearAdbKeys);
329 mEnableTerminal = findAndInitSwitchPref(ENABLE_TERMINAL);
330 if (!isPackageInstalled(getActivity(), TERMINAL_APP_PACKAGE)) {
331 debugDebuggingCategory.removePreference(mEnableTerminal);
332 mEnableTerminal = null;
335 mBugreport = findPreference(BUGREPORT);
336 mBugreportInPower = findAndInitSwitchPref(BUGREPORT_IN_POWER_KEY);
337 mKeepScreenOn = addListPreference(KEEP_SCREEN_ON_MODES);
338 mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG);
339 mEnableOemUnlock = findAndInitSwitchPref(ENABLE_OEM_UNLOCK);
340 if (!showEnableOemUnlockPreference()) {
341 removePreference(mEnableOemUnlock);
342 mEnableOemUnlock = null;
345 mDebugViewAttributes = findAndInitSwitchPref(DEBUG_VIEW_ATTRIBUTES);
346 mPassword = (PreferenceScreen) findPreference(LOCAL_BACKUP_PASSWORD);
347 mAllPrefs.add(mPassword);
350 if (!android.os.Process.myUserHandle().equals(UserHandle.OWNER)) {
351 disableForUser(mEnableAdb);
352 disableForUser(mClearAdbKeys);
353 disableForUser(mEnableTerminal);
354 disableForUser(mPassword);
357 mDebugAppPref = findPreference(DEBUG_APP_KEY);
358 mAllPrefs.add(mDebugAppPref);
359 mWaitForDebugger = findAndInitSwitchPref(WAIT_FOR_DEBUGGER_KEY);
361 mMockLocationAppPref = findPreference(MOCK_LOCATION_APP_KEY);
362 mAllPrefs.add(mMockLocationAppPref);
364 mVerifyAppsOverUsb = findAndInitSwitchPref(VERIFY_APPS_OVER_USB_KEY);
365 if (!showVerifierSetting()) {
366 if (debugDebuggingCategory != null) {
367 debugDebuggingCategory.removePreference(mVerifyAppsOverUsb);
369 mVerifyAppsOverUsb.setEnabled(false);
372 mStrictMode = findAndInitSwitchPref(STRICT_MODE_KEY);
373 mPointerLocation = findAndInitSwitchPref(POINTER_LOCATION_KEY);
374 mShowTouches = findAndInitSwitchPref(SHOW_TOUCHES_KEY);
375 mShowScreenUpdates = findAndInitSwitchPref(SHOW_SCREEN_UPDATES_KEY);
376 mDisableOverlays = findAndInitSwitchPref(DISABLE_OVERLAYS_KEY);
377 mShowCpuUsage = findAndInitSwitchPref(SHOW_CPU_USAGE_KEY);
378 mForceHardwareUi = findAndInitSwitchPref(FORCE_HARDWARE_UI_KEY);
379 mForceMsaa = findAndInitSwitchPref(FORCE_MSAA_KEY);
380 mTrackFrameTime = addListPreference(TRACK_FRAME_TIME_KEY);
381 mShowNonRectClip = addListPreference(SHOW_NON_RECTANGULAR_CLIP_KEY);
382 mShowHwScreenUpdates = findAndInitSwitchPref(SHOW_HW_SCREEN_UPDATES_KEY);
383 mShowHwLayersUpdates = findAndInitSwitchPref(SHOW_HW_LAYERS_UPDATES_KEY);
384 mDebugLayout = findAndInitSwitchPref(DEBUG_LAYOUT_KEY);
385 mForceRtlLayout = findAndInitSwitchPref(FORCE_RTL_LAYOUT_KEY);
386 mDebugHwOverdraw = addListPreference(DEBUG_HW_OVERDRAW_KEY);
387 mWifiDisplayCertification = findAndInitSwitchPref(WIFI_DISPLAY_CERTIFICATION_KEY);
388 mWifiVerboseLogging = findAndInitSwitchPref(WIFI_VERBOSE_LOGGING_KEY);
389 mWifiAggressiveHandover = findAndInitSwitchPref(WIFI_AGGRESSIVE_HANDOVER_KEY);
390 mWifiAllowScansWithTraffic = findAndInitSwitchPref(WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY);
391 mLegacyDhcpClient = findAndInitSwitchPref(WIFI_LEGACY_DHCP_CLIENT_KEY);
392 mMobileDataAlwaysOn = findAndInitSwitchPref(MOBILE_DATA_ALWAYS_ON);
393 mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY);
394 mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY);
396 mWindowAnimationScale = addListPreference(WINDOW_ANIMATION_SCALE_KEY);
397 mTransitionAnimationScale = addListPreference(TRANSITION_ANIMATION_SCALE_KEY);
398 mAnimatorDurationScale = addListPreference(ANIMATOR_DURATION_SCALE_KEY);
399 mOverlayDisplayDevices = addListPreference(OVERLAY_DISPLAY_DEVICES_KEY);
400 mEnableMultiWindow = findAndInitSwitchPref(ENABLE_MULTI_WINDOW_KEY);
401 if (!showEnableMultiWindowPreference()) {
402 final PreferenceGroup drawingGroup =
403 (PreferenceGroup)findPreference("debug_drawing_category");
404 if (drawingGroup != null) {
405 drawingGroup.removePreference(mEnableMultiWindow);
407 mEnableMultiWindow.setEnabled(false);
409 removePreference(mEnableMultiWindow);
410 mEnableMultiWindow = null;
412 mOpenGLTraces = addListPreference(OPENGL_TRACES_KEY);
413 mSimulateColorSpace = addListPreference(SIMULATE_COLOR_SPACE);
414 mUSBAudio = findAndInitSwitchPref(USB_AUDIO_KEY);
416 mImmediatelyDestroyActivities = (SwitchPreference) findPreference(
417 IMMEDIATELY_DESTROY_ACTIVITIES_KEY);
418 mAllPrefs.add(mImmediatelyDestroyActivities);
419 mResetSwitchPrefs.add(mImmediatelyDestroyActivities);
421 mAppProcessLimit = addListPreference(APP_PROCESS_LIMIT_KEY);
423 mShowAllANRs = (SwitchPreference) findPreference(
425 mAllPrefs.add(mShowAllANRs);
426 mResetSwitchPrefs.add(mShowAllANRs);
428 Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY);
429 if (hdcpChecking != null) {
430 mAllPrefs.add(hdcpChecking);
431 removePreferenceForProduction(hdcpChecking);
434 mRootAccess = (ListPreference) findPreference(ROOT_ACCESS_KEY);
435 mRootAccess.setOnPreferenceChangeListener(this);
436 if (!removeRootOptionsIfRequired()) {
437 mAllPrefs.add(mRootAccess);
440 mDevelopmentTools = (PreferenceScreen) findPreference(DEVELOPMENT_TOOLS);
441 mAllPrefs.add(mDevelopmentTools);
444 private ListPreference addListPreference(String prefKey) {
445 ListPreference pref = (ListPreference) findPreference(prefKey);
447 pref.setOnPreferenceChangeListener(this);
451 private void disableForUser(Preference pref) {
453 pref.setEnabled(false);
454 mDisabledPrefs.add(pref);
458 private SwitchPreference findAndInitSwitchPref(String key) {
459 SwitchPreference pref = (SwitchPreference) findPreference(key);
461 throw new IllegalArgumentException("Cannot find preference with key = " + key);
464 mResetSwitchPrefs.add(pref);
468 private boolean removeRootOptionsIfRequired() {
469 // user builds don't get root, and eng always gets root
470 if (!(Build.IS_DEBUGGABLE || "eng".equals(Build.TYPE))) {
471 if (mRootAccess != null) {
472 getPreferenceScreen().removePreference(mRootAccess);
481 public void onActivityCreated(Bundle savedInstanceState) {
482 super.onActivityCreated(savedInstanceState);
484 final SettingsActivity activity = (SettingsActivity) getActivity();
486 mSwitchBar = activity.getSwitchBar();
488 mSwitchBar.setEnabled(false);
492 mSwitchBar.addOnSwitchChangeListener(this);
495 private boolean removePreferenceForProduction(Preference preference) {
496 if ("user".equals(Build.TYPE)) {
497 removePreference(preference);
503 private void removePreference(Preference preference) {
504 getPreferenceScreen().removePreference(preference);
505 mAllPrefs.remove(preference);
506 mResetSwitchPrefs.remove(preference);
509 private void setPrefsEnabledState(boolean enabled) {
510 for (int i = 0; i < mAllPrefs.size(); i++) {
511 Preference pref = mAllPrefs.get(i);
512 pref.setEnabled(enabled && !mDisabledPrefs.contains(pref));
518 public void onResume() {
522 // Show error message
523 TextView emptyView = (TextView) getView().findViewById(android.R.id.empty);
524 getListView().setEmptyView(emptyView);
525 if (emptyView != null) {
526 emptyView.setText(R.string.development_settings_not_available);
531 if (mDpm.getMaximumTimeToLock(null) > 0) {
532 // A DeviceAdmin has specified a maximum time until the device
533 // will lock... in this case we can't allow the user to turn
534 // on "stay awake when plugged in" because that would defeat the
536 mDisabledPrefs.add(mKeepScreenOn);
538 mDisabledPrefs.remove(mKeepScreenOn);
541 final ContentResolver cr = getActivity().getContentResolver();
542 mLastEnabledState = Settings.Global.getInt(cr,
543 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
544 mSwitchBar.setChecked(mLastEnabledState);
545 setPrefsEnabledState(mLastEnabledState);
547 if (mHaveDebugSettings && !mLastEnabledState) {
548 // Overall debugging is disabled, but there are some debug
549 // settings that are enabled. This is an invalid state. Switch
550 // to debug settings being enabled, so the user knows there is
551 // stuff enabled and can turn it all off if they want.
552 Settings.Global.putInt(getActivity().getContentResolver(),
553 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
554 mLastEnabledState = true;
555 mSwitchBar.setChecked(mLastEnabledState);
556 setPrefsEnabledState(mLastEnabledState);
562 public View onCreateView(LayoutInflater inflater, ViewGroup container,
563 Bundle savedInstanceState) {
564 IntentFilter filter = new IntentFilter();
565 filter.addAction(UsbManager.ACTION_USB_STATE);
566 getActivity().registerReceiver(mUsbReceiver, filter);
567 return super.onCreateView(inflater, container, savedInstanceState);
571 public void onDestroyView() {
572 super.onDestroyView();
577 mSwitchBar.removeOnSwitchChangeListener(this);
579 getActivity().unregisterReceiver(mUsbReceiver);
582 void updateSwitchPreference(SwitchPreference switchPreference, boolean value) {
583 switchPreference.setChecked(value);
584 mHaveDebugSettings |= value;
587 private void updateAllOptions() {
588 final Context context = getActivity();
589 final ContentResolver cr = context.getContentResolver();
590 mHaveDebugSettings = false;
591 updateSwitchPreference(mEnableAdb, Settings.Global.getInt(cr,
592 Settings.Global.ADB_ENABLED, 0) != 0);
594 mAdbNotify.setChecked(Settings.Secure.getInt(cr,
595 Settings.Secure.ADB_NOTIFY, 1) != 0);
596 updateAdbOverNetwork();
598 if (mEnableTerminal != null) {
599 updateSwitchPreference(mEnableTerminal,
600 context.getPackageManager().getApplicationEnabledSetting(TERMINAL_APP_PACKAGE)
601 == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
603 updateSwitchPreference(mBugreportInPower, Settings.Secure.getInt(cr,
604 Settings.Secure.BUGREPORT_IN_POWER_MENU, 0) != 0);
605 updateStayAwakeOptions();
606 updateSwitchPreference(mBtHciSnoopLog, Settings.Secure.getInt(cr,
607 Settings.Secure.BLUETOOTH_HCI_LOG, 0) != 0);
608 if (mEnableOemUnlock != null) {
609 updateSwitchPreference(mEnableOemUnlock, Utils.isOemUnlockEnabled(getActivity()));
611 updateSwitchPreference(mDebugViewAttributes, Settings.Global.getInt(cr,
612 Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0);
614 updatePasswordSummary();
615 updateDebuggerOptions();
616 updateMockLocation();
617 updateStrictModeVisualOptions();
618 updatePointerLocationOptions();
619 updateShowTouchesOptions();
620 updateFlingerOptions();
621 updateCpuUsageOptions();
622 updateHardwareUiOptions();
624 updateTrackFrameTimeOptions();
625 updateShowNonRectClipOptions();
626 updateShowHwScreenUpdatesOptions();
627 updateShowHwLayersUpdatesOptions();
628 updateDebugHwOverdrawOptions();
629 updateDebugLayoutOptions();
630 updateAnimationScaleOptions();
631 updateOverlayDisplayDevicesOptions();
632 if (mEnableMultiWindow != null) {
633 updateSwitchPreference(mEnableMultiWindow,
634 SystemProperties.getBoolean(MULTI_WINDOW_SYSTEM_PROPERTY, false));
636 updateOpenGLTracesOptions();
637 updateImmediatelyDestroyActivitiesOptions();
638 updateAppProcessLimitOptions();
639 updateShowAllANRsOptions();
640 updateVerifyAppsOverUsbOptions();
641 updateBugreportOptions();
642 updateForceRtlOptions();
643 updateLogdSizeValues();
644 updateWifiDisplayCertificationOptions();
645 updateWifiVerboseLoggingOptions();
646 updateWifiAggressiveHandoverOptions();
647 updateWifiAllowScansWithTrafficOptions();
648 updateLegacyDhcpClientOptions();
649 updateMobileDataAlwaysOnOptions();
650 updateSimulateColorSpace();
651 updateUSBAudioOptions();
652 updateRootAccessOptions();
655 private void updateAdbOverNetwork() {
656 int port = Settings.Secure.getInt(getActivity().getContentResolver(),
657 Settings.Secure.ADB_PORT, 0);
658 boolean enabled = port > 0;
660 updateSwitchPreference(mAdbOverNetwork, enabled);
662 WifiInfo wifiInfo = null;
665 IWifiManager wifiManager = IWifiManager.Stub.asInterface(
666 ServiceManager.getService(Context.WIFI_SERVICE));
668 wifiInfo = wifiManager.getConnectionInfo();
669 } catch (RemoteException e) {
670 Log.e(TAG, "wifiManager, getConnectionInfo()", e);
674 if (wifiInfo != null) {
675 String hostAddress = NetworkUtils.intToInetAddress(
676 wifiInfo.getIpAddress()).getHostAddress();
677 mAdbOverNetwork.setSummary(hostAddress + ":" + String.valueOf(port));
679 mAdbOverNetwork.setSummary(R.string.adb_over_network_summary);
683 private void resetDangerousOptions() {
684 mDontPokeProperties = true;
685 for (int i=0; i< mResetSwitchPrefs.size(); i++) {
686 SwitchPreference cb = mResetSwitchPrefs.get(i);
687 if (cb.isChecked()) {
688 cb.setChecked(false);
689 onPreferenceTreeClick(null, cb);
692 resetDebuggerOptions();
693 writeLogdSizeOption(null);
694 resetRootAccessOptions();
695 writeAnimationScaleOption(0, mWindowAnimationScale, null);
696 writeAnimationScaleOption(1, mTransitionAnimationScale, null);
697 writeAnimationScaleOption(2, mAnimatorDurationScale, null);
698 // Only poke the color space setting if we control it.
699 if (usingDevelopmentColorSpace()) {
700 writeSimulateColorSpace(-1);
702 writeOverlayDisplayDevicesOptions(null);
703 writeAppProcessLimitOptions(null);
704 mHaveDebugSettings = false;
706 mDontPokeProperties = false;
707 pokeSystemProperties();
710 private void updateRootAccessOptions() {
711 String value = SystemProperties.get(ROOT_ACCESS_PROPERTY, "0");
712 mRootAccess.setValue(value);
713 mRootAccess.setSummary(getResources()
714 .getStringArray(R.array.root_access_entries)[Integer.valueOf(value)]);
717 public static boolean isRootForAppsEnabled() {
718 int value = SystemProperties.getInt(ROOT_ACCESS_PROPERTY, 0);
719 boolean daemonState =
720 SystemProperties.get("init.svc.su_daemon", "absent").equals("running");
721 return daemonState && (value == 1 || value == 3);
724 private void writeRootAccessOptions(Object newValue) {
725 String oldValue = SystemProperties.get(ROOT_ACCESS_PROPERTY, "0");
726 SystemProperties.set(ROOT_ACCESS_PROPERTY, newValue.toString());
727 if (Integer.valueOf(newValue.toString()) < 2 && !oldValue.equals(newValue)
728 && "1".equals(SystemProperties.get("service.adb.root", "0"))) {
729 SystemProperties.set("service.adb.root", "0");
730 Settings.Secure.putInt(getActivity().getContentResolver(),
731 Settings.Secure.ADB_ENABLED, 0);
732 Settings.Secure.putInt(getActivity().getContentResolver(),
733 Settings.Secure.ADB_ENABLED, 1);
735 updateRootAccessOptions();
738 private void resetRootAccessOptions() {
739 String oldValue = SystemProperties.get(ROOT_ACCESS_PROPERTY, "0");
740 SystemProperties.set(ROOT_ACCESS_PROPERTY, "0");
741 if (!oldValue.equals("0") && "1".equals(SystemProperties.get("service.adb.root", "0"))) {
742 SystemProperties.set("service.adb.root", "0");
743 Settings.Secure.putInt(getActivity().getContentResolver(),
744 Settings.Secure.ADB_ENABLED, 0);
745 Settings.Secure.putInt(getActivity().getContentResolver(),
746 Settings.Secure.ADB_ENABLED, 1);
748 updateRootAccessOptions();
751 private void updateStayAwakeOptions() {
752 int index = Settings.Global.getInt(getActivity().getContentResolver(),
753 Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0);
754 final String[] values = getResources().getStringArray(R.array.keep_screen_on_values);
755 final String[] summaries = getResources().getStringArray(R.array.keep_screen_on_titles);
756 // The old value contained 0 (disable) or 3 (BATTERY_PLUGGED_AC|BATTERY_PLUGGED_USB)
757 // Currently only have 3 values (0: Not enabled; 1: debugging over usb; >2: charging)
758 // NOTE: If we have newer values, then we need to migrate
760 if (index >= values.length) {
761 index = values.length - 1;
763 mKeepScreenOn.setValue(values[index]);
764 mKeepScreenOn.setSummary(summaries[index]);
765 mKeepScreenOn.setOnPreferenceChangeListener(this);
768 private void updateHdcpValues() {
769 ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
770 if (hdcpChecking != null) {
771 String currentValue = SystemProperties.get(HDCP_CHECKING_PROPERTY);
772 String[] values = getResources().getStringArray(R.array.hdcp_checking_values);
773 String[] summaries = getResources().getStringArray(R.array.hdcp_checking_summaries);
774 int index = 1; // Defaults to drm-only. Needs to match with R.array.hdcp_checking_values
775 for (int i = 0; i < values.length; i++) {
776 if (currentValue.equals(values[i])) {
781 hdcpChecking.setValue(values[index]);
782 hdcpChecking.setSummary(summaries[index]);
783 hdcpChecking.setOnPreferenceChangeListener(this);
787 private void updatePasswordSummary() {
789 if (mBackupManager.hasBackupPassword()) {
790 mPassword.setSummary(R.string.local_backup_password_summary_change);
792 mPassword.setSummary(R.string.local_backup_password_summary_none);
794 } catch (RemoteException e) {
795 // Not much we can do here
799 private void writeBtHciSnoopLogOptions() {
800 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
801 adapter.configHciSnoopLog(mBtHciSnoopLog.isChecked());
802 Settings.Secure.putInt(getActivity().getContentResolver(),
803 Settings.Secure.BLUETOOTH_HCI_LOG,
804 mBtHciSnoopLog.isChecked() ? 1 : 0);
807 private void writeDebuggerOptions() {
809 ActivityManagerNative.getDefault().setDebugApp(
810 mDebugApp, mWaitForDebugger.isChecked(), true);
811 } catch (RemoteException ex) {
815 private void writeMockLocation() {
816 AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
818 // Disable the app op of the previous mock location app if such.
819 List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
820 if (packageOps != null) {
821 // Should be one but in case we are in a bad state due to use of command line tools.
822 for (PackageOps packageOp : packageOps) {
823 if (packageOp.getOps().get(0).getMode() != AppOpsManager.MODE_ERRORED) {
824 String oldMockLocationApp = packageOp.getPackageName();
826 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
827 oldMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
828 appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid,
829 oldMockLocationApp, AppOpsManager.MODE_ERRORED);
830 } catch (NameNotFoundException e) {
837 // Enable the app op of the new mock location app if such.
838 if (!TextUtils.isEmpty(mMockLocationApp)) {
840 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
841 mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
842 appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid,
843 mMockLocationApp, AppOpsManager.MODE_ALLOWED);
844 } catch (NameNotFoundException e) {
850 private static void resetDebuggerOptions() {
852 ActivityManagerNative.getDefault().setDebugApp(
854 } catch (RemoteException ex) {
858 private void updateDebuggerOptions() {
859 mDebugApp = Settings.Global.getString(
860 getActivity().getContentResolver(), Settings.Global.DEBUG_APP);
861 updateSwitchPreference(mWaitForDebugger, Settings.Global.getInt(
862 getActivity().getContentResolver(), Settings.Global.WAIT_FOR_DEBUGGER, 0) != 0);
863 if (mDebugApp != null && mDebugApp.length() > 0) {
866 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mDebugApp,
867 PackageManager.GET_DISABLED_COMPONENTS);
868 CharSequence lab = getActivity().getPackageManager().getApplicationLabel(ai);
869 label = lab != null ? lab.toString() : mDebugApp;
870 } catch (PackageManager.NameNotFoundException e) {
873 mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_set, label));
874 mWaitForDebugger.setEnabled(true);
875 mHaveDebugSettings = true;
877 mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_not_set));
878 mWaitForDebugger.setEnabled(false);
882 private void updateMockLocation() {
883 AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
885 List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
886 if (packageOps != null) {
887 for (PackageOps packageOp : packageOps) {
888 if (packageOp.getOps().get(0).getMode() == AppOpsManager.MODE_ALLOWED) {
889 mMockLocationApp = packageOps.get(0).getPackageName();
895 if (!TextUtils.isEmpty(mMockLocationApp)) {
896 String label = mMockLocationApp;
898 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
899 mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
900 CharSequence appLabel = getPackageManager().getApplicationLabel(ai);
901 if (appLabel != null) {
902 label = appLabel.toString();
904 } catch (PackageManager.NameNotFoundException e) {
908 mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_set, label));
909 mHaveDebugSettings = true;
911 mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_not_set));
915 private void updateVerifyAppsOverUsbOptions() {
916 updateSwitchPreference(mVerifyAppsOverUsb, Settings.Global.getInt(getActivity().getContentResolver(),
917 Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0);
918 mVerifyAppsOverUsb.setEnabled(enableVerifierSetting());
921 private void writeVerifyAppsOverUsbOptions() {
922 Settings.Global.putInt(getActivity().getContentResolver(),
923 Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, mVerifyAppsOverUsb.isChecked() ? 1 : 0);
926 private boolean enableVerifierSetting() {
927 final ContentResolver cr = getActivity().getContentResolver();
928 if (Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, 0) == 0) {
931 if (Settings.Global.getInt(cr, Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) == 0) {
934 final PackageManager pm = getActivity().getPackageManager();
935 final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
936 verification.setType(PACKAGE_MIME_TYPE);
937 verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
938 final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(verification, 0);
939 if (receivers.size() == 0) {
946 private boolean showVerifierSetting() {
947 return Settings.Global.getInt(getActivity().getContentResolver(),
948 Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0;
951 private static boolean showEnableOemUnlockPreference() {
952 return !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("");
955 private static boolean showEnableMultiWindowPreference() {
956 return !"user".equals(Build.TYPE);
959 private void setEnableMultiWindow(boolean value) {
960 SystemProperties.set(MULTI_WINDOW_SYSTEM_PROPERTY, String.valueOf(value));
961 pokeSystemProperties();
964 private void updateBugreportOptions() {
965 final ComponentName bugreportStorageProviderComponentName =
966 new ComponentName("com.android.shell",
967 "com.android.shell.BugreportStorageProvider");
968 if ("user".equals(Build.TYPE)) {
969 final ContentResolver resolver = getActivity().getContentResolver();
970 final boolean adbEnabled = Settings.Global.getInt(
971 resolver, Settings.Global.ADB_ENABLED, 0) != 0;
973 mBugreport.setEnabled(true);
974 mBugreportInPower.setEnabled(true);
975 getPackageManager().setComponentEnabledSetting(
976 bugreportStorageProviderComponentName,
977 PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
979 mBugreport.setEnabled(false);
980 mBugreportInPower.setEnabled(false);
981 mBugreportInPower.setChecked(false);
982 Settings.Secure.putInt(resolver, Settings.Secure.BUGREPORT_IN_POWER_MENU, 0);
983 getPackageManager().setComponentEnabledSetting(
984 bugreportStorageProviderComponentName,
985 PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
988 mBugreportInPower.setEnabled(true);
989 getPackageManager().setComponentEnabledSetting(
990 bugreportStorageProviderComponentName,
991 PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
995 // Returns the current state of the system property that controls
996 // strictmode flashes. One of:
997 // 0: not explicitly set one way or another
1000 private static int currentStrictModeActiveIndex() {
1001 if (TextUtils.isEmpty(SystemProperties.get(StrictMode.VISUAL_PROPERTY))) {
1004 boolean enabled = SystemProperties.getBoolean(StrictMode.VISUAL_PROPERTY, false);
1005 return enabled ? 1 : 2;
1008 private void writeStrictModeVisualOptions() {
1010 mWindowManager.setStrictModeVisualIndicatorPreference(mStrictMode.isChecked()
1012 } catch (RemoteException e) {
1016 private void updateStrictModeVisualOptions() {
1017 updateSwitchPreference(mStrictMode, currentStrictModeActiveIndex() == 1);
1020 private void writePointerLocationOptions() {
1021 Settings.System.putInt(getActivity().getContentResolver(),
1022 Settings.System.POINTER_LOCATION, mPointerLocation.isChecked() ? 1 : 0);
1025 private void updatePointerLocationOptions() {
1026 updateSwitchPreference(mPointerLocation,
1027 Settings.System.getInt(getActivity().getContentResolver(),
1028 Settings.System.POINTER_LOCATION, 0) != 0);
1031 private void writeShowTouchesOptions() {
1032 Settings.System.putInt(getActivity().getContentResolver(),
1033 Settings.System.SHOW_TOUCHES, mShowTouches.isChecked() ? 1 : 0);
1036 private void updateShowTouchesOptions() {
1037 updateSwitchPreference(mShowTouches,
1038 Settings.System.getInt(getActivity().getContentResolver(),
1039 Settings.System.SHOW_TOUCHES, 0) != 0);
1042 private void updateFlingerOptions() {
1043 // magic communication with surface flinger.
1045 IBinder flinger = ServiceManager.getService("SurfaceFlinger");
1046 if (flinger != null) {
1047 Parcel data = Parcel.obtain();
1048 Parcel reply = Parcel.obtain();
1049 data.writeInterfaceToken("android.ui.ISurfaceComposer");
1050 flinger.transact(1010, data, reply, 0);
1051 @SuppressWarnings("unused")
1052 int showCpu = reply.readInt();
1053 @SuppressWarnings("unused")
1054 int enableGL = reply.readInt();
1055 int showUpdates = reply.readInt();
1056 updateSwitchPreference(mShowScreenUpdates, showUpdates != 0);
1057 @SuppressWarnings("unused")
1058 int showBackground = reply.readInt();
1059 int disableOverlays = reply.readInt();
1060 updateSwitchPreference(mDisableOverlays, disableOverlays != 0);
1064 } catch (RemoteException ex) {
1068 private void writeShowUpdatesOption() {
1070 IBinder flinger = ServiceManager.getService("SurfaceFlinger");
1071 if (flinger != null) {
1072 Parcel data = Parcel.obtain();
1073 data.writeInterfaceToken("android.ui.ISurfaceComposer");
1074 final int showUpdates = mShowScreenUpdates.isChecked() ? 1 : 0;
1075 data.writeInt(showUpdates);
1076 flinger.transact(1002, data, null, 0);
1079 updateFlingerOptions();
1081 } catch (RemoteException ex) {
1085 private void writeDisableOverlaysOption() {
1087 IBinder flinger = ServiceManager.getService("SurfaceFlinger");
1088 if (flinger != null) {
1089 Parcel data = Parcel.obtain();
1090 data.writeInterfaceToken("android.ui.ISurfaceComposer");
1091 final int disableOverlays = mDisableOverlays.isChecked() ? 1 : 0;
1092 data.writeInt(disableOverlays);
1093 flinger.transact(1008, data, null, 0);
1096 updateFlingerOptions();
1098 } catch (RemoteException ex) {
1102 private void updateHardwareUiOptions() {
1103 updateSwitchPreference(mForceHardwareUi, SystemProperties.getBoolean(HARDWARE_UI_PROPERTY, false));
1106 private void writeHardwareUiOptions() {
1107 SystemProperties.set(HARDWARE_UI_PROPERTY, mForceHardwareUi.isChecked() ? "true" : "false");
1108 pokeSystemProperties();
1111 private void updateMsaaOptions() {
1112 updateSwitchPreference(mForceMsaa, SystemProperties.getBoolean(MSAA_PROPERTY, false));
1115 private void writeMsaaOptions() {
1116 SystemProperties.set(MSAA_PROPERTY, mForceMsaa.isChecked() ? "true" : "false");
1117 pokeSystemProperties();
1120 private void updateTrackFrameTimeOptions() {
1121 String value = SystemProperties.get(HardwareRenderer.PROFILE_PROPERTY);
1122 if (value == null) {
1126 CharSequence[] values = mTrackFrameTime.getEntryValues();
1127 for (int i = 0; i < values.length; i++) {
1128 if (value.contentEquals(values[i])) {
1129 mTrackFrameTime.setValueIndex(i);
1130 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[i]);
1134 mTrackFrameTime.setValueIndex(0);
1135 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[0]);
1138 private void writeTrackFrameTimeOptions(Object newValue) {
1139 SystemProperties.set(HardwareRenderer.PROFILE_PROPERTY,
1140 newValue == null ? "" : newValue.toString());
1141 pokeSystemProperties();
1142 updateTrackFrameTimeOptions();
1145 private void updateShowNonRectClipOptions() {
1146 String value = SystemProperties.get(
1147 HardwareRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY);
1148 if (value == null) {
1152 CharSequence[] values = mShowNonRectClip.getEntryValues();
1153 for (int i = 0; i < values.length; i++) {
1154 if (value.contentEquals(values[i])) {
1155 mShowNonRectClip.setValueIndex(i);
1156 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[i]);
1160 mShowNonRectClip.setValueIndex(0);
1161 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[0]);
1164 private void writeStayAwakeOptions(Object newValue) {
1165 int val = Integer.parseInt((String) newValue);
1166 Settings.Global.putInt(getActivity().getContentResolver(),
1167 Settings.Global.STAY_ON_WHILE_PLUGGED_IN, val);
1168 updateStayAwakeOptions();
1171 private void writeShowNonRectClipOptions(Object newValue) {
1172 SystemProperties.set(HardwareRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY,
1173 newValue == null ? "" : newValue.toString());
1174 pokeSystemProperties();
1175 updateShowNonRectClipOptions();
1178 private void updateShowHwScreenUpdatesOptions() {
1179 updateSwitchPreference(mShowHwScreenUpdates,
1180 SystemProperties.getBoolean(HardwareRenderer.DEBUG_DIRTY_REGIONS_PROPERTY, false));
1183 private void writeShowHwScreenUpdatesOptions() {
1184 SystemProperties.set(HardwareRenderer.DEBUG_DIRTY_REGIONS_PROPERTY,
1185 mShowHwScreenUpdates.isChecked() ? "true" : null);
1186 pokeSystemProperties();
1189 private void updateShowHwLayersUpdatesOptions() {
1190 updateSwitchPreference(mShowHwLayersUpdates, SystemProperties.getBoolean(
1191 HardwareRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY, false));
1194 private void writeShowHwLayersUpdatesOptions() {
1195 SystemProperties.set(HardwareRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY,
1196 mShowHwLayersUpdates.isChecked() ? "true" : null);
1197 pokeSystemProperties();
1200 private void updateDebugHwOverdrawOptions() {
1201 String value = SystemProperties.get(HardwareRenderer.DEBUG_OVERDRAW_PROPERTY);
1202 if (value == null) {
1206 CharSequence[] values = mDebugHwOverdraw.getEntryValues();
1207 for (int i = 0; i < values.length; i++) {
1208 if (value.contentEquals(values[i])) {
1209 mDebugHwOverdraw.setValueIndex(i);
1210 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[i]);
1214 mDebugHwOverdraw.setValueIndex(0);
1215 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[0]);
1218 private void writeDebugHwOverdrawOptions(Object newValue) {
1219 SystemProperties.set(HardwareRenderer.DEBUG_OVERDRAW_PROPERTY,
1220 newValue == null ? "" : newValue.toString());
1221 pokeSystemProperties();
1222 updateDebugHwOverdrawOptions();
1225 private void updateDebugLayoutOptions() {
1226 updateSwitchPreference(mDebugLayout,
1227 SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false));
1230 private void writeDebugLayoutOptions() {
1231 SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY,
1232 mDebugLayout.isChecked() ? "true" : "false");
1233 pokeSystemProperties();
1236 private void updateSimulateColorSpace() {
1237 final ContentResolver cr = getContentResolver();
1238 final boolean enabled = Settings.Secure.getInt(
1239 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0;
1241 final String mode = Integer.toString(Settings.Secure.getInt(
1242 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
1243 AccessibilityManager.DALTONIZER_DISABLED));
1244 mSimulateColorSpace.setValue(mode);
1245 final int index = mSimulateColorSpace.findIndexOfValue(mode);
1247 // We're using a mode controlled by accessibility preferences.
1248 mSimulateColorSpace.setSummary(getString(R.string.daltonizer_type_overridden,
1249 getString(R.string.accessibility_display_daltonizer_preference_title)));
1251 mSimulateColorSpace.setSummary("%s");
1254 mSimulateColorSpace.setValue(
1255 Integer.toString(AccessibilityManager.DALTONIZER_DISABLED));
1260 * @return <code>true</code> if the color space preference is currently
1261 * controlled by development settings
1263 private boolean usingDevelopmentColorSpace() {
1264 final ContentResolver cr = getContentResolver();
1265 final boolean enabled = Settings.Secure.getInt(
1266 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0;
1268 final String mode = Integer.toString(Settings.Secure.getInt(
1269 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
1270 AccessibilityManager.DALTONIZER_DISABLED));
1271 final int index = mSimulateColorSpace.findIndexOfValue(mode);
1273 // We're using a mode controlled by developer preferences.
1280 private void writeSimulateColorSpace(Object value) {
1281 final ContentResolver cr = getContentResolver();
1282 final int newMode = Integer.parseInt(value.toString());
1284 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0);
1286 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 1);
1287 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, newMode);
1291 private void updateUSBAudioOptions() {
1292 updateSwitchPreference(mUSBAudio, Settings.Secure.getInt(getContentResolver(),
1293 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 0) != 0);
1296 private void writeUSBAudioOptions() {
1297 Settings.Secure.putInt(getContentResolver(),
1298 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED,
1299 mUSBAudio.isChecked() ? 1 : 0);
1302 private void updateForceRtlOptions() {
1303 updateSwitchPreference(mForceRtlLayout,
1304 Settings.Global.getInt(getActivity().getContentResolver(),
1305 Settings.Global.DEVELOPMENT_FORCE_RTL, 0) != 0);
1308 private void writeForceRtlOptions() {
1309 boolean value = mForceRtlLayout.isChecked();
1310 Settings.Global.putInt(getActivity().getContentResolver(),
1311 Settings.Global.DEVELOPMENT_FORCE_RTL, value ? 1 : 0);
1312 SystemProperties.set(Settings.Global.DEVELOPMENT_FORCE_RTL, value ? "1" : "0");
1313 LocalePicker.updateLocale(getActivity().getResources().getConfiguration().locale);
1316 private void updateWifiDisplayCertificationOptions() {
1317 updateSwitchPreference(mWifiDisplayCertification, Settings.Global.getInt(
1318 getActivity().getContentResolver(),
1319 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, 0) != 0);
1322 private void writeWifiDisplayCertificationOptions() {
1323 Settings.Global.putInt(getActivity().getContentResolver(),
1324 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON,
1325 mWifiDisplayCertification.isChecked() ? 1 : 0);
1328 private void updateWifiVerboseLoggingOptions() {
1329 boolean enabled = mWifiManager.getVerboseLoggingLevel() > 0;
1330 updateSwitchPreference(mWifiVerboseLogging, enabled);
1333 private void writeWifiVerboseLoggingOptions() {
1334 mWifiManager.enableVerboseLogging(mWifiVerboseLogging.isChecked() ? 1 : 0);
1337 private void updateWifiAggressiveHandoverOptions() {
1338 boolean enabled = mWifiManager.getAggressiveHandover() > 0;
1339 updateSwitchPreference(mWifiAggressiveHandover, enabled);
1342 private void writeWifiAggressiveHandoverOptions() {
1343 mWifiManager.enableAggressiveHandover(mWifiAggressiveHandover.isChecked() ? 1 : 0);
1346 private void updateWifiAllowScansWithTrafficOptions() {
1347 boolean enabled = mWifiManager.getAllowScansWithTraffic() > 0;
1348 updateSwitchPreference(mWifiAllowScansWithTraffic, enabled);
1351 private void writeWifiAllowScansWithTrafficOptions() {
1352 mWifiManager.setAllowScansWithTraffic(mWifiAllowScansWithTraffic.isChecked() ? 1 : 0);
1355 private void updateLegacyDhcpClientOptions() {
1356 updateSwitchPreference(mLegacyDhcpClient, Settings.Global.getInt(
1357 getActivity().getContentResolver(),
1358 Settings.Global.LEGACY_DHCP_CLIENT, 0) != 0);
1361 private void writeLegacyDhcpClientOptions() {
1362 Settings.Global.putInt(getActivity().getContentResolver(),
1363 Settings.Global.LEGACY_DHCP_CLIENT,
1364 mLegacyDhcpClient.isChecked() ? 1 : 0);
1367 private void updateMobileDataAlwaysOnOptions() {
1368 updateSwitchPreference(mMobileDataAlwaysOn, Settings.Global.getInt(
1369 getActivity().getContentResolver(),
1370 Settings.Global.MOBILE_DATA_ALWAYS_ON, 0) != 0);
1373 private void writeMobileDataAlwaysOnOptions() {
1374 Settings.Global.putInt(getActivity().getContentResolver(),
1375 Settings.Global.MOBILE_DATA_ALWAYS_ON,
1376 mMobileDataAlwaysOn.isChecked() ? 1 : 0);
1379 private void updateLogdSizeValues() {
1380 if (mLogdSize != null) {
1381 String currentValue = SystemProperties.get(SELECT_LOGD_SIZE_PROPERTY);
1382 if (currentValue == null) {
1383 currentValue = SystemProperties.get(SELECT_LOGD_DEFAULT_SIZE_PROPERTY);
1384 if (currentValue == null) {
1385 currentValue = "256K";
1388 String[] values = getResources().getStringArray(R.array.select_logd_size_values);
1389 String[] titles = getResources().getStringArray(R.array.select_logd_size_titles);
1390 if (SystemProperties.get("ro.config.low_ram").equals("true")) {
1391 mLogdSize.setEntries(R.array.select_logd_size_lowram_titles);
1392 titles = getResources().getStringArray(R.array.select_logd_size_lowram_titles);
1394 String[] summaries = getResources().getStringArray(R.array.select_logd_size_summaries);
1395 int index = 1; // punt to second entry if not found
1396 for (int i = 0; i < titles.length; i++) {
1397 if (currentValue.equals(values[i])
1398 || currentValue.equals(titles[i])) {
1403 mLogdSize.setValue(values[index]);
1404 mLogdSize.setSummary(summaries[index]);
1405 mLogdSize.setOnPreferenceChangeListener(this);
1409 private void writeLogdSizeOption(Object newValue) {
1410 String currentValue = SystemProperties.get(SELECT_LOGD_DEFAULT_SIZE_PROPERTY);
1411 if (currentValue != null) {
1412 DEFAULT_LOG_RING_BUFFER_SIZE_IN_BYTES = currentValue;
1414 final String size = (newValue != null) ?
1415 newValue.toString() : DEFAULT_LOG_RING_BUFFER_SIZE_IN_BYTES;
1416 SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, size);
1417 pokeSystemProperties();
1419 Process p = Runtime.getRuntime().exec("logcat -b all -G " + size);
1421 Log.i(TAG, "Logcat ring buffer sizes set to: " + size);
1422 } catch (Exception e) {
1423 Log.w(TAG, "Cannot set logcat ring buffer sizes", e);
1425 updateLogdSizeValues();
1428 private void updateUsbConfigurationValues() {
1429 if (mUsbConfiguration != null) {
1430 UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
1432 String[] values = getResources().getStringArray(R.array.usb_configuration_values);
1433 String[] titles = getResources().getStringArray(R.array.usb_configuration_titles);
1435 for (int i = 0; i < titles.length; i++) {
1436 if (manager.isFunctionEnabled(values[i])) {
1441 mUsbConfiguration.setValue(values[index]);
1442 mUsbConfiguration.setSummary(titles[index]);
1443 mUsbConfiguration.setOnPreferenceChangeListener(this);
1447 private void writeUsbConfigurationOption(Object newValue) {
1448 UsbManager manager = (UsbManager)getActivity().getSystemService(Context.USB_SERVICE);
1449 String function = newValue.toString();
1450 manager.setCurrentFunction(function);
1451 if (function.equals("none")) {
1452 manager.setUsbDataUnlocked(false);
1454 manager.setUsbDataUnlocked(true);
1458 private void updateCpuUsageOptions() {
1459 updateSwitchPreference(mShowCpuUsage,
1460 Settings.Global.getInt(getActivity().getContentResolver(),
1461 Settings.Global.SHOW_PROCESSES, 0) != 0);
1464 private void writeCpuUsageOptions() {
1465 boolean value = mShowCpuUsage.isChecked();
1466 Settings.Global.putInt(getActivity().getContentResolver(),
1467 Settings.Global.SHOW_PROCESSES, value ? 1 : 0);
1468 Intent service = (new Intent())
1469 .setClassName("com.android.systemui", "com.android.systemui.LoadAverageService");
1471 getActivity().startService(service);
1473 getActivity().stopService(service);
1477 private void writeImmediatelyDestroyActivitiesOptions() {
1479 ActivityManagerNative.getDefault().setAlwaysFinish(
1480 mImmediatelyDestroyActivities.isChecked());
1481 } catch (RemoteException ex) {
1485 private void updateImmediatelyDestroyActivitiesOptions() {
1486 updateSwitchPreference(mImmediatelyDestroyActivities, Settings.Global.getInt(
1487 getActivity().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) != 0);
1490 private void updateAnimationScaleValue(int which, ListPreference pref) {
1492 float scale = mWindowManager.getAnimationScale(which);
1494 mHaveDebugSettings = true;
1496 CharSequence[] values = pref.getEntryValues();
1497 for (int i=0; i<values.length; i++) {
1498 float val = Float.parseFloat(values[i].toString());
1500 pref.setValueIndex(i);
1501 pref.setSummary(pref.getEntries()[i]);
1505 pref.setValueIndex(values.length-1);
1506 pref.setSummary(pref.getEntries()[0]);
1507 } catch (RemoteException e) {
1511 private void updateAnimationScaleOptions() {
1512 updateAnimationScaleValue(0, mWindowAnimationScale);
1513 updateAnimationScaleValue(1, mTransitionAnimationScale);
1514 updateAnimationScaleValue(2, mAnimatorDurationScale);
1517 private void writeAnimationScaleOption(int which, ListPreference pref, Object newValue) {
1519 float scale = newValue != null ? Float.parseFloat(newValue.toString()) : 1;
1520 mWindowManager.setAnimationScale(which, scale);
1521 updateAnimationScaleValue(which, pref);
1522 } catch (RemoteException e) {
1526 private void updateOverlayDisplayDevicesOptions() {
1527 String value = Settings.Global.getString(getActivity().getContentResolver(),
1528 Settings.Global.OVERLAY_DISPLAY_DEVICES);
1529 if (value == null) {
1533 CharSequence[] values = mOverlayDisplayDevices.getEntryValues();
1534 for (int i = 0; i < values.length; i++) {
1535 if (value.contentEquals(values[i])) {
1536 mOverlayDisplayDevices.setValueIndex(i);
1537 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[i]);
1541 mOverlayDisplayDevices.setValueIndex(0);
1542 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[0]);
1545 private void writeOverlayDisplayDevicesOptions(Object newValue) {
1546 Settings.Global.putString(getActivity().getContentResolver(),
1547 Settings.Global.OVERLAY_DISPLAY_DEVICES, (String)newValue);
1548 updateOverlayDisplayDevicesOptions();
1551 private void updateOpenGLTracesOptions() {
1552 String value = SystemProperties.get(OPENGL_TRACES_PROPERTY);
1553 if (value == null) {
1557 CharSequence[] values = mOpenGLTraces.getEntryValues();
1558 for (int i = 0; i < values.length; i++) {
1559 if (value.contentEquals(values[i])) {
1560 mOpenGLTraces.setValueIndex(i);
1561 mOpenGLTraces.setSummary(mOpenGLTraces.getEntries()[i]);
1565 mOpenGLTraces.setValueIndex(0);
1566 mOpenGLTraces.setSummary(mOpenGLTraces.getEntries()[0]);
1569 private void writeOpenGLTracesOptions(Object newValue) {
1570 SystemProperties.set(OPENGL_TRACES_PROPERTY, newValue == null ? "" : newValue.toString());
1571 pokeSystemProperties();
1572 updateOpenGLTracesOptions();
1575 private void updateAppProcessLimitOptions() {
1577 int limit = ActivityManagerNative.getDefault().getProcessLimit();
1578 CharSequence[] values = mAppProcessLimit.getEntryValues();
1579 for (int i=0; i<values.length; i++) {
1580 int val = Integer.parseInt(values[i].toString());
1583 mHaveDebugSettings = true;
1585 mAppProcessLimit.setValueIndex(i);
1586 mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[i]);
1590 mAppProcessLimit.setValueIndex(0);
1591 mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[0]);
1592 } catch (RemoteException e) {
1596 private void writeAppProcessLimitOptions(Object newValue) {
1598 int limit = newValue != null ? Integer.parseInt(newValue.toString()) : -1;
1599 ActivityManagerNative.getDefault().setProcessLimit(limit);
1600 updateAppProcessLimitOptions();
1601 } catch (RemoteException e) {
1605 private void writeShowAllANRsOptions() {
1606 Settings.Secure.putInt(getActivity().getContentResolver(),
1607 Settings.Secure.ANR_SHOW_BACKGROUND,
1608 mShowAllANRs.isChecked() ? 1 : 0);
1611 private void updateShowAllANRsOptions() {
1612 updateSwitchPreference(mShowAllANRs, Settings.Secure.getInt(
1613 getActivity().getContentResolver(), Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0);
1616 private void confirmEnableOemUnlock() {
1617 DialogInterface.OnClickListener onConfirmListener = new DialogInterface.OnClickListener() {
1619 public void onClick(DialogInterface dialog, int which) {
1620 Utils.setOemUnlockEnabled(getActivity(), true);
1625 new AlertDialog.Builder(getActivity())
1626 .setTitle(R.string.confirm_enable_oem_unlock_title)
1627 .setMessage(R.string.confirm_enable_oem_unlock_text)
1628 .setPositiveButton(R.string.enable_text, onConfirmListener)
1629 .setNegativeButton(android.R.string.cancel, null)
1634 private void confirmEnableMultiWindowMode() {
1635 DialogInterface.OnClickListener onConfirmListener = new DialogInterface.OnClickListener() {
1637 public void onClick(DialogInterface dialog, int which) {
1638 setEnableMultiWindow((which == DialogInterface.BUTTON_POSITIVE) ? true : false);
1643 new AlertDialog.Builder(getActivity())
1644 .setTitle(R.string.confirm_enable_multi_window_title)
1645 .setMessage(R.string.confirm_enable_multi_window_text)
1646 .setPositiveButton(R.string.enable_text, onConfirmListener)
1647 .setNegativeButton(android.R.string.cancel, onConfirmListener)
1653 public void onSwitchChanged(Switch switchView, boolean isChecked) {
1654 if (switchView != mSwitchBar.getSwitch()) {
1657 if (isChecked != mLastEnabledState) {
1659 mDialogClicked = false;
1660 if (mEnableDialog != null) {
1663 mEnableDialog = new AlertDialog.Builder(getActivity()).setMessage(
1664 getActivity().getResources().getString(
1665 R.string.dev_settings_warning_message))
1666 .setTitle(R.string.dev_settings_warning_title)
1667 .setPositiveButton(android.R.string.yes, this)
1668 .setNegativeButton(android.R.string.no, this)
1670 mEnableDialog.setOnDismissListener(this);
1672 resetDangerousOptions();
1673 Settings.Global.putInt(getActivity().getContentResolver(),
1674 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
1675 mLastEnabledState = isChecked;
1676 setPrefsEnabledState(mLastEnabledState);
1678 // Hide development settings from the Settings menu (Android 4.2 behaviour)
1679 getActivity().getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE).edit()
1680 .putBoolean(PREF_SHOW, false)
1687 public void onActivityResult(int requestCode, int resultCode, Intent data) {
1688 if (requestCode == RESULT_DEBUG_APP) {
1689 if (resultCode == Activity.RESULT_OK) {
1690 mDebugApp = data.getAction();
1691 writeDebuggerOptions();
1692 updateDebuggerOptions();
1694 } else if (requestCode == RESULT_MOCK_LOCATION_APP) {
1695 if (resultCode == Activity.RESULT_OK) {
1696 mMockLocationApp = data.getAction();
1697 writeMockLocation();
1698 updateMockLocation();
1700 } else if (requestCode == REQUEST_CODE_ENABLE_OEM_UNLOCK) {
1701 if (resultCode == Activity.RESULT_OK) {
1702 if (mEnableOemUnlock.isChecked()) {
1703 confirmEnableOemUnlock();
1705 Utils.setOemUnlockEnabled(getActivity(), false);
1709 super.onActivityResult(requestCode, resultCode, data);
1714 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
1715 if (Utils.isMonkeyRunning()) {
1719 if (preference == mEnableAdb) {
1720 if (mEnableAdb.isChecked()) {
1721 mDialogClicked = false;
1722 if (mAdbDialog != null) {
1725 mAdbDialog = new AlertDialog.Builder(getActivity()).setMessage(
1726 getActivity().getResources().getString(R.string.adb_warning_message))
1727 .setTitle(R.string.adb_warning_title)
1728 .setPositiveButton(android.R.string.yes, this)
1729 .setNegativeButton(android.R.string.no, this)
1731 mAdbDialog.setOnDismissListener(this);
1733 Settings.Global.putInt(getActivity().getContentResolver(),
1734 Settings.Global.ADB_ENABLED, 0);
1735 mVerifyAppsOverUsb.setEnabled(false);
1736 mVerifyAppsOverUsb.setChecked(false);
1737 updateBugreportOptions();
1739 } else if (preference == mAdbNotify) {
1740 Settings.Secure.putInt(getActivity().getContentResolver(),
1741 Settings.Secure.ADB_NOTIFY,
1742 mAdbNotify.isChecked() ? 1 : 0);
1743 } else if (preference == mAdbOverNetwork) {
1744 if (mAdbOverNetwork.isChecked()) {
1745 if (mAdbTcpDialog != null) {
1748 mAdbTcpDialog = new AlertDialog.Builder(getActivity()).setMessage(
1749 getResources().getString(R.string.adb_over_network_warning))
1750 .setTitle(R.string.adb_over_network)
1751 .setPositiveButton(android.R.string.yes, this)
1752 .setNegativeButton(android.R.string.no, this)
1754 mAdbTcpDialog.setOnDismissListener(this);
1756 Settings.Secure.putInt(getActivity().getContentResolver(),
1757 Settings.Secure.ADB_PORT, -1);
1758 updateAdbOverNetwork();
1760 } else if (preference == mClearAdbKeys) {
1761 if (mAdbKeysDialog != null) dismissDialogs();
1762 mAdbKeysDialog = new AlertDialog.Builder(getActivity())
1763 .setMessage(R.string.adb_keys_warning_message)
1764 .setPositiveButton(android.R.string.ok, this)
1765 .setNegativeButton(android.R.string.cancel, null)
1767 } else if (preference == mEnableTerminal) {
1768 final PackageManager pm = getActivity().getPackageManager();
1769 pm.setApplicationEnabledSetting(TERMINAL_APP_PACKAGE,
1770 mEnableTerminal.isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1771 : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
1772 } else if (preference == mBugreportInPower) {
1773 Settings.Secure.putInt(getActivity().getContentResolver(),
1774 Settings.Secure.BUGREPORT_IN_POWER_MENU,
1775 mBugreportInPower.isChecked() ? 1 : 0);
1776 } else if (preference == mBtHciSnoopLog) {
1777 writeBtHciSnoopLogOptions();
1778 } else if (preference == mEnableOemUnlock) {
1779 if (!showKeyguardConfirmation(getResources(), REQUEST_CODE_ENABLE_OEM_UNLOCK)) {
1780 if (mEnableOemUnlock.isChecked()) {
1781 confirmEnableOemUnlock();
1783 Utils.setOemUnlockEnabled(getActivity(), false);
1786 } else if (preference == mMockLocationAppPref) {
1787 Intent intent = new Intent(getActivity(), AppPicker.class);
1788 intent.putExtra(AppPicker.EXTRA_REQUESTIING_PERMISSION,
1789 Manifest.permission.ACCESS_MOCK_LOCATION);
1790 startActivityForResult(intent, RESULT_MOCK_LOCATION_APP);
1791 } else if (preference == mDebugViewAttributes) {
1792 Settings.Global.putInt(getActivity().getContentResolver(),
1793 Settings.Global.DEBUG_VIEW_ATTRIBUTES,
1794 mDebugViewAttributes.isChecked() ? 1 : 0);
1795 } else if (preference == mDebugAppPref) {
1796 Intent intent = new Intent(getActivity(), AppPicker.class);
1797 intent.putExtra(AppPicker.EXTRA_DEBUGGABLE, true);
1798 startActivityForResult(intent, RESULT_DEBUG_APP);
1799 } else if (preference == mWaitForDebugger) {
1800 writeDebuggerOptions();
1801 } else if (preference == mVerifyAppsOverUsb) {
1802 writeVerifyAppsOverUsbOptions();
1803 } else if (preference == mStrictMode) {
1804 writeStrictModeVisualOptions();
1805 } else if (preference == mPointerLocation) {
1806 writePointerLocationOptions();
1807 } else if (preference == mShowTouches) {
1808 writeShowTouchesOptions();
1809 } else if (preference == mShowScreenUpdates) {
1810 writeShowUpdatesOption();
1811 } else if (preference == mDisableOverlays) {
1812 writeDisableOverlaysOption();
1813 } else if (preference == mEnableMultiWindow) {
1814 if (mEnableMultiWindow.isChecked()) {
1815 confirmEnableMultiWindowMode();
1817 setEnableMultiWindow(false);
1819 } else if (preference == mShowCpuUsage) {
1820 writeCpuUsageOptions();
1821 } else if (preference == mImmediatelyDestroyActivities) {
1822 writeImmediatelyDestroyActivitiesOptions();
1823 } else if (preference == mShowAllANRs) {
1824 writeShowAllANRsOptions();
1825 } else if (preference == mForceHardwareUi) {
1826 writeHardwareUiOptions();
1827 } else if (preference == mForceMsaa) {
1829 } else if (preference == mShowHwScreenUpdates) {
1830 writeShowHwScreenUpdatesOptions();
1831 } else if (preference == mShowHwLayersUpdates) {
1832 writeShowHwLayersUpdatesOptions();
1833 } else if (preference == mDebugLayout) {
1834 writeDebugLayoutOptions();
1835 } else if (preference == mForceRtlLayout) {
1836 writeForceRtlOptions();
1837 } else if (preference == mWifiDisplayCertification) {
1838 writeWifiDisplayCertificationOptions();
1839 } else if (preference == mWifiVerboseLogging) {
1840 writeWifiVerboseLoggingOptions();
1841 } else if (preference == mWifiAggressiveHandover) {
1842 writeWifiAggressiveHandoverOptions();
1843 } else if (preference == mWifiAllowScansWithTraffic) {
1844 writeWifiAllowScansWithTrafficOptions();
1845 } else if (preference == mLegacyDhcpClient) {
1846 writeLegacyDhcpClientOptions();
1847 } else if (preference == mMobileDataAlwaysOn) {
1848 writeMobileDataAlwaysOnOptions();
1849 } else if (preference == mUSBAudio) {
1850 writeUSBAudioOptions();
1851 } else if (INACTIVE_APPS_KEY.equals(preference.getKey())) {
1852 startInactiveAppsFragment();
1854 return super.onPreferenceTreeClick(preferenceScreen, preference);
1860 private void startInactiveAppsFragment() {
1861 ((SettingsActivity) getActivity()).startPreferencePanel(
1862 InactiveApps.class.getName(),
1863 null, R.string.inactive_apps_title, null, null, 0);
1866 private boolean showKeyguardConfirmation(Resources resources, int requestCode) {
1867 return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
1868 requestCode, resources.getString(R.string.oem_unlock_enable));
1872 public boolean onPreferenceChange(Preference preference, Object newValue) {
1873 if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
1874 SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString());
1876 pokeSystemProperties();
1878 } else if (preference == mLogdSize) {
1879 writeLogdSizeOption(newValue);
1881 } else if (preference == mUsbConfiguration) {
1882 writeUsbConfigurationOption(newValue);
1884 } else if (preference == mWindowAnimationScale) {
1885 writeAnimationScaleOption(0, mWindowAnimationScale, newValue);
1887 } else if (preference == mTransitionAnimationScale) {
1888 writeAnimationScaleOption(1, mTransitionAnimationScale, newValue);
1890 } else if (preference == mAnimatorDurationScale) {
1891 writeAnimationScaleOption(2, mAnimatorDurationScale, newValue);
1893 } else if (preference == mOverlayDisplayDevices) {
1894 writeOverlayDisplayDevicesOptions(newValue);
1896 } else if (preference == mOpenGLTraces) {
1897 writeOpenGLTracesOptions(newValue);
1899 } else if (preference == mTrackFrameTime) {
1900 writeTrackFrameTimeOptions(newValue);
1902 } else if (preference == mDebugHwOverdraw) {
1903 writeDebugHwOverdrawOptions(newValue);
1905 } else if (preference == mShowNonRectClip) {
1906 writeShowNonRectClipOptions(newValue);
1908 } else if (preference == mAppProcessLimit) {
1909 writeAppProcessLimitOptions(newValue);
1911 } else if (preference == mSimulateColorSpace) {
1912 writeSimulateColorSpace(newValue);
1914 } else if (preference == mRootAccess) {
1915 if ("0".equals(SystemProperties.get(ROOT_ACCESS_PROPERTY, "0"))
1916 && !"0".equals(newValue)) {
1917 mSelectedRootValue = newValue;
1918 mDialogClicked = false;
1919 if (mRootDialog != null) {
1922 mRootDialog = new AlertDialog.Builder(getActivity())
1923 .setMessage(getResources().getString(R.string.root_access_warning_message))
1924 .setTitle(R.string.root_access_warning_title)
1925 .setPositiveButton(android.R.string.yes, this)
1926 .setNegativeButton(android.R.string.no, this).show();
1927 mRootDialog.setOnDismissListener(this);
1929 writeRootAccessOptions(newValue);
1932 } else if (preference == mKeepScreenOn) {
1933 writeStayAwakeOptions(newValue);
1939 private void dismissDialogs() {
1940 if (mAdbDialog != null) {
1941 mAdbDialog.dismiss();
1944 if (mAdbTcpDialog != null) {
1945 mAdbTcpDialog.dismiss();
1946 mAdbTcpDialog = null;
1948 if (mAdbKeysDialog != null) {
1949 mAdbKeysDialog.dismiss();
1950 mAdbKeysDialog = null;
1952 if (mEnableDialog != null) {
1953 mEnableDialog.dismiss();
1954 mEnableDialog = null;
1956 if (mRootDialog != null) {
1957 mRootDialog.dismiss();
1962 public void onClick(DialogInterface dialog, int which) {
1963 if (dialog == mAdbDialog) {
1964 if (which == DialogInterface.BUTTON_POSITIVE) {
1965 mDialogClicked = true;
1966 Settings.Global.putInt(getActivity().getContentResolver(),
1967 Settings.Global.ADB_ENABLED, 1);
1968 mVerifyAppsOverUsb.setEnabled(true);
1969 updateVerifyAppsOverUsbOptions();
1970 updateBugreportOptions();
1972 } else if (dialog == mAdbTcpDialog) {
1973 if (which == DialogInterface.BUTTON_POSITIVE) {
1974 Settings.Secure.putInt(getActivity().getContentResolver(),
1975 Settings.Secure.ADB_PORT, 5555);
1977 } else if (dialog == mAdbKeysDialog) {
1978 if (which == DialogInterface.BUTTON_POSITIVE) {
1980 IBinder b = ServiceManager.getService(Context.USB_SERVICE);
1981 IUsbManager service = IUsbManager.Stub.asInterface(b);
1982 service.clearUsbDebuggingKeys();
1983 } catch (RemoteException e) {
1984 Log.e(TAG, "Unable to clear adb keys", e);
1987 } else if (dialog == mEnableDialog) {
1988 if (which == DialogInterface.BUTTON_POSITIVE) {
1989 mDialogClicked = true;
1990 Settings.Global.putInt(getActivity().getContentResolver(),
1991 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
1992 mLastEnabledState = true;
1993 setPrefsEnabledState(mLastEnabledState);
1995 // Make sure the development settings is visible in the main Settings menu
1996 // This is needed since we may have just turned off dev settings and want to
1998 getActivity().getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE).edit()
1999 .putBoolean(PREF_SHOW, true)
2002 } else if (dialog == mRootDialog) {
2003 if (which == DialogInterface.BUTTON_POSITIVE) {
2004 writeRootAccessOptions(mSelectedRootValue);
2007 writeRootAccessOptions("0");
2012 public void onDismiss(DialogInterface dialog) {
2013 // Assuming that onClick gets called first
2014 if (dialog == mAdbDialog) {
2015 if (!mDialogClicked) {
2016 mEnableAdb.setChecked(false);
2019 } else if (dialog == mAdbTcpDialog) {
2020 updateAdbOverNetwork();
2021 mAdbTcpDialog = null;
2022 } else if (dialog == mEnableDialog) {
2023 if (!mDialogClicked) {
2024 mSwitchBar.setChecked(false);
2026 mEnableDialog = null;
2027 } else if (dialog == mRootDialog) {
2028 updateRootAccessOptions();
2034 public void onDestroy() {
2039 void pokeSystemProperties() {
2040 if (!mDontPokeProperties) {
2041 //noinspection unchecked
2042 (new SystemPropPoker()).execute();
2046 private BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
2048 public void onReceive(Context context, Intent intent) {
2049 updateUsbConfigurationValues();
2053 static class SystemPropPoker extends AsyncTask<Void, Void, Void> {
2055 protected Void doInBackground(Void... params) {
2058 services = ServiceManager.listServices();
2059 } catch (RemoteException e) {
2062 for (String service : services) {
2063 IBinder obj = ServiceManager.checkService(service);
2065 Parcel data = Parcel.obtain();
2067 obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0);
2068 } catch (RemoteException e) {
2069 } catch (Exception e) {
2070 Log.i(TAG, "Someone wrote a bad service '" + service
2071 + "' that doesn't like to be poked: " + e);
2080 private static boolean isPackageInstalled(Context context, String packageName) {
2082 return context.getPackageManager().getPackageInfo(packageName, 0) != null;
2083 } catch (NameNotFoundException e) {
2091 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
2092 new BaseSearchIndexProvider() {
2094 private boolean isShowingDeveloperOptions(Context context) {
2095 return context.getSharedPreferences(DevelopmentSettings.PREF_FILE,
2096 Context.MODE_PRIVATE).getBoolean(
2097 DevelopmentSettings.PREF_SHOW,
2098 android.os.Build.TYPE.equals("eng"));
2102 public List<SearchIndexableResource> getXmlResourcesToIndex(
2103 Context context, boolean enabled) {
2105 if (!isShowingDeveloperOptions(context)) {
2109 final SearchIndexableResource sir = new SearchIndexableResource(context);
2110 sir.xmlResId = R.xml.development_prefs;
2111 return Arrays.asList(sir);
2115 public List<String> getNonIndexableKeys(Context context) {
2116 if (!isShowingDeveloperOptions(context)) {
2120 final List<String> keys = new ArrayList<String>();
2121 if (!showEnableOemUnlockPreference()) {
2122 keys.add(ENABLE_OEM_UNLOCK);
2124 if (!showEnableMultiWindowPreference()) {
2125 keys.add(ENABLE_MULTI_WINDOW_KEY);