1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.ui; 18 19 import android.content.Intent; 20 import android.os.RemoteException; 21 import android.provider.Settings; 22 import android.support.test.uiautomator.By; 23 import android.support.test.uiautomator.Direction; 24 import android.support.test.uiautomator.UiDevice; 25 import android.support.test.uiautomator.UiObject2; 26 import android.support.test.uiautomator.Until; 27 import android.system.helpers.ActivityHelper; 28 import android.test.InstrumentationTestCase; 29 import android.test.suitebuilder.annotation.MediumTest; 30 import android.text.TextUtils; 31 import android.util.Log; 32 33 import java.util.ArrayList; 34 import java.util.Arrays; 35 import java.util.Iterator; 36 37 /** Verifies basic functionality of the About Phone screen */ 38 public class AppsSettingsTests extends InstrumentationTestCase { 39 private static final boolean LOCAL_LOGV = false; 40 private static final String SETTINGS_PACKAGE = "com.android.settings"; 41 private static final String TAG = "AboutPhoneSettingsTest"; 42 private static final int TIMEOUT = 2000; 43 private ActivityHelper mActivityHelper = null; 44 45 private UiDevice mDevice; 46 47 private static final String[] sResourceTexts = { 48 "Storage", 49 "Data usage", 50 "Permissions", 51 "App notifications", 52 "Open by default", 53 "Battery", 54 "Memory" 55 }; 56 57 @Override setUp()58 public void setUp() throws Exception { 59 if (LOCAL_LOGV) { 60 Log.d(TAG, "-------"); 61 } 62 super.setUp(); 63 mDevice = UiDevice.getInstance(getInstrumentation()); 64 mActivityHelper = ActivityHelper.getInstance(); 65 try { 66 mDevice.setOrientationNatural(); 67 } catch (RemoteException e) { 68 throw new RuntimeException("Failed to freeze device orientaion", e); 69 } 70 71 // make sure we are in a clean state before starting the test 72 mDevice.pressHome(); 73 Thread.sleep(TIMEOUT * 2); 74 launchAppsSettings(); 75 UiObject2 view = 76 mDevice.wait( 77 Until.findObject(By.text("All apps")), TIMEOUT); 78 assertNotNull("Could not find Settings > Apps screen", view); 79 } 80 81 @Override tearDown()82 protected void tearDown() throws Exception { 83 mDevice.pressBack(); 84 mDevice.pressHome(); // finish settings activity 85 mDevice.waitForIdle(TIMEOUT * 2); // give UI time to finish animating 86 super.tearDown(); 87 } 88 89 @MediumTest testAppSettingsListForCalculator()90 public void testAppSettingsListForCalculator() { 91 UiObject2 calculator = mDevice.wait( 92 Until.findObject(By.text("Calculator")), TIMEOUT); 93 calculator.click(); 94 for (String setting : sResourceTexts) { 95 UiObject2 appSetting = 96 mDevice.wait( 97 Until.findObject(By.text(setting)), TIMEOUT); 98 assertNotNull("Missing setting for Calculator: " + setting, appSetting); 99 appSetting.scroll(Direction.DOWN, 10.0f); 100 } 101 } 102 103 @MediumTest testDisablingAndEnablingSystemApp()104 public void testDisablingAndEnablingSystemApp() throws Exception { 105 launchAppsSettings(); 106 UiObject2 calculator = mDevice.wait( 107 Until.findObject(By.text("Calculator")), TIMEOUT); 108 calculator.click(); 109 mDevice.waitForIdle(TIMEOUT); 110 UiObject2 appInfoList = mDevice.wait( 111 Until.findObject(By.res(SETTINGS_PACKAGE, "list")), TIMEOUT); 112 appInfoList.scroll(Direction.DOWN, 100.0f); 113 UiObject2 disableButton = mDevice.wait( 114 Until.findObject(By.text("DISABLE")), TIMEOUT); 115 disableButton.click(); 116 mDevice.waitForIdle(TIMEOUT); 117 // Click on "Disable App" on dialog. 118 mDevice.wait( 119 Until.findObject(By.text("DISABLE APP")), TIMEOUT).click(); 120 mDevice.waitForIdle(TIMEOUT); 121 UiObject2 enableButton = mDevice.wait( 122 Until.findObject(By.text("ENABLE")), TIMEOUT); 123 assertNotNull("App not disabled successfully", enableButton); 124 enableButton.click(); 125 mDevice.waitForIdle(TIMEOUT); 126 disableButton = mDevice.wait( 127 Until.findObject(By.text("DISABLE")), TIMEOUT); 128 assertNotNull("App not enabled successfully", disableButton); 129 } 130 launchAppsSettings()131 private void launchAppsSettings() throws Exception { 132 Intent appsSettingsIntent = new 133 Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS); 134 mActivityHelper.launchIntent(appsSettingsIntent); 135 } 136 } 137