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