From eb8fd1c68220bf771167051108a4f89a0eccec40 Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Wed, 7 Mar 2018 13:24:18 -0800 Subject: [PATCH] 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 Change-Id: Iea9c183078261b03be984ba4e0fad271f1548945 --- .../android/server/am/ActivityStartInterceptor.java | 7 +++---- .../server/am/ActivityStartInterceptorTest.java | 10 ++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityStartInterceptor.java b/services/core/java/com/android/server/am/ActivityStartInterceptor.java index b86a8a6f2a8dd..46f7c5eefc9e5 100644 --- a/services/core/java/com/android/server/am/ActivityStartInterceptor.java +++ b/services/core/java/com/android/server/am/ActivityStartInterceptor.java @@ -31,7 +31,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; @@ -289,9 +288,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; } diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityStartInterceptorTest.java b/services/tests/servicestests/src/com/android/server/am/ActivityStartInterceptorTest.java index 194f4ae51a62b..e02f64daaefd8 100644 --- a/services/tests/servicestests/src/com/android/server/am/ActivityStartInterceptorTest.java +++ b/services/tests/servicestests/src/com/android/server/am/ActivityStartInterceptorTest.java @@ -33,10 +33,12 @@ import android.content.pm.ApplicationInfo; import android.content.pm.UserInfo; import android.os.UserHandle; import android.os.UserManager; +import android.platform.test.annotations.Presubmit; import android.support.test.filters.SmallTest; import com.android.internal.app.UnlaunchableAppActivity; import com.android.server.LocalServices; +import com.android.server.pm.PackageManagerService; import org.junit.Before; import org.junit.Test; @@ -49,6 +51,7 @@ import org.mockito.MockitoAnnotations; * Build/Install/Run: * bit FrameworksServicesTests:com.android.server.am.ActivityStartInterceptorTest */ +@Presubmit @SmallTest public class ActivityStartInterceptorTest { private static final int TEST_USER_ID = 1; @@ -78,6 +81,8 @@ public class ActivityStartInterceptorTest { private UserController mUserController; @Mock private KeyguardManager mKeyguardManager; + @Mock + private PackageManagerService mPackageManager; private ActivityStartInterceptor mInterceptor; private ActivityInfo mAInfo = new ActivityInfo(); @@ -111,6 +116,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();