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

Commit 27ffd822 authored by Ben Gruver's avatar Ben Gruver Committed by Suprabh Shukla
Browse files

Fix ActivityStartInterceptor tests

This adds the SET_HARMFUL_APPS_WARNINGS permission required by
interceptHarmfulAppIfNeeded, and mocks out the new PackageManager calls
used by it
Test: atest ActivityStartInterceptorTest

Bug: 77607079
Change-Id: Iea9c183078261b03be984ba4e0fad271f1548945
Merged-In: Iea9c183078261b03be984ba4e0fad271f1548945
(cherry picked from commit eb8fd1c6)
parent 743d42d2
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
import static android.content.pm.ApplicationInfo.FLAG_SUSPENDED;

import android.app.ActivityOptions;
import android.app.AppGlobals;
import android.app.KeyguardManager;
import android.app.admin.DevicePolicyManagerInternal;
import android.content.Context;
@@ -293,9 +292,9 @@ class ActivityStartInterceptor {
    private boolean interceptHarmfulAppIfNeeded() {
        CharSequence harmfulAppWarning;
        try {
            harmfulAppWarning = AppGlobals.getPackageManager().getHarmfulAppWarning(
                    mAInfo.packageName, mUserId);
        } catch (RemoteException e) {
            harmfulAppWarning = mService.getPackageManager()
                    .getHarmfulAppWarning(mAInfo.packageName, mUserId);
        } catch (RemoteException ex) {
            return false;
        }

+8 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.testing.DexmakerShareClassLoaderRule;

import com.android.internal.app.UnlaunchableAppActivity;
import com.android.server.LocalServices;
import com.android.server.pm.PackageManagerService;

import org.junit.Before;
import org.junit.Rule;
@@ -84,6 +85,8 @@ public class ActivityStartInterceptorTest {
    private UserController mUserController;
    @Mock
    private KeyguardManager mKeyguardManager;
    @Mock
    private PackageManagerService mPackageManager;

    private ActivityStartInterceptor mInterceptor;
    private ActivityInfo mAInfo = new ActivityInfo();
@@ -114,6 +117,11 @@ public class ActivityStartInterceptorTest {
                nullable(CharSequence.class), nullable(CharSequence.class), eq(TEST_USER_ID))).
                thenReturn(CONFIRM_CREDENTIALS_INTENT);

        // Mock PackageManager
        when(mService.getPackageManager()).thenReturn(mPackageManager);
        when(mPackageManager.getHarmfulAppWarning(TEST_PACKAGE_NAME, TEST_USER_ID))
                .thenReturn(null);

        // Initialise activity info
        mAInfo.packageName = TEST_PACKAGE_NAME;
        mAInfo.applicationInfo = new ApplicationInfo();