Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 109057e0 authored by Todd Kennedy's avatar Todd Kennedy
Browse files

Add performance tests for query / get

Bug: 68777480
Test: m CorePerfTests
Test: adb install CorePerfTests.apk
Test: adb shell am instrument -w -e class android.os.PackageManagerPerfTest com.android.perftests.core/android.support.test.runner.AndroidJUnitRunner
Change-Id: I047d9d2e84665fe641a7c354a9f1b16c40f7ff31
parent 4e588baa
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -10,7 +10,11 @@

    <application>
        <uses-library android:name="android.test.runner" />
        <activity android:name="android.perftests.utils.StubActivity" />
        <activity android:name="android.perftests.utils.StubActivity">
          <intent-filter>
            <action android:name="com.android.perftests.core.PERFTEST" />
          </intent-filter>
        </activity>
        <service android:name="android.os.SomeService" android:exported="false" android:process=":some_service" />
    </application>

+114 −0
Original line number Diff line number Diff line
@@ -19,7 +19,10 @@ package android.os;
import static android.content.pm.PackageManager.PERMISSION_DENIED;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.perftests.utils.BenchmarkState;
import android.perftests.utils.PerfStatusReporter;
import android.support.test.InstrumentationRegistry;
@@ -33,34 +36,79 @@ import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class PermissionTest {
    private static final String PERMISSION_HAS_NAME = "com.android.perftests.core.TestPermission";
    private static final String PERMISSION_DOESNT_HAVE_NAME =
public class PackageManagerPerfTest {
    private static final String PERMISSION_NAME_EXISTS =
            "com.android.perftests.core.TestPermission";
    private static final String PERMISSION_NAME_DOESNT_EXIST =
            "com.android.perftests.core.TestBadPermission";
    private static final String THIS_PACKAGE_NAME = "com.android.perftests.core";
    private static final ComponentName TEST_ACTIVITY =
            new ComponentName("com.android.perftests.core", "android.perftests.utils.StubActivity");

    @Rule
    public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();

    @Test
    public void testHasPermission() {
    public void testCheckPermissionExists() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final Context context = InstrumentationRegistry.getTargetContext();
        final PackageManager pm = InstrumentationRegistry.getTargetContext().getPackageManager();
        final String packageName = TEST_ACTIVITY.getPackageName();

        while (state.keepRunning()) {
            int ret = pm.checkPermission(PERMISSION_NAME_EXISTS, packageName);
        }
    }

    @Test
    public void testCheckPermissionDoesntExist() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final PackageManager pm = InstrumentationRegistry.getTargetContext().getPackageManager();
        final String packageName = TEST_ACTIVITY.getPackageName();

        while (state.keepRunning()) {
            int ret = pm.checkPermission(PERMISSION_NAME_DOESNT_EXIST, packageName);
        }
    }

    @Test
    public void testQueryIntentActivities() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final PackageManager pm = InstrumentationRegistry.getTargetContext().getPackageManager();
        final Intent intent = new Intent("com.android.perftests.core.PERFTEST");

        while (state.keepRunning()) {
            pm.queryIntentActivities(intent, 0);
        }
    }

    @Test
    public void testGetPackageInfo() throws Exception {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final PackageManager pm = InstrumentationRegistry.getTargetContext().getPackageManager();
        final String packageName = TEST_ACTIVITY.getPackageName();

        while (state.keepRunning()) {
            int ret = context.getPackageManager().checkPermission(PERMISSION_HAS_NAME,
                    THIS_PACKAGE_NAME);
            pm.getPackageInfo(packageName, 0);
        }
    }

    @Test
    public void testDoesntHavePermission() {
    public void testGetApplicationInfo() throws Exception {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final Context context = InstrumentationRegistry.getTargetContext();
        final PackageManager pm = InstrumentationRegistry.getTargetContext().getPackageManager();
        final String packageName = TEST_ACTIVITY.getPackageName();
        
        while (state.keepRunning()) {
            int ret = context.getPackageManager().checkPermission(PERMISSION_DOESNT_HAVE_NAME,
                    THIS_PACKAGE_NAME);
            pm.getApplicationInfo(packageName, 0);
        }
    }

    @Test
    public void testGetActivityInfo() throws Exception {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final PackageManager pm = InstrumentationRegistry.getTargetContext().getPackageManager();
        
        while (state.keepRunning()) {
            pm.getActivityInfo(TEST_ACTIVITY, 0);
        }
    }
}