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

Commit 25f238ec authored by Ben Gruver's avatar Ben Gruver Committed by Android (Google) Code Review
Browse files

Merge changes Ia8d5fbd5,Iea9c1830

* changes:
  Add new ActivityStartInterceptor test for the harmful app warnings
  Fix ActivityStartInterceptor tests
parents 9b9f47f7 49828732
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -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;
        }

+25 −0
Original line number Diff line number Diff line
@@ -33,10 +33,13 @@ 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.internal.app.HarmfulAppWarningActivity;
import com.android.server.LocalServices;
import com.android.server.pm.PackageManagerService;

import org.junit.Before;
import org.junit.Test;
@@ -49,6 +52,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 +82,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 +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();
@@ -153,6 +164,20 @@ public class ActivityStartInterceptorTest {
        assertTrue(CONFIRM_CREDENTIALS_INTENT.filterEquals(mInterceptor.mIntent));
    }

    @Test
    public void testHarmfulAppWarning() {
        // GIVEN the package we're about to launch has a harmful app warning set
        when(mPackageManager.getHarmfulAppWarning(TEST_PACKAGE_NAME, TEST_USER_ID))
                .thenReturn("This app is bad");

        // THEN calling intercept returns true
        assertTrue(mInterceptor.intercept(null, null, mAInfo, null, null, 0, 0, null));

        // THEN the returned intent is the harmful app warning intent
        assertTrue(mInterceptor.mIntent.getComponent().getClassName().equals(
                HarmfulAppWarningActivity.class.getName()));
    }

    @Test
    public void testNoInterception() {
        // GIVEN that none of the interception conditions are met