1 /*
2  * Copyright (C) 2016 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 android.platform.test.annotations.AppModeInstant;
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 /**
29  * Tests for package resolution.
30  */
31 @RunWith(DeviceJUnit4ClassRunner.class)
32 public class PackageResolutionHostTest extends BaseAppSecurityTest {
33 
34     private static final String TINY_APK = "CtsOrderedActivityApp.apk";
35     private static final String TINY_PKG = "android.appsecurity.cts.orderedactivity";
36 
37     private String mOldVerifierValue;
38 
39     @Before
setUp()40     public void setUp() throws Exception {
41         getDevice().uninstallPackage(TINY_PKG);
42     }
43 
44     @After
tearDown()45     public void tearDown() throws Exception {
46         getDevice().uninstallPackage(TINY_PKG);
47     }
48 
49     @Test
50     @AppModeFull(reason = "'full' portion of the hostside test")
testResolveOrderedActivity_full()51     public void testResolveOrderedActivity_full() throws Exception {
52         testResolveOrderedActivity(false);
53     }
54     @Test
55     @AppModeInstant(reason = "'instant' portion of the hostside test")
testResolveOrderedActivity_instant()56     public void testResolveOrderedActivity_instant() throws Exception {
57         testResolveOrderedActivity(true);
58     }
testResolveOrderedActivity(boolean instant)59     private void testResolveOrderedActivity(boolean instant) throws Exception {
60         new InstallMultiple(instant)
61                 .addApk(TINY_APK)
62                 .run();
63         Utils.runDeviceTests(getDevice(), TINY_PKG,
64                 ".PackageResolutionTest", "queryActivityOrdered");
65     }
66 
67     @Test
68     @AppModeFull(reason = "'full' portion of the hostside test")
testResolveOrderedService_full()69     public void testResolveOrderedService_full() throws Exception {
70         testResolveOrderedService(false);
71     }
72     @Test
73     @AppModeInstant(reason = "'instant' portion of the hostside test")
testResolveOrderedService_instant()74     public void testResolveOrderedService_instant() throws Exception {
75         testResolveOrderedService(true);
76     }
testResolveOrderedService(boolean instant)77     private void testResolveOrderedService(boolean instant) throws Exception {
78         new InstallMultiple(instant)
79                 .addApk(TINY_APK)
80                 .run();
81         Utils.runDeviceTests(getDevice(), TINY_PKG,
82                 ".PackageResolutionTest", "queryServiceOrdered");
83     }
84 
85     @Test
86     @AppModeFull(reason = "'full' portion of the hostside test")
testResolveOrderedReceiver_full()87     public void testResolveOrderedReceiver_full() throws Exception {
88         testResolveOrderedReceiver(false);
89     }
90     @Test
91     @AppModeInstant(reason = "'instant' portion of the hostside test")
testResolveOrderedReceiver_instant()92     public void testResolveOrderedReceiver_instant() throws Exception {
93         testResolveOrderedReceiver(true);
94     }
testResolveOrderedReceiver(boolean instant)95     private void testResolveOrderedReceiver(boolean instant) throws Exception {
96         new InstallMultiple(instant)
97                 .addApk(TINY_APK)
98                 .run();
99         Utils.runDeviceTests(getDevice(), TINY_PKG,
100                 ".PackageResolutionTest", "queryReceiverOrdered");
101     }
102 }
103