DevelopmentSettings.java revision ad25a47e92c131c74551d811fa8dfabd17bcd99c
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 17package com.android.settings.development; 18 19import android.Manifest; 20import android.app.Activity; 21import android.app.ActivityManager; 22import android.app.AlertDialog; 23import android.app.AppOpsManager; 24import android.app.AppOpsManager.PackageOps; 25import android.app.Dialog; 26import android.app.backup.IBackupManager; 27import android.bluetooth.BluetoothA2dp; 28import android.bluetooth.BluetoothAdapter; 29import android.bluetooth.BluetoothCodecConfig; 30import android.bluetooth.BluetoothCodecStatus; 31import android.bluetooth.BluetoothHeadset; 32import android.bluetooth.BluetoothProfile; 33import android.content.BroadcastReceiver; 34import android.content.ContentResolver; 35import android.content.Context; 36import android.content.DialogInterface; 37import android.content.Intent; 38import android.content.IntentFilter; 39import android.content.pm.ApplicationInfo; 40import android.content.pm.IShortcutService; 41import android.content.pm.PackageManager; 42import android.content.pm.PackageManager.NameNotFoundException; 43import android.content.res.Resources; 44import android.hardware.usb.IUsbManager; 45import android.hardware.usb.UsbManager; 46import android.net.wifi.WifiManager; 47import android.os.AsyncTask; 48import android.os.BatteryManager; 49import android.os.Build; 50import android.os.Bundle; 51import android.os.IBinder; 52import android.os.Parcel; 53import android.os.RemoteException; 54import android.os.ServiceManager; 55import android.os.StrictMode; 56import android.os.SystemProperties; 57import android.os.UserManager; 58import android.os.storage.IStorageManager; 59import android.provider.SearchIndexableResource; 60import android.provider.Settings; 61import android.service.oemlock.OemLockManager; 62import android.support.annotation.VisibleForTesting; 63import android.support.v14.preference.SwitchPreference; 64import android.support.v7.preference.ListPreference; 65import android.support.v7.preference.Preference; 66import android.support.v7.preference.Preference.OnPreferenceChangeListener; 67import android.support.v7.preference.PreferenceGroup; 68import android.support.v7.preference.PreferenceScreen; 69import android.telephony.TelephonyManager; 70import android.text.TextUtils; 71import android.util.Log; 72import android.view.IWindowManager; 73import android.view.LayoutInflater; 74import android.view.ThreadedRenderer; 75import android.view.View; 76import android.view.ViewGroup; 77import android.view.accessibility.AccessibilityManager; 78import android.webkit.IWebViewUpdateService; 79import android.webkit.WebViewFactory; 80import android.widget.Switch; 81import android.widget.Toast; 82 83import com.android.internal.app.LocalePicker; 84import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 85import com.android.settings.R; 86import com.android.settings.RestrictedSettingsFragment; 87import com.android.settings.SettingsActivity; 88import com.android.settings.Utils; 89import com.android.settings.dashboard.DashboardFeatureProvider; 90import com.android.settings.overlay.FeatureFactory; 91import com.android.settings.password.ChooseLockSettingsHelper; 92import com.android.settings.search.BaseSearchIndexProvider; 93import com.android.settings.search.Indexable; 94import com.android.settings.webview.WebViewAppPreferenceController; 95import com.android.settings.widget.SwitchBar; 96import com.android.settingslib.RestrictedLockUtils; 97import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; 98import com.android.settingslib.RestrictedSwitchPreference; 99import com.android.settingslib.drawer.CategoryKey; 100 101import java.util.ArrayList; 102import java.util.Arrays; 103import java.util.HashSet; 104import java.util.List; 105 106/* 107 * Displays preferences for application developers. 108 */ 109public class DevelopmentSettings extends RestrictedSettingsFragment 110 implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener, 111 OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable { 112 private static final String TAG = "DevelopmentSettings"; 113 114 /** 115 * Preference file were development settings prefs are stored. 116 */ 117 public static final String PREF_FILE = "development"; 118 119 /** 120 * Whether to show the development settings to the user. Default is false. 121 */ 122 public static final String PREF_SHOW = "show"; 123 124 private static final String ENABLE_ADB = "enable_adb"; 125 private static final String CLEAR_ADB_KEYS = "clear_adb_keys"; 126 private static final String ENABLE_TERMINAL = "enable_terminal"; 127 private static final String KEEP_SCREEN_ON = "keep_screen_on"; 128 private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log"; 129 private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable"; 130 private static final String HDCP_CHECKING_KEY = "hdcp_checking"; 131 private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking"; 132 private static final String LOCAL_BACKUP_PASSWORD = "local_backup_password"; 133 private static final String HARDWARE_UI_PROPERTY = "persist.sys.ui.hw"; 134 private static final String MSAA_PROPERTY = "debug.egl.force_msaa"; 135 private static final String OPENGL_TRACES_PROPERTY = "debug.egl.trace"; 136 private static final String TUNER_UI_KEY = "tuner_ui"; 137 private static final String COLOR_TEMPERATURE_PROPERTY = "persist.sys.debug.color_temp"; 138 139 private static final String DEBUG_APP_KEY = "debug_app"; 140 private static final String WAIT_FOR_DEBUGGER_KEY = "wait_for_debugger"; 141 private static final String MOCK_LOCATION_APP_KEY = "mock_location_app"; 142 private static final String DEBUG_VIEW_ATTRIBUTES = "debug_view_attributes"; 143 private static final String FORCE_ALLOW_ON_EXTERNAL_KEY = "force_allow_on_external"; 144 private static final String STRICT_MODE_KEY = "strict_mode"; 145 private static final String POINTER_LOCATION_KEY = "pointer_location"; 146 private static final String SHOW_TOUCHES_KEY = "show_touches"; 147 private static final String SHOW_SCREEN_UPDATES_KEY = "show_screen_updates"; 148 private static final String DISABLE_OVERLAYS_KEY = "disable_overlays"; 149 private static final String SIMULATE_COLOR_SPACE = "simulate_color_space"; 150 private static final String USB_AUDIO_KEY = "usb_audio"; 151 private static final String FORCE_HARDWARE_UI_KEY = "force_hw_ui"; 152 private static final String FORCE_MSAA_KEY = "force_msaa"; 153 private static final String TRACK_FRAME_TIME_KEY = "track_frame_time"; 154 private static final String SHOW_NON_RECTANGULAR_CLIP_KEY = "show_non_rect_clip"; 155 private static final String SHOW_HW_SCREEN_UPDATES_KEY = "show_hw_screen_udpates"; 156 private static final String SHOW_HW_LAYERS_UPDATES_KEY = "show_hw_layers_udpates"; 157 private static final String DEBUG_HW_OVERDRAW_KEY = "debug_hw_overdraw"; 158 private static final String DEBUG_HW_RENDERER_KEY = "debug_hw_renderer"; 159 private static final String DEBUG_LAYOUT_KEY = "debug_layout"; 160 private static final String FORCE_RTL_LAYOUT_KEY = "force_rtl_layout_all_locales"; 161 private static final String WINDOW_ANIMATION_SCALE_KEY = "window_animation_scale"; 162 private static final String TRANSITION_ANIMATION_SCALE_KEY = "transition_animation_scale"; 163 private static final String ANIMATOR_DURATION_SCALE_KEY = "animator_duration_scale"; 164 private static final String OVERLAY_DISPLAY_DEVICES_KEY = "overlay_display_devices"; 165 private static final String DEBUG_DEBUGGING_CATEGORY_KEY = "debug_debugging_category"; 166 private static final String SELECT_LOGD_SIZE_KEY = "select_logd_size"; 167 private static final String SELECT_LOGD_SIZE_PROPERTY = "persist.logd.size"; 168 private static final String SELECT_LOGD_TAG_PROPERTY = "persist.log.tag"; 169 // Tricky, isLoggable only checks for first character, assumes silence 170 private static final String SELECT_LOGD_TAG_SILENCE = "Settings"; 171 private static final String SELECT_LOGD_SNET_TAG_PROPERTY = "persist.log.tag.snet_event_log"; 172 private static final String SELECT_LOGD_RUNTIME_SNET_TAG_PROPERTY = "log.tag.snet_event_log"; 173 private static final String SELECT_LOGD_DEFAULT_SIZE_PROPERTY = "ro.logd.size"; 174 private static final String SELECT_LOGD_DEFAULT_SIZE_VALUE = "262144"; 175 private static final String SELECT_LOGD_SVELTE_DEFAULT_SIZE_VALUE = "65536"; 176 // 32768 is merely a menu marker, 64K is our lowest log buffer size we replace it with. 177 private static final String SELECT_LOGD_MINIMUM_SIZE_VALUE = "65536"; 178 private static final String SELECT_LOGD_OFF_SIZE_MARKER_VALUE = "32768"; 179 private static final String SELECT_LOGPERSIST_KEY = "select_logpersist"; 180 private static final String SELECT_LOGPERSIST_PROPERTY = "persist.logd.logpersistd"; 181 private static final String ACTUAL_LOGPERSIST_PROPERTY = "logd.logpersistd"; 182 private static final String SELECT_LOGPERSIST_PROPERTY_SERVICE = "logcatd"; 183 private static final String SELECT_LOGPERSIST_PROPERTY_CLEAR = "clear"; 184 private static final String SELECT_LOGPERSIST_PROPERTY_STOP = "stop"; 185 private static final String SELECT_LOGPERSIST_PROPERTY_BUFFER = 186 "persist.logd.logpersistd.buffer"; 187 private static final String ACTUAL_LOGPERSIST_PROPERTY_BUFFER = "logd.logpersistd.buffer"; 188 private static final String ACTUAL_LOGPERSIST_PROPERTY_ENABLE = "logd.logpersistd.enable"; 189 190 private static final String WIFI_DISPLAY_CERTIFICATION_KEY = "wifi_display_certification"; 191 private static final String WIFI_VERBOSE_LOGGING_KEY = "wifi_verbose_logging"; 192 private static final String WIFI_AGGRESSIVE_HANDOVER_KEY = "wifi_aggressive_handover"; 193 private static final String WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY = "wifi_allow_scan_with_traffic"; 194 private static final String USB_CONFIGURATION_KEY = "select_usb_configuration"; 195 private static final String MOBILE_DATA_ALWAYS_ON = "mobile_data_always_on"; 196 private static final String TETHERING_HARDWARE_OFFLOAD = "tethering_hardware_offload"; 197 private static final String KEY_COLOR_MODE = "picture_color_mode"; 198 private static final String FORCE_RESIZABLE_KEY = "force_resizable_activities"; 199 private static final String COLOR_TEMPERATURE_KEY = "color_temperature"; 200 201 private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY = 202 "bluetooth_disable_absolute_volume"; 203 private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY = 204 "persist.bluetooth.disableabsvol"; 205 private static final String BLUETOOTH_AVRCP_VERSION_PROPERTY = 206 "persist.bluetooth.avrcpversion"; 207 private static final String BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY = 208 "persist.bluetooth.enableinbandringing"; 209 private static final String BLUETOOTH_BTSNOOP_ENABLE_PROPERTY = 210 "persist.bluetooth.btsnoopenable"; 211 212 private static final String BLUETOOTH_ENABLE_INBAND_RINGING_KEY = "bluetooth_enable_inband_ringing"; 213 private static final String BLUETOOTH_SELECT_AVRCP_VERSION_KEY = "bluetooth_select_avrcp_version"; 214 private static final String BLUETOOTH_SELECT_A2DP_CODEC_KEY = "bluetooth_select_a2dp_codec"; 215 private static final String BLUETOOTH_SELECT_A2DP_SAMPLE_RATE_KEY = "bluetooth_select_a2dp_sample_rate"; 216 private static final String BLUETOOTH_SELECT_A2DP_BITS_PER_SAMPLE_KEY = "bluetooth_select_a2dp_bits_per_sample"; 217 private static final String BLUETOOTH_SELECT_A2DP_CHANNEL_MODE_KEY = "bluetooth_select_a2dp_channel_mode"; 218 private static final String BLUETOOTH_SELECT_A2DP_LDAC_PLAYBACK_QUALITY_KEY = "bluetooth_select_a2dp_ldac_playback_quality"; 219 220 private static final String INACTIVE_APPS_KEY = "inactive_apps"; 221 222 private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY 223 = "immediately_destroy_activities"; 224 private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit"; 225 226 private static final String BACKGROUND_CHECK_KEY = "background_check"; 227 228 private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs"; 229 230 private static final String SHOW_NOTIFICATION_CHANNEL_WARNINGS_KEY = "show_notification_channel_warnings"; 231 232 private static final String TERMINAL_APP_PACKAGE = "com.android.terminal"; 233 234 private static final String KEY_CONVERT_FBE = "convert_to_file_encryption"; 235 236 private static final String OTA_DISABLE_AUTOMATIC_UPDATE_KEY = "ota_disable_automatic_update"; 237 238 private static final int RESULT_DEBUG_APP = 1000; 239 private static final int RESULT_MOCK_LOCATION_APP = 1001; 240 241 private static final String FLASH_LOCKED_PROP = "ro.boot.flash.locked"; 242 243 private static final String SHORTCUT_MANAGER_RESET_KEY = "reset_shortcut_manager_throttling"; 244 245 private static final int REQUEST_CODE_ENABLE_OEM_UNLOCK = 0; 246 247 private static final int[] MOCK_LOCATION_APP_OPS = new int[]{AppOpsManager.OP_MOCK_LOCATION}; 248 249 private IWindowManager mWindowManager; 250 private IBackupManager mBackupManager; 251 private IWebViewUpdateService mWebViewUpdateService; 252 private UserManager mUm; 253 private WifiManager mWifiManager; 254 private OemLockManager mOemLockManager; 255 private TelephonyManager mTelephonyManager; 256 257 private SwitchBar mSwitchBar; 258 259 private boolean mHaveDebugSettings; 260 private boolean mDontPokeProperties; 261 private SwitchPreference mEnableAdb; 262 private Preference mClearAdbKeys; 263 private SwitchPreference mEnableTerminal; 264 private RestrictedSwitchPreference mKeepScreenOn; 265 private SwitchPreference mBtHciSnoopLog; 266 private RestrictedSwitchPreference mEnableOemUnlock; 267 private SwitchPreference mDebugViewAttributes; 268 private SwitchPreference mForceAllowOnExternal; 269 270 private Preference mPassword; 271 private String mDebugApp; 272 private Preference mDebugAppPref; 273 274 private String mMockLocationApp; 275 private Preference mMockLocationAppPref; 276 277 private SwitchPreference mWaitForDebugger; 278 private VerifyAppsOverUsbPreferenceController mVerifyAppsOverUsbController; 279 private SwitchPreference mWifiDisplayCertification; 280 private SwitchPreference mWifiVerboseLogging; 281 private SwitchPreference mWifiAggressiveHandover; 282 private SwitchPreference mMobileDataAlwaysOn; 283 private SwitchPreference mTetheringHardwareOffload; 284 private SwitchPreference mBluetoothDisableAbsVolume; 285 private SwitchPreference mBluetoothEnableInbandRinging; 286 287 private BluetoothA2dp mBluetoothA2dp; 288 private final Object mBluetoothA2dpLock = new Object(); 289 private ListPreference mBluetoothSelectAvrcpVersion; 290 private ListPreference mBluetoothSelectA2dpCodec; 291 private ListPreference mBluetoothSelectA2dpSampleRate; 292 private ListPreference mBluetoothSelectA2dpBitsPerSample; 293 private ListPreference mBluetoothSelectA2dpChannelMode; 294 private ListPreference mBluetoothSelectA2dpLdacPlaybackQuality; 295 296 private SwitchPreference mOtaDisableAutomaticUpdate; 297 private SwitchPreference mWifiAllowScansWithTraffic; 298 private SwitchPreference mStrictMode; 299 private SwitchPreference mPointerLocation; 300 private SwitchPreference mShowTouches; 301 private SwitchPreference mShowScreenUpdates; 302 private SwitchPreference mDisableOverlays; 303 private SwitchPreference mForceHardwareUi; 304 private SwitchPreference mForceMsaa; 305 private SwitchPreference mShowHwScreenUpdates; 306 private SwitchPreference mShowHwLayersUpdates; 307 private SwitchPreference mDebugLayout; 308 private SwitchPreference mForceRtlLayout; 309 private ListPreference mDebugHwOverdraw; 310 private ListPreference mDebugHwRenderer; 311 private ListPreference mLogdSize; 312 private ListPreference mLogpersist; 313 private ListPreference mUsbConfiguration; 314 private ListPreference mTrackFrameTime; 315 private ListPreference mShowNonRectClip; 316 private ListPreference mWindowAnimationScale; 317 private ListPreference mTransitionAnimationScale; 318 private ListPreference mAnimatorDurationScale; 319 private ListPreference mOverlayDisplayDevices; 320 321 private WebViewAppPreferenceController mWebViewAppPrefController; 322 323 private ListPreference mSimulateColorSpace; 324 325 private SwitchPreference mUSBAudio; 326 private SwitchPreference mImmediatelyDestroyActivities; 327 328 private ListPreference mAppProcessLimit; 329 330 private SwitchPreference mShowAllANRs; 331 332 private SwitchPreference mShowNotificationChannelWarnings; 333 334 private ColorModePreference mColorModePreference; 335 336 private SwitchPreference mForceResizable; 337 338 private SwitchPreference mColorTemperaturePreference; 339 340 private final ArrayList<Preference> mAllPrefs = new ArrayList<>(); 341 342 private final ArrayList<SwitchPreference> mResetSwitchPrefs = new ArrayList<>(); 343 344 private final HashSet<Preference> mDisabledPrefs = new HashSet<>(); 345 // To track whether a confirmation dialog was clicked. 346 private boolean mDialogClicked; 347 private Dialog mEnableDialog; 348 private Dialog mAdbDialog; 349 350 private Dialog mAdbKeysDialog; 351 private boolean mUnavailable; 352 353 private boolean mLogpersistCleared; 354 private Dialog mLogpersistClearDialog; 355 private DashboardFeatureProvider mDashboardFeatureProvider; 356 private DevelopmentSettingsEnabler mSettingsEnabler; 357 private BugReportPreferenceController mBugReportController; 358 private BugReportInPowerPreferenceController mBugReportInPowerController; 359 private TelephonyMonitorPreferenceController mTelephonyMonitorController; 360 private CameraHalHdrplusPreferenceController mCameraHalHdrplusController; 361 362 public DevelopmentSettings() { 363 super(UserManager.DISALLOW_DEBUGGING_FEATURES); 364 } 365 366 @Override 367 public int getMetricsCategory() { 368 return MetricsEvent.DEVELOPMENT; 369 } 370 371 @Override 372 public void onAttach(Context context) { 373 super.onAttach(context); 374 mSettingsEnabler = new DevelopmentSettingsEnabler(context, getLifecycle()); 375 mDashboardFeatureProvider = FeatureFactory.getFactory(context) 376 .getDashboardFeatureProvider(context); 377 } 378 379 @Override 380 public void onCreate(Bundle icicle) { 381 super.onCreate(icicle); 382 383 mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window")); 384 mBackupManager = IBackupManager.Stub.asInterface( 385 ServiceManager.getService(Context.BACKUP_SERVICE)); 386 mWebViewUpdateService = WebViewFactory.getUpdateService(); 387 mOemLockManager = (OemLockManager) getSystemService(Context.OEM_LOCK_SERVICE); 388 mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 389 390 mUm = (UserManager) getSystemService(Context.USER_SERVICE); 391 392 mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); 393 394 mBugReportController = new BugReportPreferenceController(getActivity()); 395 mBugReportInPowerController = new BugReportInPowerPreferenceController(getActivity()); 396 mTelephonyMonitorController = new TelephonyMonitorPreferenceController(getActivity()); 397 mWebViewAppPrefController = new WebViewAppPreferenceController(getActivity()); 398 mVerifyAppsOverUsbController = new VerifyAppsOverUsbPreferenceController(getActivity()); 399 mCameraHalHdrplusController = new CameraHalHdrplusPreferenceController(getActivity()); 400 401 setIfOnlyAvailableForAdmins(true); 402 if (isUiRestricted() || !Utils.isDeviceProvisioned(getActivity())) { 403 // Block access to developer options if the user is not the owner, if user policy 404 // restricts it, or if the device has not been provisioned 405 mUnavailable = true; 406 addPreferencesFromResource(R.xml.placeholder_prefs); 407 return; 408 } 409 410 addPreferencesFromResource(R.xml.development_prefs); 411 412 final PreferenceGroup debugDebuggingCategory = (PreferenceGroup) 413 findPreference(DEBUG_DEBUGGING_CATEGORY_KEY); 414 mEnableAdb = findAndInitSwitchPref(ENABLE_ADB); 415 mClearAdbKeys = findPreference(CLEAR_ADB_KEYS); 416 if (!SystemProperties.getBoolean("ro.adb.secure", false)) { 417 if (debugDebuggingCategory != null) { 418 debugDebuggingCategory.removePreference(mClearAdbKeys); 419 } 420 } 421 mAllPrefs.add(mClearAdbKeys); 422 mEnableTerminal = findAndInitSwitchPref(ENABLE_TERMINAL); 423 if (!isPackageInstalled(getActivity(), TERMINAL_APP_PACKAGE)) { 424 debugDebuggingCategory.removePreference(mEnableTerminal); 425 mEnableTerminal = null; 426 } 427 428 mBugReportController.displayPreference(getPreferenceScreen()); 429 mBugReportInPowerController.displayPreference(getPreferenceScreen()); 430 mTelephonyMonitorController.displayPreference(getPreferenceScreen()); 431 mWebViewAppPrefController.displayPreference(getPreferenceScreen()); 432 mCameraHalHdrplusController.displayPreference(getPreferenceScreen()); 433 434 mKeepScreenOn = (RestrictedSwitchPreference) findAndInitSwitchPref(KEEP_SCREEN_ON); 435 mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG); 436 mEnableOemUnlock = (RestrictedSwitchPreference) findAndInitSwitchPref(ENABLE_OEM_UNLOCK); 437 if (!showEnableOemUnlockPreference(getActivity())) { 438 removePreference(mEnableOemUnlock); 439 mEnableOemUnlock = null; 440 } 441 442 mDebugViewAttributes = findAndInitSwitchPref(DEBUG_VIEW_ATTRIBUTES); 443 mForceAllowOnExternal = findAndInitSwitchPref(FORCE_ALLOW_ON_EXTERNAL_KEY); 444 mPassword = findPreference(LOCAL_BACKUP_PASSWORD); 445 mAllPrefs.add(mPassword); 446 447 if (!mUm.isAdminUser()) { 448 disableForUser(mEnableAdb); 449 disableForUser(mClearAdbKeys); 450 disableForUser(mEnableTerminal); 451 disableForUser(mPassword); 452 } 453 454 mDebugAppPref = findPreference(DEBUG_APP_KEY); 455 mAllPrefs.add(mDebugAppPref); 456 mWaitForDebugger = findAndInitSwitchPref(WAIT_FOR_DEBUGGER_KEY); 457 458 mMockLocationAppPref = findPreference(MOCK_LOCATION_APP_KEY); 459 mAllPrefs.add(mMockLocationAppPref); 460 461 mVerifyAppsOverUsbController.displayPreference(getPreferenceScreen()); 462 463 mStrictMode = findAndInitSwitchPref(STRICT_MODE_KEY); 464 mPointerLocation = findAndInitSwitchPref(POINTER_LOCATION_KEY); 465 mShowTouches = findAndInitSwitchPref(SHOW_TOUCHES_KEY); 466 mShowScreenUpdates = findAndInitSwitchPref(SHOW_SCREEN_UPDATES_KEY); 467 mDisableOverlays = findAndInitSwitchPref(DISABLE_OVERLAYS_KEY); 468 mForceHardwareUi = findAndInitSwitchPref(FORCE_HARDWARE_UI_KEY); 469 mForceMsaa = findAndInitSwitchPref(FORCE_MSAA_KEY); 470 mTrackFrameTime = addListPreference(TRACK_FRAME_TIME_KEY); 471 mShowNonRectClip = addListPreference(SHOW_NON_RECTANGULAR_CLIP_KEY); 472 mShowHwScreenUpdates = findAndInitSwitchPref(SHOW_HW_SCREEN_UPDATES_KEY); 473 mShowHwLayersUpdates = findAndInitSwitchPref(SHOW_HW_LAYERS_UPDATES_KEY); 474 mDebugLayout = findAndInitSwitchPref(DEBUG_LAYOUT_KEY); 475 mForceRtlLayout = findAndInitSwitchPref(FORCE_RTL_LAYOUT_KEY); 476 mDebugHwOverdraw = addListPreference(DEBUG_HW_OVERDRAW_KEY); 477 mDebugHwRenderer = addListPreference(DEBUG_HW_RENDERER_KEY); 478 mWifiDisplayCertification = findAndInitSwitchPref(WIFI_DISPLAY_CERTIFICATION_KEY); 479 mWifiVerboseLogging = findAndInitSwitchPref(WIFI_VERBOSE_LOGGING_KEY); 480 mWifiAggressiveHandover = findAndInitSwitchPref(WIFI_AGGRESSIVE_HANDOVER_KEY); 481 mWifiAllowScansWithTraffic = findAndInitSwitchPref(WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY); 482 mMobileDataAlwaysOn = findAndInitSwitchPref(MOBILE_DATA_ALWAYS_ON); 483 mTetheringHardwareOffload = findAndInitSwitchPref(TETHERING_HARDWARE_OFFLOAD); 484 mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY); 485 if ("1".equals(SystemProperties.get("ro.debuggable", "0"))) { 486 mLogpersist = addListPreference(SELECT_LOGPERSIST_KEY); 487 } else { 488 mLogpersist = (ListPreference) findPreference(SELECT_LOGPERSIST_KEY); 489 if (mLogpersist != null) { 490 mLogpersist.setEnabled(false); 491 if (debugDebuggingCategory != null) { 492 debugDebuggingCategory.removePreference(mLogpersist); 493 } 494 } 495 mLogpersist = null; 496 } 497 mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY); 498 mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY); 499 mBluetoothEnableInbandRinging = findAndInitSwitchPref(BLUETOOTH_ENABLE_INBAND_RINGING_KEY); 500 if (!BluetoothHeadset.isInbandRingingSupported(getContext())) { 501 removePreference(mBluetoothEnableInbandRinging); 502 mBluetoothEnableInbandRinging = null; 503 } 504 505 mBluetoothSelectAvrcpVersion = addListPreference(BLUETOOTH_SELECT_AVRCP_VERSION_KEY); 506 mBluetoothSelectA2dpCodec = addListPreference(BLUETOOTH_SELECT_A2DP_CODEC_KEY); 507 mBluetoothSelectA2dpSampleRate = addListPreference(BLUETOOTH_SELECT_A2DP_SAMPLE_RATE_KEY); 508 mBluetoothSelectA2dpBitsPerSample = addListPreference(BLUETOOTH_SELECT_A2DP_BITS_PER_SAMPLE_KEY); 509 mBluetoothSelectA2dpChannelMode = addListPreference(BLUETOOTH_SELECT_A2DP_CHANNEL_MODE_KEY); 510 mBluetoothSelectA2dpLdacPlaybackQuality = addListPreference(BLUETOOTH_SELECT_A2DP_LDAC_PLAYBACK_QUALITY_KEY); 511 initBluetoothConfigurationValues(); 512 513 mWindowAnimationScale = addListPreference(WINDOW_ANIMATION_SCALE_KEY); 514 mTransitionAnimationScale = addListPreference(TRANSITION_ANIMATION_SCALE_KEY); 515 mAnimatorDurationScale = addListPreference(ANIMATOR_DURATION_SCALE_KEY); 516 mOverlayDisplayDevices = addListPreference(OVERLAY_DISPLAY_DEVICES_KEY); 517 mSimulateColorSpace = addListPreference(SIMULATE_COLOR_SPACE); 518 mUSBAudio = findAndInitSwitchPref(USB_AUDIO_KEY); 519 mForceResizable = findAndInitSwitchPref(FORCE_RESIZABLE_KEY); 520 521 mImmediatelyDestroyActivities = (SwitchPreference) findPreference( 522 IMMEDIATELY_DESTROY_ACTIVITIES_KEY); 523 mAllPrefs.add(mImmediatelyDestroyActivities); 524 mResetSwitchPrefs.add(mImmediatelyDestroyActivities); 525 526 mAppProcessLimit = addListPreference(APP_PROCESS_LIMIT_KEY); 527 528 mShowAllANRs = (SwitchPreference) findPreference( 529 SHOW_ALL_ANRS_KEY); 530 mAllPrefs.add(mShowAllANRs); 531 mResetSwitchPrefs.add(mShowAllANRs); 532 533 mShowNotificationChannelWarnings = (SwitchPreference) findPreference( 534 SHOW_NOTIFICATION_CHANNEL_WARNINGS_KEY); 535 mAllPrefs.add(mShowNotificationChannelWarnings); 536 mResetSwitchPrefs.add(mShowNotificationChannelWarnings); 537 538 Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY); 539 if (hdcpChecking != null) { 540 mAllPrefs.add(hdcpChecking); 541 removePreferenceForProduction(hdcpChecking); 542 } 543 544 Preference convertFbePreference = findPreference(KEY_CONVERT_FBE); 545 546 try { 547 IBinder service = ServiceManager.getService("mount"); 548 IStorageManager storageManager = IStorageManager.Stub.asInterface(service); 549 if (!storageManager.isConvertibleToFBE()) { 550 removePreference(KEY_CONVERT_FBE); 551 } else if ("file".equals(SystemProperties.get("ro.crypto.type", "none"))) { 552 convertFbePreference.setEnabled(false); 553 convertFbePreference.setSummary(getResources() 554 .getString(R.string.convert_to_file_encryption_done)); 555 } 556 } catch (RemoteException e) { 557 removePreference(KEY_CONVERT_FBE); 558 } 559 560 mOtaDisableAutomaticUpdate = findAndInitSwitchPref(OTA_DISABLE_AUTOMATIC_UPDATE_KEY); 561 562 mColorModePreference = (ColorModePreference) findPreference(KEY_COLOR_MODE); 563 mColorModePreference.updateCurrentAndSupported(); 564 if (mColorModePreference.getColorModeCount() < 2 || 565 getContext().getDisplay().isWideColorGamut()) { 566 removePreference(KEY_COLOR_MODE); 567 mColorModePreference = null; 568 } 569 570 mColorTemperaturePreference = (SwitchPreference) findPreference(COLOR_TEMPERATURE_KEY); 571 if (getResources().getBoolean(R.bool.config_enableColorTemperature)) { 572 mAllPrefs.add(mColorTemperaturePreference); 573 mResetSwitchPrefs.add(mColorTemperaturePreference); 574 } else { 575 removePreference(COLOR_TEMPERATURE_KEY); 576 mColorTemperaturePreference = null; 577 } 578 579 addDashboardCategoryPreferences(); 580 } 581 582 @VisibleForTesting 583 void addDashboardCategoryPreferences() { 584 final PreferenceScreen screen = getPreferenceScreen(); 585 final List<Preference> tilePrefs = mDashboardFeatureProvider.getPreferencesForCategory( 586 getActivity(), getPrefContext(), getMetricsCategory(), 587 CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT); 588 if (tilePrefs != null) { 589 for (Preference preference : tilePrefs) { 590 screen.addPreference(preference); 591 } 592 } 593 } 594 595 private ListPreference addListPreference(String prefKey) { 596 ListPreference pref = (ListPreference) findPreference(prefKey); 597 mAllPrefs.add(pref); 598 pref.setOnPreferenceChangeListener(this); 599 return pref; 600 } 601 602 private void disableForUser(Preference pref) { 603 if (pref != null) { 604 pref.setEnabled(false); 605 mDisabledPrefs.add(pref); 606 } 607 } 608 609 private SwitchPreference findAndInitSwitchPref(String key) { 610 SwitchPreference pref = (SwitchPreference) findPreference(key); 611 if (pref == null) { 612 throw new IllegalArgumentException("Cannot find preference with key = " + key); 613 } 614 mAllPrefs.add(pref); 615 mResetSwitchPrefs.add(pref); 616 return pref; 617 } 618 619 @Override 620 public void onActivityCreated(Bundle savedInstanceState) { 621 super.onActivityCreated(savedInstanceState); 622 623 final SettingsActivity activity = (SettingsActivity) getActivity(); 624 625 mSwitchBar = activity.getSwitchBar(); 626 if (mUnavailable) { 627 mSwitchBar.setEnabled(false); 628 return; 629 } 630 631 mSwitchBar.addOnSwitchChangeListener(this); 632 } 633 634 private boolean removePreferenceForProduction(Preference preference) { 635 if ("user".equals(Build.TYPE)) { 636 removePreference(preference); 637 return true; 638 } 639 return false; 640 } 641 642 private void removePreference(Preference preference) { 643 getPreferenceScreen().removePreference(preference); 644 mAllPrefs.remove(preference); 645 mResetSwitchPrefs.remove(preference); 646 } 647 648 private void setPrefsEnabledState(boolean enabled) { 649 for (int i = 0; i < mAllPrefs.size(); i++) { 650 Preference pref = mAllPrefs.get(i); 651 pref.setEnabled(enabled && !mDisabledPrefs.contains(pref)); 652 } 653 mBugReportInPowerController.enablePreference(enabled); 654 mTelephonyMonitorController.enablePreference(enabled); 655 mWebViewAppPrefController.enablePreference(enabled); 656 mCameraHalHdrplusController.enablePreference(enabled); 657 updateAllOptions(); 658 } 659 660 @Override 661 public void onResume() { 662 super.onResume(); 663 664 if (mUnavailable) { 665 // Show error message 666 if (!isUiRestrictedByOnlyAdmin()) { 667 getEmptyTextView().setText(R.string.development_settings_not_available); 668 } 669 getPreferenceScreen().removeAll(); 670 return; 671 } 672 673 // A DeviceAdmin has specified a maximum time until the device 674 // will lock... in this case we can't allow the user to turn 675 // on "stay awake when plugged in" because that would defeat the 676 // restriction. 677 final EnforcedAdmin admin = RestrictedLockUtils.checkIfMaximumTimeToLockIsSet( 678 getActivity()); 679 mKeepScreenOn.setDisabledByAdmin(admin); 680 if (admin == null) { 681 mDisabledPrefs.remove(mKeepScreenOn); 682 } else { 683 mDisabledPrefs.add(mKeepScreenOn); 684 } 685 686 final boolean lastEnabledState = mSettingsEnabler.getLastEnabledState(); 687 mSwitchBar.setChecked(lastEnabledState); 688 setPrefsEnabledState(lastEnabledState); 689 690 if (mHaveDebugSettings && !lastEnabledState) { 691 // Overall debugging is disabled, but there are some debug 692 // settings that are enabled. This is an invalid state. Switch 693 // to debug settings being enabled, so the user knows there is 694 // stuff enabled and can turn it all off if they want. 695 mSettingsEnabler.enableDevelopmentSettings(); 696 mSwitchBar.setChecked(lastEnabledState); 697 setPrefsEnabledState(lastEnabledState); 698 } 699 mSwitchBar.show(); 700 701 if (mColorModePreference != null) { 702 mColorModePreference.startListening(); 703 mColorModePreference.updateCurrentAndSupported(); 704 } 705 } 706 707 @Override 708 public void onPause() { 709 super.onPause(); 710 if (mColorModePreference != null) { 711 mColorModePreference.stopListening(); 712 } 713 } 714 715 @Override 716 public View onCreateView(LayoutInflater inflater, ViewGroup container, 717 Bundle savedInstanceState) { 718 IntentFilter filter = new IntentFilter(); 719 filter.addAction(UsbManager.ACTION_USB_STATE); 720 if (getActivity().registerReceiver(mUsbReceiver, filter) == null) { 721 updateUsbConfigurationValues(); 722 } 723 724 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 725 if (adapter != null) { 726 adapter.getProfileProxy(getActivity(), 727 mBluetoothA2dpServiceListener, 728 BluetoothProfile.A2DP); 729 } 730 filter = new IntentFilter(); 731 filter.addAction(BluetoothA2dp.ACTION_CODEC_CONFIG_CHANGED); 732 if (getActivity().registerReceiver(mBluetoothA2dpReceiver, filter) == null) { 733 updateBluetoothA2dpConfigurationValues(); 734 } 735 736 return super.onCreateView(inflater, container, savedInstanceState); 737 } 738 739 @Override 740 public void onDestroyView() { 741 super.onDestroyView(); 742 743 if (mUnavailable) { 744 return; 745 } 746 mSwitchBar.removeOnSwitchChangeListener(this); 747 mSwitchBar.hide(); 748 getActivity().unregisterReceiver(mUsbReceiver); 749 getActivity().unregisterReceiver(mBluetoothA2dpReceiver); 750 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 751 if (adapter != null) { 752 adapter.closeProfileProxy(BluetoothProfile.A2DP, mBluetoothA2dp); 753 mBluetoothA2dp = null; 754 } 755 } 756 757 void updateSwitchPreference(SwitchPreference switchPreference, boolean value) { 758 switchPreference.setChecked(value); 759 mHaveDebugSettings |= value; 760 } 761 762 private void updateAllOptions() { 763 final Context context = getActivity(); 764 final ContentResolver cr = context.getContentResolver(); 765 mHaveDebugSettings = false; 766 updateSwitchPreference(mEnableAdb, Settings.Global.getInt(cr, 767 Settings.Global.ADB_ENABLED, 0) != 0); 768 if (mEnableTerminal != null) { 769 updateSwitchPreference(mEnableTerminal, 770 context.getPackageManager().getApplicationEnabledSetting(TERMINAL_APP_PACKAGE) 771 == PackageManager.COMPONENT_ENABLED_STATE_ENABLED); 772 } 773 mHaveDebugSettings |= mBugReportInPowerController.updatePreference(); 774 mHaveDebugSettings |= mTelephonyMonitorController.updatePreference(); 775 mHaveDebugSettings |= mCameraHalHdrplusController.updatePreference(); 776 updateSwitchPreference(mKeepScreenOn, Settings.Global.getInt(cr, 777 Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0) != 0); 778 updateSwitchPreference(mBtHciSnoopLog, SystemProperties.getBoolean( 779 BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, false)); 780 updateSwitchPreference(mDebugViewAttributes, Settings.Global.getInt(cr, 781 Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0); 782 updateSwitchPreference(mForceAllowOnExternal, Settings.Global.getInt(cr, 783 Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0); 784 updateHdcpValues(); 785 updatePasswordSummary(); 786 updateDebuggerOptions(); 787 updateMockLocation(); 788 updateStrictModeVisualOptions(); 789 updatePointerLocationOptions(); 790 updateShowTouchesOptions(); 791 updateFlingerOptions(); 792 updateHardwareUiOptions(); 793 updateMsaaOptions(); 794 updateTrackFrameTimeOptions(); 795 updateShowNonRectClipOptions(); 796 updateShowHwScreenUpdatesOptions(); 797 updateShowHwLayersUpdatesOptions(); 798 updateDebugHwOverdrawOptions(); 799 updateDebugHwRendererOptions(); 800 updateDebugLayoutOptions(); 801 updateAnimationScaleOptions(); 802 updateOverlayDisplayDevicesOptions(); 803 updateImmediatelyDestroyActivitiesOptions(); 804 updateAppProcessLimitOptions(); 805 updateShowAllANRsOptions(); 806 updateShowNotificationChannelWarningsOptions(); 807 mVerifyAppsOverUsbController.updatePreference(); 808 updateOtaDisableAutomaticUpdateOptions(); 809 updateBugreportOptions(); 810 updateForceRtlOptions(); 811 updateLogdSizeValues(); 812 updateLogpersistValues(); 813 updateWifiDisplayCertificationOptions(); 814 updateWifiVerboseLoggingOptions(); 815 updateWifiAggressiveHandoverOptions(); 816 updateWifiAllowScansWithTrafficOptions(); 817 updateMobileDataAlwaysOnOptions(); 818 updateTetheringHardwareOffloadOptions(); 819 updateSimulateColorSpace(); 820 updateUSBAudioOptions(); 821 updateForceResizableOptions(); 822 Preference webViewAppPref = findPreference(mWebViewAppPrefController.getPreferenceKey()); 823 mWebViewAppPrefController.updateState(webViewAppPref); 824 updateOemUnlockOptions(); 825 if (mColorTemperaturePreference != null) { 826 updateColorTemperature(); 827 } 828 updateBluetoothDisableAbsVolumeOptions(); 829 updateBluetoothEnableInbandRingingOptions(); 830 updateBluetoothA2dpConfigurationValues(); 831 } 832 833 private void resetDangerousOptions() { 834 mDontPokeProperties = true; 835 for (int i = 0; i < mResetSwitchPrefs.size(); i++) { 836 SwitchPreference cb = mResetSwitchPrefs.get(i); 837 if (cb.isChecked()) { 838 cb.setChecked(false); 839 onPreferenceTreeClick(cb); 840 } 841 } 842 mBugReportInPowerController.resetPreference(); 843 resetDebuggerOptions(); 844 writeLogpersistOption(null, true); 845 writeLogdSizeOption(null); 846 writeAnimationScaleOption(0, mWindowAnimationScale, null); 847 writeAnimationScaleOption(1, mTransitionAnimationScale, null); 848 writeAnimationScaleOption(2, mAnimatorDurationScale, null); 849 // Only poke the color space setting if we control it. 850 if (usingDevelopmentColorSpace()) { 851 writeSimulateColorSpace(-1); 852 } 853 writeOverlayDisplayDevicesOptions(null); 854 writeAppProcessLimitOptions(null); 855 mHaveDebugSettings = false; 856 updateAllOptions(); 857 mDontPokeProperties = false; 858 pokeSystemProperties(); 859 } 860 861 private void updateHdcpValues() { 862 ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY); 863 if (hdcpChecking != null) { 864 String currentValue = SystemProperties.get(HDCP_CHECKING_PROPERTY); 865 String[] values = getResources().getStringArray(R.array.hdcp_checking_values); 866 String[] summaries = getResources().getStringArray(R.array.hdcp_checking_summaries); 867 int index = 1; // Defaults to drm-only. Needs to match with R.array.hdcp_checking_values 868 for (int i = 0; i < values.length; i++) { 869 if (currentValue.equals(values[i])) { 870 index = i; 871 break; 872 } 873 } 874 hdcpChecking.setValue(values[index]); 875 hdcpChecking.setSummary(summaries[index]); 876 hdcpChecking.setOnPreferenceChangeListener(this); 877 } 878 } 879 880 private void updatePasswordSummary() { 881 try { 882 if (mBackupManager.hasBackupPassword()) { 883 mPassword.setSummary(R.string.local_backup_password_summary_change); 884 } else { 885 mPassword.setSummary(R.string.local_backup_password_summary_none); 886 } 887 } catch (RemoteException e) { 888 // Not much we can do here 889 } 890 } 891 892 private void writeBtHciSnoopLogOptions() { 893 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 894 SystemProperties.set(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, 895 Boolean.toString(mBtHciSnoopLog.isChecked())); 896 } 897 898 private void writeDebuggerOptions() { 899 try { 900 ActivityManager.getService().setDebugApp( 901 mDebugApp, mWaitForDebugger.isChecked(), true); 902 } catch (RemoteException ex) { 903 } 904 } 905 906 private void writeMockLocation() { 907 AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE); 908 909 // Disable the app op of the previous mock location app if such. 910 List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS); 911 if (packageOps != null) { 912 // Should be one but in case we are in a bad state due to use of command line tools. 913 for (PackageOps packageOp : packageOps) { 914 if (packageOp.getOps().get(0).getMode() != AppOpsManager.MODE_ERRORED) { 915 String oldMockLocationApp = packageOp.getPackageName(); 916 try { 917 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo( 918 oldMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS); 919 appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid, 920 oldMockLocationApp, AppOpsManager.MODE_ERRORED); 921 } catch (NameNotFoundException e) { 922 /* ignore */ 923 } 924 } 925 } 926 } 927 928 // Enable the app op of the new mock location app if such. 929 if (!TextUtils.isEmpty(mMockLocationApp)) { 930 try { 931 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo( 932 mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS); 933 appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid, 934 mMockLocationApp, AppOpsManager.MODE_ALLOWED); 935 } catch (NameNotFoundException e) { 936 /* ignore */ 937 } 938 } 939 } 940 941 private static void resetDebuggerOptions() { 942 try { 943 ActivityManager.getService().setDebugApp( 944 null, false, true); 945 } catch (RemoteException ex) { 946 } 947 } 948 949 private void updateDebuggerOptions() { 950 mDebugApp = Settings.Global.getString( 951 getActivity().getContentResolver(), Settings.Global.DEBUG_APP); 952 updateSwitchPreference(mWaitForDebugger, Settings.Global.getInt( 953 getActivity().getContentResolver(), Settings.Global.WAIT_FOR_DEBUGGER, 0) != 0); 954 if (mDebugApp != null && mDebugApp.length() > 0) { 955 String label; 956 try { 957 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mDebugApp, 958 PackageManager.GET_DISABLED_COMPONENTS); 959 CharSequence lab = getActivity().getPackageManager().getApplicationLabel(ai); 960 label = lab != null ? lab.toString() : mDebugApp; 961 } catch (PackageManager.NameNotFoundException e) { 962 label = mDebugApp; 963 } 964 mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_set, label)); 965 mWaitForDebugger.setEnabled(true); 966 mHaveDebugSettings = true; 967 } else { 968 mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_not_set)); 969 mWaitForDebugger.setEnabled(false); 970 } 971 } 972 973 private void updateMockLocation() { 974 AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE); 975 976 List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS); 977 if (packageOps != null) { 978 for (PackageOps packageOp : packageOps) { 979 if (packageOp.getOps().get(0).getMode() == AppOpsManager.MODE_ALLOWED) { 980 mMockLocationApp = packageOps.get(0).getPackageName(); 981 break; 982 } 983 } 984 } 985 986 if (!TextUtils.isEmpty(mMockLocationApp)) { 987 String label = mMockLocationApp; 988 try { 989 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo( 990 mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS); 991 CharSequence appLabel = getPackageManager().getApplicationLabel(ai); 992 if (appLabel != null) { 993 label = appLabel.toString(); 994 } 995 } catch (PackageManager.NameNotFoundException e) { 996 /* ignore */ 997 } 998 999 mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_set, label)); 1000 mHaveDebugSettings = true; 1001 } else { 1002 mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_not_set)); 1003 } 1004 } 1005 1006 private void updateOtaDisableAutomaticUpdateOptions() { 1007 // We use the "disabled status" in code, but show the opposite text 1008 // "Automatic system updates" on screen. So a value 0 indicates the 1009 // automatic update is enabled. 1010 updateSwitchPreference(mOtaDisableAutomaticUpdate, Settings.Global.getInt( 1011 getActivity().getContentResolver(), 1012 Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, 0) != 1); 1013 } 1014 1015 private void writeOtaDisableAutomaticUpdateOptions() { 1016 // We use the "disabled status" in code, but show the opposite text 1017 // "Automatic system updates" on screen. So a value 0 indicates the 1018 // automatic update is enabled. 1019 Settings.Global.putInt(getActivity().getContentResolver(), 1020 Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, 1021 mOtaDisableAutomaticUpdate.isChecked() ? 0 : 1); 1022 } 1023 1024 private static boolean showEnableOemUnlockPreference(Context context) { 1025 return context.getSystemService(Context.OEM_LOCK_SERVICE) != null; 1026 } 1027 1028 private boolean enableOemUnlockPreference() { 1029 return !isBootloaderUnlocked() && mOemLockManager.canUserAllowOemUnlock(); 1030 } 1031 1032 private void updateOemUnlockOptions() { 1033 if (mEnableOemUnlock != null) { 1034 updateSwitchPreference(mEnableOemUnlock, mOemLockManager.isOemUnlockAllowed()); 1035 updateOemUnlockSettingDescription(); 1036 // Showing mEnableOemUnlock preference as device has persistent data block. 1037 mEnableOemUnlock.setDisabledByAdmin(null); 1038 mEnableOemUnlock.setEnabled(enableOemUnlockPreference()); 1039 if (mEnableOemUnlock.isEnabled()) { 1040 // Check restriction, disable mEnableOemUnlock and apply policy transparency. 1041 mEnableOemUnlock.checkRestrictionAndSetDisabled(UserManager.DISALLOW_FACTORY_RESET); 1042 } 1043 if (mEnableOemUnlock.isEnabled()) { 1044 // Check restriction, disable mEnableOemUnlock and apply policy transparency. 1045 mEnableOemUnlock.checkRestrictionAndSetDisabled(UserManager.DISALLOW_OEM_UNLOCK); 1046 } 1047 } 1048 } 1049 1050 private void updateBugreportOptions() { 1051 mBugReportController.enablePreference(true); 1052 mBugReportInPowerController.updateBugreportOptions(); 1053 } 1054 1055 // Returns the current state of the system property that controls 1056 // strictmode flashes. One of: 1057 // 0: not explicitly set one way or another 1058 // 1: on 1059 // 2: off 1060 private static int currentStrictModeActiveIndex() { 1061 if (TextUtils.isEmpty(SystemProperties.get(StrictMode.VISUAL_PROPERTY))) { 1062 return 0; 1063 } 1064 boolean enabled = SystemProperties.getBoolean(StrictMode.VISUAL_PROPERTY, false); 1065 return enabled ? 1 : 2; 1066 } 1067 1068 private void writeStrictModeVisualOptions() { 1069 try { 1070 mWindowManager.setStrictModeVisualIndicatorPreference(mStrictMode.isChecked() 1071 ? "1" : ""); 1072 } catch (RemoteException e) { 1073 } 1074 } 1075 1076 private void updateStrictModeVisualOptions() { 1077 updateSwitchPreference(mStrictMode, currentStrictModeActiveIndex() == 1); 1078 } 1079 1080 private void writePointerLocationOptions() { 1081 Settings.System.putInt(getActivity().getContentResolver(), 1082 Settings.System.POINTER_LOCATION, mPointerLocation.isChecked() ? 1 : 0); 1083 } 1084 1085 private void updatePointerLocationOptions() { 1086 updateSwitchPreference(mPointerLocation, 1087 Settings.System.getInt(getActivity().getContentResolver(), 1088 Settings.System.POINTER_LOCATION, 0) != 0); 1089 } 1090 1091 private void writeShowTouchesOptions() { 1092 Settings.System.putInt(getActivity().getContentResolver(), 1093 Settings.System.SHOW_TOUCHES, mShowTouches.isChecked() ? 1 : 0); 1094 } 1095 1096 private void updateShowTouchesOptions() { 1097 updateSwitchPreference(mShowTouches, 1098 Settings.System.getInt(getActivity().getContentResolver(), 1099 Settings.System.SHOW_TOUCHES, 0) != 0); 1100 } 1101 1102 private void updateFlingerOptions() { 1103 // magic communication with surface flinger. 1104 try { 1105 IBinder flinger = ServiceManager.getService("SurfaceFlinger"); 1106 if (flinger != null) { 1107 Parcel data = Parcel.obtain(); 1108 Parcel reply = Parcel.obtain(); 1109 data.writeInterfaceToken("android.ui.ISurfaceComposer"); 1110 flinger.transact(1010, data, reply, 0); 1111 @SuppressWarnings("unused") 1112 int showCpu = reply.readInt(); 1113 @SuppressWarnings("unused") 1114 int enableGL = reply.readInt(); 1115 int showUpdates = reply.readInt(); 1116 updateSwitchPreference(mShowScreenUpdates, showUpdates != 0); 1117 @SuppressWarnings("unused") 1118 int showBackground = reply.readInt(); 1119 int disableOverlays = reply.readInt(); 1120 updateSwitchPreference(mDisableOverlays, disableOverlays != 0); 1121 reply.recycle(); 1122 data.recycle(); 1123 } 1124 } catch (RemoteException ex) { 1125 } 1126 } 1127 1128 private void writeShowUpdatesOption() { 1129 try { 1130 IBinder flinger = ServiceManager.getService("SurfaceFlinger"); 1131 if (flinger != null) { 1132 Parcel data = Parcel.obtain(); 1133 data.writeInterfaceToken("android.ui.ISurfaceComposer"); 1134 final int showUpdates = mShowScreenUpdates.isChecked() ? 1 : 0; 1135 data.writeInt(showUpdates); 1136 flinger.transact(1002, data, null, 0); 1137 data.recycle(); 1138 1139 updateFlingerOptions(); 1140 } 1141 } catch (RemoteException ex) { 1142 } 1143 } 1144 1145 private void writeDisableOverlaysOption() { 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 disableOverlays = mDisableOverlays.isChecked() ? 1 : 0; 1152 data.writeInt(disableOverlays); 1153 flinger.transact(1008, data, null, 0); 1154 data.recycle(); 1155 1156 updateFlingerOptions(); 1157 } 1158 } catch (RemoteException ex) { 1159 } 1160 } 1161 1162 private void updateHardwareUiOptions() { 1163 updateSwitchPreference(mForceHardwareUi, 1164 SystemProperties.getBoolean(HARDWARE_UI_PROPERTY, false)); 1165 } 1166 1167 private void writeHardwareUiOptions() { 1168 SystemProperties.set(HARDWARE_UI_PROPERTY, mForceHardwareUi.isChecked() ? "true" : "false"); 1169 pokeSystemProperties(); 1170 } 1171 1172 private void updateMsaaOptions() { 1173 updateSwitchPreference(mForceMsaa, SystemProperties.getBoolean(MSAA_PROPERTY, false)); 1174 } 1175 1176 private void writeMsaaOptions() { 1177 SystemProperties.set(MSAA_PROPERTY, mForceMsaa.isChecked() ? "true" : "false"); 1178 pokeSystemProperties(); 1179 } 1180 1181 private void updateTrackFrameTimeOptions() { 1182 String value = SystemProperties.get(ThreadedRenderer.PROFILE_PROPERTY); 1183 if (value == null) { 1184 value = ""; 1185 } 1186 1187 CharSequence[] values = mTrackFrameTime.getEntryValues(); 1188 for (int i = 0; i < values.length; i++) { 1189 if (value.contentEquals(values[i])) { 1190 mTrackFrameTime.setValueIndex(i); 1191 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[i]); 1192 return; 1193 } 1194 } 1195 mTrackFrameTime.setValueIndex(0); 1196 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[0]); 1197 } 1198 1199 private void writeTrackFrameTimeOptions(Object newValue) { 1200 SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY, 1201 newValue == null ? "" : newValue.toString()); 1202 pokeSystemProperties(); 1203 updateTrackFrameTimeOptions(); 1204 } 1205 1206 private void updateShowNonRectClipOptions() { 1207 String value = SystemProperties.get( 1208 ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY); 1209 if (value == null) { 1210 value = "hide"; 1211 } 1212 1213 CharSequence[] values = mShowNonRectClip.getEntryValues(); 1214 for (int i = 0; i < values.length; i++) { 1215 if (value.contentEquals(values[i])) { 1216 mShowNonRectClip.setValueIndex(i); 1217 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[i]); 1218 return; 1219 } 1220 } 1221 mShowNonRectClip.setValueIndex(0); 1222 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[0]); 1223 } 1224 1225 private void writeShowNonRectClipOptions(Object newValue) { 1226 SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY, 1227 newValue == null ? "" : newValue.toString()); 1228 pokeSystemProperties(); 1229 updateShowNonRectClipOptions(); 1230 } 1231 1232 private void updateShowHwScreenUpdatesOptions() { 1233 updateSwitchPreference(mShowHwScreenUpdates, 1234 SystemProperties.getBoolean(ThreadedRenderer.DEBUG_DIRTY_REGIONS_PROPERTY, false)); 1235 } 1236 1237 private void writeShowHwScreenUpdatesOptions() { 1238 SystemProperties.set(ThreadedRenderer.DEBUG_DIRTY_REGIONS_PROPERTY, 1239 mShowHwScreenUpdates.isChecked() ? "true" : null); 1240 pokeSystemProperties(); 1241 } 1242 1243 private void updateShowHwLayersUpdatesOptions() { 1244 updateSwitchPreference(mShowHwLayersUpdates, SystemProperties.getBoolean( 1245 ThreadedRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY, false)); 1246 } 1247 1248 private void writeShowHwLayersUpdatesOptions() { 1249 SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY, 1250 mShowHwLayersUpdates.isChecked() ? "true" : null); 1251 pokeSystemProperties(); 1252 } 1253 1254 private void updateDebugHwOverdrawOptions() { 1255 String value = SystemProperties.get(ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY); 1256 if (value == null) { 1257 value = ""; 1258 } 1259 1260 CharSequence[] values = mDebugHwOverdraw.getEntryValues(); 1261 for (int i = 0; i < values.length; i++) { 1262 if (value.contentEquals(values[i])) { 1263 mDebugHwOverdraw.setValueIndex(i); 1264 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[i]); 1265 return; 1266 } 1267 } 1268 mDebugHwOverdraw.setValueIndex(0); 1269 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[0]); 1270 } 1271 1272 private void writeDebugHwOverdrawOptions(Object newValue) { 1273 SystemProperties.set(ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY, 1274 newValue == null ? "" : newValue.toString()); 1275 pokeSystemProperties(); 1276 updateDebugHwOverdrawOptions(); 1277 } 1278 1279 private void updateDebugHwRendererOptions() { 1280 String value = SystemProperties.get(ThreadedRenderer.DEBUG_RENDERER_PROPERTY); 1281 if (value == null) { 1282 value = ""; 1283 } 1284 1285 CharSequence[] values = mDebugHwRenderer.getEntryValues(); 1286 for (int i = 0; i < values.length; i++) { 1287 if (value.contentEquals(values[i])) { 1288 mDebugHwRenderer.setValueIndex(i); 1289 mDebugHwRenderer.setSummary(mDebugHwRenderer.getEntries()[i]); 1290 return; 1291 } 1292 } 1293 mDebugHwRenderer.setValueIndex(0); 1294 mDebugHwRenderer.setSummary(mDebugHwRenderer.getEntries()[0]); 1295 } 1296 1297 private void writeDebugHwRendererOptions(Object newValue) { 1298 SystemProperties.set(ThreadedRenderer.DEBUG_RENDERER_PROPERTY, 1299 newValue == null ? "" : newValue.toString()); 1300 pokeSystemProperties(); 1301 updateDebugHwRendererOptions(); 1302 } 1303 1304 private void updateDebugLayoutOptions() { 1305 updateSwitchPreference(mDebugLayout, 1306 SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false)); 1307 } 1308 1309 private void writeDebugLayoutOptions() { 1310 SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY, 1311 mDebugLayout.isChecked() ? "true" : "false"); 1312 pokeSystemProperties(); 1313 } 1314 1315 private void updateSimulateColorSpace() { 1316 final ContentResolver cr = getContentResolver(); 1317 final boolean enabled = Settings.Secure.getInt( 1318 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0; 1319 if (enabled) { 1320 final String mode = Integer.toString(Settings.Secure.getInt( 1321 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, 1322 AccessibilityManager.DALTONIZER_DISABLED)); 1323 mSimulateColorSpace.setValue(mode); 1324 final int index = mSimulateColorSpace.findIndexOfValue(mode); 1325 if (index < 0) { 1326 // We're using a mode controlled by accessibility preferences. 1327 mSimulateColorSpace.setSummary(getString(R.string.daltonizer_type_overridden, 1328 getString(R.string.accessibility_display_daltonizer_preference_title))); 1329 } else { 1330 mSimulateColorSpace.setSummary("%s"); 1331 } 1332 } else { 1333 mSimulateColorSpace.setValue( 1334 Integer.toString(AccessibilityManager.DALTONIZER_DISABLED)); 1335 } 1336 } 1337 1338 /** 1339 * @return <code>true</code> if the color space preference is currently 1340 * controlled by development settings 1341 */ 1342 private boolean usingDevelopmentColorSpace() { 1343 final ContentResolver cr = getContentResolver(); 1344 final boolean enabled = Settings.Secure.getInt( 1345 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0; 1346 if (enabled) { 1347 final String mode = Integer.toString(Settings.Secure.getInt( 1348 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, 1349 AccessibilityManager.DALTONIZER_DISABLED)); 1350 final int index = mSimulateColorSpace.findIndexOfValue(mode); 1351 if (index >= 0) { 1352 // We're using a mode controlled by developer preferences. 1353 return true; 1354 } 1355 } 1356 return false; 1357 } 1358 1359 private void writeSimulateColorSpace(Object value) { 1360 final ContentResolver cr = getContentResolver(); 1361 final int newMode = Integer.parseInt(value.toString()); 1362 if (newMode < 0) { 1363 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0); 1364 } else { 1365 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 1); 1366 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, newMode); 1367 } 1368 } 1369 1370 private void updateColorTemperature() { 1371 updateSwitchPreference(mColorTemperaturePreference, 1372 SystemProperties.getBoolean(COLOR_TEMPERATURE_PROPERTY, false)); 1373 } 1374 1375 private void writeColorTemperature() { 1376 SystemProperties.set(COLOR_TEMPERATURE_PROPERTY, 1377 mColorTemperaturePreference.isChecked() ? "1" : "0"); 1378 pokeSystemProperties(); 1379 Toast.makeText(getActivity(), R.string.color_temperature_toast, Toast.LENGTH_LONG).show(); 1380 } 1381 1382 private void updateUSBAudioOptions() { 1383 updateSwitchPreference(mUSBAudio, Settings.Secure.getInt(getContentResolver(), 1384 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 0) != 0); 1385 } 1386 1387 private void writeUSBAudioOptions() { 1388 Settings.Secure.putInt(getContentResolver(), 1389 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 1390 mUSBAudio.isChecked() ? 1 : 0); 1391 } 1392 1393 private void updateForceResizableOptions() { 1394 updateSwitchPreference(mForceResizable, Settings.Global.getInt(getContentResolver(), 1395 Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0); 1396 } 1397 1398 private void writeForceResizableOptions() { 1399 Settings.Global.putInt(getContentResolver(), 1400 Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 1401 mForceResizable.isChecked() ? 1 : 0); 1402 } 1403 1404 private void updateForceRtlOptions() { 1405 updateSwitchPreference(mForceRtlLayout, 1406 Settings.Global.getInt(getActivity().getContentResolver(), 1407 Settings.Global.DEVELOPMENT_FORCE_RTL, 0) != 0); 1408 } 1409 1410 private void writeForceRtlOptions() { 1411 boolean value = mForceRtlLayout.isChecked(); 1412 Settings.Global.putInt(getActivity().getContentResolver(), 1413 Settings.Global.DEVELOPMENT_FORCE_RTL, value ? 1 : 0); 1414 SystemProperties.set(Settings.Global.DEVELOPMENT_FORCE_RTL, value ? "1" : "0"); 1415 LocalePicker.updateLocales(getActivity().getResources().getConfiguration().getLocales()); 1416 } 1417 1418 private void updateWifiDisplayCertificationOptions() { 1419 updateSwitchPreference(mWifiDisplayCertification, Settings.Global.getInt( 1420 getActivity().getContentResolver(), 1421 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, 0) != 0); 1422 } 1423 1424 private void writeWifiDisplayCertificationOptions() { 1425 Settings.Global.putInt(getActivity().getContentResolver(), 1426 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, 1427 mWifiDisplayCertification.isChecked() ? 1 : 0); 1428 } 1429 1430 private void updateWifiVerboseLoggingOptions() { 1431 boolean enabled = mWifiManager.getVerboseLoggingLevel() > 0; 1432 updateSwitchPreference(mWifiVerboseLogging, enabled); 1433 } 1434 1435 private void writeWifiVerboseLoggingOptions() { 1436 mWifiManager.enableVerboseLogging(mWifiVerboseLogging.isChecked() ? 1 : 0); 1437 } 1438 1439 private void updateWifiAggressiveHandoverOptions() { 1440 boolean enabled = mWifiManager.getAggressiveHandover() > 0; 1441 updateSwitchPreference(mWifiAggressiveHandover, enabled); 1442 } 1443 1444 private void writeWifiAggressiveHandoverOptions() { 1445 mWifiManager.enableAggressiveHandover(mWifiAggressiveHandover.isChecked() ? 1 : 0); 1446 } 1447 1448 private void updateWifiAllowScansWithTrafficOptions() { 1449 boolean enabled = mWifiManager.getAllowScansWithTraffic() > 0; 1450 updateSwitchPreference(mWifiAllowScansWithTraffic, enabled); 1451 } 1452 1453 private void writeWifiAllowScansWithTrafficOptions() { 1454 mWifiManager.setAllowScansWithTraffic(mWifiAllowScansWithTraffic.isChecked() ? 1 : 0); 1455 } 1456 1457 private void updateBluetoothDisableAbsVolumeOptions() { 1458 updateSwitchPreference(mBluetoothDisableAbsVolume, 1459 SystemProperties.getBoolean(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY, false)); 1460 } 1461 1462 private void writeBluetoothDisableAbsVolumeOptions() { 1463 SystemProperties.set(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY, 1464 mBluetoothDisableAbsVolume.isChecked() ? "true" : "false"); 1465 } 1466 1467 private void updateBluetoothEnableInbandRingingOptions() { 1468 if (mBluetoothEnableInbandRinging != null) { 1469 updateSwitchPreference(mBluetoothEnableInbandRinging, 1470 SystemProperties.getBoolean(BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY, true)); 1471 } 1472 } 1473 1474 private void writeBluetoothEnableInbandRingingOptions() { 1475 if (mBluetoothEnableInbandRinging != null) { 1476 SystemProperties.set(BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY, 1477 mBluetoothEnableInbandRinging.isChecked() ? "true" : "false"); 1478 } 1479 } 1480 1481 private void updateMobileDataAlwaysOnOptions() { 1482 updateSwitchPreference(mMobileDataAlwaysOn, Settings.Global.getInt( 1483 getActivity().getContentResolver(), 1484 Settings.Global.MOBILE_DATA_ALWAYS_ON, 1) != 0); 1485 } 1486 1487 private void writeMobileDataAlwaysOnOptions() { 1488 Settings.Global.putInt(getActivity().getContentResolver(), 1489 Settings.Global.MOBILE_DATA_ALWAYS_ON, 1490 mMobileDataAlwaysOn.isChecked() ? 1 : 0); 1491 } 1492 1493 private void updateTetheringHardwareOffloadOptions() { 1494 updateSwitchPreference(mTetheringHardwareOffload, Settings.Global.getInt( 1495 getActivity().getContentResolver(), 1496 Settings.Global.TETHER_OFFLOAD_DISABLED, 0) != 1); 1497 } 1498 1499 private void writeTetheringHardwareOffloadOptions() { 1500 Settings.Global.putInt(getActivity().getContentResolver(), 1501 Settings.Global.TETHER_OFFLOAD_DISABLED, 1502 mTetheringHardwareOffload.isChecked() ? 0 : 1); 1503 } 1504 1505 private String defaultLogdSizeValue() { 1506 String defaultValue = SystemProperties.get(SELECT_LOGD_DEFAULT_SIZE_PROPERTY); 1507 if ((defaultValue == null) || (defaultValue.length() == 0)) { 1508 if (SystemProperties.get("ro.config.low_ram").equals("true")) { 1509 defaultValue = SELECT_LOGD_SVELTE_DEFAULT_SIZE_VALUE; 1510 } else { 1511 defaultValue = SELECT_LOGD_DEFAULT_SIZE_VALUE; 1512 } 1513 } 1514 return defaultValue; 1515 } 1516 1517 private void updateLogdSizeValues() { 1518 if (mLogdSize != null) { 1519 String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY); 1520 String currentValue = SystemProperties.get(SELECT_LOGD_SIZE_PROPERTY); 1521 if ((currentTag != null) && currentTag.startsWith(SELECT_LOGD_TAG_SILENCE)) { 1522 currentValue = SELECT_LOGD_OFF_SIZE_MARKER_VALUE; 1523 } 1524 if (mLogpersist != null) { 1525 String currentLogpersistEnable 1526 = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY_ENABLE); 1527 if ((currentLogpersistEnable == null) 1528 || !currentLogpersistEnable.equals("true") 1529 || currentValue.equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)) { 1530 writeLogpersistOption(null, true); 1531 mLogpersist.setEnabled(false); 1532 } else if (mSettingsEnabler.getLastEnabledState()) { 1533 mLogpersist.setEnabled(true); 1534 } 1535 } 1536 if ((currentValue == null) || (currentValue.length() == 0)) { 1537 currentValue = defaultLogdSizeValue(); 1538 } 1539 String[] values = getResources().getStringArray(R.array.select_logd_size_values); 1540 String[] titles = getResources().getStringArray(R.array.select_logd_size_titles); 1541 int index = 2; // punt to second entry if not found 1542 if (SystemProperties.get("ro.config.low_ram").equals("true")) { 1543 mLogdSize.setEntries(R.array.select_logd_size_lowram_titles); 1544 titles = getResources().getStringArray(R.array.select_logd_size_lowram_titles); 1545 index = 1; 1546 } 1547 String[] summaries = getResources().getStringArray(R.array.select_logd_size_summaries); 1548 for (int i = 0; i < titles.length; i++) { 1549 if (currentValue.equals(values[i]) 1550 || currentValue.equals(titles[i])) { 1551 index = i; 1552 break; 1553 } 1554 } 1555 mLogdSize.setValue(values[index]); 1556 mLogdSize.setSummary(summaries[index]); 1557 mLogdSize.setOnPreferenceChangeListener(this); 1558 } 1559 } 1560 1561 private void writeLogdSizeOption(Object newValue) { 1562 boolean disable = (newValue != null) && 1563 (newValue.toString().equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)); 1564 String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY); 1565 if (currentTag == null) { 1566 currentTag = ""; 1567 } 1568 // filter clean and unstack all references to our setting 1569 String newTag = currentTag.replaceAll( 1570 ",+" + SELECT_LOGD_TAG_SILENCE, "").replaceFirst( 1571 "^" + SELECT_LOGD_TAG_SILENCE + ",*", "").replaceAll( 1572 ",+", ",").replaceFirst( 1573 ",+$", ""); 1574 if (disable) { 1575 newValue = SELECT_LOGD_MINIMUM_SIZE_VALUE; 1576 // Make sure snet_event_log get through first, but do not override 1577 String snetValue = SystemProperties.get(SELECT_LOGD_SNET_TAG_PROPERTY); 1578 if ((snetValue == null) || (snetValue.length() == 0)) { 1579 snetValue = SystemProperties.get(SELECT_LOGD_RUNTIME_SNET_TAG_PROPERTY); 1580 if ((snetValue == null) || (snetValue.length() == 0)) { 1581 SystemProperties.set(SELECT_LOGD_SNET_TAG_PROPERTY, "I"); 1582 } 1583 } 1584 // Silence all log sources, security logs notwithstanding 1585 if (newTag.length() != 0) { 1586 newTag = "," + newTag; 1587 } 1588 // Stack settings, stack to help preserve original value 1589 newTag = SELECT_LOGD_TAG_SILENCE + newTag; 1590 } 1591 if (!newTag.equals(currentTag)) { 1592 SystemProperties.set(SELECT_LOGD_TAG_PROPERTY, newTag); 1593 } 1594 String defaultValue = defaultLogdSizeValue(); 1595 final String size = ((newValue != null) && (newValue.toString().length() != 0)) ? 1596 newValue.toString() : defaultValue; 1597 SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, defaultValue.equals(size) ? "" : size); 1598 SystemProperties.set("ctl.start", "logd-reinit"); 1599 pokeSystemProperties(); 1600 updateLogdSizeValues(); 1601 } 1602 1603 private void updateLogpersistValues() { 1604 if (mLogpersist == null) { 1605 return; 1606 } 1607 String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY); 1608 if (currentValue == null) { 1609 currentValue = ""; 1610 } 1611 String currentBuffers = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY_BUFFER); 1612 if ((currentBuffers == null) || (currentBuffers.length() == 0)) { 1613 currentBuffers = "all"; 1614 } 1615 int index = 0; 1616 if (currentValue.equals(SELECT_LOGPERSIST_PROPERTY_SERVICE)) { 1617 index = 1; 1618 if (currentBuffers.equals("kernel")) { 1619 index = 3; 1620 } else if (!currentBuffers.equals("all") && 1621 !currentBuffers.contains("radio") && 1622 currentBuffers.contains("security") && 1623 currentBuffers.contains("kernel")) { 1624 index = 2; 1625 if (!currentBuffers.contains("default")) { 1626 String[] contains = {"main", "events", "system", "crash"}; 1627 for (int i = 0; i < contains.length; i++) { 1628 if (!currentBuffers.contains(contains[i])) { 1629 index = 1; 1630 break; 1631 } 1632 } 1633 } 1634 } 1635 } 1636 mLogpersist.setValue( 1637 getResources().getStringArray(R.array.select_logpersist_values)[index]); 1638 mLogpersist.setSummary( 1639 getResources().getStringArray(R.array.select_logpersist_summaries)[index]); 1640 mLogpersist.setOnPreferenceChangeListener(this); 1641 if (index != 0) { 1642 mLogpersistCleared = false; 1643 } else if (!mLogpersistCleared) { 1644 // would File.delete() directly but need to switch uid/gid to access 1645 SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY, SELECT_LOGPERSIST_PROPERTY_CLEAR); 1646 pokeSystemProperties(); 1647 mLogpersistCleared = true; 1648 } 1649 } 1650 1651 private void setLogpersistOff(boolean update) { 1652 SystemProperties.set(SELECT_LOGPERSIST_PROPERTY_BUFFER, ""); 1653 // deal with trampoline of empty properties 1654 SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY_BUFFER, ""); 1655 SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, ""); 1656 SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY, 1657 update ? "" : SELECT_LOGPERSIST_PROPERTY_STOP); 1658 pokeSystemProperties(); 1659 if (update) { 1660 updateLogpersistValues(); 1661 } else { 1662 for (int i = 0; i < 3; i++) { 1663 String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY); 1664 if ((currentValue == null) || currentValue.equals("")) { 1665 break; 1666 } 1667 try { 1668 Thread.sleep(100); 1669 } catch (InterruptedException e) { 1670 } 1671 } 1672 } 1673 } 1674 1675 private void writeLogpersistOption(Object newValue, boolean skipWarning) { 1676 if (mLogpersist == null) { 1677 return; 1678 } 1679 String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY); 1680 if ((currentTag != null) && currentTag.startsWith(SELECT_LOGD_TAG_SILENCE)) { 1681 newValue = null; 1682 skipWarning = true; 1683 } 1684 1685 if ((newValue == null) || newValue.toString().equals("")) { 1686 if (skipWarning) { 1687 mLogpersistCleared = false; 1688 } else if (!mLogpersistCleared) { 1689 // if transitioning from on to off, pop up an are you sure? 1690 String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY); 1691 if ((currentValue != null) && 1692 currentValue.equals(SELECT_LOGPERSIST_PROPERTY_SERVICE)) { 1693 if (mLogpersistClearDialog != null) dismissDialogs(); 1694 mLogpersistClearDialog = new AlertDialog.Builder(getActivity()).setMessage( 1695 getActivity().getResources().getString( 1696 R.string.dev_logpersist_clear_warning_message)) 1697 .setTitle(R.string.dev_logpersist_clear_warning_title) 1698 .setPositiveButton(android.R.string.yes, this) 1699 .setNegativeButton(android.R.string.no, this) 1700 .show(); 1701 mLogpersistClearDialog.setOnDismissListener(this); 1702 return; 1703 } 1704 } 1705 setLogpersistOff(true); 1706 return; 1707 } 1708 1709 String currentBuffer = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY_BUFFER); 1710 if ((currentBuffer != null) && !currentBuffer.equals(newValue.toString())) { 1711 setLogpersistOff(false); 1712 } 1713 SystemProperties.set(SELECT_LOGPERSIST_PROPERTY_BUFFER, newValue.toString()); 1714 SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, SELECT_LOGPERSIST_PROPERTY_SERVICE); 1715 pokeSystemProperties(); 1716 for (int i = 0; i < 3; i++) { 1717 String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY); 1718 if ((currentValue != null) 1719 && currentValue.equals(SELECT_LOGPERSIST_PROPERTY_SERVICE)) { 1720 break; 1721 } 1722 try { 1723 Thread.sleep(100); 1724 } catch (InterruptedException e) { 1725 } 1726 } 1727 updateLogpersistValues(); 1728 } 1729 1730 private void updateUsbConfigurationValues() { 1731 if (mUsbConfiguration != null) { 1732 UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); 1733 1734 String[] values = getResources().getStringArray(R.array.usb_configuration_values); 1735 String[] titles = getResources().getStringArray(R.array.usb_configuration_titles); 1736 int index = 0; 1737 for (int i = 0; i < titles.length; i++) { 1738 if (manager.isFunctionEnabled(values[i])) { 1739 index = i; 1740 break; 1741 } 1742 } 1743 mUsbConfiguration.setValue(values[index]); 1744 mUsbConfiguration.setSummary(titles[index]); 1745 mUsbConfiguration.setOnPreferenceChangeListener(this); 1746 } 1747 } 1748 1749 private void writeUsbConfigurationOption(Object newValue) { 1750 UsbManager manager = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE); 1751 String function = newValue.toString(); 1752 if (function.equals("none")) { 1753 manager.setCurrentFunction(function, false); 1754 } else { 1755 manager.setCurrentFunction(function, true); 1756 } 1757 } 1758 1759 private void initBluetoothConfigurationValues() { 1760 String[] values; 1761 String[] summaries; 1762 int index; 1763 1764 // Init the AVRCP Version - Default 1765 values = getResources().getStringArray(R.array.bluetooth_avrcp_version_values); 1766 summaries = getResources().getStringArray(R.array.bluetooth_avrcp_versions); 1767 String value = SystemProperties.get(BLUETOOTH_AVRCP_VERSION_PROPERTY, values[0]); 1768 index = mBluetoothSelectAvrcpVersion.findIndexOfValue(value); 1769 mBluetoothSelectAvrcpVersion.setValue(values[index]); 1770 mBluetoothSelectAvrcpVersion.setSummary(summaries[index]); 1771 1772 // Init the Codec Type - Default 1773 values = getResources().getStringArray(R.array.bluetooth_a2dp_codec_values); 1774 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_summaries); 1775 index = 0; 1776 mBluetoothSelectA2dpCodec.setValue(values[index]); 1777 mBluetoothSelectA2dpCodec.setSummary(summaries[index]); 1778 1779 // Init the Sample Rate - Default 1780 values = getResources().getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_values); 1781 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_summaries); 1782 index = 0; 1783 mBluetoothSelectA2dpSampleRate.setValue(values[index]); 1784 mBluetoothSelectA2dpSampleRate.setSummary(summaries[index]); 1785 1786 // Init the Bits Per Sample - Default 1787 values = getResources().getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_values); 1788 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_summaries); 1789 index = 0; 1790 mBluetoothSelectA2dpBitsPerSample.setValue(values[index]); 1791 mBluetoothSelectA2dpBitsPerSample.setSummary(summaries[index]); 1792 1793 // Init the Channel Mode - Default 1794 values = getResources().getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_values); 1795 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_summaries); 1796 index = 0; 1797 mBluetoothSelectA2dpChannelMode.setValue(values[index]); 1798 mBluetoothSelectA2dpChannelMode.setSummary(summaries[index]); 1799 1800 // Init the LDAC Playback Quality - ABR 1801 values = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_values); 1802 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries); 1803 index = 3; 1804 mBluetoothSelectA2dpLdacPlaybackQuality.setValue(values[index]); 1805 mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(summaries[index]); 1806 } 1807 1808 private void writeBluetoothAvrcpVersion(Object newValue) { 1809 SystemProperties.set(BLUETOOTH_AVRCP_VERSION_PROPERTY, newValue.toString()); 1810 int index = mBluetoothSelectAvrcpVersion.findIndexOfValue(newValue.toString()); 1811 if (index >= 0) { 1812 String[] titles = getResources().getStringArray(R.array.bluetooth_avrcp_versions); 1813 mBluetoothSelectAvrcpVersion.setSummary(titles[index]); 1814 } 1815 } 1816 1817 private void updateBluetoothA2dpConfigurationValues() { 1818 int index; 1819 String[] summaries; 1820 BluetoothCodecStatus codecStatus = null; 1821 BluetoothCodecConfig codecConfig = null; 1822 BluetoothCodecConfig[] codecsLocalCapabilities = null; 1823 BluetoothCodecConfig[] codecsSelectableCapabilities = null; 1824 String streaming; 1825 Resources resources = null; 1826 1827 synchronized (mBluetoothA2dpLock) { 1828 if (mBluetoothA2dp != null) { 1829 codecStatus = mBluetoothA2dp.getCodecStatus(); 1830 if (codecStatus != null) { 1831 codecConfig = codecStatus.getCodecConfig(); 1832 codecsLocalCapabilities = codecStatus.getCodecsLocalCapabilities(); 1833 codecsSelectableCapabilities = codecStatus.getCodecsSelectableCapabilities(); 1834 } 1835 } 1836 } 1837 if (codecConfig == null) { 1838 return; 1839 } 1840 1841 try { 1842 resources = getResources(); 1843 } catch (IllegalStateException e) { 1844 return; 1845 } 1846 if (resources == null) { 1847 return; 1848 } 1849 1850 // Update the Codec Type 1851 index = -1; 1852 switch (codecConfig.getCodecType()) { 1853 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC: 1854 index = 1; 1855 break; 1856 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC: 1857 index = 2; 1858 break; 1859 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX: 1860 index = 3; 1861 break; 1862 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD: 1863 index = 4; 1864 break; 1865 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC: 1866 index = 5; 1867 break; 1868 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID: 1869 default: 1870 break; 1871 } 1872 if (index >= 0 && mBluetoothSelectA2dpCodec != null) { 1873 summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_summaries); 1874 streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); 1875 mBluetoothSelectA2dpCodec.setSummary(streaming); 1876 } 1877 1878 // Update the Sample Rate 1879 index = -1; 1880 switch (codecConfig.getSampleRate()) { 1881 case BluetoothCodecConfig.SAMPLE_RATE_44100: 1882 index = 1; 1883 break; 1884 case BluetoothCodecConfig.SAMPLE_RATE_48000: 1885 index = 2; 1886 break; 1887 case BluetoothCodecConfig.SAMPLE_RATE_88200: 1888 index = 3; 1889 break; 1890 case BluetoothCodecConfig.SAMPLE_RATE_96000: 1891 index = 4; 1892 break; 1893 case BluetoothCodecConfig.SAMPLE_RATE_176400: 1894 case BluetoothCodecConfig.SAMPLE_RATE_192000: 1895 case BluetoothCodecConfig.SAMPLE_RATE_NONE: 1896 default: 1897 break; 1898 } 1899 if (index >= 0 && mBluetoothSelectA2dpSampleRate != null) { 1900 summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_summaries); 1901 streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); 1902 mBluetoothSelectA2dpSampleRate.setSummary(streaming); 1903 } 1904 1905 // Update the Bits Per Sample 1906 index = -1; 1907 switch (codecConfig.getBitsPerSample()) { 1908 case BluetoothCodecConfig.BITS_PER_SAMPLE_16: 1909 index = 1; 1910 break; 1911 case BluetoothCodecConfig.BITS_PER_SAMPLE_24: 1912 index = 2; 1913 break; 1914 case BluetoothCodecConfig.BITS_PER_SAMPLE_32: 1915 index = 3; 1916 break; 1917 case BluetoothCodecConfig.BITS_PER_SAMPLE_NONE: 1918 default: 1919 break; 1920 } 1921 if (index >= 0 && mBluetoothSelectA2dpBitsPerSample != null) { 1922 summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_summaries); 1923 streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); 1924 mBluetoothSelectA2dpBitsPerSample.setSummary(streaming); 1925 } 1926 1927 // Update the Channel Mode 1928 index = -1; 1929 switch (codecConfig.getChannelMode()) { 1930 case BluetoothCodecConfig.CHANNEL_MODE_MONO: 1931 index = 1; 1932 break; 1933 case BluetoothCodecConfig.CHANNEL_MODE_STEREO: 1934 index = 2; 1935 break; 1936 case BluetoothCodecConfig.CHANNEL_MODE_NONE: 1937 default: 1938 break; 1939 } 1940 if (index >= 0 && mBluetoothSelectA2dpChannelMode != null) { 1941 summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_summaries); 1942 streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); 1943 mBluetoothSelectA2dpChannelMode.setSummary(streaming); 1944 } 1945 1946 // Update the LDAC Playback Quality 1947 // The actual values are 0, 1, 2 - those are extracted 1948 // as mod-10 remainders of a larger value. 1949 // The reason is because within BluetoothCodecConfig we cannot use 1950 // a codec-specific value of zero. 1951 index = (int)codecConfig.getCodecSpecific1(); 1952 if (index > 0) { 1953 index %= 10; 1954 } else { 1955 index = -1; 1956 } 1957 switch (index) { 1958 case 0: 1959 case 1: 1960 case 2: 1961 case 3: 1962 break; 1963 default: 1964 index = -1; 1965 break; 1966 } 1967 if (index >= 0 && mBluetoothSelectA2dpLdacPlaybackQuality != null) { 1968 summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries); 1969 streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); 1970 mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(streaming); 1971 } 1972 } 1973 1974 private void writeBluetoothConfigurationOption(Preference preference, 1975 Object newValue) { 1976 String[] summaries; 1977 int index; 1978 int codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID; 1979 int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT; 1980 int sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_NONE; 1981 int bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_NONE; 1982 int channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_NONE; 1983 long codecSpecific1Value = 0; 1984 long codecSpecific2Value = 0; 1985 long codecSpecific3Value = 0; 1986 long codecSpecific4Value = 0; 1987 1988 // Codec Type 1989 String codecType = mBluetoothSelectA2dpCodec.getValue(); 1990 if (preference == mBluetoothSelectA2dpCodec) { 1991 codecType = newValue.toString(); 1992 index = mBluetoothSelectA2dpCodec.findIndexOfValue(newValue.toString()); 1993 if (index >= 0) { 1994 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_summaries); 1995 mBluetoothSelectA2dpCodec.setSummary(summaries[index]); 1996 } 1997 } 1998 index = mBluetoothSelectA2dpCodec.findIndexOfValue(codecType); 1999 switch (index) { 2000 case 0: 2001 // Reset the priority of the current codec to default 2002 String oldValue = mBluetoothSelectA2dpCodec.getValue(); 2003 switch (mBluetoothSelectA2dpCodec.findIndexOfValue(oldValue)) { 2004 case 0: 2005 break; // No current codec 2006 case 1: 2007 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC; 2008 break; 2009 case 2: 2010 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC; 2011 break; 2012 case 3: 2013 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX; 2014 break; 2015 case 4: 2016 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD; 2017 break; 2018 case 5: 2019 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC; 2020 break; 2021 default: 2022 break; 2023 } 2024 break; 2025 case 1: 2026 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC; 2027 codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; 2028 break; 2029 case 2: 2030 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC; 2031 codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; 2032 break; 2033 case 3: 2034 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX; 2035 codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; 2036 break; 2037 case 4: 2038 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD; 2039 codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; 2040 break; 2041 case 5: 2042 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC; 2043 codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; 2044 break; 2045 case 6: 2046 synchronized (mBluetoothA2dpLock) { 2047 if (mBluetoothA2dp != null) { 2048 mBluetoothA2dp.enableOptionalCodecs(); 2049 } 2050 } 2051 return; 2052 case 7: 2053 synchronized (mBluetoothA2dpLock) { 2054 if (mBluetoothA2dp != null) { 2055 mBluetoothA2dp.disableOptionalCodecs(); 2056 } 2057 } 2058 return; 2059 default: 2060 break; 2061 } 2062 2063 // Sample Rate 2064 String sampleRate = mBluetoothSelectA2dpSampleRate.getValue(); 2065 if (preference == mBluetoothSelectA2dpSampleRate) { 2066 sampleRate = newValue.toString(); 2067 index = mBluetoothSelectA2dpSampleRate.findIndexOfValue(newValue.toString()); 2068 if (index >= 0) { 2069 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_summaries); 2070 mBluetoothSelectA2dpSampleRate.setSummary(summaries[index]); 2071 } 2072 } 2073 index = mBluetoothSelectA2dpSampleRate.findIndexOfValue(sampleRate); 2074 switch (index) { 2075 case 0: 2076 // Reset to default 2077 break; 2078 case 1: 2079 sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_44100; 2080 break; 2081 case 2: 2082 sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_48000; 2083 break; 2084 case 3: 2085 sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_88200; 2086 break; 2087 case 4: 2088 sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_96000; 2089 break; 2090 default: 2091 break; 2092 } 2093 2094 // Bits Per Sample 2095 String bitsPerSample = mBluetoothSelectA2dpBitsPerSample.getValue(); 2096 if (preference == mBluetoothSelectA2dpBitsPerSample) { 2097 bitsPerSample = newValue.toString(); 2098 index = mBluetoothSelectA2dpBitsPerSample.findIndexOfValue(newValue.toString()); 2099 if (index >= 0) { 2100 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_summaries); 2101 mBluetoothSelectA2dpBitsPerSample.setSummary(summaries[index]); 2102 } 2103 } 2104 index = mBluetoothSelectA2dpBitsPerSample.findIndexOfValue(bitsPerSample); 2105 switch (index) { 2106 case 0: 2107 // Reset to default 2108 break; 2109 case 1: 2110 bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_16; 2111 break; 2112 case 2: 2113 bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_24; 2114 break; 2115 case 3: 2116 bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_32; 2117 break; 2118 default: 2119 break; 2120 } 2121 2122 // Channel Mode 2123 String channelMode = mBluetoothSelectA2dpChannelMode.getValue(); 2124 if (preference == mBluetoothSelectA2dpChannelMode) { 2125 channelMode = newValue.toString(); 2126 index = mBluetoothSelectA2dpChannelMode.findIndexOfValue(newValue.toString()); 2127 if (index >= 0) { 2128 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_summaries); 2129 mBluetoothSelectA2dpChannelMode.setSummary(summaries[index]); 2130 } 2131 } 2132 index = mBluetoothSelectA2dpChannelMode.findIndexOfValue(channelMode); 2133 switch (index) { 2134 case 0: 2135 // Reset to default 2136 break; 2137 case 1: 2138 channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_MONO; 2139 break; 2140 case 2: 2141 channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_STEREO; 2142 break; 2143 default: 2144 break; 2145 } 2146 2147 // LDAC Playback Quality 2148 String ldacPlaybackQuality = mBluetoothSelectA2dpLdacPlaybackQuality.getValue(); 2149 if (preference == mBluetoothSelectA2dpLdacPlaybackQuality) { 2150 ldacPlaybackQuality = newValue.toString(); 2151 index = mBluetoothSelectA2dpLdacPlaybackQuality.findIndexOfValue(newValue.toString()); 2152 if (index >= 0) { 2153 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries); 2154 mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(summaries[index]); 2155 } 2156 } 2157 index = mBluetoothSelectA2dpLdacPlaybackQuality.findIndexOfValue(ldacPlaybackQuality); 2158 switch (index) { 2159 case 0: 2160 case 1: 2161 case 2: 2162 case 3: 2163 codecSpecific1Value = 1000 + index; 2164 break; 2165 default: 2166 break; 2167 } 2168 2169 BluetoothCodecConfig codecConfig = 2170 new BluetoothCodecConfig(codecTypeValue, codecPriorityValue, 2171 sampleRateValue, bitsPerSampleValue, 2172 channelModeValue, codecSpecific1Value, 2173 codecSpecific2Value, codecSpecific3Value, 2174 codecSpecific4Value); 2175 2176 synchronized (mBluetoothA2dpLock) { 2177 if (mBluetoothA2dp != null) { 2178 mBluetoothA2dp.setCodecConfigPreference(codecConfig); 2179 } 2180 } 2181 } 2182 2183 private void writeImmediatelyDestroyActivitiesOptions() { 2184 try { 2185 ActivityManager.getService().setAlwaysFinish( 2186 mImmediatelyDestroyActivities.isChecked()); 2187 } catch (RemoteException ex) { 2188 } 2189 } 2190 2191 private void updateImmediatelyDestroyActivitiesOptions() { 2192 updateSwitchPreference(mImmediatelyDestroyActivities, Settings.Global.getInt( 2193 getActivity().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) 2194 != 0); 2195 } 2196 2197 private void updateAnimationScaleValue(int which, ListPreference pref) { 2198 try { 2199 float scale = mWindowManager.getAnimationScale(which); 2200 if (scale != 1) { 2201 mHaveDebugSettings = true; 2202 } 2203 CharSequence[] values = pref.getEntryValues(); 2204 for (int i = 0; i < values.length; i++) { 2205 float val = Float.parseFloat(values[i].toString()); 2206 if (scale <= val) { 2207 pref.setValueIndex(i); 2208 pref.setSummary(pref.getEntries()[i]); 2209 return; 2210 } 2211 } 2212 pref.setValueIndex(values.length - 1); 2213 pref.setSummary(pref.getEntries()[0]); 2214 } catch (RemoteException e) { 2215 } 2216 } 2217 2218 private void updateAnimationScaleOptions() { 2219 updateAnimationScaleValue(0, mWindowAnimationScale); 2220 updateAnimationScaleValue(1, mTransitionAnimationScale); 2221 updateAnimationScaleValue(2, mAnimatorDurationScale); 2222 } 2223 2224 private void writeAnimationScaleOption(int which, ListPreference pref, Object newValue) { 2225 try { 2226 float scale = newValue != null ? Float.parseFloat(newValue.toString()) : 1; 2227 mWindowManager.setAnimationScale(which, scale); 2228 updateAnimationScaleValue(which, pref); 2229 } catch (RemoteException e) { 2230 } 2231 } 2232 2233 private void updateOverlayDisplayDevicesOptions() { 2234 String value = Settings.Global.getString(getActivity().getContentResolver(), 2235 Settings.Global.OVERLAY_DISPLAY_DEVICES); 2236 if (value == null) { 2237 value = ""; 2238 } 2239 2240 CharSequence[] values = mOverlayDisplayDevices.getEntryValues(); 2241 for (int i = 0; i < values.length; i++) { 2242 if (value.contentEquals(values[i])) { 2243 mOverlayDisplayDevices.setValueIndex(i); 2244 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[i]); 2245 return; 2246 } 2247 } 2248 mOverlayDisplayDevices.setValueIndex(0); 2249 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[0]); 2250 } 2251 2252 private void writeOverlayDisplayDevicesOptions(Object newValue) { 2253 Settings.Global.putString(getActivity().getContentResolver(), 2254 Settings.Global.OVERLAY_DISPLAY_DEVICES, (String) newValue); 2255 updateOverlayDisplayDevicesOptions(); 2256 } 2257 2258 private void updateAppProcessLimitOptions() { 2259 try { 2260 int limit = ActivityManager.getService().getProcessLimit(); 2261 CharSequence[] values = mAppProcessLimit.getEntryValues(); 2262 for (int i = 0; i < values.length; i++) { 2263 int val = Integer.parseInt(values[i].toString()); 2264 if (val >= limit) { 2265 if (i != 0) { 2266 mHaveDebugSettings = true; 2267 } 2268 mAppProcessLimit.setValueIndex(i); 2269 mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[i]); 2270 return; 2271 } 2272 } 2273 mAppProcessLimit.setValueIndex(0); 2274 mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[0]); 2275 } catch (RemoteException e) { 2276 } 2277 } 2278 2279 private void writeAppProcessLimitOptions(Object newValue) { 2280 try { 2281 int limit = newValue != null ? Integer.parseInt(newValue.toString()) : -1; 2282 ActivityManager.getService().setProcessLimit(limit); 2283 updateAppProcessLimitOptions(); 2284 } catch (RemoteException e) { 2285 } 2286 } 2287 2288 private void writeShowAllANRsOptions() { 2289 Settings.Secure.putInt(getActivity().getContentResolver(), 2290 Settings.Secure.ANR_SHOW_BACKGROUND, 2291 mShowAllANRs.isChecked() ? 1 : 0); 2292 } 2293 2294 private void updateShowAllANRsOptions() { 2295 updateSwitchPreference(mShowAllANRs, Settings.Secure.getInt( 2296 getActivity().getContentResolver(), Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0); 2297 } 2298 2299 private void writeShowNotificationChannelWarningsOptions() { 2300 Settings.Global.putInt(getActivity().getContentResolver(), 2301 Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, 2302 mShowNotificationChannelWarnings.isChecked() ? 1 : 0); 2303 } 2304 2305 private void updateShowNotificationChannelWarningsOptions() { 2306 final int defaultWarningEnabled = Build.IS_DEBUGGABLE ? 1 : 0; 2307 updateSwitchPreference(mShowNotificationChannelWarnings, Settings.Global.getInt( 2308 getActivity().getContentResolver(), 2309 Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, defaultWarningEnabled) != 0); 2310 } 2311 2312 private void confirmEnableOemUnlock() { 2313 DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() { 2314 @Override 2315 public void onClick(DialogInterface dialog, int which) { 2316 if (which == DialogInterface.BUTTON_POSITIVE) { 2317 mOemLockManager.setOemUnlockAllowedByUser(true); 2318 } 2319 } 2320 }; 2321 2322 DialogInterface.OnDismissListener onDismissListener = 2323 new DialogInterface.OnDismissListener() { 2324 @Override 2325 public void onDismiss(DialogInterface dialog) { 2326 if (getActivity() == null) { 2327 return; 2328 } 2329 updateAllOptions(); 2330 } 2331 }; 2332 2333 new AlertDialog.Builder(getActivity()) 2334 .setTitle(R.string.confirm_enable_oem_unlock_title) 2335 .setMessage(R.string.confirm_enable_oem_unlock_text) 2336 .setPositiveButton(R.string.enable_text, onClickListener) 2337 .setNegativeButton(android.R.string.cancel, null) 2338 .setOnDismissListener(onDismissListener) 2339 .create() 2340 .show(); 2341 } 2342 2343 @Override 2344 public void onSwitchChanged(Switch switchView, boolean isChecked) { 2345 if (switchView != mSwitchBar.getSwitch()) { 2346 return; 2347 } 2348 final boolean lastEnabledState = mSettingsEnabler.getLastEnabledState(); 2349 if (isChecked != lastEnabledState) { 2350 if (isChecked) { 2351 mDialogClicked = false; 2352 if (mEnableDialog != null) dismissDialogs(); 2353 mEnableDialog = new AlertDialog.Builder(getActivity()).setMessage( 2354 getActivity().getResources().getString( 2355 R.string.dev_settings_warning_message)) 2356 .setTitle(R.string.dev_settings_warning_title) 2357 .setPositiveButton(android.R.string.yes, this) 2358 .setNegativeButton(android.R.string.no, this) 2359 .show(); 2360 mEnableDialog.setOnDismissListener(this); 2361 } else { 2362 resetDangerousOptions(); 2363 mSettingsEnabler.disableDevelopmentSettings(); 2364 setPrefsEnabledState(false); 2365 } 2366 } 2367 } 2368 2369 @Override 2370 public void onActivityResult(int requestCode, int resultCode, Intent data) { 2371 if (requestCode == RESULT_DEBUG_APP) { 2372 if (resultCode == Activity.RESULT_OK) { 2373 mDebugApp = data.getAction(); 2374 writeDebuggerOptions(); 2375 updateDebuggerOptions(); 2376 } 2377 } else if (requestCode == RESULT_MOCK_LOCATION_APP) { 2378 if (resultCode == Activity.RESULT_OK) { 2379 mMockLocationApp = data.getAction(); 2380 writeMockLocation(); 2381 updateMockLocation(); 2382 } 2383 } else if (requestCode == REQUEST_CODE_ENABLE_OEM_UNLOCK) { 2384 if (resultCode == Activity.RESULT_OK) { 2385 if (mEnableOemUnlock.isChecked()) { 2386 confirmEnableOemUnlock(); 2387 } else { 2388 mOemLockManager.setOemUnlockAllowedByUser(false); 2389 } 2390 } 2391 } else { 2392 super.onActivityResult(requestCode, resultCode, data); 2393 } 2394 } 2395 2396 @Override 2397 public boolean onPreferenceTreeClick(Preference preference) { 2398 if (Utils.isMonkeyRunning()) { 2399 return false; 2400 } 2401 2402 if (mBugReportInPowerController.handlePreferenceTreeClick(preference)) { 2403 return true; 2404 } 2405 2406 if (mTelephonyMonitorController.handlePreferenceTreeClick(preference)) { 2407 return true; 2408 } 2409 2410 if (mWebViewAppPrefController.handlePreferenceTreeClick(preference)) { 2411 return true; 2412 } 2413 2414 if (mVerifyAppsOverUsbController.handlePreferenceTreeClick(preference)) { 2415 return true; 2416 } 2417 2418 if (mCameraHalHdrplusController.handlePreferenceTreeClick(preference)) { 2419 return true; 2420 } 2421 2422 if (preference == mEnableAdb) { 2423 if (mEnableAdb.isChecked()) { 2424 mDialogClicked = false; 2425 if (mAdbDialog != null) dismissDialogs(); 2426 mAdbDialog = new AlertDialog.Builder(getActivity()).setMessage( 2427 getActivity().getResources().getString(R.string.adb_warning_message)) 2428 .setTitle(R.string.adb_warning_title) 2429 .setPositiveButton(android.R.string.yes, this) 2430 .setNegativeButton(android.R.string.no, this) 2431 .show(); 2432 mAdbDialog.setOnDismissListener(this); 2433 } else { 2434 Settings.Global.putInt(getActivity().getContentResolver(), 2435 Settings.Global.ADB_ENABLED, 0); 2436 mVerifyAppsOverUsbController.updatePreference(); 2437 updateBugreportOptions(); 2438 } 2439 } else if (preference == mClearAdbKeys) { 2440 if (mAdbKeysDialog != null) dismissDialogs(); 2441 mAdbKeysDialog = new AlertDialog.Builder(getActivity()) 2442 .setMessage(R.string.adb_keys_warning_message) 2443 .setPositiveButton(android.R.string.ok, this) 2444 .setNegativeButton(android.R.string.cancel, null) 2445 .show(); 2446 } else if (preference == mEnableTerminal) { 2447 final PackageManager pm = getActivity().getPackageManager(); 2448 pm.setApplicationEnabledSetting(TERMINAL_APP_PACKAGE, 2449 mEnableTerminal.isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED 2450 : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0); 2451 } else if (preference == mKeepScreenOn) { 2452 Settings.Global.putInt(getActivity().getContentResolver(), 2453 Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 2454 mKeepScreenOn.isChecked() ? 2455 (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB 2456 | BatteryManager.BATTERY_PLUGGED_WIRELESS) : 0); 2457 } else if (preference == mBtHciSnoopLog) { 2458 writeBtHciSnoopLogOptions(); 2459 } else if (preference == mEnableOemUnlock && mEnableOemUnlock.isEnabled()) { 2460 if (mEnableOemUnlock.isChecked()) { 2461 if (!showKeyguardConfirmation(getResources(), REQUEST_CODE_ENABLE_OEM_UNLOCK)) { 2462 confirmEnableOemUnlock(); 2463 } 2464 } else { 2465 mOemLockManager.setOemUnlockAllowedByUser(false); 2466 } 2467 } else if (preference == mMockLocationAppPref) { 2468 Intent intent = new Intent(getActivity(), AppPicker.class); 2469 intent.putExtra(AppPicker.EXTRA_REQUESTIING_PERMISSION, 2470 Manifest.permission.ACCESS_MOCK_LOCATION); 2471 startActivityForResult(intent, RESULT_MOCK_LOCATION_APP); 2472 } else if (preference == mDebugViewAttributes) { 2473 Settings.Global.putInt(getActivity().getContentResolver(), 2474 Settings.Global.DEBUG_VIEW_ATTRIBUTES, 2475 mDebugViewAttributes.isChecked() ? 1 : 0); 2476 } else if (preference == mForceAllowOnExternal) { 2477 Settings.Global.putInt(getActivity().getContentResolver(), 2478 Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 2479 mForceAllowOnExternal.isChecked() ? 1 : 0); 2480 } else if (preference == mDebugAppPref) { 2481 Intent intent = new Intent(getActivity(), AppPicker.class); 2482 intent.putExtra(AppPicker.EXTRA_DEBUGGABLE, true); 2483 startActivityForResult(intent, RESULT_DEBUG_APP); 2484 } else if (preference == mWaitForDebugger) { 2485 writeDebuggerOptions(); 2486 } else if (preference == mOtaDisableAutomaticUpdate) { 2487 writeOtaDisableAutomaticUpdateOptions(); 2488 } else if (preference == mStrictMode) { 2489 writeStrictModeVisualOptions(); 2490 } else if (preference == mPointerLocation) { 2491 writePointerLocationOptions(); 2492 } else if (preference == mShowTouches) { 2493 writeShowTouchesOptions(); 2494 } else if (preference == mShowScreenUpdates) { 2495 writeShowUpdatesOption(); 2496 } else if (preference == mDisableOverlays) { 2497 writeDisableOverlaysOption(); 2498 } else if (preference == mImmediatelyDestroyActivities) { 2499 writeImmediatelyDestroyActivitiesOptions(); 2500 } else if (preference == mShowAllANRs) { 2501 writeShowAllANRsOptions(); 2502 } else if (preference == mShowNotificationChannelWarnings) { 2503 writeShowNotificationChannelWarningsOptions(); 2504 } else if (preference == mForceHardwareUi) { 2505 writeHardwareUiOptions(); 2506 } else if (preference == mForceMsaa) { 2507 writeMsaaOptions(); 2508 } else if (preference == mShowHwScreenUpdates) { 2509 writeShowHwScreenUpdatesOptions(); 2510 } else if (preference == mShowHwLayersUpdates) { 2511 writeShowHwLayersUpdatesOptions(); 2512 } else if (preference == mDebugLayout) { 2513 writeDebugLayoutOptions(); 2514 } else if (preference == mForceRtlLayout) { 2515 writeForceRtlOptions(); 2516 } else if (preference == mWifiDisplayCertification) { 2517 writeWifiDisplayCertificationOptions(); 2518 } else if (preference == mWifiVerboseLogging) { 2519 writeWifiVerboseLoggingOptions(); 2520 } else if (preference == mWifiAggressiveHandover) { 2521 writeWifiAggressiveHandoverOptions(); 2522 } else if (preference == mWifiAllowScansWithTraffic) { 2523 writeWifiAllowScansWithTrafficOptions(); 2524 } else if (preference == mMobileDataAlwaysOn) { 2525 writeMobileDataAlwaysOnOptions(); 2526 } else if (preference == mTetheringHardwareOffload) { 2527 writeTetheringHardwareOffloadOptions(); 2528 } else if (preference == mColorTemperaturePreference) { 2529 writeColorTemperature(); 2530 } else if (preference == mUSBAudio) { 2531 writeUSBAudioOptions(); 2532 } else if (preference == mForceResizable) { 2533 writeForceResizableOptions(); 2534 } else if (preference == mBluetoothDisableAbsVolume) { 2535 writeBluetoothDisableAbsVolumeOptions(); 2536 } else if (preference == mBluetoothEnableInbandRinging) { 2537 writeBluetoothEnableInbandRingingOptions(); 2538 } else if (SHORTCUT_MANAGER_RESET_KEY.equals(preference.getKey())) { 2539 resetShortcutManagerThrottling(); 2540 } else { 2541 return super.onPreferenceTreeClick(preference); 2542 } 2543 2544 return false; 2545 } 2546 2547 private boolean showKeyguardConfirmation(Resources resources, int requestCode) { 2548 return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity( 2549 requestCode, resources.getString(R.string.oem_unlock_enable)); 2550 } 2551 2552 @Override 2553 public boolean onPreferenceChange(Preference preference, Object newValue) { 2554 if (HDCP_CHECKING_KEY.equals(preference.getKey())) { 2555 SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString()); 2556 updateHdcpValues(); 2557 pokeSystemProperties(); 2558 return true; 2559 } else if (preference == mBluetoothSelectAvrcpVersion) { 2560 writeBluetoothAvrcpVersion(newValue); 2561 return true; 2562 } else if ((preference == mBluetoothSelectA2dpCodec) || 2563 (preference == mBluetoothSelectA2dpSampleRate) || 2564 (preference == mBluetoothSelectA2dpBitsPerSample) || 2565 (preference == mBluetoothSelectA2dpChannelMode) || 2566 (preference == mBluetoothSelectA2dpLdacPlaybackQuality)) { 2567 writeBluetoothConfigurationOption(preference, newValue); 2568 return true; 2569 } else if (preference == mLogdSize) { 2570 writeLogdSizeOption(newValue); 2571 return true; 2572 } else if (preference == mLogpersist) { 2573 writeLogpersistOption(newValue, false); 2574 return true; 2575 } else if (preference == mUsbConfiguration) { 2576 writeUsbConfigurationOption(newValue); 2577 return true; 2578 } else if (preference == mWindowAnimationScale) { 2579 writeAnimationScaleOption(0, mWindowAnimationScale, newValue); 2580 return true; 2581 } else if (preference == mTransitionAnimationScale) { 2582 writeAnimationScaleOption(1, mTransitionAnimationScale, newValue); 2583 return true; 2584 } else if (preference == mAnimatorDurationScale) { 2585 writeAnimationScaleOption(2, mAnimatorDurationScale, newValue); 2586 return true; 2587 } else if (preference == mOverlayDisplayDevices) { 2588 writeOverlayDisplayDevicesOptions(newValue); 2589 return true; 2590 } else if (preference == mTrackFrameTime) { 2591 writeTrackFrameTimeOptions(newValue); 2592 return true; 2593 } else if (preference == mDebugHwOverdraw) { 2594 writeDebugHwOverdrawOptions(newValue); 2595 return true; 2596 } else if (preference == mDebugHwRenderer) { 2597 writeDebugHwRendererOptions(newValue); 2598 return true; 2599 } else if (preference == mShowNonRectClip) { 2600 writeShowNonRectClipOptions(newValue); 2601 return true; 2602 } else if (preference == mAppProcessLimit) { 2603 writeAppProcessLimitOptions(newValue); 2604 return true; 2605 } else if (preference == mSimulateColorSpace) { 2606 writeSimulateColorSpace(newValue); 2607 return true; 2608 } 2609 return false; 2610 } 2611 2612 private void dismissDialogs() { 2613 if (mAdbDialog != null) { 2614 mAdbDialog.dismiss(); 2615 mAdbDialog = null; 2616 } 2617 if (mAdbKeysDialog != null) { 2618 mAdbKeysDialog.dismiss(); 2619 mAdbKeysDialog = null; 2620 } 2621 if (mEnableDialog != null) { 2622 mEnableDialog.dismiss(); 2623 mEnableDialog = null; 2624 } 2625 if (mLogpersistClearDialog != null) { 2626 mLogpersistClearDialog.dismiss(); 2627 mLogpersistClearDialog = null; 2628 } 2629 } 2630 2631 public void onClick(DialogInterface dialog, int which) { 2632 if (dialog == mAdbDialog) { 2633 if (which == DialogInterface.BUTTON_POSITIVE) { 2634 mDialogClicked = true; 2635 Settings.Global.putInt(getActivity().getContentResolver(), 2636 Settings.Global.ADB_ENABLED, 1); 2637 mVerifyAppsOverUsbController.updatePreference(); 2638 updateBugreportOptions(); 2639 } else { 2640 // Reset the toggle 2641 mEnableAdb.setChecked(false); 2642 } 2643 } else if (dialog == mAdbKeysDialog) { 2644 if (which == DialogInterface.BUTTON_POSITIVE) { 2645 try { 2646 IBinder b = ServiceManager.getService(Context.USB_SERVICE); 2647 IUsbManager service = IUsbManager.Stub.asInterface(b); 2648 service.clearUsbDebuggingKeys(); 2649 } catch (RemoteException e) { 2650 Log.e(TAG, "Unable to clear adb keys", e); 2651 } 2652 } 2653 } else if (dialog == mEnableDialog) { 2654 if (which == DialogInterface.BUTTON_POSITIVE) { 2655 mDialogClicked = true; 2656 mSettingsEnabler.enableDevelopmentSettings(); 2657 setPrefsEnabledState(true); 2658 } else { 2659 // Reset the toggle 2660 mSwitchBar.setChecked(false); 2661 } 2662 } else if (dialog == mLogpersistClearDialog) { 2663 if (which == DialogInterface.BUTTON_POSITIVE) { 2664 setLogpersistOff(true); 2665 } else { 2666 updateLogpersistValues(); 2667 } 2668 } 2669 } 2670 2671 public void onDismiss(DialogInterface dialog) { 2672 // Assuming that onClick gets called first 2673 if (dialog == mAdbDialog) { 2674 if (!mDialogClicked) { 2675 mEnableAdb.setChecked(false); 2676 } 2677 mAdbDialog = null; 2678 } else if (dialog == mEnableDialog) { 2679 if (!mDialogClicked) { 2680 mSwitchBar.setChecked(false); 2681 } 2682 mEnableDialog = null; 2683 } else if (dialog == mLogpersistClearDialog) { 2684 mLogpersistClearDialog = null; 2685 } 2686 } 2687 2688 @Override 2689 public void onDestroy() { 2690 dismissDialogs(); 2691 super.onDestroy(); 2692 } 2693 2694 void pokeSystemProperties() { 2695 if (!mDontPokeProperties) { 2696 //noinspection unchecked 2697 (new SystemPropPoker()).execute(); 2698 } 2699 } 2700 2701 private BroadcastReceiver mUsbReceiver = new BroadcastReceiver() { 2702 @Override 2703 public void onReceive(Context context, Intent intent) { 2704 updateUsbConfigurationValues(); 2705 } 2706 }; 2707 2708 private BroadcastReceiver mBluetoothA2dpReceiver = new BroadcastReceiver() { 2709 @Override 2710 public void onReceive(Context context, Intent intent) { 2711 Log.d(TAG, "mBluetoothA2dpReceiver.onReceive intent=" + intent); 2712 String action = intent.getAction(); 2713 2714 if (BluetoothA2dp.ACTION_CODEC_CONFIG_CHANGED.equals(action)) { 2715 BluetoothCodecStatus codecStatus = 2716 (BluetoothCodecStatus)intent.getParcelableExtra(BluetoothCodecStatus.EXTRA_CODEC_STATUS); 2717 Log.d(TAG, "Received BluetoothCodecStatus=" + codecStatus); 2718 updateBluetoothA2dpConfigurationValues(); 2719 } 2720 } 2721 }; 2722 2723 private BluetoothProfile.ServiceListener mBluetoothA2dpServiceListener = 2724 new BluetoothProfile.ServiceListener() { 2725 public void onServiceConnected(int profile, 2726 BluetoothProfile proxy) { 2727 synchronized (mBluetoothA2dpLock) { 2728 mBluetoothA2dp = (BluetoothA2dp) proxy; 2729 } 2730 updateBluetoothA2dpConfigurationValues(); 2731 } 2732 2733 public void onServiceDisconnected(int profile) { 2734 synchronized (mBluetoothA2dpLock) { 2735 mBluetoothA2dp = null; 2736 } 2737 updateBluetoothA2dpConfigurationValues(); 2738 } 2739 }; 2740 2741 public static class SystemPropPoker extends AsyncTask<Void, Void, Void> { 2742 @Override 2743 protected Void doInBackground(Void... params) { 2744 String[] services = ServiceManager.listServices(); 2745 for (String service : services) { 2746 IBinder obj = ServiceManager.checkService(service); 2747 if (obj != null) { 2748 Parcel data = Parcel.obtain(); 2749 try { 2750 obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0); 2751 } catch (RemoteException e) { 2752 } catch (Exception e) { 2753 Log.i(TAG, "Someone wrote a bad service '" + service 2754 + "' that doesn't like to be poked: " + e); 2755 } 2756 data.recycle(); 2757 } 2758 } 2759 return null; 2760 } 2761 } 2762 2763 private static boolean isPackageInstalled(Context context, String packageName) { 2764 try { 2765 return context.getPackageManager().getPackageInfo(packageName, 0) != null; 2766 } catch (NameNotFoundException e) { 2767 return false; 2768 } 2769 } 2770 2771 2772 /** 2773 * For Search. 2774 */ 2775 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 2776 new BaseSearchIndexProvider() { 2777 2778 @Override 2779 protected boolean isPageSearchEnabled(Context context) { 2780 return context.getSharedPreferences(DevelopmentSettings.PREF_FILE, 2781 Context.MODE_PRIVATE).getBoolean( 2782 DevelopmentSettings.PREF_SHOW, 2783 android.os.Build.TYPE.equals("eng")); 2784 } 2785 2786 @Override 2787 public List<SearchIndexableResource> getXmlResourcesToIndex( 2788 Context context, boolean enabled) { 2789 2790 final SearchIndexableResource sir = new SearchIndexableResource(context); 2791 sir.xmlResId = R.xml.development_prefs; 2792 return Arrays.asList(sir); 2793 } 2794 2795 @Override 2796 public List<String> getNonIndexableKeys(Context context) { 2797 final List<String> keys = super.getNonIndexableKeys(context); 2798 2799 if (!showEnableOemUnlockPreference(context)) { 2800 keys.add(ENABLE_OEM_UNLOCK); 2801 } 2802 return keys; 2803 } 2804 }; 2805 2806 private void resetShortcutManagerThrottling() { 2807 final IShortcutService service = IShortcutService.Stub.asInterface( 2808 ServiceManager.getService(Context.SHORTCUT_SERVICE)); 2809 if (service != null) { 2810 try { 2811 service.resetThrottling(); 2812 Toast.makeText(getActivity(), R.string.reset_shortcut_manager_throttling_complete, 2813 Toast.LENGTH_SHORT).show(); 2814 } catch (RemoteException e) { 2815 Log.e(TAG, "Failed to reset rate limiting", e); 2816 } 2817 } 2818 } 2819 2820 private void updateOemUnlockSettingDescription() { 2821 if (mEnableOemUnlock != null) { 2822 int oemUnlockSummary = R.string.oem_unlock_enable_summary; 2823 if (isBootloaderUnlocked()) { 2824 oemUnlockSummary = R.string.oem_unlock_enable_disabled_summary_bootloader_unlocked; 2825 } else if (isSimLockedDevice()) { 2826 oemUnlockSummary = R.string.oem_unlock_enable_disabled_summary_sim_locked_device; 2827 } else if (!mOemLockManager.canUserAllowOemUnlock()) { 2828 // If the device isn't SIM-locked but OEM unlock is disallowed by some party, this 2829 // means either some other carrier restriction is in place or the device hasn't been 2830 // able to confirm which restrictions (SIM-lock or otherwise) apply. 2831 oemUnlockSummary = 2832 R.string.oem_unlock_enable_disabled_summary_connectivity_or_locked; 2833 } 2834 mEnableOemUnlock.setSummary(getString(oemUnlockSummary)); 2835 } 2836 } 2837 2838 /** Returns {@code true} if the device is SIM-locked. Otherwise, returns {@code false}. */ 2839 private boolean isSimLockedDevice() { 2840 int phoneCount = mTelephonyManager.getPhoneCount(); 2841 for (int i = 0; i < phoneCount; i++) { 2842 if (mTelephonyManager.getAllowedCarriers(i).size() > 0) { 2843 return true; 2844 } 2845 } 2846 return false; 2847 } 2848 2849 /** 2850 * Returns {@code true} if the bootloader has been unlocked. Otherwise, returns {code false}. 2851 */ 2852 private boolean isBootloaderUnlocked() { 2853 return mOemLockManager.isDeviceOemUnlocked(); 2854 } 2855 2856 2857} 2858