Debian Codegraph @

apct-tests/perftests/packagemanager/src/android/os/PackageManagerPerfTest.java

raw symbols SCIP
1 /*
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
17 package android.os;
18
19 import static libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges;
20 import static libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges;
21
22 import android.compat.testing.PlatformCompatChangeRule;
23 import android.content.ComponentName;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.content.pm.PackageManager;
27 import android.perftests.utils.BenchmarkState;
28 import android.perftests.utils.PerfStatusReporter;
29
30 import androidx.test.ext.junit.runners.AndroidJUnit4;
31 import androidx.test.filters.LargeTest;
32 import androidx.test.platform.app.InstrumentationRegistry;
33
34 import org.junit.Before;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38
39 @RunWith(AndroidJUnit4.class)
40 @LargeTest
41 public 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";
46 private static final ComponentName TEST_ACTIVITY =
47 new ComponentName("com.android.perftests.packagemanager",
48 "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
61 @Before
62 public void setup() {
63 PackageManager.disableApplicationInfoCache();
64 PackageManager.disablePackageInfoCache();
65 }
66
67 @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()) {
132 pm.getPackageInfo(TEST_ACTIVITY.getPackageName(), 0);
133 }
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()) {
150 pm.getApplicationInfo(TEST_ACTIVITY.getPackageName(), 0);
151 }
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 }