blob: 673c6a39f4b358f0d6a2de03df09ef542bea528d [file] [log] [blame]
Patrick Baumann88c1e2a2020-01-30 09:53:01 -08001/*
2 * Copyright (C) 2020 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
17package android.os;
18
19import static libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges;
20import static libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges;
21
22import android.compat.testing.PlatformCompatChangeRule;
23import android.content.ComponentName;
24import android.content.Context;
25import android.content.Intent;
26import android.content.pm.PackageManager;
27import android.perftests.utils.BenchmarkState;
28import android.perftests.utils.PerfStatusReporter;
29
30import androidx.test.ext.junit.runners.AndroidJUnit4;
31import androidx.test.filters.LargeTest;
32import androidx.test.platform.app.InstrumentationRegistry;
33
Patrick Baumannd3990132020-02-21 13:16:19 -080034import org.junit.Before;
Patrick Baumann88c1e2a2020-01-30 09:53:01 -080035import org.junit.Rule;
36import org.junit.Test;
37import org.junit.runner.RunWith;
38
39@RunWith(AndroidJUnit4.class)
40@LargeTest
41public class PackageManagerPerfTest {
42 private static final String PERMISSION_NAME_EXISTS =
43 "com.android.perftests.packagemanager.TestPermission";
44 private static final String PERMISSION_NAME_DOESNT_EXIST =
45 "com.android.perftests.packagemanager.TestBadPermission";
Patrick Baumann88c1e2a2020-01-30 09:53:01 -080046 private static final ComponentName TEST_ACTIVITY =
Patrick Baumann1e753632020-03-02 13:53:53 -080047 new ComponentName("com.android.perftests.packagemanager",
Patrick Baumann88c1e2a2020-01-30 09:53:01 -080048 "android.perftests.utils.PerfTestActivity");
49
50 @Rule
51 public final PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
52
53 @Rule
54 public final PlatformCompatChangeRule mPlatformCompatChangeRule =
55 new PlatformCompatChangeRule();
56
57 public PackageManagerPerfTest() throws PackageManager.NameNotFoundException {
58 final Context context = InstrumentationRegistry.getInstrumentation().getContext();
59 }
60
Patrick Baumannd3990132020-02-21 13:16:19 -080061 @Before
62 public void setup() {
63 PackageManager.disableApplicationInfoCache();
64 PackageManager.disablePackageInfoCache();
65 }
66
Patrick Baumann88c1e2a2020-01-30 09:53:01 -080067 @Test
68 @DisableCompatChanges(PackageManager.FILTER_APPLICATION_QUERY)
69 public void testCheckPermissionExists() {
70 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
71 final PackageManager pm =
72 InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageManager();
73 final String packageName = TEST_ACTIVITY.getPackageName();
74
75 while (state.keepRunning()) {
76 int ret = pm.checkPermission(PERMISSION_NAME_EXISTS, packageName);
77 }
78 }
79
80 @Test
81 @EnableCompatChanges(PackageManager.FILTER_APPLICATION_QUERY)
82 public void testCheckPermissionExistsWithFiltering() {
83 testCheckPermissionExists();
84 }
85
86 @Test
87 @DisableCompatChanges(PackageManager.FILTER_APPLICATION_QUERY)
88 public void testCheckPermissionDoesntExist() {
89 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
90 final PackageManager pm =
91 InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageManager();
92 final String packageName = TEST_ACTIVITY.getPackageName();
93
94 while (state.keepRunning()) {
95 int ret = pm.checkPermission(PERMISSION_NAME_DOESNT_EXIST, packageName);
96 }
97 }
98
99 @Test
100 @EnableCompatChanges(PackageManager.FILTER_APPLICATION_QUERY)
101 public void testCheckPermissionDoesntExistWithFiltering() {
102 testCheckPermissionDoesntExist();
103 }
104
105 @Test
106 @DisableCompatChanges(PackageManager.FILTER_APPLICATION_QUERY)
107 public void testQueryIntentActivities() {
108 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
109 final PackageManager pm =
110 InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageManager();
111 final Intent intent = new Intent("com.android.perftests.core.PERFTEST");
112
113 while (state.keepRunning()) {
114 pm.queryIntentActivities(intent, 0);
115 }
116 }
117
118 @Test
119 @EnableCompatChanges(PackageManager.FILTER_APPLICATION_QUERY)
120 public void testQueryIntentActivitiesWithFiltering() {
121 testQueryIntentActivities();
122 }
123
124 @Test
125 @DisableCompatChanges(PackageManager.FILTER_APPLICATION_QUERY)
126 public void testGetPackageInfo() throws Exception {
127 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
128 final PackageManager pm =
129 InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageManager();
130
131 while (state.keepRunning()) {
Patrick Baumann1e753632020-03-02 13:53:53 -0800132 pm.getPackageInfo(TEST_ACTIVITY.getPackageName(), 0);
Patrick Baumann88c1e2a2020-01-30 09:53:01 -0800133 }
134 }
135
136 @Test
137 @EnableCompatChanges(PackageManager.FILTER_APPLICATION_QUERY)
138 public void testGetPackageInfoWithFiltering() throws Exception {
139 testGetPackageInfo();
140 }
141
142 @Test
143 @DisableCompatChanges(PackageManager.FILTER_APPLICATION_QUERY)
144 public void testGetApplicationInfo() throws Exception {
145 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
146 final PackageManager pm =
147 InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageManager();
148
149 while (state.keepRunning()) {
Patrick Baumann1e753632020-03-02 13:53:53 -0800150 pm.getApplicationInfo(TEST_ACTIVITY.getPackageName(), 0);
Patrick Baumann88c1e2a2020-01-30 09:53:01 -0800151 }
152 }
153
154 @Test
155 @EnableCompatChanges(PackageManager.FILTER_APPLICATION_QUERY)
156 public void testGetApplicationInfoWithFiltering() throws Exception {
157 testGetApplicationInfo();
158 }
159
160 @Test
161 @DisableCompatChanges(PackageManager.FILTER_APPLICATION_QUERY)
162 public void testGetActivityInfo() throws Exception {
163 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
164 final PackageManager pm =
165 InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageManager();
166
167 while (state.keepRunning()) {
168 pm.getActivityInfo(TEST_ACTIVITY, 0);
169 }
170 }
171
172 @Test
173 @EnableCompatChanges(PackageManager.FILTER_APPLICATION_QUERY)
174 public void testGetActivityInfoWithFiltering() throws Exception {
175 testGetActivityInfo();
176 }
177
178 @Test
179 @DisableCompatChanges(PackageManager.FILTER_APPLICATION_QUERY)
180 public void testGetInstalledPackages() throws Exception {
181 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
182 final PackageManager pm =
183 InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageManager();
184
185 while (state.keepRunning()) {
186 pm.getInstalledPackages(0);
187 }
188 }
189
190 @Test
191 @EnableCompatChanges(PackageManager.FILTER_APPLICATION_QUERY)
192 public void testGetInstalledPackagesWithFiltering() throws Exception {
193 testGetInstalledPackages();
194 }
195}