Loading core/java/android/content/pm/CrossProfileApps.java +5 −1 Original line number Diff line number Diff line Loading @@ -64,7 +64,11 @@ public class CrossProfileApps { public void startMainActivity(@NonNull ComponentName component, @NonNull UserHandle targetUser) { try { mService.startActivityAsUser(mContext.getPackageName(), component, targetUser); mService.startActivityAsUser( mContext.getIApplicationThread(), mContext.getPackageName(), component, targetUser); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } Loading core/java/android/content/pm/ICrossProfileApps.aidl +3 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.content.pm; import android.app.IApplicationThread; import android.content.ComponentName; import android.content.Intent; import android.graphics.Rect; Loading @@ -26,7 +27,7 @@ import android.os.UserHandle; * @hide */ interface ICrossProfileApps { void startActivityAsUser(in String callingPackage, in ComponentName component, in UserHandle user); void startActivityAsUser(in IApplicationThread caller, in String callingPackage, in ComponentName component, in UserHandle user); List<UserHandle> getTargetUserProfiles(in String callingPackage); } No newline at end of file services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java +15 −9 Original line number Diff line number Diff line Loading @@ -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 android.annotation.UserIdInt; import android.app.ActivityManagerInternal; import android.app.ActivityOptions; import android.app.AppOpsManager; import android.app.IApplicationThread; import android.content.ComponentName; import android.content.Context; import android.content.Intent; Loading Loading @@ -71,6 +73,7 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub { @Override public void startActivityAsUser( IApplicationThread caller, String callingPackage, ComponentName component, UserHandle user) throws RemoteException { Loading Loading @@ -107,15 +110,12 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub { launchIntent.setPackage(component.getPackageName()); verifyActivityCanHandleIntentAndExported(launchIntent, component, callingUid, user); final long ident = mInjector.clearCallingIdentity(); try { launchIntent.setPackage(null); launchIntent.setComponent(component); mContext.startActivityAsUser(launchIntent, ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle(), user); } finally { mInjector.restoreCallingIdentity(ident); } mInjector.getActivityManagerInternal().startActivityAsUser( caller, callingPackage, launchIntent, ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle(), user.getIdentifier()); } private List<UserHandle> getTargetUserProfilesUnchecked( Loading Loading @@ -236,6 +236,11 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub { public AppOpsManager getAppOpsManager() { return mContext.getSystemService(AppOpsManager.class); } @Override public ActivityManagerInternal getActivityManagerInternal() { return LocalServices.getService(ActivityManagerInternal.class); } } @VisibleForTesting Loading @@ -258,5 +263,6 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub { AppOpsManager getAppOpsManager(); ActivityManagerInternal getActivityManagerInternal(); } } services/tests/servicestests/src/com/android/server/pm/CrossProfileAppsServiceImplTest.java +45 −14 Original line number Diff line number Diff line Loading @@ -13,7 +13,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.testng.Assert.assertThrows; import android.app.ActivityManagerInternal; import android.app.AppOpsManager; import android.app.IApplicationThread; import android.content.ComponentName; import android.content.Context; import android.content.Intent; Loading Loading @@ -68,10 +70,13 @@ public class CrossProfileAppsServiceImplTest { private PackageManagerInternal mPackageManagerInternal; @Mock private AppOpsManager mAppOpsManager; @Mock private ActivityManagerInternal mActivityManagerInternal; private TestInjector mTestInjector; private ActivityInfo mActivityInfo; private CrossProfileAppsServiceImpl mCrossProfileAppsServiceImpl; private IApplicationThread mIApplicationThread; private SparseArray<Boolean> mUserEnabled = new SparseArray<>(); Loading Loading @@ -200,15 +205,18 @@ public class CrossProfileAppsServiceImplTest { SecurityException.class, () -> mCrossProfileAppsServiceImpl.startActivityAsUser( mIApplicationThread, PACKAGE_ONE, ACTIVITY_COMPONENT, UserHandle.of(PRIMARY_USER))); verify(mContext, never()) verify(mActivityManagerInternal, never()) .startActivityAsUser( nullable(IApplicationThread.class), anyString(), any(Intent.class), nullable(Bundle.class), any(UserHandle.class)); anyInt()); } @Test Loading @@ -219,15 +227,18 @@ public class CrossProfileAppsServiceImplTest { SecurityException.class, () -> mCrossProfileAppsServiceImpl.startActivityAsUser( mIApplicationThread, PACKAGE_ONE, ACTIVITY_COMPONENT, UserHandle.of(PROFILE_OF_PRIMARY_USER))); verify(mContext, never()) verify(mActivityManagerInternal, never()) .startActivityAsUser( nullable(IApplicationThread.class), anyString(), any(Intent.class), nullable(Bundle.class), any(UserHandle.class)); anyInt()); } @Test Loading @@ -236,15 +247,18 @@ public class CrossProfileAppsServiceImplTest { SecurityException.class, () -> mCrossProfileAppsServiceImpl.startActivityAsUser( mIApplicationThread, PACKAGE_TWO, ACTIVITY_COMPONENT, UserHandle.of(PROFILE_OF_PRIMARY_USER))); verify(mContext, never()) verify(mActivityManagerInternal, never()) .startActivityAsUser( nullable(IApplicationThread.class), anyString(), any(Intent.class), nullable(Bundle.class), any(UserHandle.class)); anyInt()); } @Test Loading @@ -255,15 +269,18 @@ public class CrossProfileAppsServiceImplTest { SecurityException.class, () -> mCrossProfileAppsServiceImpl.startActivityAsUser( mIApplicationThread, PACKAGE_ONE, ACTIVITY_COMPONENT, UserHandle.of(PROFILE_OF_PRIMARY_USER))); verify(mContext, never()) verify(mActivityManagerInternal, never()) .startActivityAsUser( nullable(IApplicationThread.class), anyString(), any(Intent.class), nullable(Bundle.class), any(UserHandle.class)); anyInt()); } @Test Loading @@ -272,15 +289,18 @@ public class CrossProfileAppsServiceImplTest { SecurityException.class, () -> mCrossProfileAppsServiceImpl.startActivityAsUser( mIApplicationThread, PACKAGE_ONE, new ComponentName(PACKAGE_TWO, "test"), UserHandle.of(PROFILE_OF_PRIMARY_USER))); verify(mContext, never()) verify(mActivityManagerInternal, never()) .startActivityAsUser( nullable(IApplicationThread.class), anyString(), any(Intent.class), nullable(Bundle.class), any(UserHandle.class)); anyInt()); } @Test Loading @@ -289,15 +309,18 @@ public class CrossProfileAppsServiceImplTest { SecurityException.class, () -> mCrossProfileAppsServiceImpl.startActivityAsUser( mIApplicationThread, PACKAGE_ONE, ACTIVITY_COMPONENT, UserHandle.of(SECONDARY_USER))); verify(mContext, never()) verify(mActivityManagerInternal, never()) .startActivityAsUser( nullable(IApplicationThread.class), anyString(), any(Intent.class), nullable(Bundle.class), any(UserHandle.class)); anyInt()); } @Test Loading @@ -305,15 +328,18 @@ public class CrossProfileAppsServiceImplTest { mTestInjector.setCallingUserId(PROFILE_OF_PRIMARY_USER); mCrossProfileAppsServiceImpl.startActivityAsUser( mIApplicationThread, PACKAGE_ONE, ACTIVITY_COMPONENT, UserHandle.of(PRIMARY_USER)); verify(mContext) verify(mActivityManagerInternal) .startActivityAsUser( nullable(IApplicationThread.class), eq(PACKAGE_ONE), any(Intent.class), nullable(Bundle.class), eq(UserHandle.of(PRIMARY_USER))); eq(PRIMARY_USER)); } private void mockAppsInstalled(String packageName, int user, boolean installed) { Loading Loading @@ -401,5 +427,10 @@ public class CrossProfileAppsServiceImplTest { public AppOpsManager getAppOpsManager() { return mAppOpsManager; } @Override public ActivityManagerInternal getActivityManagerInternal() { return mActivityManagerInternal; } } } Loading
core/java/android/content/pm/CrossProfileApps.java +5 −1 Original line number Diff line number Diff line Loading @@ -64,7 +64,11 @@ public class CrossProfileApps { public void startMainActivity(@NonNull ComponentName component, @NonNull UserHandle targetUser) { try { mService.startActivityAsUser(mContext.getPackageName(), component, targetUser); mService.startActivityAsUser( mContext.getIApplicationThread(), mContext.getPackageName(), component, targetUser); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } Loading
core/java/android/content/pm/ICrossProfileApps.aidl +3 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.content.pm; import android.app.IApplicationThread; import android.content.ComponentName; import android.content.Intent; import android.graphics.Rect; Loading @@ -26,7 +27,7 @@ import android.os.UserHandle; * @hide */ interface ICrossProfileApps { void startActivityAsUser(in String callingPackage, in ComponentName component, in UserHandle user); void startActivityAsUser(in IApplicationThread caller, in String callingPackage, in ComponentName component, in UserHandle user); List<UserHandle> getTargetUserProfiles(in String callingPackage); } No newline at end of file
services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java +15 −9 Original line number Diff line number Diff line Loading @@ -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 android.annotation.UserIdInt; import android.app.ActivityManagerInternal; import android.app.ActivityOptions; import android.app.AppOpsManager; import android.app.IApplicationThread; import android.content.ComponentName; import android.content.Context; import android.content.Intent; Loading Loading @@ -71,6 +73,7 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub { @Override public void startActivityAsUser( IApplicationThread caller, String callingPackage, ComponentName component, UserHandle user) throws RemoteException { Loading Loading @@ -107,15 +110,12 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub { launchIntent.setPackage(component.getPackageName()); verifyActivityCanHandleIntentAndExported(launchIntent, component, callingUid, user); final long ident = mInjector.clearCallingIdentity(); try { launchIntent.setPackage(null); launchIntent.setComponent(component); mContext.startActivityAsUser(launchIntent, ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle(), user); } finally { mInjector.restoreCallingIdentity(ident); } mInjector.getActivityManagerInternal().startActivityAsUser( caller, callingPackage, launchIntent, ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle(), user.getIdentifier()); } private List<UserHandle> getTargetUserProfilesUnchecked( Loading Loading @@ -236,6 +236,11 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub { public AppOpsManager getAppOpsManager() { return mContext.getSystemService(AppOpsManager.class); } @Override public ActivityManagerInternal getActivityManagerInternal() { return LocalServices.getService(ActivityManagerInternal.class); } } @VisibleForTesting Loading @@ -258,5 +263,6 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub { AppOpsManager getAppOpsManager(); ActivityManagerInternal getActivityManagerInternal(); } }
services/tests/servicestests/src/com/android/server/pm/CrossProfileAppsServiceImplTest.java +45 −14 Original line number Diff line number Diff line Loading @@ -13,7 +13,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.testng.Assert.assertThrows; import android.app.ActivityManagerInternal; import android.app.AppOpsManager; import android.app.IApplicationThread; import android.content.ComponentName; import android.content.Context; import android.content.Intent; Loading Loading @@ -68,10 +70,13 @@ public class CrossProfileAppsServiceImplTest { private PackageManagerInternal mPackageManagerInternal; @Mock private AppOpsManager mAppOpsManager; @Mock private ActivityManagerInternal mActivityManagerInternal; private TestInjector mTestInjector; private ActivityInfo mActivityInfo; private CrossProfileAppsServiceImpl mCrossProfileAppsServiceImpl; private IApplicationThread mIApplicationThread; private SparseArray<Boolean> mUserEnabled = new SparseArray<>(); Loading Loading @@ -200,15 +205,18 @@ public class CrossProfileAppsServiceImplTest { SecurityException.class, () -> mCrossProfileAppsServiceImpl.startActivityAsUser( mIApplicationThread, PACKAGE_ONE, ACTIVITY_COMPONENT, UserHandle.of(PRIMARY_USER))); verify(mContext, never()) verify(mActivityManagerInternal, never()) .startActivityAsUser( nullable(IApplicationThread.class), anyString(), any(Intent.class), nullable(Bundle.class), any(UserHandle.class)); anyInt()); } @Test Loading @@ -219,15 +227,18 @@ public class CrossProfileAppsServiceImplTest { SecurityException.class, () -> mCrossProfileAppsServiceImpl.startActivityAsUser( mIApplicationThread, PACKAGE_ONE, ACTIVITY_COMPONENT, UserHandle.of(PROFILE_OF_PRIMARY_USER))); verify(mContext, never()) verify(mActivityManagerInternal, never()) .startActivityAsUser( nullable(IApplicationThread.class), anyString(), any(Intent.class), nullable(Bundle.class), any(UserHandle.class)); anyInt()); } @Test Loading @@ -236,15 +247,18 @@ public class CrossProfileAppsServiceImplTest { SecurityException.class, () -> mCrossProfileAppsServiceImpl.startActivityAsUser( mIApplicationThread, PACKAGE_TWO, ACTIVITY_COMPONENT, UserHandle.of(PROFILE_OF_PRIMARY_USER))); verify(mContext, never()) verify(mActivityManagerInternal, never()) .startActivityAsUser( nullable(IApplicationThread.class), anyString(), any(Intent.class), nullable(Bundle.class), any(UserHandle.class)); anyInt()); } @Test Loading @@ -255,15 +269,18 @@ public class CrossProfileAppsServiceImplTest { SecurityException.class, () -> mCrossProfileAppsServiceImpl.startActivityAsUser( mIApplicationThread, PACKAGE_ONE, ACTIVITY_COMPONENT, UserHandle.of(PROFILE_OF_PRIMARY_USER))); verify(mContext, never()) verify(mActivityManagerInternal, never()) .startActivityAsUser( nullable(IApplicationThread.class), anyString(), any(Intent.class), nullable(Bundle.class), any(UserHandle.class)); anyInt()); } @Test Loading @@ -272,15 +289,18 @@ public class CrossProfileAppsServiceImplTest { SecurityException.class, () -> mCrossProfileAppsServiceImpl.startActivityAsUser( mIApplicationThread, PACKAGE_ONE, new ComponentName(PACKAGE_TWO, "test"), UserHandle.of(PROFILE_OF_PRIMARY_USER))); verify(mContext, never()) verify(mActivityManagerInternal, never()) .startActivityAsUser( nullable(IApplicationThread.class), anyString(), any(Intent.class), nullable(Bundle.class), any(UserHandle.class)); anyInt()); } @Test Loading @@ -289,15 +309,18 @@ public class CrossProfileAppsServiceImplTest { SecurityException.class, () -> mCrossProfileAppsServiceImpl.startActivityAsUser( mIApplicationThread, PACKAGE_ONE, ACTIVITY_COMPONENT, UserHandle.of(SECONDARY_USER))); verify(mContext, never()) verify(mActivityManagerInternal, never()) .startActivityAsUser( nullable(IApplicationThread.class), anyString(), any(Intent.class), nullable(Bundle.class), any(UserHandle.class)); anyInt()); } @Test Loading @@ -305,15 +328,18 @@ public class CrossProfileAppsServiceImplTest { mTestInjector.setCallingUserId(PROFILE_OF_PRIMARY_USER); mCrossProfileAppsServiceImpl.startActivityAsUser( mIApplicationThread, PACKAGE_ONE, ACTIVITY_COMPONENT, UserHandle.of(PRIMARY_USER)); verify(mContext) verify(mActivityManagerInternal) .startActivityAsUser( nullable(IApplicationThread.class), eq(PACKAGE_ONE), any(Intent.class), nullable(Bundle.class), eq(UserHandle.of(PRIMARY_USER))); eq(PRIMARY_USER)); } private void mockAppsInstalled(String packageName, int user, boolean installed) { Loading Loading @@ -401,5 +427,10 @@ public class CrossProfileAppsServiceImplTest { public AppOpsManager getAppOpsManager() { return mAppOpsManager; } @Override public ActivityManagerInternal getActivityManagerInternal() { return mActivityManagerInternal; } } }