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 android.appsecurity.cts; 18 19 import static org.junit.Assert.assertNotNull; 20 21 import android.platform.test.annotations.AppModeFull; 22 import android.platform.test.annotations.AppModeInstant; 23 24 import com.android.tradefed.device.DeviceNotAvailableException; 25 import com.android.tradefed.testtype.Abi; 26 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 27 import com.android.tradefed.testtype.IAbi; 28 import com.android.tradefed.util.AbiUtils; 29 30 import org.junit.After; 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 35 import java.io.FileNotFoundException; 36 import java.util.HashMap; 37 import java.util.Set; 38 39 /** 40 * Tests that verify installing of various split APKs from host side. 41 */ 42 @RunWith(DeviceJUnit4ClassRunner.class) 43 public class SplitTests extends BaseAppSecurityTest { 44 static final String PKG_NO_RESTART = "com.android.cts.norestart"; 45 static final String APK_NO_RESTART_BASE = "CtsNoRestartBase.apk"; 46 static final String APK_NO_RESTART_FEATURE = "CtsNoRestartFeature.apk"; 47 48 static final String APK_NEED_SPLIT_BASE = "CtsNeedSplitApp.apk"; 49 static final String APK_NEED_SPLIT_FEATURE_WARM = "CtsNeedSplitFeatureWarm.apk"; 50 static final String APK_NEED_SPLIT_CONFIG = "CtsNeedSplitApp_xxhdpi-v4.apk"; 51 52 static final String PKG = "com.android.cts.splitapp"; 53 static final String CLASS = PKG + ".SplitAppTest"; 54 55 static final String APK = "CtsSplitApp.apk"; 56 57 static final String APK_mdpi = "CtsSplitApp_mdpi-v4.apk"; 58 static final String APK_hdpi = "CtsSplitApp_hdpi-v4.apk"; 59 static final String APK_xhdpi = "CtsSplitApp_xhdpi-v4.apk"; 60 static final String APK_xxhdpi = "CtsSplitApp_xxhdpi-v4.apk"; 61 62 private static final String APK_v7 = "CtsSplitApp_v7.apk"; 63 private static final String APK_v23 = "CtsSplitApp_v23.apk"; 64 private static final String APK_fr = "CtsSplitApp_fr.apk"; 65 private static final String APK_de = "CtsSplitApp_de.apk"; 66 67 private static final String APK_x86 = "CtsSplitApp_x86.apk"; 68 private static final String APK_x86_64 = "CtsSplitApp_x86_64.apk"; 69 private static final String APK_armeabi_v7a = "CtsSplitApp_armeabi-v7a.apk"; 70 private static final String APK_armeabi = "CtsSplitApp_armeabi.apk"; 71 private static final String APK_arm64_v8a = "CtsSplitApp_arm64-v8a.apk"; 72 private static final String APK_mips64 = "CtsSplitApp_mips64.apk"; 73 private static final String APK_mips = "CtsSplitApp_mips.apk"; 74 75 private static final String APK_NUMBER_PROVIDER_A = "CtsSplitApp_number_provider_a.apk"; 76 private static final String APK_NUMBER_PROVIDER_B = "CtsSplitApp_number_provider_b.apk"; 77 private static final String APK_NUMBER_PROXY = "CtsSplitApp_number_proxy.apk"; 78 79 private static final String APK_DIFF_REVISION = "CtsSplitAppDiffRevision.apk"; 80 private static final String APK_DIFF_REVISION_v7 = "CtsSplitAppDiffRevision_v7.apk"; 81 82 private static final String APK_DIFF_VERSION = "CtsSplitAppDiffVersion.apk"; 83 private static final String APK_DIFF_VERSION_v7 = "CtsSplitAppDiffVersion_v7.apk"; 84 85 private static final String APK_DIFF_CERT = "CtsSplitAppDiffCert.apk"; 86 private static final String APK_DIFF_CERT_v7 = "CtsSplitAppDiffCert_v7.apk"; 87 88 private static final String APK_FEATURE_WARM = "CtsSplitAppFeatureWarm.apk"; 89 private static final String APK_FEATURE_WARM_v7 = "CtsSplitAppFeatureWarm_v7.apk"; 90 private static final String APK_FEATURE_WARM_v23 = "CtsSplitAppFeatureWarm_v23.apk"; 91 92 private static final String APK_FEATURE_ROSE = "CtsSplitAppFeatureRose.apk"; 93 private static final String APK_FEATURE_ROSE_v23 = "CtsSplitAppFeatureRose_v23.apk"; 94 95 private static final String APK_REVISION_A = "CtsSplitAppRevisionA.apk"; 96 private static final String APK_FEATURE_WARM_REVISION_A = "CtsSplitAppFeatureWarmRevisionA.apk"; 97 98 // Apk includes a provider and service declared in other split apk. And only could be tested in 99 // instant app mode. 100 static final String APK_INSTANT = "CtsSplitInstantApp.apk"; 101 102 static final HashMap<String, String> ABI_TO_APK = new HashMap<>(); 103 static final HashMap<String, String> ABI_TO_REVISION_APK = new HashMap<>(); 104 105 static { 106 ABI_TO_APK.put("x86", APK_x86); 107 ABI_TO_APK.put("x86_64", APK_x86_64); 108 ABI_TO_APK.put("armeabi-v7a", APK_armeabi_v7a); 109 ABI_TO_APK.put("armeabi", APK_armeabi); 110 ABI_TO_APK.put("arm64-v8a", APK_arm64_v8a); 111 ABI_TO_APK.put("mips64", APK_mips64); 112 ABI_TO_APK.put("mips", APK_mips); 113 114 ABI_TO_REVISION_APK.put("x86", "CtsSplitApp_revision12_x86.apk"); 115 ABI_TO_REVISION_APK.put("x86_64", "CtsSplitApp_revision12_x86_64.apk"); 116 ABI_TO_REVISION_APK.put("armeabi-v7a", "CtsSplitApp_revision12_armeabi-v7a.apk"); 117 ABI_TO_REVISION_APK.put("armeabi", "CtsSplitApp_revision12_armeabi.apk"); 118 ABI_TO_REVISION_APK.put("arm64-v8a", "CtsSplitApp_revision12_arm64-v8a.apk"); 119 ABI_TO_REVISION_APK.put("mips64", "CtsSplitApp_revision12_mips64.apk"); 120 ABI_TO_REVISION_APK.put("mips", "CtsSplitApp_revision12_mips.apk"); 121 } 122 123 @Before setUp()124 public void setUp() throws Exception { 125 Utils.prepareSingleUser(getDevice()); 126 getDevice().uninstallPackage(PKG); 127 getDevice().uninstallPackage(PKG_NO_RESTART); 128 } 129 130 @After tearDown()131 public void tearDown() throws Exception { 132 getDevice().uninstallPackage(PKG); 133 getDevice().uninstallPackage(PKG_NO_RESTART); 134 } 135 136 @Test 137 @AppModeFull(reason = "'full' portion of the hostside test") testSingleBase_full()138 public void testSingleBase_full() throws Exception { 139 testSingleBase(false); 140 } 141 @Test 142 @AppModeInstant(reason = "'instant' portion of the hostside test") testSingleBase_instant()143 public void testSingleBase_instant() throws Exception { 144 testSingleBase(true); 145 } testSingleBase(boolean instant)146 private void testSingleBase(boolean instant) throws Exception { 147 new InstallMultiple(instant).addFile(APK).run(); 148 runDeviceTests(PKG, CLASS, "testSingleBase"); 149 } 150 151 @Test 152 @AppModeFull(reason = "'full' portion of the hostside test") testDensitySingle_full()153 public void testDensitySingle_full() throws Exception { 154 testDensitySingle(false); 155 } 156 @Test 157 @AppModeInstant(reason = "'instant' portion of the hostside test") testDensitySingle_instant()158 public void testDensitySingle_instant() throws Exception { 159 testDensitySingle(true); 160 } testDensitySingle(boolean instant)161 private void testDensitySingle(boolean instant) throws Exception { 162 new InstallMultiple(instant).addFile(APK).addFile(APK_mdpi).run(); 163 runDeviceTests(PKG, CLASS, "testDensitySingle"); 164 } 165 166 @Test 167 @AppModeFull(reason = "'full' portion of the hostside test") testDensityAll_full()168 public void testDensityAll_full() throws Exception { 169 testDensityAll(false); 170 } 171 @Test 172 @AppModeInstant(reason = "'instant' portion of the hostside test") testDensityAll_instant()173 public void testDensityAll_instant() throws Exception { 174 testDensityAll(true); 175 } testDensityAll(boolean instant)176 private void testDensityAll(boolean instant) throws Exception { 177 new InstallMultiple(instant).addFile(APK).addFile(APK_mdpi).addFile(APK_hdpi).addFile(APK_xhdpi) 178 .addFile(APK_xxhdpi).run(); 179 runDeviceTests(PKG, CLASS, "testDensityAll"); 180 } 181 182 /** 183 * Install first with low-resolution resources, then add a split that offers 184 * higher-resolution resources. 185 */ 186 @Test 187 @AppModeFull(reason = "'full' portion of the hostside test") testDensityBest_full()188 public void testDensityBest_full() throws Exception { 189 testDensityBest(false); 190 } 191 @Test 192 @AppModeInstant(reason = "'instant' portion of the hostside test") testDensityBest_instant()193 public void testDensityBest_instant() throws Exception { 194 testDensityBest(true); 195 } testDensityBest(boolean instant)196 private void testDensityBest(boolean instant) throws Exception { 197 new InstallMultiple(instant).addFile(APK).addFile(APK_mdpi).run(); 198 runDeviceTests(PKG, CLASS, "testDensityBest1"); 199 200 // Now splice in an additional split which offers better resources 201 new InstallMultiple(instant).inheritFrom(PKG).addFile(APK_xxhdpi).run(); 202 runDeviceTests(PKG, CLASS, "testDensityBest2"); 203 } 204 205 /** 206 * Verify that an API-based split can change enabled/disabled state of 207 * manifest elements. 208 */ 209 @Test 210 @AppModeFull(reason = "'full' portion of the hostside test") testApi_full()211 public void testApi_full() throws Exception { 212 testApi(false); 213 } 214 @Test 215 @AppModeInstant(reason = "'instant' portion of the hostside test") testApi_instant()216 public void testApi_instant() throws Exception { 217 testApi(true); 218 } testApi(boolean instant)219 private void testApi(boolean instant) throws Exception { 220 new InstallMultiple(instant).addFile(APK).addFile(APK_v7).run(); 221 runDeviceTests(PKG, CLASS, "testApi"); 222 } 223 224 @Test 225 @AppModeFull(reason = "'full' portion of the hostside test") testLocale_full()226 public void testLocale_full() throws Exception { 227 testLocale(false); 228 } 229 @Test 230 @AppModeInstant(reason = "'instant' portion of the hostside test") testLocale_instant()231 public void testLocale_instant() throws Exception { 232 testLocale(true); 233 } testLocale(boolean instant)234 private void testLocale(boolean instant) throws Exception { 235 new InstallMultiple(instant).addFile(APK).addFile(APK_de).addFile(APK_fr).run(); 236 runDeviceTests(PKG, CLASS, "testLocale"); 237 } 238 239 /** 240 * Install test app with <em>single</em> split that exactly matches the 241 * currently active ABI. This also explicitly forces ABI when installing. 242 */ 243 @Test 244 @AppModeFull(reason = "'full' portion of the hostside test") testNativeSingle_full()245 public void testNativeSingle_full() throws Exception { 246 testNativeSingle(false, false); 247 } 248 @Test 249 @AppModeInstant(reason = "'instant' portion of the hostside test") testNativeSingle_instant()250 public void testNativeSingle_instant() throws Exception { 251 testNativeSingle(true, false); 252 } 253 getInstallMultiple(boolean instant, boolean useNaturalAbi)254 private InstallMultiple getInstallMultiple(boolean instant, boolean useNaturalAbi) { 255 final InstallMultiple installMultiple = new InstallMultiple(instant); 256 if (useNaturalAbi) { 257 return installMultiple.useNaturalAbi(); 258 } 259 return installMultiple; 260 } 261 testNativeSingle(boolean instant, boolean useNaturalAbi)262 private void testNativeSingle(boolean instant, boolean useNaturalAbi) throws Exception { 263 final String abi = getAbi().getName(); 264 final String apk = ABI_TO_APK.get(abi); 265 final String revisionApk = ABI_TO_REVISION_APK.get(abi); 266 assertNotNull("Failed to find APK for ABI " + abi, apk); 267 268 getInstallMultiple(instant, useNaturalAbi).addFile(APK).addFile(apk).run(); 269 runDeviceTests(PKG, CLASS, "testNative"); 270 runDeviceTests(PKG, CLASS, "testNativeRevision_sub_shouldImplementBadly"); 271 getInstallMultiple(instant, useNaturalAbi).inheritFrom(PKG).addFile(revisionApk).run(); 272 runDeviceTests(PKG, CLASS, "testNativeRevision_sub_shouldImplementWell"); 273 274 getInstallMultiple(instant, useNaturalAbi).inheritFrom(PKG) 275 .addFile(APK_NUMBER_PROVIDER_A) 276 .addFile(APK_NUMBER_PROVIDER_B) 277 .addFile(APK_NUMBER_PROXY).run(); 278 runDeviceTests(PKG, CLASS, "testNative_getNumberADirectly_shouldBeSeven"); 279 runDeviceTests(PKG, CLASS, "testNative_getNumberAViaProxy_shouldBeSeven"); 280 runDeviceTests(PKG, CLASS, "testNative_getNumberBDirectly_shouldBeEleven"); 281 runDeviceTests(PKG, CLASS, "testNative_getNumberBViaProxy_shouldBeEleven"); 282 } 283 284 @Test 285 @AppModeFull(reason = "'full' portion of the hostside test") testNativeSplitForEachSupportedAbi_full()286 public void testNativeSplitForEachSupportedAbi_full() throws Exception { 287 testNativeForEachSupportedAbi(false); 288 } 289 290 @Test 291 @AppModeInstant(reason = "'instant' portion of the hostside test") testNativeSplitForEachSupportedAbi_instant()292 public void testNativeSplitForEachSupportedAbi_instant() throws Exception { 293 testNativeForEachSupportedAbi(true); 294 } 295 296 specifyAbiToTest(boolean instant, String abiListProperty, String testMethodName)297 private void specifyAbiToTest(boolean instant, String abiListProperty, String testMethodName) 298 throws FileNotFoundException, DeviceNotAvailableException { 299 final String propertyAbiListValue = getDevice().getProperty(abiListProperty); 300 final Set<String> supportedAbiSet = 301 AbiUtils.parseAbiListFromProperty(propertyAbiListValue); 302 for (String abi : supportedAbiSet) { 303 String apk = ABI_TO_APK.get(abi); 304 new InstallMultiple(instant, true).inheritFrom(PKG).addFile(apk).run(); 305 306 // Without specifying abi for executing "adb shell am", 307 // a UnsatisfiedLinkError will happen. 308 IAbi iAbi = new Abi(abi, AbiUtils.getBitness(abi)); 309 setAbi(iAbi); 310 runDeviceTests(PKG, CLASS, testMethodName); 311 } 312 } 313 testNativeForEachSupportedAbi(boolean instant)314 private void testNativeForEachSupportedAbi(boolean instant) 315 throws DeviceNotAvailableException, FileNotFoundException { 316 new InstallMultiple(instant, true).addFile(APK).run(); 317 318 // make sure this device can run both 32 bit and 64 bit 319 specifyAbiToTest(instant, "ro.product.cpu.abilist64", "testNative64Bit"); 320 specifyAbiToTest(instant, "ro.product.cpu.abilist32", "testNative32Bit"); 321 } 322 323 /** 324 * Install test app with <em>single</em> split that exactly matches the 325 * currently active ABI. This variant <em>does not</em> force the ABI when 326 * installing, instead exercising the system's ability to choose the ABI 327 * through inspection of the installed app. 328 */ 329 @Test 330 @AppModeFull(reason = "'full' portion of the hostside test") testNativeSingleNatural_full()331 public void testNativeSingleNatural_full() throws Exception { 332 testNativeSingle(false, true); 333 } 334 @Test 335 @AppModeInstant(reason = "'instant' portion of the hostside test") testNativeSingleNatural_instant()336 public void testNativeSingleNatural_instant() throws Exception { 337 testNativeSingle(true, true); 338 } 339 340 /** 341 * Install test app with <em>all</em> possible ABI splits. This also 342 * explicitly forces ABI when installing. 343 */ 344 @Test 345 @AppModeFull(reason = "'full' portion of the hostside test") testNativeAll_full()346 public void testNativeAll_full() throws Exception { 347 testNativeAll(false, false); 348 } 349 @Test 350 @AppModeInstant(reason = "'instant' portion of the hostside test") testNativeAll_instant()351 public void testNativeAll_instant() throws Exception { 352 testNativeAll(true, false); 353 } testNativeAll(boolean instant, boolean useNaturalAbi)354 private void testNativeAll(boolean instant, boolean useNaturalAbi) throws Exception { 355 final InstallMultiple inst = getInstallMultiple(instant, useNaturalAbi).addFile(APK); 356 for (String apk : ABI_TO_APK.values()) { 357 inst.addFile(apk); 358 } 359 inst.run(); 360 runDeviceTests(PKG, CLASS, "testNative"); 361 runDeviceTests(PKG, CLASS, "testNativeRevision_sub_shouldImplementBadly"); 362 363 final InstallMultiple instInheritFrom = 364 getInstallMultiple(instant, useNaturalAbi).inheritFrom(PKG); 365 for (String apk : ABI_TO_REVISION_APK.values()) { 366 instInheritFrom.addFile(apk); 367 } 368 instInheritFrom.addFile(APK_NUMBER_PROVIDER_A); 369 instInheritFrom.addFile(APK_NUMBER_PROVIDER_B); 370 instInheritFrom.addFile(APK_NUMBER_PROXY); 371 instInheritFrom.run(); 372 runDeviceTests(PKG, CLASS, "testNativeRevision_sub_shouldImplementWell"); 373 374 runDeviceTests(PKG, CLASS, "testNative_getNumberADirectly_shouldBeSeven"); 375 runDeviceTests(PKG, CLASS, "testNative_getNumberAViaProxy_shouldBeSeven"); 376 runDeviceTests(PKG, CLASS, "testNative_getNumberBDirectly_shouldBeEleven"); 377 runDeviceTests(PKG, CLASS, "testNative_getNumberBViaProxy_shouldBeEleven"); 378 } 379 380 /** 381 * Install test app with <em>all</em> possible ABI splits. This variant 382 * <em>does not</em> force the ABI when installing, instead exercising the 383 * system's ability to choose the ABI through inspection of the installed 384 * app. 385 */ 386 @Test 387 @AppModeFull(reason = "'full' portion of the hostside test") testNativeAllNatural_full()388 public void testNativeAllNatural_full() throws Exception { 389 testNativeAll(false, true); 390 } 391 @Test 392 @AppModeInstant(reason = "'instant' portion of the hostside test") testNativeAllNatural_instant()393 public void testNativeAllNatural_instant() throws Exception { 394 testNativeAll(true, true); 395 } 396 397 @Test 398 @AppModeFull(reason = "'full' portion of the hostside test") testDuplicateBase_full()399 public void testDuplicateBase_full() throws Exception { 400 testDuplicateBase(false); 401 } 402 @Test 403 @AppModeInstant(reason = "'instant' portion of the hostside test") testDuplicateBase_instant()404 public void testDuplicateBase_instant() throws Exception { 405 testDuplicateBase(true); 406 } testDuplicateBase(boolean instant)407 private void testDuplicateBase(boolean instant) throws Exception { 408 new InstallMultiple(instant).addFile(APK).addFile(APK).runExpectingFailure(); 409 } 410 411 @Test 412 @AppModeFull(reason = "'full' portion of the hostside test") testDuplicateSplit_full()413 public void testDuplicateSplit_full() throws Exception { 414 testDuplicateSplit(false); 415 } 416 @Test 417 @AppModeInstant(reason = "'instant' portion of the hostside test") testDuplicateSplit_instant()418 public void testDuplicateSplit_instant() throws Exception { 419 testDuplicateSplit(true); 420 } testDuplicateSplit(boolean instant)421 private void testDuplicateSplit(boolean instant) throws Exception { 422 new InstallMultiple(instant).addFile(APK).addFile(APK_v7).addFile(APK_v7).runExpectingFailure(); 423 } 424 425 @Test 426 @AppModeFull(reason = "'full' portion of the hostside test") testDiffCert_full()427 public void testDiffCert_full() throws Exception { 428 testDiffCert(false); 429 } 430 @Test 431 @AppModeInstant(reason = "'instant' portion of the hostside test") testDiffCert_instant()432 public void testDiffCert_instant() throws Exception { 433 testDiffCert(true); 434 } testDiffCert(boolean instant)435 private void testDiffCert(boolean instant) throws Exception { 436 new InstallMultiple(instant).addFile(APK).addFile(APK_DIFF_CERT_v7).runExpectingFailure(); 437 } 438 439 @Test 440 @AppModeFull(reason = "'full' portion of the hostside test") testDiffCertInherit_full()441 public void testDiffCertInherit_full() throws Exception { 442 testDiffCertInherit(false); 443 } 444 @Test 445 @AppModeInstant(reason = "'instant' portion of the hostside test") testDiffCertInherit_instant()446 public void testDiffCertInherit_instant() throws Exception { 447 testDiffCertInherit(true); 448 } testDiffCertInherit(boolean instant)449 private void testDiffCertInherit(boolean instant) throws Exception { 450 new InstallMultiple(instant).addFile(APK).run(); 451 new InstallMultiple(instant).inheritFrom(PKG).addFile(APK_DIFF_CERT_v7).runExpectingFailure(); 452 } 453 454 @Test 455 @AppModeFull(reason = "'full' portion of the hostside test") testDiffVersion_full()456 public void testDiffVersion_full() throws Exception { 457 testDiffVersion(false); 458 } 459 @Test 460 @AppModeInstant(reason = "'instant' portion of the hostside test") testDiffVersion_instant()461 public void testDiffVersion_instant() throws Exception { 462 testDiffVersion(true); 463 } testDiffVersion(boolean instant)464 private void testDiffVersion(boolean instant) throws Exception { 465 new InstallMultiple(instant).addFile(APK).addFile(APK_DIFF_VERSION_v7).runExpectingFailure(); 466 } 467 468 @Test 469 @AppModeFull(reason = "'full' portion of the hostside test") testDiffVersionInherit_full()470 public void testDiffVersionInherit_full() throws Exception { 471 testDiffVersionInherit(false); 472 } 473 @Test 474 @AppModeInstant(reason = "'instant' portion of the hostside test") testDiffVersionInherit_instant()475 public void testDiffVersionInherit_instant() throws Exception { 476 testDiffVersionInherit(true); 477 } testDiffVersionInherit(boolean instant)478 private void testDiffVersionInherit(boolean instant) throws Exception { 479 new InstallMultiple(instant).addFile(APK).run(); 480 new InstallMultiple(instant).inheritFrom(PKG).addFile(APK_DIFF_VERSION_v7).runExpectingFailure(); 481 } 482 483 @Test 484 @AppModeFull(reason = "'full' portion of the hostside test") testDiffRevision_full()485 public void testDiffRevision_full() throws Exception { 486 testDiffRevision(false); 487 } 488 @Test 489 @AppModeInstant(reason = "'instant' portion of the hostside test") testDiffRevision_instant()490 public void testDiffRevision_instant() throws Exception { 491 testDiffRevision(true); 492 } testDiffRevision(boolean instant)493 private void testDiffRevision(boolean instant) throws Exception { 494 new InstallMultiple(instant).addFile(APK).addFile(APK_DIFF_REVISION_v7).run(); 495 runDeviceTests(PKG, CLASS, "testRevision0_12"); 496 } 497 498 @Test 499 @AppModeFull(reason = "'full' portion of the hostside test") testDiffRevisionInheritBase_full()500 public void testDiffRevisionInheritBase_full() throws Exception { 501 testDiffRevisionInheritBase(false); 502 } 503 @Test 504 @AppModeInstant(reason = "'instant' portion of the hostside test") testDiffRevisionInheritBase_instant()505 public void testDiffRevisionInheritBase_instant() throws Exception { 506 testDiffRevisionInheritBase(true); 507 } testDiffRevisionInheritBase(boolean instant)508 private void testDiffRevisionInheritBase(boolean instant) throws Exception { 509 new InstallMultiple(instant).addFile(APK).addFile(APK_v7).run(); 510 runDeviceTests(PKG, CLASS, "testRevision0_0"); 511 new InstallMultiple(instant).inheritFrom(PKG).addFile(APK_DIFF_REVISION_v7).run(); 512 runDeviceTests(PKG, CLASS, "testRevision0_12"); 513 } 514 515 @Test 516 @AppModeFull(reason = "'full' portion of the hostside test") testDiffRevisionInheritSplit_full()517 public void testDiffRevisionInheritSplit_full() throws Exception { 518 testDiffRevisionInheritSplit(false); 519 } 520 @Test 521 @AppModeInstant(reason = "'instant' portion of the hostside test") testDiffRevisionInheritSplit_instant()522 public void testDiffRevisionInheritSplit_instant() throws Exception { 523 testDiffRevisionInheritSplit(true); 524 } testDiffRevisionInheritSplit(boolean instant)525 private void testDiffRevisionInheritSplit(boolean instant) throws Exception { 526 new InstallMultiple(instant).addFile(APK).addFile(APK_v7).run(); 527 runDeviceTests(PKG, CLASS, "testRevision0_0"); 528 new InstallMultiple(instant).inheritFrom(PKG).addFile(APK_DIFF_REVISION).run(); 529 runDeviceTests(PKG, CLASS, "testRevision12_0"); 530 } 531 532 @Test 533 @AppModeFull(reason = "'full' portion of the hostside test") testDiffRevisionDowngrade_full()534 public void testDiffRevisionDowngrade_full() throws Exception { 535 testDiffRevisionDowngrade(false); 536 } 537 @Test 538 @AppModeInstant(reason = "'instant' portion of the hostside test") testDiffRevisionDowngrade_instant()539 public void testDiffRevisionDowngrade_instant() throws Exception { 540 testDiffRevisionDowngrade(true); 541 } testDiffRevisionDowngrade(boolean instant)542 private void testDiffRevisionDowngrade(boolean instant) throws Exception { 543 new InstallMultiple(instant).addFile(APK).addFile(APK_DIFF_REVISION_v7).run(); 544 new InstallMultiple(instant).inheritFrom(PKG).addFile(APK_v7).runExpectingFailure(); 545 } 546 547 @Test 548 @AppModeFull(reason = "'full' portion of the hostside test") testFeatureWarmBase_full()549 public void testFeatureWarmBase_full() throws Exception { 550 testFeatureWarmBase(false); 551 } 552 @Test 553 @AppModeInstant(reason = "'instant' portion of the hostside test") testFeatureWarmBase_instant()554 public void testFeatureWarmBase_instant() throws Exception { 555 testFeatureWarmBase(true); 556 } testFeatureWarmBase(boolean instant)557 private void testFeatureWarmBase(boolean instant) throws Exception { 558 new InstallMultiple(instant).addFile(APK).addFile(APK_FEATURE_WARM).run(); 559 runDeviceTests(PKG, CLASS, "testFeatureWarmBase"); 560 } 561 562 @Test 563 @AppModeFull(reason = "'full' portion of the hostside test") testFeatureWarmApi_full()564 public void testFeatureWarmApi_full() throws Exception { 565 testFeatureWarmApi(false); 566 } 567 @Test 568 @AppModeInstant(reason = "'instant' portion of the hostside test") testFeatureWarmApi_instant()569 public void testFeatureWarmApi_instant() throws Exception { 570 testFeatureWarmApi(true); 571 } testFeatureWarmApi(boolean instant)572 private void testFeatureWarmApi(boolean instant) throws Exception { 573 new InstallMultiple(instant).addFile(APK).addFile(APK_FEATURE_WARM) 574 .addFile(APK_FEATURE_WARM_v7).run(); 575 runDeviceTests(PKG, CLASS, "testFeatureWarmApi"); 576 } 577 578 @Test 579 @AppModeFull(reason = "'full' portion of the hostside test") testInheritUpdatedBase_full()580 public void testInheritUpdatedBase_full() throws Exception { 581 testInheritUpdatedBase(false); 582 } 583 @Test 584 @AppModeInstant(reason = "'instant' portion of the hostside test") testInheritUpdatedBase_instant()585 public void testInheritUpdatedBase_instant() throws Exception { 586 testInheritUpdatedBase(true); 587 } testInheritUpdatedBase(boolean instant)588 public void testInheritUpdatedBase(boolean instant) throws Exception { 589 new InstallMultiple(instant).addFile(APK).addFile(APK_FEATURE_WARM).run(); 590 new InstallMultiple(instant).inheritFrom(PKG).addFile(APK_REVISION_A).run(); 591 runDeviceTests(PKG, CLASS, "testInheritUpdatedBase_withRevisionA", instant); 592 } 593 594 @Test 595 @AppModeFull(reason = "'full' portion of the hostside test") testInheritUpdatedSplit_full()596 public void testInheritUpdatedSplit_full() throws Exception { 597 testInheritUpdatedSplit(false); 598 } 599 @Test 600 @AppModeInstant(reason = "'instant' portion of the hostside test") testInheritUpdatedSplit_instant()601 public void testInheritUpdatedSplit_instant() throws Exception { 602 testInheritUpdatedSplit(true); 603 } testInheritUpdatedSplit(boolean instant)604 private void testInheritUpdatedSplit(boolean instant) throws Exception { 605 new InstallMultiple(instant).addFile(APK).addFile(APK_FEATURE_WARM).run(); 606 new InstallMultiple(instant).inheritFrom(PKG).addFile(APK_FEATURE_WARM_REVISION_A).run(); 607 runDeviceTests(PKG, CLASS, "testInheritUpdatedSplit_withRevisionA", instant); 608 } 609 610 @Test 611 @AppModeFull(reason = "'full' portion of the hostside test") testFeatureWithoutRestart_full()612 public void testFeatureWithoutRestart_full() throws Exception { 613 testFeatureWithoutRestart(false); 614 } 615 @Test 616 @AppModeInstant(reason = "'instant' portion of the hostside test") testFeatureWithoutRestart_instant()617 public void testFeatureWithoutRestart_instant() throws Exception { 618 testFeatureWithoutRestart(true); 619 } testFeatureWithoutRestart(boolean instant)620 private void testFeatureWithoutRestart(boolean instant) throws Exception { 621 // always install as a full app; we're testing that the instant app can be 622 // updated without restarting and need a broadcast receiver to ensure the 623 // correct behaviour. So, this component must be visible to instant apps. 624 new InstallMultiple().addFile(APK).run(); 625 626 new InstallMultiple(instant).addFile(APK_NO_RESTART_BASE).run(); 627 runDeviceTests(PKG, CLASS, "testBaseInstalled", instant); 628 new InstallMultiple(instant) 629 .addArg("--dont-kill") 630 .inheritFrom(PKG_NO_RESTART) 631 .addFile(APK_NO_RESTART_FEATURE) 632 .run(); 633 runDeviceTests(PKG, CLASS, "testFeatureInstalled", instant); 634 } 635 636 @Test 637 @AppModeFull(reason = "'full' portion of the hostside test") testRequiredSplitMissing_full()638 public void testRequiredSplitMissing_full() throws Exception { 639 testRequiredSplitMissing(false); 640 } 641 @Test 642 @AppModeInstant(reason = "'instant' portion of the hostside test") testRequiredSplitMissing_instant()643 public void testRequiredSplitMissing_instant() throws Exception { 644 testRequiredSplitMissing(true); 645 } testRequiredSplitMissing(boolean instant)646 private void testRequiredSplitMissing(boolean instant) throws Exception { 647 new InstallMultiple(instant).addFile(APK_NEED_SPLIT_BASE) 648 .runExpectingFailure("INSTALL_FAILED_MISSING_SPLIT"); 649 } 650 651 @Test 652 @AppModeFull(reason = "'full' portion of the hostside test") testRequiredSplitInstalledFeatureWarm_full()653 public void testRequiredSplitInstalledFeatureWarm_full() throws Exception { 654 testRequiredSplitInstalledFeatureWarm(false); 655 } 656 @Test 657 @AppModeInstant(reason = "'instant' portion of the hostside test") testRequiredSplitInstalledFeatureWarm_instant()658 public void testRequiredSplitInstalledFeatureWarm_instant() throws Exception { 659 testRequiredSplitInstalledFeatureWarm(true); 660 } testRequiredSplitInstalledFeatureWarm(boolean instant)661 private void testRequiredSplitInstalledFeatureWarm(boolean instant) throws Exception { 662 new InstallMultiple(instant).addFile(APK_NEED_SPLIT_BASE) 663 .addFile(APK_NEED_SPLIT_FEATURE_WARM).run(); 664 } 665 666 @Test 667 @AppModeFull(reason = "'full' portion of the hostside test") testRequiredSplitInstalledConfig_full()668 public void testRequiredSplitInstalledConfig_full() throws Exception { 669 testRequiredSplitInstalledConfig(false); 670 } 671 @Test 672 @AppModeInstant(reason = "'instant' portion of the hostside test") testRequiredSplitInstalledConfig_instant()673 public void testRequiredSplitInstalledConfig_instant() throws Exception { 674 testRequiredSplitInstalledConfig(true); 675 } testRequiredSplitInstalledConfig(boolean instant)676 private void testRequiredSplitInstalledConfig(boolean instant) throws Exception { 677 new InstallMultiple(instant).addFile(APK_NEED_SPLIT_BASE).addFile(APK_NEED_SPLIT_CONFIG) 678 .run(); 679 } 680 681 @Test 682 @AppModeFull(reason = "'full' portion of the hostside test") testRequiredSplitRemoved_full()683 public void testRequiredSplitRemoved_full() throws Exception { 684 testRequiredSplitRemoved(false); 685 } 686 @Test 687 @AppModeInstant(reason = "'instant' portion of the hostside test") testRequiredSplitRemoved_instant()688 public void testRequiredSplitRemoved_instant() throws Exception { 689 testRequiredSplitRemoved(true); 690 } testRequiredSplitRemoved(boolean instant)691 private void testRequiredSplitRemoved(boolean instant) throws Exception { 692 // start with a base and two splits 693 new InstallMultiple(instant) 694 .addFile(APK_NEED_SPLIT_BASE) 695 .addFile(APK_NEED_SPLIT_FEATURE_WARM) 696 .addFile(APK_NEED_SPLIT_CONFIG) 697 .run(); 698 // it's okay to remove one of the splits 699 new InstallMultiple(instant).inheritFrom(PKG).removeSplit("feature_warm").run(); 700 // but, not to remove all of them 701 new InstallMultiple(instant).inheritFrom(PKG).removeSplit("config.xxhdpi") 702 .runExpectingFailure("INSTALL_FAILED_MISSING_SPLIT"); 703 } 704 705 /** 706 * Verify that installing a new version of app wipes code cache. 707 */ 708 @Test 709 @AppModeFull(reason = "'full' portion of the hostside test") testClearCodeCache_full()710 public void testClearCodeCache_full() throws Exception { 711 testClearCodeCache(false); 712 } 713 @Test 714 @AppModeInstant(reason = "'instant' portion of the hostside test") testClearCodeCache_instant()715 public void testClearCodeCache_instant() throws Exception { 716 testClearCodeCache(true); 717 } testClearCodeCache(boolean instant)718 private void testClearCodeCache(boolean instant) throws Exception { 719 new InstallMultiple(instant).addFile(APK).run(); 720 runDeviceTests(PKG, CLASS, "testCodeCacheWrite"); 721 new InstallMultiple(instant).addArg("-r").addFile(APK_DIFF_VERSION).run(); 722 runDeviceTests(PKG, CLASS, "testCodeCacheRead"); 723 } 724 725 @Test 726 @AppModeInstant(reason = "'instant' portion of the hostside test") testComponentWithSplitName_instant()727 public void testComponentWithSplitName_instant() throws Exception { 728 new InstallMultiple(true).addFile(APK_INSTANT).run(); 729 runDeviceTests(PKG, CLASS, "testComponentWithSplitName_singleBase"); 730 new InstallMultiple(true).inheritFrom(PKG).addFile(APK_FEATURE_WARM).run(); 731 runDeviceTests(PKG, CLASS, "testComponentWithSplitName_featureWarmInstalled"); 732 } 733 734 @Test 735 @AppModeFull(reason = "'full' portion of the hostside test") testTheme_installBase_full()736 public void testTheme_installBase_full() throws Exception { 737 testTheme_installBase(false); 738 } 739 @Test 740 @AppModeInstant(reason = "'instant' portion of the hostside test") testTheme_installBase_instant()741 public void testTheme_installBase_instant() throws Exception { 742 testTheme_installBase(true); 743 } testTheme_installBase(boolean instant)744 private void testTheme_installBase(boolean instant) throws Exception { 745 new InstallMultiple(instant).addFile(APK).run(); 746 runDeviceTests(PKG, CLASS, "launchBaseActivity_withThemeBase_baseApplied"); 747 } 748 749 @Test 750 @AppModeFull(reason = "'full' portion of the hostside test") testTheme_installBaseV23_full()751 public void testTheme_installBaseV23_full() throws Exception { 752 testTheme_installBaseV23(false); 753 } 754 @Test 755 @AppModeInstant(reason = "'instant' portion of the hostside test") testTheme_installBaseV23_instant()756 public void testTheme_installBaseV23_instant() throws Exception { 757 testTheme_installBaseV23(true); 758 } testTheme_installBaseV23(boolean instant)759 private void testTheme_installBaseV23(boolean instant) throws Exception { 760 new InstallMultiple(instant).addFile(APK).addFile(APK_v23).run(); 761 runDeviceTests(PKG, CLASS, "launchBaseActivity_withThemeBaseLt_baseLtApplied"); 762 } 763 764 @Test 765 @AppModeFull(reason = "'full' portion of the hostside test") testTheme_installFeatureWarm_full()766 public void testTheme_installFeatureWarm_full() throws Exception { 767 testTheme_installFeatureWarm(false); 768 } 769 @Test 770 @AppModeInstant(reason = "'instant' portion of the hostside test") testTheme_installFeatureWarm_instant()771 public void testTheme_installFeatureWarm_instant() throws Exception { 772 testTheme_installFeatureWarm(true); 773 } testTheme_installFeatureWarm(boolean instant)774 private void testTheme_installFeatureWarm(boolean instant) throws Exception { 775 new InstallMultiple(instant).addFile(APK).addFile(APK_FEATURE_WARM).run(); 776 runDeviceTests(PKG, CLASS, "launchBaseActivity_withThemeWarm_warmApplied"); 777 runDeviceTests(PKG, CLASS, "launchWarmActivity_withThemeBase_baseApplied"); 778 runDeviceTests(PKG, CLASS, "launchWarmActivity_withThemeWarm_warmApplied"); 779 } 780 781 @Test 782 @AppModeFull(reason = "'full' portion of the hostside test") testTheme_installFeatureWarmV23_full()783 public void testTheme_installFeatureWarmV23_full() throws Exception { 784 testTheme_installFeatureWarmV23(false); 785 } 786 @Test 787 @AppModeInstant(reason = "'instant' portion of the hostside test") testTheme_installFeatureWarmV23_instant()788 public void testTheme_installFeatureWarmV23_instant() throws Exception { 789 testTheme_installFeatureWarmV23(true); 790 } testTheme_installFeatureWarmV23(boolean instant)791 private void testTheme_installFeatureWarmV23(boolean instant) throws Exception { 792 new InstallMultiple(instant).addFile(APK).addFile(APK_v23).addFile(APK_FEATURE_WARM) 793 .addFile(APK_FEATURE_WARM_v23).run(); 794 runDeviceTests(PKG, CLASS, "launchBaseActivity_withThemeWarmLt_warmLtApplied"); 795 runDeviceTests(PKG, CLASS, "launchWarmActivity_withThemeBaseLt_baseLtApplied"); 796 runDeviceTests(PKG, CLASS, "launchWarmActivity_withThemeWarmLt_warmLtApplied"); 797 } 798 799 @Test 800 @AppModeFull(reason = "'full' portion of the hostside test") testTheme_installFeatureWarmV23_removeV23_full()801 public void testTheme_installFeatureWarmV23_removeV23_full() throws Exception { 802 testTheme_installFeatureWarmV23_removeV23(false); 803 } 804 @Test 805 @AppModeInstant(reason = "'instant' portion of the hostside test") testTheme_installFeatureWarmV23_removeV23_instant()806 public void testTheme_installFeatureWarmV23_removeV23_instant() throws Exception { 807 testTheme_installFeatureWarmV23_removeV23(true); 808 } testTheme_installFeatureWarmV23_removeV23(boolean instant)809 private void testTheme_installFeatureWarmV23_removeV23(boolean instant) throws Exception { 810 new InstallMultiple(instant).addFile(APK).addFile(APK_v23).addFile(APK_FEATURE_WARM) 811 .addFile(APK_FEATURE_WARM_v23).run(); 812 new InstallMultiple(instant).inheritFrom(PKG).removeSplit("config.v23") 813 .removeSplit("feature_warm.config.v23").run(); 814 runDeviceTests(PKG, CLASS, "launchBaseActivity_withThemeWarm_warmApplied"); 815 runDeviceTests(PKG, CLASS, "launchWarmActivity_withThemeBase_baseApplied"); 816 runDeviceTests(PKG, CLASS, "launchWarmActivity_withThemeWarm_warmApplied"); 817 } 818 819 @Test 820 @AppModeFull(reason = "'full' portion of the hostside test") testTheme_installFeatureWarmAndRose_full()821 public void testTheme_installFeatureWarmAndRose_full() throws Exception { 822 testTheme_installFeatureWarmAndRose(false); 823 } 824 @Test 825 @AppModeInstant(reason = "'instant' portion of the hostside test") testTheme_installFeatureWarmAndRose_instant()826 public void testTheme_installFeatureWarmAndRose_instant() throws Exception { 827 testTheme_installFeatureWarmAndRose(true); 828 } testTheme_installFeatureWarmAndRose(boolean instant)829 private void testTheme_installFeatureWarmAndRose(boolean instant) throws Exception { 830 new InstallMultiple(instant).addFile(APK).addFile(APK_FEATURE_WARM) 831 .addFile(APK_FEATURE_ROSE).run(); 832 runDeviceTests(PKG, CLASS, "launchWarmActivity_withThemeWarm_warmApplied"); 833 runDeviceTests(PKG, CLASS, "launchWarmActivity_withThemeRose_roseApplied"); 834 runDeviceTests(PKG, CLASS, "launchRoseActivity_withThemeWarm_warmApplied"); 835 runDeviceTests(PKG, CLASS, "launchRoseActivity_withThemeRose_roseApplied"); 836 } 837 838 @Test 839 @AppModeFull(reason = "'full' portion of the hostside test") testTheme_installFeatureWarmAndRoseV23_full()840 public void testTheme_installFeatureWarmAndRoseV23_full() throws Exception { 841 testTheme_installFeatureWarmAndRoseV23(false); 842 } 843 @Test 844 @AppModeInstant(reason = "'instant' portion of the hostside test") testTheme_installFeatureWarmAndRoseV23_instant()845 public void testTheme_installFeatureWarmAndRoseV23_instant() throws Exception { 846 testTheme_installFeatureWarmAndRoseV23(true); 847 } testTheme_installFeatureWarmAndRoseV23(boolean instant)848 private void testTheme_installFeatureWarmAndRoseV23(boolean instant) throws Exception { 849 new InstallMultiple(instant).addFile(APK).addFile(APK_v23) 850 .addFile(APK_FEATURE_WARM).addFile(APK_FEATURE_WARM_v23) 851 .addFile(APK_FEATURE_ROSE).addFile(APK_FEATURE_ROSE_v23).run(); 852 runDeviceTests(PKG, CLASS, "launchWarmActivity_withThemeWarmLt_warmLtApplied"); 853 runDeviceTests(PKG, CLASS, "launchWarmActivity_withThemeRoseLt_roseLtApplied"); 854 runDeviceTests(PKG, CLASS, "launchRoseActivity_withThemeWarmLt_warmLtApplied"); 855 runDeviceTests(PKG, CLASS, "launchRoseActivity_withThemeRoseLt_roseLtApplied"); 856 } 857 } 858