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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user