1 /* 2 * Copyright (C) 2019 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.appsecurity.cts; 18 19 import android.platform.test.annotations.AppModeFull; 20 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 21 22 import org.junit.After; 23 import org.junit.Before; 24 import org.junit.Test; 25 import org.junit.runner.RunWith; 26 27 @RunWith(DeviceJUnit4ClassRunner.class) 28 @AppModeFull 29 public final class UseEmbeddedDexTest extends BaseAppSecurityTest { 30 31 private static final String PACKAGE_NAME = "com.android.cts.useembeddeddex"; 32 private static final String APK_CANONICAL = "CtsUseEmbeddedDexApp_Canonical.apk"; 33 private static final String APK_DEX_COMPRESSED = "CtsUseEmbeddedDexApp_DexCompressed.apk"; 34 private static final String APK_SPLIT_CANONICAL = 35 "CtsUseEmbeddedDexAppSplit_Canonical.apk"; 36 private static final String APK_SPLIT_COMPRESSED_DEX = 37 "CtsUseEmbeddedDexAppSplit_CompressedDex.apk"; 38 39 @After tearDown()40 public void tearDown() throws Exception { 41 getDevice().uninstallPackage(PACKAGE_NAME); 42 } 43 44 @Test testCanonicalInstall()45 public void testCanonicalInstall() throws Exception { 46 new InstallMultiple().addFile(APK_CANONICAL).run(); 47 } 48 49 @Test testIsolatedService()50 public void testIsolatedService() throws Exception { 51 new InstallMultiple().addFile(APK_CANONICAL).run(); 52 getDevice().executeShellCommand("cmd package compile -f -m speed " + PACKAGE_NAME); 53 runDeviceTests(PACKAGE_NAME, PACKAGE_NAME + ".EmbeddedDexTest", "testIsolatedService"); 54 } 55 56 @Test testBadInstallWithCompressedDex()57 public void testBadInstallWithCompressedDex() throws Exception { 58 new InstallMultiple().addFile(APK_DEX_COMPRESSED).runExpectingFailure(); 59 } 60 61 @Test testCanonicalInstallWithSplit()62 public void testCanonicalInstallWithSplit() throws Exception { 63 new InstallMultiple().addFile(APK_CANONICAL).addFile(APK_SPLIT_CANONICAL).run(); 64 } 65 66 @Test testBadInstallWithDexCompressedSplit()67 public void testBadInstallWithDexCompressedSplit() throws Exception { 68 new InstallMultiple().addFile(APK_CANONICAL).addFile(APK_SPLIT_COMPRESSED_DEX) 69 .runExpectingFailure(); 70 } 71 72 @Test testCanonicalInstallWithBaseThenSplit()73 public void testCanonicalInstallWithBaseThenSplit() throws Exception { 74 new InstallMultiple().addFile(APK_CANONICAL).run(); 75 new InstallMultiple().inheritFrom(PACKAGE_NAME).addFile(APK_SPLIT_CANONICAL).run(); 76 } 77 78 @Test testBadInstallWithBaseThenDexCompressedSplit()79 public void testBadInstallWithBaseThenDexCompressedSplit() throws Exception { 80 new InstallMultiple().addFile(APK_CANONICAL).run(); 81 new InstallMultiple().inheritFrom(PACKAGE_NAME).addFile(APK_SPLIT_COMPRESSED_DEX) 82 .runExpectingFailure(); 83 } 84 } 85