1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  */
16 package android.appsecurity.cts;
17 
18 import android.platform.test.annotations.AppModeFull;
19 import android.platform.test.annotations.AppModeInstant;
20 
21 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
22 
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 
28 import java.io.FileNotFoundException;
29 
30 @RunWith(DeviceJUnit4ClassRunner.class)
31 public class IsolatedSplitsTests extends BaseAppSecurityTest {
32     private static final String PKG = "com.android.cts.isolatedsplitapp";
33     private static final String TEST_CLASS = PKG + ".SplitAppTest";
34 
35     /* The feature hierarchy looks like this:
36 
37         APK_BASE <- APK_FEATURE_A <- APK_FEATURE_B
38             ^------ APK_FEATURE_C
39 
40      */
41     private static final String APK_BASE = "CtsIsolatedSplitApp.apk";
42     private static final String APK_BASE_pl = "CtsIsolatedSplitApp_pl.apk";
43     private static final String APK_FEATURE_A = "CtsIsolatedSplitAppFeatureA.apk";
44     private static final String APK_FEATURE_A_pl = "CtsIsolatedSplitAppFeatureA_pl.apk";
45     private static final String APK_FEATURE_B = "CtsIsolatedSplitAppFeatureB.apk";
46     private static final String APK_FEATURE_B_pl = "CtsIsolatedSplitAppFeatureB_pl.apk";
47     private static final String APK_FEATURE_C = "CtsIsolatedSplitAppFeatureC.apk";
48     private static final String APK_FEATURE_C_pl = "CtsIsolatedSplitAppFeatureC_pl.apk";
49     private static final String APK_FEATURE_A_DiffRev = "CtsIsolatedSplitAppFeatureADiffRev.apk";
50 
51     private static final String APK_BASE_WITHOUT_EXTRACTING = APK_BASE;
52     private static final String APK_FEATURE_JNI_WITHOUT_EXTRACTING =
53             "CtsIsolatedSplitAppExtractNativeLibsFalseJni.apk";
54     private static final String APK_FEATURE_PROVIDER_A_WITHOUT_EXTRACTING =
55             "CtsIsolatedSplitAppExtractNativeLibsFalseNumberProviderA.apk";
56     private static final String APK_FEATURE_PROVIDER_B_WITHOUT_EXTRACTING =
57             "CtsIsolatedSplitAppExtractNativeLibsFalseNumberProviderB.apk";
58     private static final String APK_FEATURE_PROXY_WITHOUT_EXTRACTING =
59             "CtsIsolatedSplitAppExtractNativeLibsFalseNumberProxy.apk";
60 
61     private static final String APK_BASE_WITH_EXTRACTING =
62             "CtsIsolatedSplitAppExtractNativeLibsTrue.apk";
63     private static final String APK_FEATURE_JNI_WITH_EXTRACTING =
64             "CtsIsolatedSplitAppExtractNativeLibsTrueJni.apk";
65     private static final String APK_FEATURE_PROVIDER_A_WITH_EXTRACTING =
66             "CtsIsolatedSplitAppExtractNativeLibsTrueNumberProviderA.apk";
67     private static final String APK_FEATURE_PROVIDER_B_WITH_EXTRACTING =
68             "CtsIsolatedSplitAppExtractNativeLibsTrueNumberProviderB.apk";
69     private static final String APK_FEATURE_PROXY_WITH_EXTRACTING =
70             "CtsIsolatedSplitAppExtractNativeLibsTrueNumberProxy.apk";
71 
72     @Before
setUp()73     public void setUp() throws Exception {
74         Utils.prepareSingleUser(getDevice());
75         getDevice().uninstallPackage(PKG);
76     }
77 
78     @After
tearDown()79     public void tearDown() throws Exception {
80         getDevice().uninstallPackage(PKG);
81     }
82 
83     @Test
84     @AppModeFull(reason = "'full' portion of the hostside test")
testInstallBase_full()85     public void testInstallBase_full() throws Exception {
86         testInstallBase(false);
87     }
88 
89     @Test
90     @AppModeInstant(reason = "'instant' portion of the hostside test")
testInstallBase_instant()91     public void testInstallBase_instant() throws Exception {
92         testInstallBase(true);
93     }
94 
testInstallBase(boolean instant)95     private void testInstallBase(boolean instant) throws Exception {
96         new InstallMultiple(instant).addFile(APK_BASE).run();
97         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS, "shouldLoadDefault");
98     }
99 
100     @Test
101     @AppModeFull(reason = "'full' portion of the hostside test")
testInstallBaseAndConfigSplit_full()102     public void testInstallBaseAndConfigSplit_full() throws Exception {
103         testInstallBaseAndConfigSplit(false);
104     }
105 
106     @Test
107     @AppModeInstant(reason = "'instant' portion of the hostside test")
testInstallBaseAndConfigSplit_instant()108     public void testInstallBaseAndConfigSplit_instant() throws Exception {
109         testInstallBaseAndConfigSplit(true);
110     }
111 
testInstallBaseAndConfigSplit(boolean instant)112     private void testInstallBaseAndConfigSplit(boolean instant) throws Exception {
113         new InstallMultiple(instant).addFile(APK_BASE).addFile(APK_BASE_pl).run();
114         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS, "shouldLoadPolishLocale");
115     }
116 
117     @Test
118     @AppModeFull(reason = "'full' portion of the hostside test")
testInstallMissingDependency_usesSplit_full()119     public void testInstallMissingDependency_usesSplit_full() throws Exception {
120         testInstallMissingDependency_usesSplit(false);
121     }
122 
123     @Test
124     @AppModeInstant(reason = "'instant' portion of the hostside test")
testInstallMissingDependency_usesSplit_instant()125     public void testInstallMissingDependency_usesSplit_instant() throws Exception {
126         testInstallMissingDependency_usesSplit(true);
127     }
128 
testInstallMissingDependency_usesSplit(boolean instant)129     private void testInstallMissingDependency_usesSplit(boolean instant) throws Exception {
130         new InstallMultiple(instant).addFile(APK_BASE).addFile(APK_FEATURE_B).runExpectingFailure();
131     }
132 
133     @Test
134     @AppModeFull(reason = "'full' portion of the hostside test")
testInstallMissingDependency_configForSplit_full()135     public void testInstallMissingDependency_configForSplit_full() throws Exception {
136         testInstallMissingDependency_configForSplit(false);
137     }
138 
139     @Test
140     @AppModeInstant(reason = "'instant' portion of the hostside test")
testInstallMissingDependency_configForSplit_instant()141     public void testInstallMissingDependency_configForSplit_instant() throws Exception {
142         testInstallMissingDependency_configForSplit(true);
143     }
144 
testInstallMissingDependency_configForSplit(boolean instant)145     private void testInstallMissingDependency_configForSplit(boolean instant) throws Exception {
146         new InstallMultiple(instant).addFile(APK_BASE).addFile(
147                 APK_FEATURE_A_pl).runExpectingFailure();
148     }
149 
150     @Test
151     @AppModeFull(reason = "b/109878606; instant applications can't send broadcasts to manifest "
152             + "receivers")
testInstallOneFeatureSplit_full()153     public void testInstallOneFeatureSplit_full() throws Exception {
154         testInstallOneFeatureSplit(false);
155     }
156 
testInstallOneFeatureSplit(boolean instant)157     private void testInstallOneFeatureSplit(boolean instant) throws Exception {
158         new InstallMultiple(instant).addFile(APK_BASE).addFile(APK_FEATURE_A).run();
159         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS, "shouldLoadDefault");
160         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
161                 "shouldLoadFeatureADefault");
162         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
163                 "shouldLoadFeatureAReceivers");
164     }
165 
166     @Test
167     @AppModeFull(reason = "'full' portion of the hostside test")
testInstallOneFeatureSplitAndConfigSplits_full()168     public void testInstallOneFeatureSplitAndConfigSplits_full() throws Exception {
169         testInstallOneFeatureSplitAndConfigSplits(false);
170     }
171 
172     @Test
173     @AppModeInstant(reason = "'instant' portion of the hostside test")
testInstallOneFeatureSplitAndConfigSplits_instant()174     public void testInstallOneFeatureSplitAndConfigSplits_instant() throws Exception {
175         testInstallOneFeatureSplitAndConfigSplits(true);
176     }
177 
testInstallOneFeatureSplitAndConfigSplits(boolean instant)178     private void testInstallOneFeatureSplitAndConfigSplits(boolean instant) throws Exception {
179         new InstallMultiple(instant).addFile(APK_BASE).addFile(APK_FEATURE_A).addFile(APK_BASE_pl)
180                 .addFile(APK_FEATURE_A_pl).run();
181         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS, "shouldLoadPolishLocale");
182         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
183                 "shouldLoadFeatureAPolishLocale");
184     }
185 
186     @Test
187     @AppModeFull(reason = "b/109878606; instant applications can't send broadcasts to manifest "
188             + "receivers")
testInstallDependentFeatureSplits_full()189     public void testInstallDependentFeatureSplits_full() throws Exception {
190         testInstallDependentFeatureSplits(false);
191     }
192 
testInstallDependentFeatureSplits(boolean instant)193     private void testInstallDependentFeatureSplits(boolean instant) throws Exception {
194         new InstallMultiple(instant)
195                 .addFile(APK_BASE).addFile(APK_FEATURE_A).addFile(APK_FEATURE_B).run();
196         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS, "shouldLoadDefault");
197         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
198                 "shouldLoadFeatureADefault");
199         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
200                 "shouldLoadFeatureBDefault");
201         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
202                 "shouldLoadFeatureAAndBReceivers");
203     }
204 
205     @Test
206     @AppModeFull(reason = "'full' portion of the hostside test")
testInstallDependentFeatureSplitsAndConfigSplits_full()207     public void testInstallDependentFeatureSplitsAndConfigSplits_full() throws Exception {
208         testInstallDependentFeatureSplitsAndConfigSplits(false);
209     }
210 
211     @Test
212     @AppModeInstant(reason = "'instant' portion of the hostside test")
testInstallDependentFeatureSplitsAndConfigSplits_instant()213     public void testInstallDependentFeatureSplitsAndConfigSplits_instant() throws Exception {
214         testInstallDependentFeatureSplitsAndConfigSplits(true);
215     }
216 
testInstallDependentFeatureSplitsAndConfigSplits(boolean instant)217     private void testInstallDependentFeatureSplitsAndConfigSplits(boolean instant)
218             throws Exception {
219         new InstallMultiple(instant).addFile(APK_BASE).addFile(APK_FEATURE_A).addFile(APK_FEATURE_B)
220                 .addFile(APK_BASE_pl).addFile(APK_FEATURE_A_pl).addFile(APK_FEATURE_B_pl).run();
221         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS, "shouldLoadPolishLocale");
222         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
223                 "shouldLoadFeatureAPolishLocale");
224         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
225                 "shouldLoadFeatureBPolishLocale");
226     }
227 
228     @Test
229     @AppModeFull(reason = "b/109878606; instant applications can't send broadcasts to manifest "
230             + "receivers")
testInstallAllFeatureSplits_full()231     public void testInstallAllFeatureSplits_full() throws Exception {
232         testInstallAllFeatureSplits(false);
233     }
234 
testInstallAllFeatureSplits(boolean instant)235     private void testInstallAllFeatureSplits(boolean instant) throws Exception {
236         new InstallMultiple(instant).addFile(APK_BASE).addFile(APK_FEATURE_A).addFile(APK_FEATURE_B)
237                 .addFile(APK_FEATURE_C).run();
238         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS, "shouldLoadDefault");
239         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
240                 "shouldLoadFeatureADefault");
241         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
242                 "shouldLoadFeatureBDefault");
243         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
244                 "shouldLoadFeatureCDefault");
245         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
246                 "shouldLoadFeatureAAndBAndCReceivers");
247     }
248 
249     @Test
250     @AppModeFull(reason = "'full' portion of the hostside test")
testInstallAllFeatureSplitsAndConfigSplits_full()251     public void testInstallAllFeatureSplitsAndConfigSplits_full() throws Exception {
252         testInstallAllFeatureSplitsAndConfigSplits(false);
253     }
254 
255     @Test
256     @AppModeInstant(reason = "'instant' portion of the hostside test")
testInstallAllFeatureSplitsAndConfigSplits_instant()257     public void testInstallAllFeatureSplitsAndConfigSplits_instant() throws Exception {
258         testInstallAllFeatureSplitsAndConfigSplits(true);
259     }
260 
testInstallAllFeatureSplitsAndConfigSplits(boolean instant)261     private void testInstallAllFeatureSplitsAndConfigSplits(boolean instant) throws Exception {
262         new InstallMultiple(instant).addFile(APK_BASE).addFile(APK_FEATURE_A).addFile(APK_FEATURE_B)
263                 .addFile(APK_FEATURE_C).addFile(APK_BASE_pl).addFile(APK_FEATURE_A_pl)
264                 .addFile(APK_FEATURE_C_pl).run();
265         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS, "shouldLoadDefault");
266         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
267                 "shouldLoadFeatureADefault");
268         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
269                 "shouldLoadFeatureBDefault");
270         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
271                 "shouldLoadFeatureCDefault");
272     }
273 
274     @Test
275     @AppModeFull(reason = "'full' portion of the hostside test")
testSplitsInheritInstall_full()276     public void testSplitsInheritInstall_full() throws Exception {
277         testSplitsInheritInstall(false);
278     }
279 
280     @Test
281     @AppModeInstant(reason = "'instant' portion of the hostside test")
testSplitsInheritInstall_instant()282     public void testSplitsInheritInstall_instant() throws Exception {
283         testSplitsInheritInstall(true);
284     }
285 
testSplitsInheritInstall(boolean instant)286     private void testSplitsInheritInstall(boolean instant) throws Exception {
287         new InstallMultiple(instant).addFile(APK_BASE).addFile(APK_FEATURE_A).addFile(APK_FEATURE_B)
288                 .addFile(APK_FEATURE_C).run();
289         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
290                 "shouldLoadFeatureADefault");
291 
292         new InstallMultiple(instant).inheritFrom(PKG).addFile(APK_FEATURE_A_DiffRev).run();
293         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
294                 "shouldLoadFeatureADiffRevision");
295     }
296 
297     @Test
298     @AppModeFull(reason = "'full' portion of the hostside test")
testSplitsRemoved_full()299     public void testSplitsRemoved_full() throws Exception {
300         testSplitsRemoved(false);
301     }
302 
303     @Test
304     @AppModeInstant(reason = "'instant' portion of the hostside test")
testSplitsRemoved_instant()305     public void testSplitsRemoved_instant() throws Exception {
306         testSplitsRemoved(true);
307     }
308 
testSplitsRemoved(boolean instant)309     private void testSplitsRemoved(boolean instant) throws Exception {
310         new InstallMultiple(instant).addFile(APK_BASE).addFile(APK_FEATURE_A).addFile(APK_FEATURE_B)
311                 .addFile(APK_FEATURE_C).run();
312         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
313                 "shouldLoadFeatureCDefault");
314 
315         new InstallMultiple(instant).inheritFrom(PKG).removeSplit("feature_c").run();
316         Utils.runDeviceTestsAsCurrentUser(getDevice(), PKG, TEST_CLASS,
317                 "shouldNotFoundFeatureC");
318     }
319 
configureInstallMultiple(boolean instant, String...apks)320     private InstallMultiple configureInstallMultiple(boolean instant, String...apks)
321             throws FileNotFoundException {
322         InstallMultiple installMultiple = new InstallMultiple(instant);
323         for (String apk : apks) {
324             installMultiple.addFile(apk);
325         }
326         return installMultiple;
327     }
328 
329     @Test
330     @AppModeFull(reason = "'full' portion of the hostside test")
testNativeInstallable_extractNativeLibs_baseFalse_splitTrue_full()331     public void testNativeInstallable_extractNativeLibs_baseFalse_splitTrue_full()
332             throws Exception {
333         configureInstallMultiple(false, APK_BASE_WITHOUT_EXTRACTING,
334                 APK_FEATURE_JNI_WITH_EXTRACTING, APK_FEATURE_PROXY_WITH_EXTRACTING,
335                 APK_FEATURE_PROVIDER_A_WITH_EXTRACTING).runExpectingFailure(
336                 "INSTALL_FAILED_INVALID_APK");
337     }
338 
339     @Test
340     @AppModeInstant(reason = "'instant' portion of the hostside test")
testNativeInstallable_extractNativeLibs_baseFalse_splitTrue_instant()341     public void testNativeInstallable_extractNativeLibs_baseFalse_splitTrue_instant()
342             throws Exception {
343         configureInstallMultiple(true, APK_BASE_WITHOUT_EXTRACTING, APK_FEATURE_JNI_WITH_EXTRACTING,
344                 APK_FEATURE_PROXY_WITH_EXTRACTING,
345                 APK_FEATURE_PROVIDER_A_WITH_EXTRACTING).runExpectingFailure(
346                 "INSTALL_FAILED_INVALID_APK");
347     }
348 
349     @Test
350     @AppModeFull(reason = "'full' portion of the hostside test")
testNativeInstallable_extractNativeLibs_baseFalse_splitFalse_full()351     public void testNativeInstallable_extractNativeLibs_baseFalse_splitFalse_full()
352             throws Exception {
353         configureInstallMultiple(false, APK_BASE_WITHOUT_EXTRACTING,
354                 APK_FEATURE_JNI_WITHOUT_EXTRACTING, APK_FEATURE_PROXY_WITHOUT_EXTRACTING,
355                 APK_FEATURE_PROVIDER_A_WITHOUT_EXTRACTING).run();
356     }
357 
358     @Test
359     @AppModeInstant(reason = "'instant' portion of the hostside test")
testNativeInstallable_extractNativeLibs_baseFalse_splitFalse_instant()360     public void testNativeInstallable_extractNativeLibs_baseFalse_splitFalse_instant()
361             throws Exception {
362         configureInstallMultiple(true, APK_BASE_WITHOUT_EXTRACTING,
363                 APK_FEATURE_JNI_WITHOUT_EXTRACTING, APK_FEATURE_PROXY_WITHOUT_EXTRACTING,
364                 APK_FEATURE_PROVIDER_A_WITHOUT_EXTRACTING).run();
365     }
366 
367     @Test
368     @AppModeFull(reason = "'full' portion of the hostside test")
testNativeInstallable_extractNativeLibs_baseTrue_splitTrue_full()369     public void testNativeInstallable_extractNativeLibs_baseTrue_splitTrue_full()
370             throws Exception {
371         configureInstallMultiple(false, APK_BASE_WITH_EXTRACTING,
372                 APK_FEATURE_JNI_WITH_EXTRACTING,
373                 APK_FEATURE_PROXY_WITH_EXTRACTING, APK_FEATURE_PROVIDER_A_WITH_EXTRACTING).run();
374     }
375 
376     @Test
377     @AppModeInstant(reason = "'instant' portion of the hostside test")
testNativeInstallable_extractNativeLibs_baseTrue_splitTrue_instant()378     public void testNativeInstallable_extractNativeLibs_baseTrue_splitTrue_instant()
379             throws Exception {
380         configureInstallMultiple(true, APK_BASE_WITH_EXTRACTING, APK_FEATURE_JNI_WITH_EXTRACTING,
381                 APK_FEATURE_PROXY_WITH_EXTRACTING, APK_FEATURE_PROVIDER_A_WITH_EXTRACTING).run();
382     }
383 
384     @Test
385     @AppModeFull(reason = "'full' portion of the hostside test")
testNativeInstallable_extractNativeLibs_baseTrue_splitFalse_full()386     public void testNativeInstallable_extractNativeLibs_baseTrue_splitFalse_full()
387             throws Exception {
388         configureInstallMultiple(false, APK_BASE_WITH_EXTRACTING,
389                 APK_FEATURE_JNI_WITHOUT_EXTRACTING, APK_FEATURE_PROXY_WITHOUT_EXTRACTING,
390                 APK_FEATURE_PROVIDER_A_WITHOUT_EXTRACTING).run();
391     }
392 
393     @Test
394     @AppModeInstant(reason = "'instant' portion of the hostside test")
testNativeInstallable_extractNativeLibs_baseTrue_splitFalse_instant()395     public void testNativeInstallable_extractNativeLibs_baseTrue_splitFalse_instant()
396             throws Exception {
397         configureInstallMultiple(true, APK_BASE_WITH_EXTRACTING, APK_FEATURE_JNI_WITHOUT_EXTRACTING,
398                 APK_FEATURE_PROXY_WITHOUT_EXTRACTING,
399                 APK_FEATURE_PROVIDER_A_WITHOUT_EXTRACTING).run();
400     }
401 
402     @Test
403     @AppModeFull(reason = "'full' portion of the hostside test")
testAccessNativeSymbol_bothBaseAndSplitExtracting_full()404     public void testAccessNativeSymbol_bothBaseAndSplitExtracting_full() throws Exception {
405         testAccessNativeSymbol(false, true, APK_BASE_WITH_EXTRACTING,
406                 APK_FEATURE_JNI_WITH_EXTRACTING, APK_FEATURE_PROVIDER_A_WITH_EXTRACTING,
407                 APK_FEATURE_PROVIDER_B_WITH_EXTRACTING, APK_FEATURE_PROXY_WITH_EXTRACTING);
408     }
409 
410     @Test
411     @AppModeInstant(reason = "'instant' portion of the hostside test")
testAccessNativeSymbol_bothBaseAndSplitExtracting_instant()412     public void testAccessNativeSymbol_bothBaseAndSplitExtracting_instant() throws Exception {
413         testAccessNativeSymbol(true, true, APK_BASE_WITH_EXTRACTING,
414                 APK_FEATURE_JNI_WITH_EXTRACTING, APK_FEATURE_PROVIDER_A_WITH_EXTRACTING,
415                 APK_FEATURE_PROVIDER_B_WITH_EXTRACTING, APK_FEATURE_PROXY_WITH_EXTRACTING);
416     }
417 
418     @Test
419     @AppModeFull(reason = "'full' portion of the hostside test")
testAccessNativeSymbol_onlyBaseExtracting_full()420     public void testAccessNativeSymbol_onlyBaseExtracting_full() throws Exception {
421         testAccessNativeSymbol(false, true, APK_BASE_WITH_EXTRACTING,
422                 APK_FEATURE_JNI_WITHOUT_EXTRACTING, APK_FEATURE_PROVIDER_A_WITHOUT_EXTRACTING,
423                 APK_FEATURE_PROVIDER_B_WITHOUT_EXTRACTING, APK_FEATURE_PROXY_WITHOUT_EXTRACTING);
424     }
425 
426     @Test
427     @AppModeInstant(reason = "'instant' portion of the hostside test")
testAccessNativeSymbol_onlyBaseExtracting_instant()428     public void testAccessNativeSymbol_onlyBaseExtracting_instant() throws Exception {
429         testAccessNativeSymbol(true, true, APK_BASE_WITH_EXTRACTING,
430                 APK_FEATURE_JNI_WITHOUT_EXTRACTING, APK_FEATURE_PROVIDER_A_WITHOUT_EXTRACTING,
431                 APK_FEATURE_PROVIDER_B_WITHOUT_EXTRACTING, APK_FEATURE_PROXY_WITHOUT_EXTRACTING);
432     }
433 
434     @Test
435     @AppModeFull(reason = "'full' portion of the hostside test")
testAccessNativeSymbol_neitherBaseNorSplitExtracting_full()436     public void testAccessNativeSymbol_neitherBaseNorSplitExtracting_full() throws Exception {
437         testAccessNativeSymbol(false, false, APK_BASE_WITHOUT_EXTRACTING,
438                 APK_FEATURE_JNI_WITHOUT_EXTRACTING, APK_FEATURE_PROVIDER_A_WITHOUT_EXTRACTING,
439                 APK_FEATURE_PROVIDER_B_WITHOUT_EXTRACTING, APK_FEATURE_PROXY_WITHOUT_EXTRACTING);
440     }
441 
442     @Test
443     @AppModeInstant(reason = "'instant' portion of the hostside test")
testAccessNativeSymbol_neitherBaseNorSplitExtracting_instant()444     public void testAccessNativeSymbol_neitherBaseNorSplitExtracting_instant() throws Exception {
445         testAccessNativeSymbol(true, false, APK_BASE_WITHOUT_EXTRACTING,
446                 APK_FEATURE_JNI_WITHOUT_EXTRACTING, APK_FEATURE_PROVIDER_A_WITHOUT_EXTRACTING,
447                 APK_FEATURE_PROVIDER_B_WITHOUT_EXTRACTING, APK_FEATURE_PROXY_WITHOUT_EXTRACTING);
448     }
449 
testAccessNativeSymbol(boolean instant, boolean expectedLoadedLibrary, String baseApk, String jniApk, String providerAApk, String providerBApk, String providerProxyApk)450     private void testAccessNativeSymbol(boolean instant, boolean expectedLoadedLibrary,
451             String baseApk, String jniApk, String providerAApk, String providerBApk,
452             String providerProxyApk) throws Exception {
453         configureInstallMultiple(instant, baseApk, jniApk, providerAApk, providerBApk,
454                 providerProxyApk).run();
455         if (expectedLoadedLibrary) {
456             runDeviceTests(PKG, TEST_CLASS, "testNative_getNumberAViaProxy_shouldBeSeven");
457             runDeviceTests(PKG, TEST_CLASS, "testNative_getNumberBDirectly_shouldBeEleven");
458             runDeviceTests(PKG, TEST_CLASS, "testNative_getNumberADirectly_shouldBeSeven");
459             runDeviceTests(PKG, TEST_CLASS, "testNative_getNumberBViaProxy_shouldBeEleven");
460         } else {
461             runDeviceTests(PKG, TEST_CLASS, "testNative_cannotLoadSharedLibrary");
462             runDeviceTests(
463                     PKG,
464                     TEST_CLASS,
465                     "testNativeSplit_withoutExtractLibs_nativeLibraryCannotBeLoaded");
466         }
467     }
468 }
469