1 /* 2 * Copyright (C) 2016 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 android.system.helpers; 18 19 import android.bluetooth.BluetoothAdapter; 20 import android.bluetooth.BluetoothManager; 21 import android.content.ComponentName; 22 import android.content.ContentResolver; 23 import android.content.Context; 24 import android.content.Intent; 25 import android.net.wifi.WifiManager; 26 import android.provider.Settings; 27 import android.provider.Settings.SettingNotFoundException; 28 import android.support.test.InstrumentationRegistry; 29 import android.support.test.uiautomator.By; 30 import android.support.test.uiautomator.BySelector; 31 import android.support.test.uiautomator.Direction; 32 import android.support.test.uiautomator.UiDevice; 33 import android.support.test.uiautomator.UiObject; 34 import android.support.test.uiautomator.UiObject2; 35 import android.support.test.uiautomator.UiObjectNotFoundException; 36 import android.support.test.uiautomator.UiScrollable; 37 import android.support.test.uiautomator.UiSelector; 38 import android.support.test.uiautomator.Until; 39 import android.util.Log; 40 import android.widget.Switch; 41 import android.widget.TextView; 42 43 import junit.framework.Assert; 44 45 import java.util.Random; 46 import java.util.regex.Pattern; 47 48 /** 49 * Implement common helper methods for settings. 50 */ 51 public class SettingsHelper { 52 private static final String TAG = SettingsHelper.class.getSimpleName(); 53 private static final String ANDROID_PACKAGE = "android"; 54 private static final String SETTINGS_PACKAGE = "com.android.settings"; 55 private static final String SETTINGS_APP = "Settings"; 56 private static final String SWITCH_WIDGET = "switch_widget"; 57 private static final String WIFI = "Wi-Fi"; 58 private static final String BLUETOOTH = "Bluetooth"; 59 private static final String AIRPLANE = "Airplane mode"; 60 private static final String LOCATION = "Location"; 61 private static final String DND = "Do not disturb"; 62 private static final String ZEN_MODE = "zen_mode"; 63 private static final String FLASHLIGHT = "Flashlight"; 64 private static final String AUTO_ROTATE_SCREEN = "Auto-rotate screen"; 65 private static final BySelector SETTINGS_DASHBOARD = By.res(SETTINGS_PACKAGE, 66 "dashboard_container"); 67 private static final String ACTION_SEARCH = "com.android.settings.action.SETTINGS_SEARCH"; 68 private static final String NO_RESULT_QUERY = "no_result_query"; 69 private static final String RES_ID_SEARCH_UI_TEXT_BOX = "search_src_text"; 70 private static final String RES_ID_SEARCH_UI_NO_RESULT_IMAGE = "no_result_layout"; 71 72 private static final UiSelector LIST_ITEM_VALUE = 73 new UiSelector().className(TextView.class); 74 public static final int TIMEOUT = 2000; 75 76 private static SettingsHelper sInstance = null; 77 private ActivityHelper mActivityHelper = null; 78 private ContentResolver mResolver = null; 79 private Context mContext = null; 80 private UiDevice mDevice = null; 81 SettingsHelper()82 public SettingsHelper() { 83 mContext = InstrumentationRegistry.getTargetContext(); 84 mResolver = mContext.getContentResolver(); 85 mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); 86 mActivityHelper = ActivityHelper.getInstance(); 87 } 88 getInstance()89 public static SettingsHelper getInstance() { 90 if (sInstance == null) { 91 sInstance = new SettingsHelper(); 92 } 93 return sInstance; 94 } 95 96 /** 97 * Opens Settings search page 98 */ openSearch(Context context)99 public void openSearch(Context context) throws Exception { 100 launchSettingsPage(context, ACTION_SEARCH); 101 // Wait for the search UI to appear 102 mDevice.wait(Until.hasObject(By.res(RES_ID_SEARCH_UI_TEXT_BOX)), 103 TIMEOUT); 104 } 105 106 /** 107 * Performs a query that has no result and clears query afterwards. 108 */ performNoResultQuery()109 public void performNoResultQuery() { 110 final String randomQuery = NO_RESULT_QUERY + new Random().nextInt(); 111 112 mDevice.wait(Until.findObject(By.res(ANDROID_PACKAGE, RES_ID_SEARCH_UI_TEXT_BOX)), TIMEOUT) 113 .setText(randomQuery); 114 115 mDevice.wait(Until.hasObject(By.res(RES_ID_SEARCH_UI_NO_RESULT_IMAGE)), 116 TIMEOUT); 117 mDevice.wait(Until.findObject(By.res(ANDROID_PACKAGE, RES_ID_SEARCH_UI_TEXT_BOX)), TIMEOUT) 118 .clear(); 119 } 120 121 public enum SettingsType { 122 SYSTEM, SECURE, GLOBAL 123 } 124 125 /** 126 * @return Settings package name 127 */ getPackage()128 public String getPackage() { 129 return SETTINGS_PACKAGE; 130 } 131 132 /** 133 * @return Settings app name 134 */ getLauncherName()135 public String getLauncherName() { 136 return SETTINGS_APP; 137 } 138 139 /** 140 * Scroll through settings page 141 * @param numberOfFlings 142 * @throws Exception 143 */ scrollThroughSettings(int numberOfFlings)144 public void scrollThroughSettings(int numberOfFlings) throws Exception { 145 UiObject2 settingsList = loadAllSettings(); 146 int count = 0; 147 while (count <= numberOfFlings && settingsList.fling(Direction.DOWN)) { 148 count++; 149 } 150 } 151 152 /** 153 * Move to top of settings page 154 * @throws Exception 155 */ flingSettingsToStart()156 public void flingSettingsToStart() throws Exception { 157 UiObject2 settingsList = loadAllSettings(); 158 while (settingsList.fling(Direction.UP)); 159 } 160 161 /** 162 * Launch specific settings page 163 * @param ctx 164 * @param pageName 165 * @throws Exception 166 */ launchSettingsPage(Context ctx, String pageName)167 public static void launchSettingsPage(Context ctx, String pageName) throws Exception { 168 Intent intent = new Intent(pageName); 169 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 170 ctx.startActivity(intent); 171 Thread.sleep(TIMEOUT * 2); 172 } 173 174 /** 175 * Scroll vertically up or down 176 * @param isUp 177 */ scrollVert(boolean isUp)178 public void scrollVert(boolean isUp) { 179 int w = mDevice.getDisplayWidth(); 180 int h = mDevice.getDisplayHeight(); 181 mDevice.swipe(w / 2, h / 2, w / 2, isUp ? h : 0, 2); 182 } 183 184 /** 185 * On N, the settingsDashboard is initially collapsed, and the user can see the "See all" 186 * element. On hitting "See all", the same settings dashboard element is now scrollable. For 187 * pre-N, the settings Dashboard is always scrollable, hence the check in the while loop. All 188 * this method does is expand the Settings list if needed, before returning the element. 189 */ loadAllSettings()190 public UiObject2 loadAllSettings() throws Exception { 191 UiObject2 settingsDashboard = mDevice.wait(Until.findObject(SETTINGS_DASHBOARD), 192 TIMEOUT * 2); 193 Assert.assertNotNull("Could not find the settings dashboard object.", settingsDashboard); 194 int count = 0; 195 while (!settingsDashboard.isScrollable() && count <= 2) { 196 mDevice.wait(Until.findObject(By.text("SEE ALL")), TIMEOUT * 2).click(); 197 settingsDashboard = mDevice.wait(Until.findObject(SETTINGS_DASHBOARD), 198 TIMEOUT * 2); 199 count++; 200 } 201 return settingsDashboard; 202 } 203 204 /** 205 * Performs click action on a setting when setting name is provided as exact string 206 * @param settingName 207 * @throws InterruptedException 208 */ clickSetting(String settingName)209 public void clickSetting(String settingName) throws InterruptedException { 210 int count = 5; 211 while (count > 0 && mDevice.wait(Until.findObject(By.text(settingName)), TIMEOUT) == null) { 212 scrollVert(false); 213 count--; 214 } 215 mDevice.wait(Until.findObject(By.text(settingName)), TIMEOUT).click(); 216 Thread.sleep(TIMEOUT); 217 } 218 219 /** 220 * Performs click action on a setting when setting has been found 221 * 222 * @throws InterruptedException,UiObjectNotFoundException 223 */ selectSettingFor(String settingName)224 public boolean selectSettingFor(String settingName) 225 throws InterruptedException, UiObjectNotFoundException { 226 UiScrollable settingsList = new UiScrollable( 227 new UiSelector().resourceId("android:id/content")); 228 UiObject appSettings = settingsList.getChildByText(LIST_ITEM_VALUE, settingName); 229 if (appSettings != null) { 230 return appSettings.click(); 231 } 232 return false; 233 } 234 235 /** 236 * Performs click action on a setting when setting name is provided as pattern 237 * 238 * @param settingName 239 * @throws InterruptedException 240 */ clickSetting(Pattern settingName)241 public void clickSetting(Pattern settingName) throws InterruptedException { 242 mDevice.wait(Until.findObject(By.text(settingName)), TIMEOUT).click(); 243 Thread.sleep(400); 244 } 245 246 /** 247 * Gets string value of a setting 248 * @param type 249 * @param sName 250 * @return 251 */ getStringSetting(SettingsType type, String sName)252 public String getStringSetting(SettingsType type, String sName) { 253 switch (type) { 254 case SYSTEM: 255 return Settings.System.getString(mResolver, sName); 256 case GLOBAL: 257 return Settings.Global.getString(mResolver, sName); 258 case SECURE: 259 return Settings.Secure.getString(mResolver, sName); 260 } 261 return ""; 262 } 263 264 /** 265 * Get int value of a setting 266 * @param type 267 * @param sName 268 * @return 269 * @throws SettingNotFoundException 270 */ getIntSetting(SettingsType type, String sName)271 public int getIntSetting(SettingsType type, String sName) throws SettingNotFoundException { 272 switch (type) { 273 case SYSTEM: 274 return Settings.System.getInt(mResolver, sName); 275 case GLOBAL: 276 return Settings.Global.getInt(mResolver, sName); 277 case SECURE: 278 return Settings.Secure.getInt(mResolver, sName); 279 } 280 return Integer.MIN_VALUE; 281 } 282 283 /** 284 * Set string value of a setting 285 * @param type 286 * @param sName 287 * @param value 288 */ setStringSetting(SettingsType type, String sName, String value)289 public void setStringSetting(SettingsType type, String sName, String value) 290 throws InterruptedException { 291 switch (type) { 292 case SYSTEM: 293 Settings.System.putString(mResolver, sName, value); 294 break; 295 case GLOBAL: 296 Settings.Global.putString(mResolver, sName, value); 297 break; 298 case SECURE: 299 Settings.Secure.putString(mResolver, sName, value); 300 break; 301 } 302 Thread.sleep(TIMEOUT); 303 } 304 305 /** 306 * Sets int value of a setting 307 * @param type 308 * @param sName 309 * @param value 310 */ setIntSetting(SettingsType type, String sName, int value)311 public void setIntSetting(SettingsType type, String sName, int value) 312 throws InterruptedException { 313 switch (type) { 314 case SYSTEM: 315 Settings.System.putInt(mResolver, sName, value); 316 break; 317 case GLOBAL: 318 Settings.Global.putInt(mResolver, sName, value); 319 break; 320 case SECURE: 321 Settings.Secure.putInt(mResolver, sName, value); 322 break; 323 } 324 Thread.sleep(TIMEOUT); 325 } 326 327 /** 328 * Toggles setting and verifies the action, when setting name is passed as string 329 * @param type 330 * @param settingAction 331 * @param settingName 332 * @param internalName 333 * @return 334 * @throws Exception 335 */ verifyToggleSetting(SettingsType type, String settingAction, String settingName, String internalName)336 public boolean verifyToggleSetting(SettingsType type, String settingAction, 337 String settingName, String internalName) throws Exception { 338 return verifyToggleSetting( 339 type, settingAction, Pattern.compile(settingName), internalName, true); 340 } 341 342 /** 343 * Toggles setting and verifies the action, when setting name is passed as pattern 344 * @param type 345 * @param settingAction 346 * @param settingName 347 * @param internalName 348 * @return 349 * @throws Exception 350 */ verifyToggleSetting(SettingsType type, String settingAction, Pattern settingName, String internalName)351 public boolean verifyToggleSetting(SettingsType type, String settingAction, 352 Pattern settingName, String internalName) throws Exception { 353 return verifyToggleSetting(type, settingAction, settingName, internalName, true); 354 } 355 356 /** 357 * Toggles setting and verifies the action, when setting name is passed as string 358 * and settings page needs to be launched or not 359 * @param type 360 * @param settingAction 361 * @param settingName 362 * @param internalName 363 * @param doLaunch 364 * @return 365 * @throws Exception 366 */ verifyToggleSetting(SettingsType type, String settingAction, String settingName, String internalName, boolean doLaunch)367 public boolean verifyToggleSetting(SettingsType type, String settingAction, 368 String settingName, String internalName, boolean doLaunch) throws Exception { 369 return verifyToggleSetting( 370 type, settingAction, Pattern.compile(settingName), internalName, doLaunch); 371 } 372 373 /** 374 * Toggles setting and verifies the action 375 * @param type 376 * @param settingAction 377 * @param settingName 378 * @param internalName 379 * @param doLaunch 380 * @return 381 * @throws Exception 382 */ verifyToggleSetting(SettingsType type, String settingAction, Pattern settingName, String internalName, boolean doLaunch)383 public boolean verifyToggleSetting(SettingsType type, String settingAction, 384 Pattern settingName, String internalName, boolean doLaunch) throws Exception { 385 String onSettingBaseVal = getStringSetting(type, internalName); 386 if (onSettingBaseVal == null) { 387 // Per bug b/35717943 default for charging sounds is ON 388 // So if null, the value should be set to 1. 389 if (settingName.matcher("Charging sounds").matches()) { 390 onSettingBaseVal = "1"; 391 } 392 else { 393 onSettingBaseVal = "0"; 394 } 395 } 396 int onSetting = Integer.parseInt(onSettingBaseVal); 397 Log.d(TAG, "On Setting value is : " + onSetting); 398 if (doLaunch) { 399 launchSettingsPage(mContext, settingAction); 400 } 401 clickSetting(settingName); 402 Log.d(TAG, "Clicked setting : " + settingName); 403 Thread.sleep(5000); 404 String changedSetting = getStringSetting(type, internalName); 405 Log.d(TAG, "Changed Setting value is : " + changedSetting); 406 if (changedSetting == null) { 407 Log.d(TAG, "Changed Setting value is : NULL"); 408 changedSetting = "0"; 409 } 410 return (1 - onSetting) == Integer.parseInt(changedSetting); 411 } 412 413 /** 414 * @param type 415 * @param settingAction 416 * @param baseName 417 * @param settingName 418 * @param internalName 419 * @param testVal 420 * @return 421 * @throws Exception 422 */ verifyRadioSetting(SettingsType type, String settingAction, String baseName, String settingName, String internalName, String testVal)423 public boolean verifyRadioSetting(SettingsType type, String settingAction, 424 String baseName, String settingName, 425 String internalName, String testVal) throws Exception { 426 if (baseName != null) 427 clickSetting(baseName); 428 clickSetting(settingName); 429 Thread.sleep(500); 430 return getStringSetting(type, internalName).equals(testVal); 431 } 432 toggleWiFiOnOffAndVerify(boolean verifyOn, boolean isQuickSettings)433 public void toggleWiFiOnOffAndVerify(boolean verifyOn, boolean isQuickSettings) 434 throws Exception { 435 String switchText = (verifyOn ? "OFF" : "ON"); 436 WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); 437 wifiManager.setWifiEnabled(!verifyOn); 438 Thread.sleep(TIMEOUT * 3); 439 if (isQuickSettings) { 440 launchAndClickSettings(isQuickSettings, null, By.descContains(WIFI) 441 .clazz(Switch.class)); 442 } else { 443 launchAndClickSettings(isQuickSettings, Settings.ACTION_WIFI_SETTINGS, 444 By.res(SETTINGS_PACKAGE, SWITCH_WIDGET).text(switchText)); 445 } 446 Thread.sleep(TIMEOUT * 3); 447 String wifiValue = Settings.Global.getString(mResolver, Settings.Global.WIFI_ON); 448 if (verifyOn) { 449 Assert.assertFalse(wifiValue == "0"); 450 } else { 451 Assert.assertEquals("0", wifiValue); 452 } 453 mDevice.pressHome(); 454 Thread.sleep(TIMEOUT * 3); 455 } 456 toggleBTOnOffAndVerify(boolean verifyOn, boolean isQuickSettings)457 public void toggleBTOnOffAndVerify(boolean verifyOn, boolean isQuickSettings) 458 throws Exception { 459 String switchText = (verifyOn ? "OFF" : "ON"); 460 BluetoothAdapter bluetoothAdapter = ((BluetoothManager) mContext 461 .getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter(); 462 boolean isEnabled = bluetoothAdapter.isEnabled(); 463 boolean success = (verifyOn ? bluetoothAdapter.disable() : bluetoothAdapter.enable()); 464 Thread.sleep(TIMEOUT * 3); 465 if (isQuickSettings) { 466 launchAndClickSettings(isQuickSettings, null, 467 By.descContains(BLUETOOTH).clazz(Switch.class)); 468 } else { 469 launchAndClickSettings(isQuickSettings, Settings.ACTION_BLUETOOTH_SETTINGS, 470 By.res(SETTINGS_PACKAGE, SWITCH_WIDGET).text(switchText)); 471 } 472 Thread.sleep(TIMEOUT * 3); 473 String bluetoothValue = Settings.Global.getString( 474 mResolver, 475 Settings.Global.BLUETOOTH_ON); 476 Assert.assertEquals((verifyOn ? "1" : "0"), bluetoothValue); 477 if (isEnabled) { 478 bluetoothAdapter.enable(); 479 } else { 480 bluetoothAdapter.disable(); 481 } 482 mDevice.pressHome(); 483 Thread.sleep(TIMEOUT * 3); 484 } 485 toggleAirplaneModeOnOrOffAndVerify(boolean verifyOn, boolean isQuickSettings)486 public void toggleAirplaneModeOnOrOffAndVerify(boolean verifyOn, boolean isQuickSettings) 487 throws Exception { 488 String settingValToPut = (verifyOn ? "0" : "1"); 489 Settings.Global.putString(mResolver, Settings.Global.AIRPLANE_MODE_ON, settingValToPut); 490 if (isQuickSettings) { 491 launchAndClickSettings(isQuickSettings, null, By.descContains(AIRPLANE)); 492 } else { 493 launchAndClickSettings(isQuickSettings, Settings.ACTION_WIRELESS_SETTINGS, 494 By.text(AIRPLANE)); 495 } 496 Thread.sleep(TIMEOUT * 3); 497 String airplaneModeValue = Settings.Global 498 .getString(mResolver, 499 Settings.Global.AIRPLANE_MODE_ON); 500 Assert.assertEquals((verifyOn ? "1" : "0"), airplaneModeValue); 501 mDevice.pressHome(); 502 Thread.sleep(TIMEOUT * 3); 503 } 504 toggleLocationSettingsOnOrOffAndVerify(boolean verifyOn, boolean isQuickSettings)505 public void toggleLocationSettingsOnOrOffAndVerify(boolean verifyOn, boolean isQuickSettings) 506 throws Exception { 507 // Set location flag 508 int settingValToPut = (verifyOn ? Settings.Secure.LOCATION_MODE_OFF 509 : Settings.Secure.LOCATION_MODE_SENSORS_ONLY); 510 Settings.Secure.putInt(mResolver, Settings.Secure.LOCATION_MODE, settingValToPut); 511 // Load location settings 512 if (isQuickSettings) { 513 launchAndClickSettings(isQuickSettings, null, By.descContains(LOCATION)); 514 } else { 515 launchAndClickSettings(isQuickSettings, Settings.ACTION_LOCATION_SOURCE_SETTINGS, 516 By.res(SETTINGS_PACKAGE, SWITCH_WIDGET)); 517 } 518 Thread.sleep(TIMEOUT * 3); 519 // Verify change in setting 520 int locationEnabled = Settings.Secure.getInt(mResolver, 521 Settings.Secure.LOCATION_MODE); 522 if (verifyOn) { 523 Assert.assertFalse("Location not enabled correctly", locationEnabled == 0); 524 } else { 525 Assert.assertEquals("Location not disabled correctly", 0, locationEnabled); 526 } 527 mDevice.pressHome(); 528 Thread.sleep(TIMEOUT * 3); 529 } 530 launchAndClickSettings(boolean isQuickSettings, String settingsPage, BySelector bySelector)531 public void launchAndClickSettings(boolean isQuickSettings, String settingsPage, 532 BySelector bySelector) throws Exception { 533 if (isQuickSettings) { 534 launchQuickSettingsAndWait(); 535 UiObject2 qsTile = mDevice.wait(Until.findObject(bySelector), TIMEOUT * 3); 536 qsTile.findObject(By.clazz("android.widget.FrameLayout")).click(); 537 } else { 538 mActivityHelper.launchIntent(settingsPage); 539 mDevice.wait(Until.findObject(bySelector), TIMEOUT * 3).click(); 540 } 541 } 542 543 /** 544 * Verify Quick Setting DND can be toggled DND default value is OFF 545 * @throws Exception 546 */ toggleQuickSettingDNDAndVerify()547 public void toggleQuickSettingDNDAndVerify() throws Exception { 548 try { 549 int onSetting = Settings.Global.getInt(mResolver, ZEN_MODE); 550 launchQuickSettingsAndWait(); 551 mDevice.wait(Until.findObject(By.descContains(DND).clazz(Switch.class)), 552 TIMEOUT * 3).getChildren().get(0).click(); 553 Thread.sleep(TIMEOUT * 3); 554 int changedSetting = Settings.Global.getInt(mResolver, ZEN_MODE); 555 Assert.assertFalse(onSetting == changedSetting); 556 mDevice.pressHome(); 557 Thread.sleep(TIMEOUT * 3); 558 } finally { 559 // change to DND default value 560 int setting = Settings.Global.getInt(mResolver, ZEN_MODE); 561 if (setting > 0) { 562 launchQuickSettingsAndWait(); 563 mDevice.wait(Until.findObject(By.descContains(DND).clazz(Switch.class)), 564 TIMEOUT * 3).getChildren().get(0).click(); 565 Thread.sleep(TIMEOUT * 3); 566 } 567 } 568 } 569 toggleQuickSettingFlashLightAndVerify()570 public void toggleQuickSettingFlashLightAndVerify() throws Exception { 571 String lightOn = "On"; 572 String lightOff = "Off"; 573 boolean verifyOn = false; 574 launchQuickSettingsAndWait(); 575 UiObject2 flashLight = mDevice.wait( 576 Until.findObject(By.desc(FLASHLIGHT)), 577 TIMEOUT * 3); 578 if (flashLight != null && flashLight.getText().equals(lightOn)) { 579 verifyOn = true; 580 } 581 mDevice.wait(Until.findObject(By.desc(FLASHLIGHT)), 582 TIMEOUT * 3).click(); 583 Thread.sleep(TIMEOUT * 3); 584 flashLight = mDevice.wait( 585 Until.findObject(By.desc(FLASHLIGHT)), 586 TIMEOUT * 3); 587 if (flashLight != null) { 588 String txt = flashLight.getText(); 589 if (verifyOn) { 590 Assert.assertTrue(txt.equals(lightOff)); 591 } else { 592 Assert.assertTrue(txt.equals(lightOn)); 593 mDevice.wait(Until.findObject(By.textContains(FLASHLIGHT)), 594 TIMEOUT * 3).click(); 595 } 596 } 597 mDevice.pressHome(); 598 Thread.sleep(TIMEOUT * 3); 599 } 600 toggleQuickSettingOrientationAndVerify()601 public void toggleQuickSettingOrientationAndVerify() throws Exception { 602 launchQuickSettingsAndWait(); 603 mDevice.wait(Until.findObject(By.descContains(AUTO_ROTATE_SCREEN)), 604 TIMEOUT * 3).click(); 605 Thread.sleep(TIMEOUT * 3); 606 String rotation = Settings.System.getString(mResolver, 607 Settings.System.ACCELEROMETER_ROTATION); 608 Assert.assertEquals("1", rotation); 609 mDevice.setOrientationNatural(); 610 mDevice.pressHome(); 611 Thread.sleep(TIMEOUT * 3); 612 } 613 launchQuickSettingsAndWait()614 public void launchQuickSettingsAndWait() throws Exception { 615 mDevice.openQuickSettings(); 616 Thread.sleep(TIMEOUT * 2); 617 } 618 launchSettingsPageByComponentName(Context ctx, String name)619 public void launchSettingsPageByComponentName(Context ctx, String name) { 620 Intent intent = new Intent(Intent.ACTION_MAIN); 621 ComponentName settingComponent = new ComponentName(SETTINGS_PACKAGE, 622 String.format("%s.%s$%s", SETTINGS_PACKAGE, SETTINGS_APP, name)); 623 intent.setComponent(settingComponent); 624 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 625 ctx.startActivity(intent); 626 } 627 } 628