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

Commit 66fca3e4 authored by android-build-team Robot's avatar android-build-team Robot Committed by android-build-merger
Browse files

Merge "Propagate calling UID to AM from CrossProfileApps" into pi-dev am: 7bfb942e

am: 3f1c2382

Change-Id: If002ec36dfa98c5699b5f6270eb60e22b1dffa87
parents 6e85e8ec 3f1c2382
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -64,7 +64,11 @@ public class CrossProfileApps {
    public void startMainActivity(@NonNull ComponentName component,
    public void startMainActivity(@NonNull ComponentName component,
            @NonNull UserHandle targetUser) {
            @NonNull UserHandle targetUser) {
        try {
        try {
            mService.startActivityAsUser(mContext.getPackageName(), component, targetUser);
            mService.startActivityAsUser(
                    mContext.getIApplicationThread(),
                    mContext.getPackageName(),
                    component,
                    targetUser);
        } catch (RemoteException ex) {
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
            throw ex.rethrowFromSystemServer();
        }
        }
+3 −2
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package android.content.pm;
package android.content.pm;


import android.app.IApplicationThread;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Intent;
import android.content.Intent;
import android.graphics.Rect;
import android.graphics.Rect;
@@ -26,7 +27,7 @@ import android.os.UserHandle;
 * @hide
 * @hide
 */
 */
interface ICrossProfileApps {
interface ICrossProfileApps {
    void startActivityAsUser(in String callingPackage, in ComponentName component,
    void startActivityAsUser(in IApplicationThread caller, in String callingPackage,
        in UserHandle user);
            in ComponentName component, in UserHandle user);
    List<UserHandle> getTargetUserProfiles(in String callingPackage);
    List<UserHandle> getTargetUserProfiles(in String callingPackage);
}
}
 No newline at end of file
+15 −9
Original line number Original line Diff line number Diff line
@@ -19,8 +19,10 @@ import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE;
import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE;


import android.annotation.UserIdInt;
import android.annotation.UserIdInt;
import android.app.ActivityManagerInternal;
import android.app.ActivityOptions;
import android.app.ActivityOptions;
import android.app.AppOpsManager;
import android.app.AppOpsManager;
import android.app.IApplicationThread;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
@@ -71,6 +73,7 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub {


    @Override
    @Override
    public void startActivityAsUser(
    public void startActivityAsUser(
            IApplicationThread caller,
            String callingPackage,
            String callingPackage,
            ComponentName component,
            ComponentName component,
            UserHandle user) throws RemoteException {
            UserHandle user) throws RemoteException {
@@ -107,15 +110,12 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub {
        launchIntent.setPackage(component.getPackageName());
        launchIntent.setPackage(component.getPackageName());
        verifyActivityCanHandleIntentAndExported(launchIntent, component, callingUid, user);
        verifyActivityCanHandleIntentAndExported(launchIntent, component, callingUid, user);


        final long ident = mInjector.clearCallingIdentity();
        try {
        launchIntent.setPackage(null);
        launchIntent.setPackage(null);
        launchIntent.setComponent(component);
        launchIntent.setComponent(component);
            mContext.startActivityAsUser(launchIntent,
        mInjector.getActivityManagerInternal().startActivityAsUser(
                    ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle(), user);
                caller, callingPackage, launchIntent,
        } finally {
                ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle(),
            mInjector.restoreCallingIdentity(ident);
                user.getIdentifier());
        }
    }
    }


    private List<UserHandle> getTargetUserProfilesUnchecked(
    private List<UserHandle> getTargetUserProfilesUnchecked(
@@ -236,6 +236,11 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub {
        public AppOpsManager getAppOpsManager() {
        public AppOpsManager getAppOpsManager() {
            return mContext.getSystemService(AppOpsManager.class);
            return mContext.getSystemService(AppOpsManager.class);
        }
        }

        @Override
        public ActivityManagerInternal getActivityManagerInternal() {
            return LocalServices.getService(ActivityManagerInternal.class);
        }
    }
    }


    @VisibleForTesting
    @VisibleForTesting
@@ -258,5 +263,6 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub {


        AppOpsManager getAppOpsManager();
        AppOpsManager getAppOpsManager();


        ActivityManagerInternal getActivityManagerInternal();
    }
    }
}
}
+45 −14
Original line number Original line Diff line number Diff line
@@ -13,7 +13,9 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertThrows;
import static org.testng.Assert.assertThrows;


import android.app.ActivityManagerInternal;
import android.app.AppOpsManager;
import android.app.AppOpsManager;
import android.app.IApplicationThread;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
@@ -68,10 +70,13 @@ public class CrossProfileAppsServiceImplTest {
    private PackageManagerInternal mPackageManagerInternal;
    private PackageManagerInternal mPackageManagerInternal;
    @Mock
    @Mock
    private AppOpsManager mAppOpsManager;
    private AppOpsManager mAppOpsManager;
    @Mock
    private ActivityManagerInternal mActivityManagerInternal;


    private TestInjector mTestInjector;
    private TestInjector mTestInjector;
    private ActivityInfo mActivityInfo;
    private ActivityInfo mActivityInfo;
    private CrossProfileAppsServiceImpl mCrossProfileAppsServiceImpl;
    private CrossProfileAppsServiceImpl mCrossProfileAppsServiceImpl;
    private IApplicationThread mIApplicationThread;


    private SparseArray<Boolean> mUserEnabled = new SparseArray<>();
    private SparseArray<Boolean> mUserEnabled = new SparseArray<>();


@@ -200,15 +205,18 @@ public class CrossProfileAppsServiceImplTest {
                SecurityException.class,
                SecurityException.class,
                () ->
                () ->
                        mCrossProfileAppsServiceImpl.startActivityAsUser(
                        mCrossProfileAppsServiceImpl.startActivityAsUser(
                                mIApplicationThread,
                                PACKAGE_ONE,
                                PACKAGE_ONE,
                                ACTIVITY_COMPONENT,
                                ACTIVITY_COMPONENT,
                                UserHandle.of(PRIMARY_USER)));
                                UserHandle.of(PRIMARY_USER)));


        verify(mContext, never())
        verify(mActivityManagerInternal, never())
                .startActivityAsUser(
                .startActivityAsUser(
                        nullable(IApplicationThread.class),
                        anyString(),
                        any(Intent.class),
                        any(Intent.class),
                        nullable(Bundle.class),
                        nullable(Bundle.class),
                        any(UserHandle.class));
                        anyInt());
    }
    }


    @Test
    @Test
@@ -219,15 +227,18 @@ public class CrossProfileAppsServiceImplTest {
                SecurityException.class,
                SecurityException.class,
                () ->
                () ->
                        mCrossProfileAppsServiceImpl.startActivityAsUser(
                        mCrossProfileAppsServiceImpl.startActivityAsUser(
                                mIApplicationThread,
                                PACKAGE_ONE,
                                PACKAGE_ONE,
                                ACTIVITY_COMPONENT,
                                ACTIVITY_COMPONENT,
                                UserHandle.of(PROFILE_OF_PRIMARY_USER)));
                                UserHandle.of(PROFILE_OF_PRIMARY_USER)));


        verify(mContext, never())
        verify(mActivityManagerInternal, never())
                .startActivityAsUser(
                .startActivityAsUser(
                        nullable(IApplicationThread.class),
                        anyString(),
                        any(Intent.class),
                        any(Intent.class),
                        nullable(Bundle.class),
                        nullable(Bundle.class),
                        any(UserHandle.class));
                        anyInt());
    }
    }


    @Test
    @Test
@@ -236,15 +247,18 @@ public class CrossProfileAppsServiceImplTest {
                SecurityException.class,
                SecurityException.class,
                () ->
                () ->
                        mCrossProfileAppsServiceImpl.startActivityAsUser(
                        mCrossProfileAppsServiceImpl.startActivityAsUser(
                                mIApplicationThread,
                                PACKAGE_TWO,
                                PACKAGE_TWO,
                                ACTIVITY_COMPONENT,
                                ACTIVITY_COMPONENT,
                                UserHandle.of(PROFILE_OF_PRIMARY_USER)));
                                UserHandle.of(PROFILE_OF_PRIMARY_USER)));


        verify(mContext, never())
        verify(mActivityManagerInternal, never())
                .startActivityAsUser(
                .startActivityAsUser(
                        nullable(IApplicationThread.class),
                        anyString(),
                        any(Intent.class),
                        any(Intent.class),
                        nullable(Bundle.class),
                        nullable(Bundle.class),
                        any(UserHandle.class));
                        anyInt());
    }
    }


    @Test
    @Test
@@ -255,15 +269,18 @@ public class CrossProfileAppsServiceImplTest {
                SecurityException.class,
                SecurityException.class,
                () ->
                () ->
                        mCrossProfileAppsServiceImpl.startActivityAsUser(
                        mCrossProfileAppsServiceImpl.startActivityAsUser(
                                mIApplicationThread,
                                PACKAGE_ONE,
                                PACKAGE_ONE,
                                ACTIVITY_COMPONENT,
                                ACTIVITY_COMPONENT,
                                UserHandle.of(PROFILE_OF_PRIMARY_USER)));
                                UserHandle.of(PROFILE_OF_PRIMARY_USER)));


        verify(mContext, never())
        verify(mActivityManagerInternal, never())
                .startActivityAsUser(
                .startActivityAsUser(
                        nullable(IApplicationThread.class),
                        anyString(),
                        any(Intent.class),
                        any(Intent.class),
                        nullable(Bundle.class),
                        nullable(Bundle.class),
                        any(UserHandle.class));
                        anyInt());
    }
    }


    @Test
    @Test
@@ -272,15 +289,18 @@ public class CrossProfileAppsServiceImplTest {
                SecurityException.class,
                SecurityException.class,
                () ->
                () ->
                        mCrossProfileAppsServiceImpl.startActivityAsUser(
                        mCrossProfileAppsServiceImpl.startActivityAsUser(
                                mIApplicationThread,
                                PACKAGE_ONE,
                                PACKAGE_ONE,
                                new ComponentName(PACKAGE_TWO, "test"),
                                new ComponentName(PACKAGE_TWO, "test"),
                                UserHandle.of(PROFILE_OF_PRIMARY_USER)));
                                UserHandle.of(PROFILE_OF_PRIMARY_USER)));


        verify(mContext, never())
        verify(mActivityManagerInternal, never())
                .startActivityAsUser(
                .startActivityAsUser(
                        nullable(IApplicationThread.class),
                        anyString(),
                        any(Intent.class),
                        any(Intent.class),
                        nullable(Bundle.class),
                        nullable(Bundle.class),
                        any(UserHandle.class));
                        anyInt());
    }
    }


    @Test
    @Test
@@ -289,15 +309,18 @@ public class CrossProfileAppsServiceImplTest {
                SecurityException.class,
                SecurityException.class,
                () ->
                () ->
                        mCrossProfileAppsServiceImpl.startActivityAsUser(
                        mCrossProfileAppsServiceImpl.startActivityAsUser(
                                mIApplicationThread,
                                PACKAGE_ONE,
                                PACKAGE_ONE,
                                ACTIVITY_COMPONENT,
                                ACTIVITY_COMPONENT,
                                UserHandle.of(SECONDARY_USER)));
                                UserHandle.of(SECONDARY_USER)));


        verify(mContext, never())
        verify(mActivityManagerInternal, never())
                .startActivityAsUser(
                .startActivityAsUser(
                        nullable(IApplicationThread.class),
                        anyString(),
                        any(Intent.class),
                        any(Intent.class),
                        nullable(Bundle.class),
                        nullable(Bundle.class),
                        any(UserHandle.class));
                        anyInt());
    }
    }


    @Test
    @Test
@@ -305,15 +328,18 @@ public class CrossProfileAppsServiceImplTest {
        mTestInjector.setCallingUserId(PROFILE_OF_PRIMARY_USER);
        mTestInjector.setCallingUserId(PROFILE_OF_PRIMARY_USER);


        mCrossProfileAppsServiceImpl.startActivityAsUser(
        mCrossProfileAppsServiceImpl.startActivityAsUser(
                mIApplicationThread,
                PACKAGE_ONE,
                PACKAGE_ONE,
                ACTIVITY_COMPONENT,
                ACTIVITY_COMPONENT,
                UserHandle.of(PRIMARY_USER));
                UserHandle.of(PRIMARY_USER));


        verify(mContext)
        verify(mActivityManagerInternal)
                .startActivityAsUser(
                .startActivityAsUser(
                        nullable(IApplicationThread.class),
                        eq(PACKAGE_ONE),
                        any(Intent.class),
                        any(Intent.class),
                        nullable(Bundle.class),
                        nullable(Bundle.class),
                        eq(UserHandle.of(PRIMARY_USER)));
                        eq(PRIMARY_USER));
    }
    }


    private void mockAppsInstalled(String packageName, int user, boolean installed) {
    private void mockAppsInstalled(String packageName, int user, boolean installed) {
@@ -401,5 +427,10 @@ public class CrossProfileAppsServiceImplTest {
        public AppOpsManager getAppOpsManager() {
        public AppOpsManager getAppOpsManager() {
            return mAppOpsManager;
            return mAppOpsManager;
        }
        }

        @Override
        public ActivityManagerInternal getActivityManagerInternal() {
            return mActivityManagerInternal;
        }
    }
    }
}
}