Home | History | Annotate | Download | only in devicepolicy
      1 /*
      2  * Copyright (C) 2014 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.device.DeviceNotAvailableException;
     21 import com.android.tradefed.log.LogUtil.CLog;
     22 
     23 import java.util.Collections;
     24 
     25 /**
     26  * Set of tests for LauncherApps with managed profiles.
     27  */
     28 public class LauncherAppsSingleUserTest extends BaseLauncherAppsTest {
     29 
     30     private boolean mHasLauncherApps;
     31     private String mSerialNumber;
     32 
     33     @Override
     34     protected void setUp() throws Exception {
     35         super.setUp();
     36         mHasLauncherApps = getDevice().getApiLevel() >= 21;
     37 
     38         if (mHasLauncherApps) {
     39             mSerialNumber = Integer.toString(getUserSerialNumber(USER_SYSTEM));
     40             installTestApps();
     41         }
     42     }
     43 
     44     @Override
     45     protected void tearDown() throws Exception {
     46         if (mHasLauncherApps) {
     47             uninstallTestApps();
     48         }
     49         super.tearDown();
     50     }
     51 
     52     public void testInstallAppMainUser() throws Exception {
     53         if (!mHasLauncherApps) {
     54             return;
     55         }
     56         installAppAsUser(SIMPLE_APP_APK, mPrimaryUserId);
     57         runDeviceTestsAsUser(LAUNCHER_TESTS_PKG,
     58                 LAUNCHER_TESTS_CLASS, "testSimpleAppInstalledForUser",
     59                 mPrimaryUserId, Collections.singletonMap(PARAM_TEST_USER, mSerialNumber));
     60     }
     61 
     62     public void testLauncherCallbackPackageAddedMainUser() throws Exception {
     63         if (!mHasLauncherApps) {
     64             return;
     65         }
     66         startCallbackService();
     67         installAppAsUser(SIMPLE_APP_APK, mPrimaryUserId);
     68 
     69         runDeviceTestsAsUser(LAUNCHER_TESTS_PKG,
     70                 LAUNCHER_TESTS_CLASS,
     71                 "testPackageAddedCallbackForUser",
     72                 mPrimaryUserId, Collections.singletonMap(PARAM_TEST_USER, mSerialNumber));
     73     }
     74 
     75     public void testLauncherCallbackPackageRemovedMainUser() throws Exception {
     76         if (!mHasLauncherApps) {
     77             return;
     78         }
     79         installAppAsUser(SIMPLE_APP_APK, mPrimaryUserId);
     80         startCallbackService();
     81         getDevice().uninstallPackage(SIMPLE_APP_PKG);
     82         runDeviceTestsAsUser(LAUNCHER_TESTS_PKG,
     83                 LAUNCHER_TESTS_CLASS,
     84                 "testPackageRemovedCallbackForUser",
     85                 mPrimaryUserId, Collections.singletonMap(PARAM_TEST_USER, mSerialNumber));
     86     }
     87 
     88     public void testLauncherCallbackPackageChangedMainUser() throws Exception {
     89         if (!mHasLauncherApps) {
     90             return;
     91         }
     92         installAppAsUser(SIMPLE_APP_APK, mPrimaryUserId);
     93         startCallbackService();
     94         installAppAsUser(SIMPLE_APP_APK, mPrimaryUserId);
     95         runDeviceTestsAsUser(LAUNCHER_TESTS_PKG,
     96                 LAUNCHER_TESTS_CLASS,
     97                 "testPackageChangedCallbackForUser",
     98                 mPrimaryUserId, Collections.singletonMap(PARAM_TEST_USER, mSerialNumber));
     99     }
    100 
    101     public void testLauncherNonExportedAppFails() throws Exception {
    102         if (!mHasLauncherApps) {
    103             return;
    104         }
    105         installAppAsUser(SIMPLE_APP_APK, mPrimaryUserId);
    106         runDeviceTestsAsUser(LAUNCHER_TESTS_PKG,
    107                 LAUNCHER_TESTS_CLASS, "testLaunchNonExportActivityFails",
    108                 mPrimaryUserId, Collections.singletonMap(PARAM_TEST_USER, mSerialNumber));
    109     }
    110 
    111     public void testLaunchNonExportActivityFails() throws Exception {
    112         if (!mHasLauncherApps) {
    113             return;
    114         }
    115         installAppAsUser(SIMPLE_APP_APK, mPrimaryUserId);
    116         runDeviceTestsAsUser(LAUNCHER_TESTS_PKG,
    117                 LAUNCHER_TESTS_CLASS, "testLaunchNonExportLauncherFails",
    118                 mPrimaryUserId, Collections.singletonMap(PARAM_TEST_USER, mSerialNumber));
    119     }
    120 
    121     public void testLaunchMainActivity() throws Exception {
    122         if (!mHasLauncherApps) {
    123             return;
    124         }
    125         installAppAsUser(SIMPLE_APP_APK, mPrimaryUserId);
    126         runDeviceTestsAsUser(LAUNCHER_TESTS_PKG,
    127                 LAUNCHER_TESTS_CLASS, "testLaunchMainActivity",
    128                 mPrimaryUserId, Collections.singletonMap(PARAM_TEST_USER, mSerialNumber));
    129     }
    130 }
    131