/src/com/android/settings/DevelopmentSettings.java

http://github.com/CyanogenMod/android_packages_apps_Settings · Java · 2601 lines · 2238 code · 260 blank · 103 comment · 599 complexity · 59c4468fa987a0c2594cdf4158f8326d MD5 · raw file

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