1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.tradefed.targetprep; 18 19 import com.android.ddmlib.IDevice; 20 import com.android.tradefed.build.IBuildInfo; 21 import com.android.tradefed.config.Option; 22 import com.android.tradefed.config.OptionClass; 23 import com.android.tradefed.device.DeviceNotAvailableException; 24 import com.android.tradefed.device.ITestDevice; 25 import com.android.tradefed.device.StubDevice; 26 import com.android.tradefed.log.LogUtil.CLog; 27 import com.android.tradefed.util.BinaryState; 28 import com.android.tradefed.util.MultiMap; 29 30 import com.google.common.annotations.VisibleForTesting; 31 32 import java.io.File; 33 import java.util.ArrayList; 34 import java.util.Collection; 35 import java.util.HashMap; 36 import java.util.List; 37 import java.util.Map; 38 39 /** 40 * A {@link ITargetPreparer} that configures a device for testing based on provided {@link Option}s. 41 * 42 * <p>Requires a device where 'adb root' is possible, typically a userdebug build type. 43 * 44 * <p>Should be performed <strong>after</strong> a new build is flashed. 45 */ 46 @OptionClass(alias = "device-setup") 47 public class DeviceSetup extends BaseTargetPreparer implements ITargetCleaner { 48 49 // Networking 50 @Option(name = "airplane-mode", 51 description = "Turn airplane mode on or off") 52 protected BinaryState mAirplaneMode = BinaryState.IGNORE; 53 // ON: settings put global airplane_mode_on 1 54 // am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true 55 // OFF: settings put global airplane_mode_on 0 56 // am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false 57 58 @Option(name = "data", description = "Turn mobile data on or off") 59 protected BinaryState mData = BinaryState.IGNORE; 60 // ON: settings put global mobile_data 1 61 // svc data enable 62 // OFF: settings put global mobile_data 0 63 // svc data disable 64 65 @Option(name = "cell", description = "Turn cellular radio on or off") 66 protected BinaryState mCell = BinaryState.IGNORE; 67 // ON: settings put global cell_on 1 68 // OFF: settings put global cell_on 0 69 70 @Option(name = "cell-auto-setting", description = "Turn wear cellular mediator on or off") 71 protected BinaryState mCellAutoSetting = BinaryState.IGNORE; 72 // ON: settings put global clockwork_cell_auto_setting 1 73 // OFF: settings put global clockwork_cell_auto_setting 0 74 75 @Option(name = "wifi", description = "Turn wifi on or off") 76 protected BinaryState mWifi = BinaryState.IGNORE; 77 // ON: settings put global wifi_on 1 78 // svc wifi enable 79 // OFF: settings put global wifi_off 0 80 // svc wifi disable 81 82 @Option(name = "wifi-network", 83 description = "The SSID of the network to connect to. Will only attempt to " + 84 "connect to a network if set") 85 protected String mWifiSsid = null; 86 87 @Option(name = "wifi-psk", 88 description = "The passphrase used to connect to a secured network") 89 protected String mWifiPsk = null; 90 91 @Option(name = "wifi-ssid-to-psk", description = "A map of wifi SSIDs to passwords.") 92 protected Map<String, String> mWifiSsidToPsk = new HashMap<>(); 93 94 @Option(name = "wifi-watchdog", 95 description = "Turn wifi watchdog on or off") 96 protected BinaryState mWifiWatchdog = BinaryState.IGNORE; 97 // ON: settings put global wifi_watchdog 1 98 // OFF: settings put global wifi_watchdog 0 99 100 @Option(name = "disable-cw-wifi-mediator", description = "Turn wifi mediator on or off") 101 protected BinaryState mDisableCwWifiMediator = BinaryState.IGNORE; 102 // ON: settings put global cw_disable_wifimediator 1 103 // OFF: settings put global cw_disable_wifimediator 0 104 105 @Option( 106 name = "wifi-scan-always-enabled", 107 description = "Turn wifi scan always enabled on or off" 108 ) 109 protected BinaryState mWifiScanAlwaysEnabled = BinaryState.IGNORE; 110 // ON: settings put global wifi_scan_always_enabled 1 111 // OFF: settings put global wifi_scan_always_enabled 0 112 113 @Option(name = "ethernet", 114 description = "Turn ethernet on or off") 115 protected BinaryState mEthernet = BinaryState.IGNORE; 116 // ON: ifconfig eth0 up 117 // OFF: ifconfig eth0 down 118 119 @Option(name = "bluetooth", 120 description = "Turn bluetooth on or off") 121 protected BinaryState mBluetooth = BinaryState.IGNORE; 122 // ON: service call bluetooth_manager 6 123 // OFF: service call bluetooth_manager 8 124 125 @Option(name = "nfc", 126 description = "Turn nfc on or off") 127 protected BinaryState mNfc = BinaryState.IGNORE; 128 // ON: svc nfc enable 129 // OFF: svc nfc disable 130 131 // Screen 132 @Option(name = "screen-adaptive-brightness", 133 description = "Turn screen adaptive brightness on or off") 134 protected BinaryState mScreenAdaptiveBrightness = BinaryState.IGNORE; 135 // ON: settings put system screen_brightness_mode 1 136 // OFF: settings put system screen_brightness_mode 0 137 138 @Option(name = "screen-brightness", 139 description = "Set the screen brightness. This is uncalibrated from product to product") 140 protected Integer mScreenBrightness = null; 141 // settings put system screen_brightness $N 142 143 @Option(name = "screen-always-on", 144 description = "Turn 'screen always on' on or off. If ON, then screen-timeout-secs " + 145 "must be unset. Will only work when the device is plugged in") 146 protected BinaryState mScreenAlwaysOn = BinaryState.ON; 147 // ON: svc power stayon true 148 // OFF: svc power stayon false 149 150 @Option(name = "screen-timeout-secs", 151 description = "Set the screen timeout in seconds. If set, then screen-always-on must " + 152 "be OFF or DEFAULT") 153 protected Long mScreenTimeoutSecs = null; 154 // settings put system screen_off_timeout $(N * 1000) 155 156 @Option(name = "screen-ambient-mode", 157 description = "Turn screen ambient mode on or off") 158 protected BinaryState mScreenAmbientMode = BinaryState.IGNORE; 159 // ON: settings put secure doze_enabled 1 160 // OFF: settings put secure doze_enabled 0 161 162 @Option(name = "wake-gesture", 163 description = "Turn wake gesture on or off") 164 protected BinaryState mWakeGesture = BinaryState.IGNORE; 165 // ON: settings put secure wake_gesture_enabled 1 166 // OFF: settings put secure wake_gesture_enabled 0 167 168 @Option(name = "screen-saver", 169 description = "Turn screen saver on or off") 170 protected BinaryState mScreenSaver = BinaryState.IGNORE; 171 // ON: settings put secure screensaver_enabled 1 172 // OFF: settings put secure screensaver_enabled 0 173 174 @Option(name = "notification-led", 175 description = "Turn the notification led on or off") 176 protected BinaryState mNotificationLed = BinaryState.IGNORE; 177 // ON: settings put system notification_light_pulse 1 178 // OFF: settings put system notification_light_pulse 0 179 180 @Option(name = "install-non-market-apps", 181 description = "Allow or prevent non-market app to initiate an apk install request") 182 protected BinaryState mInstallNonMarketApps = BinaryState.IGNORE; 183 // ON: settings put secure install_non_market_apps 1 184 // OFF: settings put secure install_non_market_apps 0 185 186 // Media 187 @Option(name = "trigger-media-mounted", 188 description = "Trigger a MEDIA_MOUNTED broadcast") 189 protected boolean mTriggerMediaMounted = false; 190 // am broadcast -a android.intent.action.MEDIA_MOUNTED -d file://${EXTERNAL_STORAGE} 191 // --receiver-include-background 192 193 // Location 194 @Option(name = "location-gps", description = "Turn the GPS location on or off") 195 protected BinaryState mLocationGps = BinaryState.IGNORE; 196 // ON: settings put secure location_providers_allowed +gps 197 // OFF: settings put secure location_providers_allowed -gps 198 199 @Option(name = "location-network", 200 description = "Turn the network location on or off") 201 protected BinaryState mLocationNetwork = BinaryState.IGNORE; 202 // ON: settings put secure location_providers_allowed +network 203 // OFF: settings put secure location_providers_allowed -network 204 205 // Sensor 206 @Option(name = "auto-rotate", 207 description = "Turn auto rotate on or off") 208 protected BinaryState mAutoRotate = BinaryState.IGNORE; 209 // ON: settings put system accelerometer_rotation 1 210 // OFF: settings put system accelerometer_rotation 0 211 212 // Power 213 @Option(name = "battery-saver-mode", 214 description = "Turn battery saver mode manually on or off. If OFF but battery is " + 215 "less battery-saver-trigger, the device will still go into battery saver mode") 216 protected BinaryState mBatterySaver = BinaryState.IGNORE; 217 // ON: dumpsys battery set usb 0 218 // settings put global low_power 1 219 // OFF: settings put global low_power 0 220 221 @Option(name = "battery-saver-trigger", 222 description = "Set the battery saver trigger level. Should be [1-99] to enable, or " + 223 "0 to disable automatic battery saver mode") 224 protected Integer mBatterySaverTrigger = null; 225 // settings put global low_power_trigger_level $N 226 227 @Option(name = "enable-full-battery-stats-history", 228 description = "Enable full history for batterystats. This option is only " + 229 "applicable for L+") 230 protected boolean mEnableFullBatteryStatsHistory = false; 231 // dumpsys batterystats --enable full-history 232 233 @Option(name = "disable-doze", 234 description = "Disable device from going into doze mode. This option is only " + 235 "applicable for M+") 236 protected boolean mDisableDoze = false; 237 // dumpsys deviceidle disable 238 239 // Time 240 @Option(name = "auto-update-time", 241 description = "Turn auto update time on or off") 242 protected BinaryState mAutoUpdateTime = BinaryState.IGNORE; 243 // ON: settings put global auto_time 1 244 // OFF: settings put global auto_time 0 245 246 @Option(name = "auto-update-timezone", description = "Turn auto update timezone on or off") 247 protected BinaryState mAutoUpdateTimezone = BinaryState.IGNORE; 248 // ON: settings put global auto_timezone 1 249 // OFF: settings put global auto_timezone 0 250 251 @Option( 252 name = "set-timezone", 253 description = 254 "Set timezone property by TZ name " 255 + "(http://en.wikipedia.org/wiki/List_of_tz_database_time_zones)" 256 ) 257 protected String mTimezone = null; 258 259 // Calling 260 @Option(name = "disable-dialing", 261 description = "Disable dialing") 262 protected boolean mDisableDialing = true; 263 // setprop ro.telephony.disable-call true" 264 265 @Option(name = "default-sim-data", 266 description = "Set the default sim card slot for data. Leave unset for single SIM " + 267 "devices") 268 protected Integer mDefaultSimData = null; 269 // settings put global multi_sim_data_call $N 270 271 @Option(name = "default-sim-voice", 272 description = "Set the default sim card slot for voice calls. Leave unset for single " + 273 "SIM devices") 274 protected Integer mDefaultSimVoice = null; 275 // settings put global multi_sim_voice_call $N 276 277 @Option(name = "default-sim-sms", 278 description = "Set the default sim card slot for SMS. Leave unset for single SIM " + 279 "devices") 280 protected Integer mDefaultSimSms = null; 281 // settings put global multi_sim_sms $N 282 283 // Audio 284 private static final boolean DEFAULT_DISABLE_AUDIO = true; 285 @Option(name = "disable-audio", 286 description = "Disable the audio") 287 protected boolean mDisableAudio = DEFAULT_DISABLE_AUDIO; 288 // setprop ro.audio.silent 1" 289 290 @Option(name = "force-skip-system-props", 291 description = "Force setup to not modify any device system properties. All other " + 292 "system property options will be ignored") 293 protected boolean mForceSkipSystemProps = false; 294 295 @Option(name = "force-skip-settings", 296 description = "Force setup to not modify any device settings. All other setting " + 297 "options will be ignored.") 298 protected boolean mForceSkipSettings = false; 299 300 @Option(name = "force-skip-run-commands", 301 description = "Force setup to not run any additional commands. All other commands " + 302 "will be ignored.") 303 protected boolean mForceSkipRunCommands = false; 304 305 @Option(name = "set-test-harness", 306 description = "Set the read-only test harness flag on boot") 307 protected boolean mSetTestHarness = true; 308 // setprop ro.monkey 1 309 // setprop ro.test_harness 1 310 311 @Option(name = "disable-dalvik-verifier", 312 description = "Disable the dalvik verifier on device. Allows package-private " + 313 "framework tests to run.") 314 protected boolean mDisableDalvikVerifier = false; 315 // setprop dalvik.vm.dexopt-flags v=n 316 317 @Option(name = "set-property", 318 description = "Set the specified property on boot. Option may be repeated but only " + 319 "the last value for a given key will be set.") 320 protected Map<String, String> mSetProps = new HashMap<>(); 321 322 @Option( 323 name = "restore-properties", 324 description = 325 "Restore previous /data/local.prop on tear down, restoring any properties DeviceSetup changed by modifying /data/local.prop." 326 ) 327 protected boolean mRestoreProperties = false; 328 329 protected File mPreviousProperties; 330 331 @Option(name = "set-system-setting", 332 description = "Change a system (non-secure) setting. Option may be repeated and all " + 333 "key/value pairs will be set in order.") 334 // Use a Multimap since it is possible for a setting to have multiple values for the same key 335 protected MultiMap<String, String> mSystemSettings = new MultiMap<>(); 336 337 @Option(name = "set-secure-setting", 338 description = "Change a secure setting. Option may be repeated and all key/value " + 339 "pairs will be set in order.") 340 // Use a Multimap since it is possible for a setting to have multiple values for the same key 341 protected MultiMap<String, String> mSecureSettings = new MultiMap<>(); 342 343 @Option(name = "set-global-setting", 344 description = "Change a global setting. Option may be repeated and all key/value " + 345 "pairs will be set in order.") 346 // Use a Multimap since it is possible for a setting to have multiple values for the same key 347 protected MultiMap<String, String> mGlobalSettings = new MultiMap<>(); 348 349 @Option( 350 name = "restore-settings", 351 description = "Restore settings modified by this preparer on tear down." 352 ) 353 protected boolean mRestoreSettings = false; 354 355 private Map<String, String> mPreviousSystemSettings = new HashMap<>(); 356 private Map<String, String> mPreviousSecureSettings = new HashMap<>(); 357 private Map<String, String> mPreviousGlobalSettings = new HashMap<>(); 358 359 protected List<String> mRunCommandBeforeSettings = new ArrayList<>(); 360 361 @Option(name = "run-command", 362 description = "Run an adb shell command. Option may be repeated") 363 protected List<String> mRunCommandAfterSettings = new ArrayList<>(); 364 365 @Option(name = "disconnect-wifi-after-test", 366 description = "Disconnect from wifi network after test completes.") 367 private boolean mDisconnectWifiAfterTest = true; 368 369 private static final long DEFAULT_MIN_EXTERNAL_STORAGE_KB = 500; 370 @Option(name = "min-external-storage-kb", 371 description="The minimum amount of free space in KB that must be present on device's " + 372 "external storage.") 373 protected long mMinExternalStorageKb = DEFAULT_MIN_EXTERNAL_STORAGE_KB; 374 375 @Option(name = "local-data-path", 376 description = "Optional local file path of test data to sync to device's external " + 377 "storage. Use --remote-data-path to set remote location.") 378 protected File mLocalDataFile = null; 379 380 @Option(name = "remote-data-path", 381 description = "Optional file path on device's external storage to sync test data. " + 382 "Must be used with --local-data-path.") 383 protected String mRemoteDataPath = null; 384 385 // Deprecated options follow 386 /** 387 * @deprecated use min-external-storage-kb instead. 388 */ 389 @Option(name = "min-external-store-space", 390 description = "deprecated, use option min-external-storage-kb. The minimum amount of " + 391 "free space in KB that must be present on device's external storage.") 392 @Deprecated 393 private long mDeprecatedMinExternalStoreSpace = DEFAULT_MIN_EXTERNAL_STORAGE_KB; 394 395 /** 396 * @deprecated use option disable-audio instead. 397 */ 398 @Option(name = "audio-silent", 399 description = "deprecated, use option disable-audio. set ro.audio.silent on boot.") 400 @Deprecated 401 private boolean mDeprecatedSetAudioSilent = DEFAULT_DISABLE_AUDIO; 402 403 /** 404 * @deprecated use option set-property instead. 405 */ 406 @Option(name = "setprop", 407 description = "deprecated, use option set-property. set the specified property on " + 408 "boot. Format: --setprop key=value. May be repeated.") 409 @Deprecated 410 private Collection<String> mDeprecatedSetProps = new ArrayList<String>(); 411 412 private static final String PERSIST_PREFIX = "persist."; 413 414 /** 415 * {@inheritDoc} 416 */ 417 @Override setUp(ITestDevice device, IBuildInfo buildInfo)418 public void setUp(ITestDevice device, IBuildInfo buildInfo) throws DeviceNotAvailableException, 419 TargetSetupError { 420 if (isDisabled()) { 421 return; 422 } 423 424 CLog.i("Performing setup on %s", device.getSerialNumber()); 425 426 if (device.getOptions().isEnableAdbRoot() && !device.enableAdbRoot()) { 427 throw new TargetSetupError(String.format("Failed to enable adb root on %s", 428 device.getSerialNumber()), device.getDeviceDescriptor()); 429 } 430 431 // Convert deprecated options into current options 432 processDeprecatedOptions(device); 433 // Convert options into settings and run commands 434 processOptions(device); 435 436 // Change system props (will reboot device) 437 changeSystemProps(device); 438 // Handle screen always on setting 439 handleScreenAlwaysOnSetting(device); 440 // Run commands designated to be run before changing settings 441 runCommands(device, mRunCommandBeforeSettings); 442 // Change settings 443 changeSettings(device); 444 // Connect wifi after settings since this may take a while 445 connectWifi(device); 446 // Sync data after settings since this may take a while 447 syncTestData(device); 448 // Run commands designated to be run after changing settings 449 runCommands(device, mRunCommandAfterSettings); 450 // Throw an error if there is not enough storage space 451 checkExternalStoreSpace(device); 452 453 device.clearErrorDialogs(); 454 } 455 456 /** 457 * {@inheritDoc} 458 */ 459 @Override tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable e)460 public void tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable e) 461 throws DeviceNotAvailableException { 462 // ignore tearDown if it's a stub device, since there is no real device to clean. 463 if (isDisabled() || device.getIDevice() instanceof StubDevice) { 464 return; 465 } 466 467 CLog.i("Performing teardown on %s", device.getSerialNumber()); 468 469 if (e instanceof DeviceFailedToBootError) { 470 CLog.d("boot failure: skipping teardown"); 471 return; 472 } 473 474 // Only try to disconnect if wifi ssid is set since isWifiEnabled() is a heavy operation 475 // which should be avoided when possible 476 boolean wifiSet = mWifiSsid != null || !mWifiSsidToPsk.isEmpty(); 477 if (mDisconnectWifiAfterTest && wifiSet && device.isWifiEnabled()) { 478 boolean result = device.disconnectFromWifi(); 479 if (result) { 480 CLog.i("Successfully disconnected from wifi network on %s", 481 device.getSerialNumber()); 482 } else { 483 CLog.w("Failed to disconnect from wifi network on %s", device.getSerialNumber()); 484 } 485 } 486 487 if (mRestoreProperties) { 488 if (mPreviousProperties != null) { 489 device.pushFile(mPreviousProperties, "/data/local.prop"); 490 } else { 491 device.deleteFile("/data/local.prop"); 492 } 493 device.reboot(); 494 } 495 496 if (mRestoreSettings) { 497 for (Map.Entry<String, String> entry : mPreviousSystemSettings.entrySet()) { 498 device.setSetting("system", entry.getKey(), entry.getValue()); 499 } 500 for (Map.Entry<String, String> entry : mPreviousGlobalSettings.entrySet()) { 501 device.setSetting("global", entry.getKey(), entry.getValue()); 502 } 503 for (Map.Entry<String, String> entry : mPreviousSecureSettings.entrySet()) { 504 device.setSetting("secure", entry.getKey(), entry.getValue()); 505 } 506 } 507 } 508 509 /** 510 * Processes the deprecated options converting them into the currently used options. 511 * <p> 512 * This method should be run before any other processing methods. Will throw a 513 * {@link TargetSetupError} if the deprecated option overrides a specified non-deprecated 514 * option. 515 * </p> 516 * @throws TargetSetupError if there is a conflict 517 */ processDeprecatedOptions(ITestDevice device)518 public void processDeprecatedOptions(ITestDevice device) throws TargetSetupError { 519 if (mDeprecatedMinExternalStoreSpace != DEFAULT_MIN_EXTERNAL_STORAGE_KB) { 520 if (mMinExternalStorageKb != DEFAULT_MIN_EXTERNAL_STORAGE_KB) { 521 throw new TargetSetupError("Deprecated option min-external-store-space conflicts " + 522 "with option min-external-storage-kb", device.getDeviceDescriptor()); 523 } 524 mMinExternalStorageKb = mDeprecatedMinExternalStoreSpace; 525 } 526 527 if (mDeprecatedSetAudioSilent != DEFAULT_DISABLE_AUDIO) { 528 if (mDisableAudio != DEFAULT_DISABLE_AUDIO) { 529 throw new TargetSetupError("Deprecated option audio-silent conflicts with " + 530 "option disable-audio", device.getDeviceDescriptor()); 531 } 532 mDisableAudio = mDeprecatedSetAudioSilent; 533 } 534 535 if (!mDeprecatedSetProps.isEmpty()) { 536 if (!mSetProps.isEmpty()) { 537 throw new TargetSetupError("Deprecated option setprop conflicts with option " + 538 "set-property ", device.getDeviceDescriptor()); 539 } 540 for (String prop : mDeprecatedSetProps) { 541 String[] parts = prop.split("=", 2); 542 String key = parts[0].trim(); 543 String value = parts.length == 2 ? parts[1].trim() : ""; 544 mSetProps.put(key, value); 545 } 546 } 547 } 548 549 /** 550 * Process all the {@link Option}s and turn them into system props, settings, or run commands. 551 * Does not run any commands on the device at this time. 552 * <p> 553 * Exposed so that children classes may override this. 554 * </p> 555 * 556 * @param device The {@link ITestDevice} 557 * @throws DeviceNotAvailableException if the device is not available 558 * @throws TargetSetupError if the {@link Option}s conflict 559 */ processOptions(ITestDevice device)560 public void processOptions(ITestDevice device) throws DeviceNotAvailableException, 561 TargetSetupError { 562 setSettingForBinaryState(mData, mGlobalSettings, "mobile_data", "1", "0"); 563 setCommandForBinaryState( 564 mData, mRunCommandAfterSettings, "svc data enable", "svc data disable"); 565 566 setSettingForBinaryState(mCell, mGlobalSettings, "cell_on", "1", "0"); 567 setSettingForBinaryState( 568 mCellAutoSetting, mGlobalSettings, "clockwork_cell_auto_setting", "1", "0"); 569 570 setSettingForBinaryState(mWifi, mGlobalSettings, "wifi_on", "1", "0"); 571 setCommandForBinaryState( 572 mWifi, mRunCommandAfterSettings, "svc wifi enable", "svc wifi disable"); 573 574 setSettingForBinaryState(mWifiWatchdog, mGlobalSettings, "wifi_watchdog", "1", "0"); 575 setSettingForBinaryState( 576 mDisableCwWifiMediator, mGlobalSettings, "cw_disable_wifimediator", "1", "0"); 577 578 setSettingForBinaryState(mWifiScanAlwaysEnabled, mGlobalSettings, 579 "wifi_scan_always_enabled", "1", "0"); 580 581 setCommandForBinaryState(mEthernet, mRunCommandAfterSettings, 582 "ifconfig eth0 up", "ifconfig eth0 down"); 583 584 setCommandForBinaryState(mBluetooth, mRunCommandAfterSettings, 585 "service call bluetooth_manager 6", "service call bluetooth_manager 8"); 586 587 setCommandForBinaryState(mNfc, mRunCommandAfterSettings, 588 "svc nfc enable", "svc nfc disable"); 589 590 if (mScreenBrightness != null && BinaryState.ON.equals(mScreenAdaptiveBrightness)) { 591 throw new TargetSetupError("Option screen-brightness cannot be set when " + 592 "screen-adaptive-brightness is set to ON", device.getDeviceDescriptor()); 593 } 594 595 setSettingForBinaryState(mScreenAdaptiveBrightness, mSystemSettings, 596 "screen_brightness_mode", "1", "0"); 597 598 if (mScreenBrightness != null) { 599 mSystemSettings.put("screen_brightness", Integer.toString(mScreenBrightness)); 600 } 601 602 if (mScreenTimeoutSecs != null) { 603 mSystemSettings.put("screen_off_timeout", Long.toString(mScreenTimeoutSecs * 1000)); 604 } 605 606 setSettingForBinaryState(mScreenAmbientMode, mSecureSettings, "doze_enabled", "1", "0"); 607 608 setSettingForBinaryState(mWakeGesture, mSecureSettings, "wake_gesture_enabled", "1", "0"); 609 610 setSettingForBinaryState(mScreenSaver, mSecureSettings, "screensaver_enabled", "1", "0"); 611 612 setSettingForBinaryState(mNotificationLed, mSystemSettings, 613 "notification_light_pulse", "1", "0"); 614 615 setSettingForBinaryState(mInstallNonMarketApps, mSecureSettings, 616 "install_non_market_apps", "1", "0"); 617 618 if (mTriggerMediaMounted) { 619 mRunCommandAfterSettings.add( 620 "am broadcast -a android.intent.action.MEDIA_MOUNTED -d " 621 + "file://${EXTERNAL_STORAGE} --receiver-include-background"); 622 } 623 624 setSettingForBinaryState(mLocationGps, mSecureSettings, 625 "location_providers_allowed", "+gps", "-gps"); 626 627 setSettingForBinaryState(mLocationNetwork, mSecureSettings, 628 "location_providers_allowed", "+network", "-network"); 629 630 setSettingForBinaryState(mAutoRotate, mSystemSettings, "accelerometer_rotation", "1", "0"); 631 632 if (device.getApiLevel() < 22) { 633 setCommandForBinaryState(mBatterySaver, mRunCommandBeforeSettings, 634 "dumpsys battery set usb 0", null); 635 } else { 636 setCommandForBinaryState(mBatterySaver, mRunCommandBeforeSettings, 637 "dumpsys battery unplug", null); 638 } 639 setSettingForBinaryState(mBatterySaver, mGlobalSettings, "low_power", "1", "0"); 640 641 if (mBatterySaverTrigger != null) { 642 mGlobalSettings.put("low_power_trigger_level", Integer.toString(mBatterySaverTrigger)); 643 } 644 645 if (mEnableFullBatteryStatsHistory) { 646 mRunCommandAfterSettings.add("dumpsys batterystats --enable full-history"); 647 } 648 649 if (mDisableDoze) { 650 mRunCommandAfterSettings.add("dumpsys deviceidle disable"); 651 } 652 653 setSettingForBinaryState(mAutoUpdateTime, mGlobalSettings, "auto_time", "1", "0"); 654 655 setSettingForBinaryState(mAutoUpdateTimezone, mGlobalSettings, "auto_timezone", "1", "0"); 656 657 if (mTimezone != null) { 658 mSetProps.put("persist.sys.timezone", mTimezone); 659 } 660 661 if (mDisableDialing) { 662 mSetProps.put("ro.telephony.disable-call", "true"); 663 } 664 665 if (mDefaultSimData != null) { 666 mGlobalSettings.put("multi_sim_data_call", Integer.toString(mDefaultSimData)); 667 } 668 669 if (mDefaultSimVoice != null) { 670 mGlobalSettings.put("multi_sim_voice_call", Integer.toString(mDefaultSimVoice)); 671 } 672 673 if (mDefaultSimSms != null) { 674 mGlobalSettings.put("multi_sim_sms", Integer.toString(mDefaultSimSms)); 675 } 676 677 if (mDisableAudio) { 678 mSetProps.put("ro.audio.silent", "1"); 679 } 680 681 if (mSetTestHarness) { 682 // set both ro.monkey and ro.test_harness, for compatibility with older platforms 683 mSetProps.put("ro.monkey", "1"); 684 mSetProps.put("ro.test_harness", "1"); 685 } 686 687 if (mDisableDalvikVerifier) { 688 mSetProps.put("dalvik.vm.dexopt-flags", "v=n"); 689 } 690 } 691 692 /** 693 * Change the system properties on the device. 694 * 695 * @param device The {@link ITestDevice} 696 * @throws DeviceNotAvailableException if the device is not available 697 * @throws TargetSetupError if there was a failure setting the system properties 698 */ changeSystemProps(ITestDevice device)699 private void changeSystemProps(ITestDevice device) throws DeviceNotAvailableException, 700 TargetSetupError { 701 if (mForceSkipSystemProps) { 702 CLog.d("Skipping system props due to force-skip-system-props"); 703 return; 704 } 705 706 if (mSetProps.size() > 0 && !device.getOptions().isEnableAdbRoot()) { 707 throw new TargetSetupError( 708 String.format( 709 "Cannot set system props %s on %s without adb root. Setting " 710 + "'force-skip-system-props' or 'enable-root' to avoid error", 711 mSetProps.toString(), device.getSerialNumber()), 712 device.getDeviceDescriptor()); 713 } 714 715 StringBuilder sb = new StringBuilder(); 716 for (Map.Entry<String, String> prop : mSetProps.entrySet()) { 717 if (prop.getKey().startsWith(PERSIST_PREFIX)) { 718 // TODO: Check that set was successful 719 device.setProperty(prop.getKey(), prop.getValue()); 720 } else { 721 sb.append(String.format("%s=%s\n", prop.getKey(), prop.getValue())); 722 } 723 } 724 725 if (sb.length() == 0) { 726 return; 727 } 728 729 if (mRestoreProperties) { 730 mPreviousProperties = device.pullFile("/data/local.prop"); 731 } 732 CLog.d("Pushing the following properties to /data/local.prop:\n%s", sb.toString()); 733 boolean result = device.pushString(sb.toString(), "/data/local.prop"); 734 if (!result) { 735 throw new TargetSetupError(String.format("Failed to push /data/local.prop to %s", 736 device.getSerialNumber()), device.getDeviceDescriptor()); 737 } 738 // Set reasonable permissions for /data/local.prop 739 device.executeShellCommand("chmod 644 /data/local.prop"); 740 CLog.i("Rebooting %s due to system property change", device.getSerialNumber()); 741 device.reboot(); 742 } 743 744 /** 745 * Handles screen always on settings. 746 * <p> 747 * This is done in a dedicated function because special handling is required in case of setting 748 * screen to always on. 749 * @throws DeviceNotAvailableException 750 */ handleScreenAlwaysOnSetting(ITestDevice device)751 private void handleScreenAlwaysOnSetting(ITestDevice device) 752 throws DeviceNotAvailableException { 753 String cmd = "svc power stayon %s"; 754 switch (mScreenAlwaysOn) { 755 case ON: 756 CLog.d("Setting screen always on to true"); 757 device.executeShellCommand(String.format(cmd, "true")); 758 // send MENU press in case keygaurd needs to be dismissed again 759 device.executeShellCommand("input keyevent 82"); 760 // send HOME press in case keyguard was already dismissed, so we bring device back 761 // to home screen 762 device.executeShellCommand("input keyevent 3"); 763 break; 764 case OFF: 765 CLog.d("Setting screen always on to false"); 766 device.executeShellCommand(String.format(cmd, "false")); 767 break; 768 case IGNORE: 769 break; 770 } 771 } 772 773 /** 774 * Change the settings on the device. 775 * <p> 776 * Exposed so children classes may override. 777 * </p> 778 * 779 * @param device The {@link ITestDevice} 780 * @throws DeviceNotAvailableException if the device is not available 781 * @throws TargetSetupError if there was a failure setting the settings 782 */ changeSettings(ITestDevice device)783 public void changeSettings(ITestDevice device) throws DeviceNotAvailableException, 784 TargetSetupError { 785 if (mForceSkipSettings) { 786 CLog.d("Skipping settings due to force-skip-setttings"); 787 return; 788 } 789 790 if (mSystemSettings.isEmpty() && mSecureSettings.isEmpty() && mGlobalSettings.isEmpty() && 791 BinaryState.IGNORE.equals(mAirplaneMode)) { 792 CLog.d("No settings to change"); 793 return; 794 } 795 796 if (device.getApiLevel() < 22) { 797 throw new TargetSetupError(String.format("Changing setting not supported on %s, " + 798 "must be API 22+", device.getSerialNumber()), device.getDeviceDescriptor()); 799 } 800 801 // Special case airplane mode since it needs to be set before other connectivity settings 802 // For example, it is possible to enable airplane mode and then turn wifi on 803 String command = "am broadcast -a android.intent.action.AIRPLANE_MODE --ez state %s"; 804 switch (mAirplaneMode) { 805 case ON: 806 CLog.d("Changing global setting airplane_mode_on to 1"); 807 device.setSetting("global", "airplane_mode_on", "1"); 808 if (!mForceSkipRunCommands) { 809 device.executeShellCommand(String.format(command, "true")); 810 } 811 break; 812 case OFF: 813 CLog.d("Changing global setting airplane_mode_on to 0"); 814 device.setSetting("global", "airplane_mode_on", "0"); 815 if (!mForceSkipRunCommands) { 816 device.executeShellCommand(String.format(command, "false")); 817 } 818 break; 819 case IGNORE: 820 // No-op 821 break; 822 } 823 824 for (String key : mSystemSettings.keySet()) { 825 for (String value : mSystemSettings.get(key)) { 826 if (mRestoreSettings) { 827 String previousSetting = device.getSetting("system", key); 828 mPreviousSystemSettings.put(key, previousSetting); 829 } 830 CLog.d("Changing system setting %s to %s", key, value); 831 device.setSetting("system", key, value); 832 } 833 } 834 for (String key : mSecureSettings.keySet()) { 835 for (String value : mSecureSettings.get(key)) { 836 if (mRestoreSettings) { 837 String previousSetting = device.getSetting("secure", key); 838 mPreviousSecureSettings.put(key, previousSetting); 839 } 840 CLog.d("Changing secure setting %s to %s", key, value); 841 device.setSetting("secure", key, value); 842 } 843 } 844 845 for (String key : mGlobalSettings.keySet()) { 846 for (String value : mGlobalSettings.get(key)) { 847 if (mRestoreSettings) { 848 String previousSetting = device.getSetting("global", key); 849 mPreviousGlobalSettings.put(key, previousSetting); 850 } 851 CLog.d("Changing global setting %s to %s", key, value); 852 device.setSetting("global", key, value); 853 } 854 } 855 } 856 857 /** 858 * Execute additional commands on the device. 859 * 860 * @param device The {@link ITestDevice} 861 * @param commands The list of commands to run 862 * @throws DeviceNotAvailableException if the device is not available 863 * @throws TargetSetupError if there was a failure setting the settings 864 */ runCommands(ITestDevice device, List<String> commands)865 private void runCommands(ITestDevice device, List<String> commands) 866 throws DeviceNotAvailableException, TargetSetupError { 867 if (mForceSkipRunCommands) { 868 CLog.d("Skipping run commands due to force-skip-run-commands"); 869 return; 870 } 871 872 for (String command : commands) { 873 device.executeShellCommand(command); 874 } 875 } 876 877 /** 878 * Connects device to Wifi if SSID is specified. 879 * 880 * @param device The {@link ITestDevice} 881 * @throws DeviceNotAvailableException if the device is not available 882 * @throws TargetSetupError if there was a failure setting the settings 883 */ connectWifi(ITestDevice device)884 private void connectWifi(ITestDevice device) throws DeviceNotAvailableException, 885 TargetSetupError { 886 if (mForceSkipRunCommands) { 887 CLog.d("Skipping connect wifi due to force-skip-run-commands"); 888 return; 889 } 890 891 if (mWifiSsid != null && device.connectToWifiNetwork(mWifiSsid, mWifiPsk)) { 892 return; 893 } 894 for (Map.Entry<String, String> ssidToPsk : mWifiSsidToPsk.entrySet()) { 895 String psk = "".equals(ssidToPsk.getValue()) ? null : ssidToPsk.getValue(); 896 if (device.connectToWifiNetwork(ssidToPsk.getKey(), psk)) { 897 return; 898 } 899 } 900 // Error message does not acknowledge mWifiSsidToPsk for parity with existing monitoring. 901 if (mWifiSsid != null || !mWifiSsidToPsk.isEmpty()) { 902 throw new TargetSetupError( 903 String.format( 904 "Failed to connect to wifi network %s on %s", 905 mWifiSsid, device.getSerialNumber()), 906 device.getDeviceDescriptor()); 907 } 908 } 909 910 /** 911 * Syncs a set of test data files, specified via local-data-path, to devices external storage. 912 * 913 * @param device The {@link ITestDevice} 914 * @throws DeviceNotAvailableException if the device is not available 915 * @throws TargetSetupError if data fails to sync 916 */ syncTestData(ITestDevice device)917 private void syncTestData(ITestDevice device) throws DeviceNotAvailableException, 918 TargetSetupError { 919 if (mLocalDataFile == null) { 920 return; 921 } 922 923 if (!mLocalDataFile.exists() || !mLocalDataFile.isDirectory()) { 924 throw new TargetSetupError(String.format( 925 "local-data-path %s is not a directory", mLocalDataFile.getAbsolutePath()), 926 device.getDeviceDescriptor()); 927 } 928 String fullRemotePath = device.getIDevice().getMountPoint(IDevice.MNT_EXTERNAL_STORAGE); 929 if (fullRemotePath == null) { 930 throw new TargetSetupError(String.format( 931 "failed to get external storage path on device %s", device.getSerialNumber()), 932 device.getDeviceDescriptor()); 933 } 934 if (mRemoteDataPath != null) { 935 fullRemotePath = String.format("%s/%s", fullRemotePath, mRemoteDataPath); 936 } 937 boolean result = device.syncFiles(mLocalDataFile, fullRemotePath); 938 if (!result) { 939 // TODO: get exact error code and respond accordingly 940 throw new TargetSetupError(String.format( 941 "failed to sync test data from local-data-path %s to %s on device %s", 942 mLocalDataFile.getAbsolutePath(), fullRemotePath, device.getSerialNumber()), 943 device.getDeviceDescriptor()); 944 } 945 } 946 947 /** 948 * Check that device external store has the required space 949 * 950 * @param device The {@link ITestDevice} 951 * @throws DeviceNotAvailableException if the device is not available or if the device does not 952 * have the required space 953 */ checkExternalStoreSpace(ITestDevice device)954 private void checkExternalStoreSpace(ITestDevice device) throws DeviceNotAvailableException { 955 if (mMinExternalStorageKb <= 0) { 956 return; 957 } 958 959 long freeSpace = device.getExternalStoreFreeSpace(); 960 if (freeSpace < mMinExternalStorageKb) { 961 throw new DeviceNotAvailableException(String.format( 962 "External store free space %dK is less than required %dK for device %s", 963 freeSpace , mMinExternalStorageKb, device.getSerialNumber()), 964 device.getSerialNumber()); 965 } 966 } 967 968 /** 969 * Helper method to add an ON/OFF setting to a setting map. 970 * 971 * @param state The {@link BinaryState} 972 * @param settingsMap The {@link MultiMap} used to store the settings. 973 * @param setting The setting key 974 * @param onValue The value if ON 975 * @param offValue The value if OFF 976 */ setSettingForBinaryState(BinaryState state, MultiMap<String, String> settingsMap, String setting, String onValue, String offValue)977 public static void setSettingForBinaryState(BinaryState state, 978 MultiMap<String, String> settingsMap, String setting, String onValue, String offValue) { 979 switch (state) { 980 case ON: 981 settingsMap.put(setting, onValue); 982 break; 983 case OFF: 984 settingsMap.put(setting, offValue); 985 break; 986 case IGNORE: 987 // Do nothing 988 break; 989 } 990 } 991 992 /** 993 * Helper method to add an ON/OFF run command to be executed on the device. 994 * 995 * @param state The {@link BinaryState} 996 * @param commands The list of commands to add the on or off command to. 997 * @param onCommand The command to run if ON. Ignored if the command is {@code null} 998 * @param offCommand The command to run if OFF. Ignored if the command is {@code null} 999 */ setCommandForBinaryState(BinaryState state, List<String> commands, String onCommand, String offCommand)1000 public static void setCommandForBinaryState(BinaryState state, List<String> commands, 1001 String onCommand, String offCommand) { 1002 switch (state) { 1003 case ON: 1004 if (onCommand != null) { 1005 commands.add(onCommand); 1006 } 1007 break; 1008 case OFF: 1009 if (offCommand != null) { 1010 commands.add(offCommand); 1011 } 1012 break; 1013 case IGNORE: 1014 // Do nothing 1015 break; 1016 } 1017 } 1018 1019 /** Exposed for unit testing */ setForceSkipSystemProps(boolean force)1020 protected void setForceSkipSystemProps(boolean force) { 1021 mForceSkipSystemProps = force; 1022 } 1023 1024 /** 1025 * Exposed for unit testing 1026 */ setAirplaneMode(BinaryState airplaneMode)1027 protected void setAirplaneMode(BinaryState airplaneMode) { 1028 mAirplaneMode = airplaneMode; 1029 } 1030 1031 /* Exposed for unit testing */ 1032 @VisibleForTesting setData(BinaryState data)1033 protected void setData(BinaryState data) { 1034 mData = data; 1035 } 1036 1037 /* Exposed for unit testing */ 1038 @VisibleForTesting setCell(BinaryState cell)1039 protected void setCell(BinaryState cell) { 1040 mCell = cell; 1041 } 1042 1043 /* Exposed for unit testing */ 1044 @VisibleForTesting setCellAutoSetting(BinaryState cellAutoSetting)1045 protected void setCellAutoSetting(BinaryState cellAutoSetting) { 1046 mCellAutoSetting = cellAutoSetting; 1047 } 1048 1049 /** 1050 * Exposed for unit testing 1051 */ setWifi(BinaryState wifi)1052 protected void setWifi(BinaryState wifi) { 1053 mWifi = wifi; 1054 } 1055 1056 /** 1057 * Exposed for unit testing 1058 */ setWifiNetwork(String wifiNetwork)1059 protected void setWifiNetwork(String wifiNetwork) { 1060 mWifiSsid = wifiNetwork; 1061 } 1062 1063 /* Exposed for unit testing */ 1064 @VisibleForTesting setWifiPsk(String wifiPsk)1065 protected void setWifiPsk(String wifiPsk) { 1066 mWifiPsk = wifiPsk; 1067 } 1068 1069 /* Exposed for unit testing */ 1070 @VisibleForTesting setWifiSsidToPsk(Map<String, String> wifiSssidToPsk)1071 protected void setWifiSsidToPsk(Map<String, String> wifiSssidToPsk) { 1072 mWifiSsidToPsk = wifiSssidToPsk; 1073 } 1074 1075 /** 1076 * Exposed for unit testing 1077 */ setWifiWatchdog(BinaryState wifiWatchdog)1078 protected void setWifiWatchdog(BinaryState wifiWatchdog) { 1079 mWifiWatchdog = wifiWatchdog; 1080 } 1081 1082 /* Exposed for unit testing */ 1083 @VisibleForTesting setDisableCwWifiMediator(BinaryState disableCwWifiMediator)1084 protected void setDisableCwWifiMediator(BinaryState disableCwWifiMediator) { 1085 mDisableCwWifiMediator = disableCwWifiMediator; 1086 } 1087 1088 /** 1089 * Exposed for unit testing 1090 */ setWifiScanAlwaysEnabled(BinaryState wifiScanAlwaysEnabled)1091 protected void setWifiScanAlwaysEnabled(BinaryState wifiScanAlwaysEnabled) { 1092 mWifiScanAlwaysEnabled = wifiScanAlwaysEnabled; 1093 } 1094 1095 /** 1096 * Exposed for unit testing 1097 */ setEthernet(BinaryState ethernet)1098 protected void setEthernet(BinaryState ethernet) { 1099 mEthernet = ethernet; 1100 } 1101 1102 /** 1103 * Exposed for unit testing 1104 */ setBluetooth(BinaryState bluetooth)1105 protected void setBluetooth(BinaryState bluetooth) { 1106 mBluetooth = bluetooth; 1107 } 1108 1109 /** 1110 * Exposed for unit testing 1111 */ setNfc(BinaryState nfc)1112 protected void setNfc(BinaryState nfc) { 1113 mNfc = nfc; 1114 } 1115 1116 /** 1117 * Exposed for unit testing 1118 */ setScreenAdaptiveBrightness(BinaryState screenAdaptiveBrightness)1119 protected void setScreenAdaptiveBrightness(BinaryState screenAdaptiveBrightness) { 1120 mScreenAdaptiveBrightness = screenAdaptiveBrightness; 1121 } 1122 1123 /** 1124 * Exposed for unit testing 1125 */ setScreenBrightness(Integer screenBrightness)1126 protected void setScreenBrightness(Integer screenBrightness) { 1127 mScreenBrightness = screenBrightness; 1128 } 1129 1130 /** 1131 * Exposed for unit testing 1132 */ setScreenAlwaysOn(BinaryState screenAlwaysOn)1133 protected void setScreenAlwaysOn(BinaryState screenAlwaysOn) { 1134 mScreenAlwaysOn = screenAlwaysOn; 1135 } 1136 1137 /** 1138 * Exposed for unit testing 1139 */ setScreenTimeoutSecs(Long screenTimeoutSecs)1140 protected void setScreenTimeoutSecs(Long screenTimeoutSecs) { 1141 mScreenTimeoutSecs = screenTimeoutSecs; 1142 } 1143 1144 /** 1145 * Exposed for unit testing 1146 */ setScreenAmbientMode(BinaryState screenAmbientMode)1147 protected void setScreenAmbientMode(BinaryState screenAmbientMode) { 1148 mScreenAmbientMode = screenAmbientMode; 1149 } 1150 1151 /** 1152 * Exposed for unit testing 1153 */ setWakeGesture(BinaryState wakeGesture)1154 protected void setWakeGesture(BinaryState wakeGesture) { 1155 mWakeGesture = wakeGesture; 1156 } 1157 1158 /** 1159 * Exposed for unit testing 1160 */ setScreenSaver(BinaryState screenSaver)1161 protected void setScreenSaver(BinaryState screenSaver) { 1162 mScreenSaver = screenSaver; 1163 } 1164 1165 /** 1166 * Exposed for unit testing 1167 */ setNotificationLed(BinaryState notificationLed)1168 protected void setNotificationLed(BinaryState notificationLed) { 1169 mNotificationLed = notificationLed; 1170 } 1171 1172 /** 1173 * Exposed for unit testing 1174 */ setInstallNonMarketApps(BinaryState installNonMarketApps)1175 protected void setInstallNonMarketApps(BinaryState installNonMarketApps) { 1176 mInstallNonMarketApps = installNonMarketApps; 1177 } 1178 1179 /** 1180 * Exposed for unit testing 1181 */ setTriggerMediaMounted(boolean triggerMediaMounted)1182 protected void setTriggerMediaMounted(boolean triggerMediaMounted) { 1183 mTriggerMediaMounted = triggerMediaMounted; 1184 } 1185 1186 /** 1187 * Exposed for unit testing 1188 */ setLocationGps(BinaryState locationGps)1189 protected void setLocationGps(BinaryState locationGps) { 1190 mLocationGps = locationGps; 1191 } 1192 1193 /** 1194 * Exposed for unit testing 1195 */ setLocationNetwork(BinaryState locationNetwork)1196 protected void setLocationNetwork(BinaryState locationNetwork) { 1197 mLocationNetwork = locationNetwork; 1198 } 1199 1200 /** 1201 * Exposed for unit testing 1202 */ setAutoRotate(BinaryState autoRotate)1203 protected void setAutoRotate(BinaryState autoRotate) { 1204 mAutoRotate = autoRotate; 1205 } 1206 1207 /** 1208 * Exposed for unit testing 1209 */ setBatterySaver(BinaryState batterySaver)1210 protected void setBatterySaver(BinaryState batterySaver) { 1211 mBatterySaver = batterySaver; 1212 } 1213 1214 /** 1215 * Exposed for unit testing 1216 */ setBatterySaverTrigger(Integer batterySaverTrigger)1217 protected void setBatterySaverTrigger(Integer batterySaverTrigger) { 1218 mBatterySaverTrigger = batterySaverTrigger; 1219 } 1220 1221 /** 1222 * Exposed for unit testing 1223 */ setEnableFullBatteryStatsHistory(boolean enableFullBatteryStatsHistory)1224 protected void setEnableFullBatteryStatsHistory(boolean enableFullBatteryStatsHistory) { 1225 mEnableFullBatteryStatsHistory = enableFullBatteryStatsHistory; 1226 } 1227 1228 /** 1229 * Exposed for unit testing 1230 */ setDisableDoze(boolean disableDoze)1231 protected void setDisableDoze(boolean disableDoze) { 1232 mDisableDoze = disableDoze; 1233 } 1234 1235 /** 1236 * Exposed for unit testing 1237 */ setAutoUpdateTime(BinaryState autoUpdateTime)1238 protected void setAutoUpdateTime(BinaryState autoUpdateTime) { 1239 mAutoUpdateTime = autoUpdateTime; 1240 } 1241 1242 /** 1243 * Exposed for unit testing 1244 */ setAutoUpdateTimezone(BinaryState autoUpdateTimezone)1245 protected void setAutoUpdateTimezone(BinaryState autoUpdateTimezone) { 1246 mAutoUpdateTimezone = autoUpdateTimezone; 1247 } 1248 1249 /** 1250 * Exposed for unit testing 1251 */ setTimezone(String timezone)1252 protected void setTimezone(String timezone) { 1253 mTimezone = timezone; 1254 } 1255 1256 /** 1257 * Exposed for unit testing 1258 */ setDisableDialing(boolean disableDialing)1259 protected void setDisableDialing(boolean disableDialing) { 1260 mDisableDialing = disableDialing; 1261 } 1262 1263 /** 1264 * Exposed for unit testing 1265 */ setDefaultSimData(Integer defaultSimData)1266 protected void setDefaultSimData(Integer defaultSimData) { 1267 mDefaultSimData = defaultSimData; 1268 } 1269 1270 /** 1271 * Exposed for unit testing 1272 */ setDefaultSimVoice(Integer defaultSimVoice)1273 protected void setDefaultSimVoice(Integer defaultSimVoice) { 1274 mDefaultSimVoice = defaultSimVoice; 1275 } 1276 1277 /** 1278 * Exposed for unit testing 1279 */ setDefaultSimSms(Integer defaultSimSms)1280 protected void setDefaultSimSms(Integer defaultSimSms) { 1281 mDefaultSimSms = defaultSimSms; 1282 } 1283 1284 /** 1285 * Exposed for unit testing 1286 */ setDisableAudio(boolean disable)1287 protected void setDisableAudio(boolean disable) { 1288 mDisableAudio = disable; 1289 } 1290 1291 /** 1292 * Exposed for unit testing 1293 */ setTestHarness(boolean setTestHarness)1294 protected void setTestHarness(boolean setTestHarness) { 1295 mSetTestHarness = setTestHarness; 1296 } 1297 1298 /** 1299 * Exposed for unit testing 1300 */ setDisableDalvikVerifier(boolean disableDalvikVerifier)1301 protected void setDisableDalvikVerifier(boolean disableDalvikVerifier) { 1302 mDisableDalvikVerifier = disableDalvikVerifier; 1303 } 1304 1305 /** 1306 * Exposed for unit testing 1307 */ setLocalDataPath(File path)1308 protected void setLocalDataPath(File path) { 1309 mLocalDataFile = path; 1310 } 1311 1312 /** 1313 * Exposed for unit testing 1314 */ setMinExternalStorageKb(long storageKb)1315 protected void setMinExternalStorageKb(long storageKb) { 1316 mMinExternalStorageKb = storageKb; 1317 } 1318 1319 /** 1320 * Exposed for unit testing 1321 */ setProperty(String key, String value)1322 protected void setProperty(String key, String value) { 1323 mSetProps.put(key, value); 1324 } 1325 1326 /** Exposed for unit testing */ setGlobalSetting(String key, String value)1327 public void setGlobalSetting(String key, String value) { 1328 mGlobalSettings.put(key, value); 1329 } 1330 1331 /** Exposed for unit testing */ setSecureSetting(String key, String value)1332 public void setSecureSetting(String key, String value) { 1333 mSecureSettings.put(key, value); 1334 } 1335 1336 /** Exposed for unit testing */ setSystemSetting(String key, String value)1337 public void setSystemSetting(String key, String value) { 1338 mSystemSettings.put(key, value); 1339 } 1340 1341 /** Exposed for unit testing */ setRestoreProperties(boolean restoreProperties)1342 protected void setRestoreProperties(boolean restoreProperties) { 1343 mRestoreProperties = restoreProperties; 1344 } 1345 1346 /** Exposed for unit testing */ setRestoreSettings(boolean restoreSettings)1347 protected void setRestoreSettings(boolean restoreSettings) { 1348 mRestoreSettings = restoreSettings; 1349 } 1350 1351 /** 1352 * Exposed for unit testing 1353 * @deprecated use {@link #setMinExternalStorageKb(long)} instead. 1354 */ 1355 @Deprecated setDeprecatedMinExternalStoreSpace(long storeSpace)1356 protected void setDeprecatedMinExternalStoreSpace(long storeSpace) { 1357 mDeprecatedMinExternalStoreSpace = storeSpace; 1358 } 1359 1360 /** 1361 * Exposed for unit testing 1362 * @deprecated use {@link #setDisableAudio(boolean)} instead. 1363 */ 1364 @Deprecated setDeprecatedAudioSilent(boolean silent)1365 protected void setDeprecatedAudioSilent(boolean silent) { 1366 mDeprecatedSetAudioSilent = silent; 1367 } 1368 1369 /** 1370 * Exposed for unit testing 1371 * @deprecated use {@link #setProperty(String, String)} instead. 1372 */ 1373 @Deprecated setDeprecatedSetProp(String prop)1374 protected void setDeprecatedSetProp(String prop) { 1375 mDeprecatedSetProps.add(prop); 1376 } 1377 } 1378