Merge "Propagate calling UID to AM from CrossProfileApps" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7bfb942e2d
@@ -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();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
import android.app.IApplicationThread;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Rect;
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -71,6 +73,7 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub {
|
||||
|
||||
@Override
|
||||
public void startActivityAsUser(
|
||||
IApplicationThread caller,
|
||||
String callingPackage,
|
||||
ComponentName component,
|
||||
UserHandle user) throws RemoteException {
|
||||
@@ -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);
|
||||
}
|
||||
launchIntent.setPackage(null);
|
||||
launchIntent.setComponent(component);
|
||||
mInjector.getActivityManagerInternal().startActivityAsUser(
|
||||
caller, callingPackage, launchIntent,
|
||||
ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle(),
|
||||
user.getIdentifier());
|
||||
}
|
||||
|
||||
private List<UserHandle> getTargetUserProfilesUnchecked(
|
||||
@@ -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
|
||||
@@ -258,5 +263,6 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub {
|
||||
|
||||
AppOpsManager getAppOpsManager();
|
||||
|
||||
ActivityManagerInternal getActivityManagerInternal();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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<>();
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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) {
|
||||
@@ -401,5 +427,10 @@ public class CrossProfileAppsServiceImplTest {
|
||||
public AppOpsManager getAppOpsManager() {
|
||||
return mAppOpsManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivityManagerInternal getActivityManagerInternal() {
|
||||
return mActivityManagerInternal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user