1 /* 2 * Copyright (C) 2015 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.cts.devicepolicy; 18 19 import com.android.ddmlib.Log.LogLevel; 20 import com.android.tradefed.log.LogUtil.CLog; 21 22 /** 23 * Common code for the various LauncherApps tests. 24 */ 25 public class BaseLauncherAppsTest extends BaseDevicePolicyTest { 26 27 protected static final String SIMPLE_APP_PKG = "com.android.cts.launcherapps.simpleapp"; 28 protected static final String SIMPLE_APP_APK = "CtsSimpleApp.apk"; 29 protected static final String LAUNCHER_TESTS_PKG = "com.android.cts.launchertests"; 30 protected static final String LAUNCHER_TESTS_CLASS = LAUNCHER_TESTS_PKG + ".LauncherAppsTests"; 31 private static final String LAUNCHER_TESTS_APK = "CtsLauncherAppsTests.apk"; 32 private static final String LAUNCHER_TESTS_SUPPORT_PKG = 33 "com.android.cts.launchertests.support"; 34 private static final String LAUNCHER_TESTS_SUPPORT_APK = "CtsLauncherAppsTestsSupport.apk"; 35 installTestApps()36 protected void installTestApps() throws Exception { 37 uninstallTestApps(); 38 installApp(LAUNCHER_TESTS_APK); 39 installApp(LAUNCHER_TESTS_SUPPORT_APK); 40 } 41 uninstallTestApps()42 protected void uninstallTestApps() throws Exception { 43 getDevice().uninstallPackage(LAUNCHER_TESTS_PKG); 44 getDevice().uninstallPackage(LAUNCHER_TESTS_SUPPORT_PKG); 45 getDevice().uninstallPackage(SIMPLE_APP_PKG); 46 } 47 removeTestUsers()48 protected void removeTestUsers() throws Exception { 49 for (int userId : listUsers()) { 50 if (userId != 0) { 51 removeUser(userId); 52 } 53 } 54 } 55 startCallbackService()56 protected void startCallbackService() throws Exception { 57 String command = "am startservice --user 0 " 58 + "-a " + LAUNCHER_TESTS_SUPPORT_PKG + ".REGISTER_CALLBACK " 59 + LAUNCHER_TESTS_SUPPORT_PKG + "/.LauncherCallbackTestsService"; 60 CLog.logAndDisplay(LogLevel.INFO, "Output for command " + command + ": " 61 + getDevice().executeShellCommand(command)); 62 63 } 64 } 65