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 android.classloaders.cts; 18 19 import android.platform.test.annotations.AppModeFull; 20 import android.platform.test.annotations.AppModeInstant; 21 22 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 23 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; 24 25 import org.junit.After; 26 import org.junit.Before; 27 import org.junit.Test; 28 import org.junit.runner.RunWith; 29 30 /** 31 * Set of tests that verify behavior of runtime permissions, including both 32 * dynamic granting and behavior of legacy apps. 33 */ 34 @AppModeFull(reason = "TODO verify whether or not these should run in instant mode") 35 @RunWith(DeviceJUnit4ClassRunner.class) 36 public class UsesLibraryHostTest extends BaseHostJUnit4Test { 37 private static final String PKG = "com.android.cts.useslibrary"; 38 39 private static final String APK = "CtsUsesLibraryApp.apk"; 40 private static final String APK_COMPAT = "CtsUsesLibraryAppCompat.apk"; 41 42 43 @Before setUp()44 public void setUp() throws Exception { 45 Utils.prepareSingleUser(getDevice()); 46 getDevice().uninstallPackage(PKG); 47 } 48 49 @After tearDown()50 public void tearDown() throws Exception { 51 getDevice().uninstallPackage(PKG); 52 } 53 54 @Test 55 @AppModeFull testUsesLibrary_full()56 public void testUsesLibrary_full() throws Exception { 57 testUsesLibrary(false); 58 } testUsesLibrary(boolean instant)59 private void testUsesLibrary(boolean instant) throws Exception { 60 new InstallMultiple(instant).addApk(APK).run(); 61 Utils.runDeviceTests(getDevice(), PKG, ".UsesLibraryTest", "testUsesLibrary"); 62 } 63 64 @Test 65 @AppModeFull testMissingLibrary_full()66 public void testMissingLibrary_full() throws Exception { 67 testMissingLibrary(false); 68 } testMissingLibrary(boolean instant)69 public void testMissingLibrary(boolean instant) throws Exception { 70 new InstallMultiple(instant).addApk(APK).run(); 71 Utils.runDeviceTests(getDevice(), PKG, ".UsesLibraryTest", "testMissingLibrary"); 72 } 73 74 @Test 75 @AppModeFull testDuplicateLibrary_full()76 public void testDuplicateLibrary_full() throws Exception { 77 testDuplicateLibrary(false); 78 } testDuplicateLibrary(boolean instant)79 public void testDuplicateLibrary(boolean instant) throws Exception { 80 new InstallMultiple(instant).addApk(APK).run(); 81 Utils.runDeviceTests(getDevice(), PKG, ".UsesLibraryTest", "testDuplicateLibrary"); 82 } 83 84 protected class InstallMultiple extends BaseInstallMultiple<InstallMultiple> { InstallMultiple()85 public InstallMultiple() { 86 this(false); 87 } InstallMultiple(boolean instant)88 public InstallMultiple(boolean instant) { 89 super(getDevice(), getBuild(), getAbi()); 90 addArg(instant ? "--instant" : ""); 91 } 92 } 93 } 94