summaryrefslogtreecommitdiff
path: root/hostsidetests/appsecurity/src/android/appsecurity/cts/EphemeralTest.java
blob: fbc01dfa51c3c0bead60bcbd03e7ec41df46e57d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package android.appsecurity.cts;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

import android.platform.test.annotations.AppModeFull;
import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper;
import com.android.tradefed.log.LogUtil.CLog;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Tests for ephemeral packages.
 */
@RunWith(DeviceJUnit4ClassRunner.class)
@AppModeFull(reason = "Already handles instant installs when needed")
public class EphemeralTest extends BaseAppSecurityTest {

    // a normally installed application
    private static final String NORMAL_APK = "CtsEphemeralTestsNormalApp.apk";
    private static final String NORMAL_PKG = "com.android.cts.normalapp";

    // the first ephemerally installed application
    private static final String EPHEMERAL_1_APK = "CtsEphemeralTestsEphemeralApp1.apk";
    private static final String EPHEMERAL_1_PKG = "com.android.cts.ephemeralapp1";

    // the second ephemerally installed application
    private static final String EPHEMERAL_2_APK = "CtsEphemeralTestsEphemeralApp2.apk";
    private static final String EPHEMERAL_2_PKG = "com.android.cts.ephemeralapp2";

    // a normally installed application with implicitly exposed components
    private static final String IMPLICIT_APK = "CtsEphemeralTestsImplicitApp.apk";
    private static final String IMPLICIT_PKG = "com.android.cts.implicitapp";

    // a normally installed application with no exposed components
    private static final String UNEXPOSED_APK = "CtsEphemeralTestsUnexposedApp.apk";
    private static final String UNEXPOSED_PKG = "com.android.cts.unexposedapp";

    // an application that gets upgraded from 'instant' to 'full'
    private static final String UPGRADED_APK = "CtsInstantUpgradeApp.apk";
    private static final String UPGRADED_PKG = "com.android.cts.instantupgradeapp";

    private static final String TEST_CLASS = ".ClientTest";
    private static final String WEBVIEW_TEST_CLASS = ".WebViewTest";

    private static final List<Map<String, String>> EXPECTED_EXPOSED_INTENTS =
            new ArrayList<>();
    static {
        // Framework intents we expect the system to expose to instant applications
        EXPECTED_EXPOSED_INTENTS.add(makeArgs(
                "android.intent.action.CHOOSER",
                null, null));
        // Contact intents we expect the system to expose to instant applications
        EXPECTED_EXPOSED_INTENTS.add(makeArgs(
                "android.intent.action.PICK", null, "vnd.android.cursor.dir/contact"));
        EXPECTED_EXPOSED_INTENTS.add(makeArgs(
                "android.intent.action.PICK", null, "vnd.android.cursor.dir/phone_v2"));
        EXPECTED_EXPOSED_INTENTS.add(makeArgs(
                "android.intent.action.PICK", null, "vnd.android.cursor.dir/email_v2"));
        EXPECTED_EXPOSED_INTENTS.add(makeArgs(
                "android.intent.action.PICK", null, "vnd.android.cursor.dir/postal-address_v2"));
        // Storage intents we expect the system to expose to instant applications
        EXPECTED_EXPOSED_INTENTS.add(makeArgs(
                "android.intent.action.OPEN_DOCUMENT",
                "android.intent.category.OPENABLE", "\\*/\\*"));
        EXPECTED_EXPOSED_INTENTS.add(makeArgs(
                "android.intent.action.OPEN_DOCUMENT", null, "\\*/\\*"));
        EXPECTED_EXPOSED_INTENTS.add(makeArgs(
                "android.intent.action.GET_CONTENT",
                "android.intent.category.OPENABLE", "\\*/\\*"));
        EXPECTED_EXPOSED_INTENTS.add(makeArgs(
                "android.intent.action.GET_CONTENT", null, "\\*/\\*"));
        EXPECTED_EXPOSED_INTENTS.add(makeArgs(
                "android.intent.action.OPEN_DOCUMENT_TREE", null, null));
        EXPECTED_EXPOSED_INTENTS.add(makeArgs(
                "android.intent.action.CREATE_DOCUMENT",
                "android.intent.category.OPENABLE", "text/plain"));
        EXPECTED_EXPOSED_INTENTS.add(makeArgs(
                "android.intent.action.CREATE_DOCUMENT", null, "text/plain"));
        /** Camera intents we expect the system to expose to instant applications */
        EXPECTED_EXPOSED_INTENTS.add(makeArgs(
                "android.media.action.IMAGE_CAPTURE", null, null));
        EXPECTED_EXPOSED_INTENTS.add(makeArgs(
                "android.media.action.VIDEO_CAPTURE", null, null));
    }

    private String mOldVerifierValue;
    private Boolean mIsUnsupportedDevice;

    @Before
    public void setUp() throws Exception {
        mIsUnsupportedDevice = isDeviceUnsupported();
        if (mIsUnsupportedDevice) {
            return;
        }

        Utils.prepareSingleUser(getDevice());
        assertNotNull(getAbi());
        assertNotNull(getBuild());

        uninstallTestPackages();
        installTestPackages();
    }

    @After
    public void tearDown() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        uninstallTestPackages();
    }

    @Test
    public void testNormalQuery() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), NORMAL_PKG, TEST_CLASS, "testQuery");
    }

    @Test
    public void testNormalStartNormal() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), NORMAL_PKG, TEST_CLASS, "testStartNormal");
    }

    @Test
    public void testNormalStartEphemeral() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), NORMAL_PKG, TEST_CLASS,
                "testStartEphemeral");
    }

    @Test
    public void testEphemeralQuery() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS, "testQuery");
    }

    @Test
    public void testEphemeralStartNormal() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testStartNormal");
    }

    // each connection to an exposed component needs to run in its own test to
    // avoid sharing state. once an instant app is exposed to a component, it's
    // exposed until the device restarts or the instant app is removed.
    @Test
    public void testEphemeralStartExposed01() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testStartExposed01");
    }
    @Test
    public void testEphemeralStartExposed02() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testStartExposed02");
    }
    @Test
    public void testEphemeralStartExposed03() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testStartExposed03");
    }
    @Test
    public void testEphemeralStartExposed04() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testStartExposed04");
    }
    @Test
    public void testEphemeralStartExposed05() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testStartExposed05");
    }
    @Test
    public void testEphemeralStartExposed06() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testStartExposed06");
    }
    @Test
    public void testEphemeralStartExposed07() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testStartExposed07");
    }
    @Test
    public void testEphemeralStartExposed08() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testStartExposed08");
    }
    @Test
    public void testEphemeralStartExposed09() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testStartExposed09");
    }
    @Test
    public void testEphemeralStartExposed10() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testStartExposed10");
    }
    @Test
    public void testEphemeralStartExposed11() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testStartExposed11");
    }

    @Test
    public void testEphemeralStartEphemeral() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testStartEphemeral");
    }

    @Test
    public void testEphemeralGetInstaller01() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        installEphemeralApp(EPHEMERAL_1_APK, "com.android.cts.normalapp");
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testGetInstaller01");
    }
    @Test
    public void testEphemeralGetInstaller02() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        installApp(NORMAL_APK, "com.android.cts.normalapp");
        installEphemeralApp(EPHEMERAL_1_APK, "com.android.cts.normalapp");
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testGetInstaller02");
    }
    @Test
    public void testEphemeralGetInstaller03() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        installApp(NORMAL_APK, "com.android.cts.normalapp");
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testGetInstaller03");
    }

    @Test
    public void testExposedSystemActivities() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        for (Map<String, String> testArgs : EXPECTED_EXPOSED_INTENTS) {
            final boolean exposed = isIntentExposed(testArgs);
            if (exposed) {
                Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                        "testExposedActivity", testArgs);
            } else {
                CLog.w("Skip intent; " + dumpArgs(testArgs));
            }
        }
    }

    @Test
    public void testBuildSerialUnknown() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testBuildSerialUnknown");
    }

    @Test
    public void testPackageInfo() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testPackageInfo");
    }

    @Test
    public void testActivityInfo() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testActivityInfo");
    }

    @Test
    public void testWebViewLoads() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, WEBVIEW_TEST_CLASS,
                "testWebViewLoads");
    }

    @Test
    public void testInstallPermissionNotGranted() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testInstallPermissionNotGranted");
    }

    @Test
    public void testInstallPermissionGranted() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testInstallPermissionGranted");
    }

    @Test
    public void testInstallPermissionNotGrantedInPackageInfo() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testInstallPermissionNotGrantedInPackageInfo");
    }

    @Test
    public void testInstallPermissionGrantedInPackageInfo() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testInstallPermissionGrantedInPackageInfo");
    }

    /** Test for android.permission.INSTANT_APP_FOREGROUND_SERVICE */
    @Test
    public void testStartForegroundService() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        // Make sure the test package does not have INSTANT_APP_FOREGROUND_SERVICE
        getDevice().executeShellCommand("cmd package revoke " + EPHEMERAL_1_PKG
                + " android.permission.INSTANT_APP_FOREGROUND_SERVICE");
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testStartForegroundService");
    }

    /** Test for android.permission.RECORD_AUDIO */
    @Test
    public void testRecordAudioPermission() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testRecordAudioPermission");
    }

    /** Test for android.permission.CAMERA */
    @Test
    public void testCameraPermission() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testCameraPermission");
    }

    /** Test for android.permission.READ_PHONE_NUMBERS */
    @Test
    public void testReadPhoneNumbersPermission() throws Exception {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testReadPhoneNumbersPermission");
    }

    /** Test for android.permission.ACCESS_COARSE_LOCATION */
    @Test
    public void testAccessCoarseLocationPermission() throws Throwable {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testAccessCoarseLocationPermission");
    }

    /** Test for android.permission.NETWORK */
    @Test
    public void testInternetPermission() throws Throwable {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testInternetPermission");
    }

    /** Test for android.permission.VIBRATE */
    @Test
    public void testVibratePermission() throws Throwable {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testVibratePermission");
    }

    /** Test for android.permission.WAKE_LOCK */
    @Test
    public void testWakeLockPermission() throws Throwable {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testWakeLockPermission");
    }

    /** Test for search manager */
    @Test
    public void testGetSearchableInfo() throws Throwable {
        if (mIsUnsupportedDevice) {
            return;
        }
        Utils.runDeviceTestsAsCurrentUser(getDevice(), EPHEMERAL_1_PKG, TEST_CLASS,
                "testGetSearchableInfo");
    }

    /** Test for upgrade from instant --> full */
    @Test
    public void testInstantAppUpgrade() throws Throwable {
        if (mIsUnsupportedDevice) {
            return;
        }
        installEphemeralApp(UPGRADED_APK);
        Utils.runDeviceTestsAsCurrentUser(getDevice(), UPGRADED_PKG, TEST_CLASS,
                "testInstantApplicationWritePreferences");
        Utils.runDeviceTestsAsCurrentUser(getDevice(), UPGRADED_PKG, TEST_CLASS,
                "testInstantApplicationWriteFile");
        installFullApp(UPGRADED_APK);
        Utils.runDeviceTestsAsCurrentUser(getDevice(), UPGRADED_PKG, TEST_CLASS,
                "testFullApplicationReadPreferences");
        Utils.runDeviceTestsAsCurrentUser(getDevice(), UPGRADED_PKG, TEST_CLASS,
                "testFullApplicationReadFile");
    }

    private static final HashMap<String, String> makeArgs(
            String action, String category, String mimeType) {
        if (action == null || action.length() == 0) {
            fail("action not specified");
        }
        final HashMap<String, String> testArgs = new HashMap<>();
        testArgs.put("action", action);
        if (category != null && category.length() > 0) {
            testArgs.put("category", category);
        }
        if (mimeType != null && mimeType.length() > 0) {
            testArgs.put("mime_type", mimeType);
        }
        return testArgs;
    }

    private static final String[] sUnsupportedFeatures = {
            "feature:android.hardware.type.watch",
            "android.hardware.type.embedded",
    };
    private boolean isDeviceUnsupported() throws Exception {
        for (String unsupportedFeature : sUnsupportedFeatures) {
            if (getDevice().hasFeature(unsupportedFeature)) {
                return true;
            }
        }
        return false;
    }

    private boolean isIntentExposed(Map<String, String> testArgs)
            throws Exception {
        final StringBuffer command = new StringBuffer();
        command.append("cmd package query-activities");
        command.append(" -a ").append(testArgs.get("action"));
        if (testArgs.get("category") != null) {
            command.append(" -c ").append(testArgs.get("category"));
        }
        if (testArgs.get("mime_type") != null) {
            command.append(" -t ").append(testArgs.get("mime_type"));
        }
        final String output = getDevice().executeShellCommand(command.toString()).trim();
        return !"No activities found".equals(output);
    }

    private static final String dumpArgs(Map<String, String> testArgs) {
        final StringBuffer dump = new StringBuffer();
        dump.append("action: ").append(testArgs.get("action"));
        if (testArgs.get("category") != null) {
            dump.append(", category: ").append(testArgs.get("category"));
        }
        if (testArgs.get("mime_type") != null) {
            dump.append(", type: ").append(testArgs.get("mime_type"));
        }
        return dump.toString();
    }

    private void installApp(String apk) throws Exception {
        new InstallMultiple(false /* instant */)
                .addFile(apk)
                .run();
    }

    private void installApp(String apk, String installer) throws Exception {
        new InstallMultiple(false /* instant */)
                .addFile(apk)
                .addArg("-i " + installer)
                .run();
    }

    private void installEphemeralApp(String apk) throws Exception {
        new InstallMultiple(true /* instant */)
                .addFile(apk)
                .run();
    }

    private void installEphemeralApp(String apk, String installer) throws Exception {
        new InstallMultiple(true /* instant */)
                .addFile(apk)
                .addArg("-i " + installer)
                .run();
    }

    private void installFullApp(String apk) throws Exception {
        new InstallMultiple(false /* instant */)
                .addFile(apk)
                .addArg("--full")
                .run();
    }

    private void installTestPackages() throws Exception {
        installApp(NORMAL_APK);
        installApp(UNEXPOSED_APK);
        installApp(IMPLICIT_APK);

        installEphemeralApp(EPHEMERAL_1_APK);
        installEphemeralApp(EPHEMERAL_2_APK);
    }

    private void uninstallTestPackages() throws Exception {
        uninstallPackage(NORMAL_PKG);
        uninstallPackage(UNEXPOSED_PKG);
        uninstallPackage(IMPLICIT_PKG);
        uninstallPackage(EPHEMERAL_1_PKG);
        uninstallPackage(EPHEMERAL_2_PKG);
        uninstallPackage(UPGRADED_PKG);
    }
}