Merge changes from topic "pm_cross_user_package_visibility_8"
* changes: Fix cross user package visibility leakage for activitySupportsIntent Fix cross user package visibility leakage for PackageManager (8/n) Add a user id parameter to getProperty API
This commit is contained in:
@@ -3716,15 +3716,7 @@ public class ApplicationPackageManager extends PackageManager {
|
||||
throws NameNotFoundException {
|
||||
Objects.requireNonNull(packageName);
|
||||
Objects.requireNonNull(propertyName);
|
||||
try {
|
||||
final Property property = mPM.getProperty(propertyName, packageName, null);
|
||||
if (property == null) {
|
||||
throw new NameNotFoundException();
|
||||
}
|
||||
return property;
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowAsRuntimeException();
|
||||
}
|
||||
return getPropertyAsUser(propertyName, packageName, null /* className */, getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -3732,9 +3724,18 @@ public class ApplicationPackageManager extends PackageManager {
|
||||
throws NameNotFoundException {
|
||||
Objects.requireNonNull(component);
|
||||
Objects.requireNonNull(propertyName);
|
||||
return getPropertyAsUser(propertyName,
|
||||
component.getPackageName(), component.getClassName(), getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property getPropertyAsUser(@NonNull String propertyName, @NonNull String packageName,
|
||||
@Nullable String className, int userId) throws NameNotFoundException {
|
||||
Objects.requireNonNull(packageName);
|
||||
Objects.requireNonNull(propertyName);
|
||||
try {
|
||||
final Property property = mPM.getProperty(
|
||||
propertyName, component.getPackageName(), component.getClassName());
|
||||
final Property property = mPM.getPropertyAsUser(propertyName,
|
||||
packageName, className, userId);
|
||||
if (property == null) {
|
||||
throw new NameNotFoundException();
|
||||
}
|
||||
|
||||
@@ -89,8 +89,8 @@ interface IPackageManager {
|
||||
|
||||
ActivityInfo getActivityInfo(in ComponentName className, long flags, int userId);
|
||||
|
||||
boolean activitySupportsIntent(in ComponentName className, in Intent intent,
|
||||
String resolvedType);
|
||||
boolean activitySupportsIntentAsUser(in ComponentName className, in Intent intent,
|
||||
String resolvedType, int userId);
|
||||
|
||||
ActivityInfo getReceiverInfo(in ComponentName className, long flags, int userId);
|
||||
|
||||
@@ -795,7 +795,8 @@ interface IPackageManager {
|
||||
|
||||
void holdLock(in IBinder token, in int durationMs);
|
||||
|
||||
PackageManager.Property getProperty(String propertyName, String packageName, String className);
|
||||
PackageManager.Property getPropertyAsUser(String propertyName, String packageName,
|
||||
String className, int userId);
|
||||
ParceledListSlice queryProperty(String propertyName, int componentType);
|
||||
|
||||
void setKeepUninstalledPackages(in List<String> packageList);
|
||||
|
||||
@@ -10224,6 +10224,21 @@ public abstract class PackageManager {
|
||||
"getProperty not implemented in subclass");
|
||||
}
|
||||
|
||||
/**
|
||||
* If the provided className is {@code null}, returns the property defined on the application.
|
||||
* Otherwise, returns the property defined on the component.
|
||||
*
|
||||
* @throws NameNotFoundException if the given package is not installed on the calling user or
|
||||
* component does not exist or if the given property is not defined within the manifest.
|
||||
* @hide
|
||||
*/
|
||||
@NonNull
|
||||
public Property getPropertyAsUser(@NonNull String propertyName, @NonNull String packageName,
|
||||
@Nullable String className, int userId) throws NameNotFoundException {
|
||||
throw new UnsupportedOperationException(
|
||||
"getPropertyAsUser not implemented in subclass");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the property definition for all <application> tags.
|
||||
* <p>If the property is not defined with any <application> tag,
|
||||
|
||||
@@ -189,8 +189,9 @@ public class BackupEligibilityRules {
|
||||
boolean isDebuggable = (app.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
|
||||
if (UserHandle.isCore(app.uid) || isPrivileged) {
|
||||
try {
|
||||
return mPackageManager.getProperty(PackageManager.PROPERTY_ALLOW_ADB_BACKUP,
|
||||
packageName).getBoolean();
|
||||
return mPackageManager.getPropertyAsUser(
|
||||
PackageManager.PROPERTY_ALLOW_ADB_BACKUP, packageName,
|
||||
null /* className */, mUserId).getBoolean();
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Slog.w(TAG, "Failed to read allowAdbBackup property for + "
|
||||
+ packageName);
|
||||
|
||||
@@ -110,7 +110,7 @@ final class PackageUtils {
|
||||
|
||||
final ComponentName componentName = service.getComponentName();
|
||||
|
||||
if (isPrimaryCompanionDeviceService(pm, componentName)) {
|
||||
if (isPrimaryCompanionDeviceService(pm, componentName, userId)) {
|
||||
// "Primary" service should be at the head of the list.
|
||||
services.add(0, componentName);
|
||||
} else {
|
||||
@@ -122,9 +122,10 @@ final class PackageUtils {
|
||||
}
|
||||
|
||||
private static boolean isPrimaryCompanionDeviceService(@NonNull PackageManager pm,
|
||||
@NonNull ComponentName componentName) {
|
||||
@NonNull ComponentName componentName, @UserIdInt int userId) {
|
||||
try {
|
||||
return pm.getProperty(PROPERTY_PRIMARY_TAG, componentName).getBoolean();
|
||||
return pm.getPropertyAsUser(PROPERTY_PRIMARY_TAG, componentName.getPackageName(),
|
||||
componentName.getClassName(), userId).getBoolean();
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3728,7 +3728,8 @@ class StorageManagerService extends IStorageManager.Stub
|
||||
|
||||
try {
|
||||
final PackageManager.Property noAppStorageProp = mContext.getPackageManager()
|
||||
.getProperty(PackageManager.PROPERTY_NO_APP_DATA_STORAGE, callingPkg);
|
||||
.getPropertyAsUser(PackageManager.PROPERTY_NO_APP_DATA_STORAGE, callingPkg,
|
||||
null /* className */, userId);
|
||||
if (noAppStorageProp != null && noAppStorageProp.getBoolean()) {
|
||||
throw new SecurityException(callingPkg + " should not have " + appPath);
|
||||
}
|
||||
|
||||
@@ -349,8 +349,9 @@ public interface Computer extends PackageDataSnapshot {
|
||||
|
||||
int getTargetSdkVersion(@NonNull String packageName);
|
||||
|
||||
boolean activitySupportsIntent(@NonNull ComponentName resolveComponentName,
|
||||
@NonNull ComponentName component, @NonNull Intent intent, String resolvedType);
|
||||
boolean activitySupportsIntentAsUser(@NonNull ComponentName resolveComponentName,
|
||||
@NonNull ComponentName component, @NonNull Intent intent, String resolvedType,
|
||||
int userId);
|
||||
|
||||
@Nullable
|
||||
ActivityInfo getReceiverInfo(@NonNull ComponentName component,
|
||||
|
||||
@@ -3821,14 +3821,16 @@ public class ComputerEngine implements Computer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activitySupportsIntent(@NonNull ComponentName resolveComponentName,
|
||||
@NonNull ComponentName component, @NonNull Intent intent, String resolvedType) {
|
||||
public boolean activitySupportsIntentAsUser(@NonNull ComponentName resolveComponentName,
|
||||
@NonNull ComponentName component, @NonNull Intent intent, String resolvedType,
|
||||
int userId) {
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
enforceCrossUserPermission(callingUid, userId, false /* requireFullPermission */,
|
||||
false /* checkShell */, "activitySupportsIntentAsUser");
|
||||
if (component.equals(resolveComponentName)) {
|
||||
// The resolver supports EVERYTHING!
|
||||
return true;
|
||||
}
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
final int callingUserId = UserHandle.getUserId(callingUid);
|
||||
ParsedActivity a = mComponentResolver.getActivity(component);
|
||||
if (a == null) {
|
||||
return false;
|
||||
@@ -3838,7 +3840,7 @@ public class ComputerEngine implements Computer {
|
||||
return false;
|
||||
}
|
||||
if (shouldFilterApplication(
|
||||
ps, callingUid, component, TYPE_ACTIVITY, callingUserId)) {
|
||||
ps, callingUid, component, TYPE_ACTIVITY, userId, true /* filterUninstall */)) {
|
||||
return false;
|
||||
}
|
||||
for (int i=0; i< a.getIntents().size(); i++) {
|
||||
@@ -5011,7 +5013,7 @@ public class ComputerEngine implements Computer {
|
||||
if (ps == null) {
|
||||
return true;
|
||||
}
|
||||
if (shouldFilterApplication(ps, callingUid, userId)) {
|
||||
if (shouldFilterApplicationIncludingUninstalled(ps, callingUid, userId)) {
|
||||
return true;
|
||||
}
|
||||
return ps.getUserStateOrDefault(userId).isHidden();
|
||||
@@ -5075,11 +5077,12 @@ public class ComputerEngine implements Computer {
|
||||
|
||||
@Override
|
||||
public boolean getBlockUninstallForUser(@NonNull String packageName, @UserIdInt int userId) {
|
||||
final PackageStateInternal ps = mSettings.getPackage(packageName);
|
||||
if (ps == null || shouldFilterApplication(ps, Binder.getCallingUid(), userId)) {
|
||||
return false;
|
||||
}
|
||||
return mSettings.getBlockUninstall(userId, packageName);
|
||||
final PackageStateInternal ps = mSettings.getPackage(packageName);
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
if (ps == null || shouldFilterApplicationIncludingUninstalled(ps, callingUid, userId)) {
|
||||
return false;
|
||||
}
|
||||
return mSettings.getBlockUninstall(userId, packageName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -5471,13 +5474,10 @@ public class ComputerEngine implements Computer {
|
||||
enforceCrossUserPermission(callingUid, userId, true /* requireFullPermission */,
|
||||
false /* checkShell */, "get install reason");
|
||||
final PackageStateInternal ps = mSettings.getPackage(packageName);
|
||||
if (shouldFilterApplication(ps, callingUid, userId)) {
|
||||
if (ps == null || shouldFilterApplicationIncludingUninstalled(ps, callingUid, userId)) {
|
||||
return PackageManager.INSTALL_REASON_UNKNOWN;
|
||||
}
|
||||
if (ps != null) {
|
||||
return ps.getUserStateOrDefault(userId).getInstallReason();
|
||||
}
|
||||
return PackageManager.INSTALL_REASON_UNKNOWN;
|
||||
return ps.getUserStateOrDefault(userId).getInstallReason();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -93,9 +93,9 @@ public final class DistractingPackageHelper {
|
||||
for (int i = 0; i < packageNames.length; i++) {
|
||||
final String packageName = packageNames[i];
|
||||
final PackageStateInternal packageState =
|
||||
snapshot.getPackageStateInternal(packageName);
|
||||
if (packageState == null
|
||||
|| snapshot.shouldFilterApplication(packageState, callingUid, userId)) {
|
||||
snapshot.getPackageStateForInstalledAndFiltered(
|
||||
packageName, callingUid, userId);
|
||||
if (packageState == null) {
|
||||
Slog.w(PackageManagerService.TAG,
|
||||
"Could not find package setting for package: " + packageName
|
||||
+ ". Skipping...");
|
||||
|
||||
@@ -148,10 +148,10 @@ public abstract class IPackageManagerBase extends IPackageManager.Stub {
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean activitySupportsIntent(ComponentName component, Intent intent,
|
||||
String resolvedType) {
|
||||
return snapshot().activitySupportsIntent(mResolveComponentName, component, intent,
|
||||
resolvedType);
|
||||
public final boolean activitySupportsIntentAsUser(ComponentName component, Intent intent,
|
||||
String resolvedType, int userId) {
|
||||
return snapshot().activitySupportsIntentAsUser(mResolveComponentName, component, intent,
|
||||
resolvedType, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -711,12 +711,17 @@ public abstract class IPackageManagerBase extends IPackageManager.Stub {
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final PackageManager.Property getProperty(String propertyName, String packageName,
|
||||
String className) {
|
||||
public final PackageManager.Property getPropertyAsUser(String propertyName, String packageName,
|
||||
String className, int userId) {
|
||||
Objects.requireNonNull(propertyName);
|
||||
Objects.requireNonNull(packageName);
|
||||
PackageStateInternal packageState = snapshot().getPackageStateForInstalledAndFiltered(
|
||||
packageName, Binder.getCallingUid(), UserHandle.getCallingUserId());
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
final Computer snapshot = snapshot();
|
||||
snapshot.enforceCrossUserOrProfilePermission(callingUid, userId,
|
||||
/* requireFullPermission */ false,
|
||||
/* checkShell */ false, "getPropertyAsUser");
|
||||
PackageStateInternal packageState = snapshot.getPackageStateForInstalledAndFiltered(
|
||||
packageName, callingUid, userId);
|
||||
if (packageState == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -80,10 +80,9 @@ public final class MovePackageHelper {
|
||||
final PackageManager pm = mPm.mContext.getPackageManager();
|
||||
|
||||
Computer snapshot = mPm.snapshotComputer();
|
||||
final PackageStateInternal packageState = snapshot.getPackageStateInternal(packageName);
|
||||
if (packageState == null
|
||||
|| packageState.getPkg() == null
|
||||
|| snapshot.shouldFilterApplication(packageState, callingUid, user.getIdentifier())) {
|
||||
final PackageStateInternal packageState = snapshot.getPackageStateForInstalledAndFiltered(
|
||||
packageName, callingUid, user.getIdentifier());
|
||||
if (packageState == null || packageState.getPkg() == null) {
|
||||
throw new PackageManagerException(MOVE_FAILED_DOESNT_EXIST, "Missing package");
|
||||
}
|
||||
final AndroidPackage pkg = packageState.getPkg();
|
||||
|
||||
@@ -4378,12 +4378,11 @@ public class PackageManagerService implements PackageSender, TestUtilityService
|
||||
true /* requireFullPermission */, true /* checkShell */, "stop package");
|
||||
|
||||
final PackageStateInternal packageState =
|
||||
snapshot.getPackageStateInternal(packageName);
|
||||
snapshot.getPackageStateForInstalledAndFiltered(
|
||||
packageName, callingUid, userId);
|
||||
final PackageUserState packageUserState = packageState == null
|
||||
? null : packageState.getUserStateOrDefault(userId);
|
||||
if (packageState != null
|
||||
&& !snapshot.shouldFilterApplication(packageState, callingUid, userId)
|
||||
&& packageUserState.isStopped() != stopped) {
|
||||
if (packageState != null && packageUserState.isStopped() != stopped) {
|
||||
boolean wasNotLaunched = packageUserState.isNotLaunched();
|
||||
commitPackageStateMutation(null, packageName, state -> {
|
||||
PackageUserStateWrite userState = state.userState(userId);
|
||||
@@ -5237,11 +5236,10 @@ public class PackageManagerService implements PackageSender, TestUtilityService
|
||||
final int callingUserId = UserHandle.getCallingUserId();
|
||||
final Computer snapshot = snapshotComputer();
|
||||
final List<PackageManager.Property> result =
|
||||
mPackageProperty.queryProperty(propertyName, componentType, packageName -> {
|
||||
final PackageStateInternal ps =
|
||||
snapshot.getPackageStateInternal(packageName);
|
||||
return snapshot.shouldFilterApplication(ps, callingUid, callingUserId);
|
||||
});
|
||||
mPackageProperty.queryProperty(propertyName, componentType,
|
||||
packageName -> snapshot.getPackageStateForInstalledAndFiltered(
|
||||
packageName, callingUid, callingUserId) == null
|
||||
);
|
||||
if (result == null) {
|
||||
return ParceledListSlice.emptyList();
|
||||
}
|
||||
@@ -5600,19 +5598,17 @@ public class PackageManagerService implements PackageSender, TestUtilityService
|
||||
}
|
||||
|
||||
PackageStateInternal targetPackageState =
|
||||
snapshot.getPackageStateInternal(targetPackage);
|
||||
if (targetPackageState == null
|
||||
|| snapshot.shouldFilterApplication(targetPackageState, callingUid,
|
||||
callingUserId)) {
|
||||
snapshot.getPackageStateForInstalledAndFiltered(
|
||||
targetPackage, callingUid, callingUserId);
|
||||
if (targetPackageState == null) {
|
||||
throw new IllegalArgumentException("Unknown target package: " + targetPackage);
|
||||
}
|
||||
|
||||
PackageStateInternal installerPackageState = null;
|
||||
if (installerPackageName != null) {
|
||||
installerPackageState = snapshot.getPackageStateInternal(installerPackageName);
|
||||
if (installerPackageState == null
|
||||
|| snapshot.shouldFilterApplication(
|
||||
installerPackageState, callingUid, callingUserId)) {
|
||||
installerPackageState = snapshot.getPackageStateForInstalledAndFiltered(
|
||||
installerPackageName, callingUid, callingUserId);
|
||||
if (installerPackageState == null) {
|
||||
throw new IllegalArgumentException("Unknown installer package: "
|
||||
+ installerPackageName);
|
||||
}
|
||||
|
||||
@@ -127,9 +127,9 @@ public final class SuspendPackageHelper {
|
||||
continue;
|
||||
}
|
||||
final PackageStateInternal packageState =
|
||||
snapshot.getPackageStateInternal(packageName);
|
||||
if (packageState == null
|
||||
|| snapshot.shouldFilterApplication(packageState, callingUid, userId)) {
|
||||
snapshot.getPackageStateForInstalledAndFiltered(
|
||||
packageName, callingUid, userId);
|
||||
if (packageState == null) {
|
||||
Slog.w(TAG, "Could not find package setting for package: " + packageName
|
||||
+ ". Skipping suspending/un-suspending.");
|
||||
unmodifiablePackages.add(packageName);
|
||||
|
||||
@@ -957,8 +957,8 @@ class ActivityStarter {
|
||||
&& sourceRecord.info.applicationInfo.uid != aInfo.applicationInfo.uid) {
|
||||
try {
|
||||
intent.addCategory(Intent.CATEGORY_VOICE);
|
||||
if (!mService.getPackageManager().activitySupportsIntent(
|
||||
intent.getComponent(), intent, resolvedType)) {
|
||||
if (!mService.getPackageManager().activitySupportsIntentAsUser(
|
||||
intent.getComponent(), intent, resolvedType, userId)) {
|
||||
Slog.w(TAG, "Activity being started in current voice task does not support "
|
||||
+ "voice: " + intent);
|
||||
err = ActivityManager.START_NOT_VOICE_COMPATIBLE;
|
||||
@@ -974,8 +974,8 @@ class ActivityStarter {
|
||||
// If the caller is starting a new voice session, just make sure the target
|
||||
// is actually allowing it to run this way.
|
||||
try {
|
||||
if (!mService.getPackageManager().activitySupportsIntent(intent.getComponent(),
|
||||
intent, resolvedType)) {
|
||||
if (!mService.getPackageManager().activitySupportsIntentAsUser(
|
||||
intent.getComponent(), intent, resolvedType, userId)) {
|
||||
Slog.w(TAG,
|
||||
"Activity being started in new voice task does not support: " + intent);
|
||||
err = ActivityManager.START_NOT_VOICE_COMPATIBLE;
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
package com.android.server.pm.test.appenumeration;
|
||||
|
||||
import static android.Manifest.permission.CLEAR_APP_USER_DATA;
|
||||
import static android.Manifest.permission.DELETE_PACKAGES;
|
||||
import static android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS;
|
||||
import static android.Manifest.permission.MOVE_PACKAGE;
|
||||
import static android.content.pm.PackageManager.MOVE_FAILED_DOESNT_EXIST;
|
||||
|
||||
import static com.android.compatibility.common.util.ShellUtils.runShellCommand;
|
||||
|
||||
@@ -26,7 +30,9 @@ import static org.junit.Assert.assertThrows;
|
||||
|
||||
import android.app.AppGlobals;
|
||||
import android.app.Instrumentation;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.IPackageDataObserver;
|
||||
import android.content.pm.IPackageManager;
|
||||
import android.content.pm.KeySet;
|
||||
@@ -41,6 +47,7 @@ import com.android.bedstead.harrier.BedsteadJUnit4;
|
||||
import com.android.bedstead.harrier.DeviceState;
|
||||
import com.android.bedstead.harrier.annotations.EnsureHasSecondaryUser;
|
||||
import com.android.bedstead.nene.users.UserReference;
|
||||
import com.android.compatibility.common.util.PollingCheck;
|
||||
import com.android.compatibility.common.util.TestUtils;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -71,6 +78,11 @@ public class CrossUserPackageVisibilityTests {
|
||||
private static final File SHARED_USER_TEST_APK_FILE =
|
||||
new File(TEST_DATA_DIR, "AppEnumerationSharedUserTestApp.apk");
|
||||
|
||||
private static final String ACTION_CROSS_USER_TEST =
|
||||
"com.android.appenumeration.action.CROSS_USER_TEST";
|
||||
private static final ComponentName TEST_ACTIVITY_COMPONENT_NAME = new ComponentName(
|
||||
CROSS_USER_TEST_PACKAGE_NAME, "com.android.appenumeration.testapp.DummyActivity");
|
||||
|
||||
private static final long DEFAULT_TIMEOUT_MS = 5000;
|
||||
|
||||
@ClassRule
|
||||
@@ -203,6 +215,55 @@ public class CrossUserPackageVisibilityTests {
|
||||
assertThat(clearApplicationUserData(CROSS_USER_TEST_PACKAGE_NAME)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBlockUninstallForUser_cannotDetectStubPkg() throws Exception {
|
||||
mInstrumentation.getUiAutomation().adoptShellPermissionIdentity(DELETE_PACKAGES);
|
||||
assertThat(mIPackageManager.setBlockUninstallForUser(
|
||||
CROSS_USER_TEST_PACKAGE_NAME, true, mCurrentUser.id())).isTrue();
|
||||
try {
|
||||
assertThat(mIPackageManager.getBlockUninstallForUser(
|
||||
CROSS_USER_TEST_PACKAGE_NAME, mCurrentUser.id())).isFalse();
|
||||
|
||||
installPackageForUser(CROSS_USER_TEST_APK_FILE, mOtherUser);
|
||||
|
||||
assertThat(mIPackageManager.getBlockUninstallForUser(
|
||||
CROSS_USER_TEST_PACKAGE_NAME, mCurrentUser.id())).isFalse();
|
||||
} finally {
|
||||
assertThat(mIPackageManager.setBlockUninstallForUser(
|
||||
CROSS_USER_TEST_PACKAGE_NAME, false, mCurrentUser.id())).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMovePackage_cannotDetectStubPkg() throws Exception {
|
||||
mInstrumentation.getUiAutomation().adoptShellPermissionIdentity(
|
||||
MOVE_PACKAGE, MOUNT_UNMOUNT_FILESYSTEMS);
|
||||
assertThat(movePackage(CROSS_USER_TEST_PACKAGE_NAME, null /* volumeUuid */))
|
||||
.isEqualTo(MOVE_FAILED_DOESNT_EXIST);
|
||||
|
||||
installPackageForUser(CROSS_USER_TEST_APK_FILE, mOtherUser);
|
||||
|
||||
assertThat(movePackage(CROSS_USER_TEST_PACKAGE_NAME, null /* volumeUuid */))
|
||||
.isEqualTo(MOVE_FAILED_DOESNT_EXIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActivitySupportsIntentAsUser_cannotDetectStubPkg() throws Exception {
|
||||
assertThat(mIPackageManager.activitySupportsIntentAsUser(
|
||||
TEST_ACTIVITY_COMPONENT_NAME,
|
||||
new Intent(ACTION_CROSS_USER_TEST),
|
||||
null,
|
||||
mCurrentUser.id())).isFalse();
|
||||
|
||||
installPackageForUser(CROSS_USER_TEST_APK_FILE, mOtherUser);
|
||||
|
||||
assertThat(mIPackageManager.activitySupportsIntentAsUser(
|
||||
TEST_ACTIVITY_COMPONENT_NAME,
|
||||
new Intent(ACTION_CROSS_USER_TEST),
|
||||
null,
|
||||
mCurrentUser.id())).isFalse();
|
||||
}
|
||||
|
||||
private boolean clearApplicationUserData(String packageName) throws Exception {
|
||||
final AtomicInteger result = new AtomicInteger(-1);
|
||||
final IPackageDataObserver localObserver = new IPackageDataObserver.Stub() {
|
||||
@@ -221,6 +282,15 @@ public class CrossUserPackageVisibilityTests {
|
||||
return result.get() == 1;
|
||||
}
|
||||
|
||||
private int movePackage(String packageName, String volumeUuid) throws Exception {
|
||||
final int moveId = mIPackageManager.movePackage(packageName, volumeUuid);
|
||||
PollingCheck.check(
|
||||
"Waiting for the package " + packageName + " moving timeout",
|
||||
DEFAULT_TIMEOUT_MS,
|
||||
() -> PackageManager.isMoveStatusFinished(mIPackageManager.getMoveStatus(moveId)));
|
||||
return mIPackageManager.getMoveStatus(moveId);
|
||||
}
|
||||
|
||||
private static void installPackage(File apk) {
|
||||
installPackageForUser(apk, null, false /* forceQueryable */);
|
||||
}
|
||||
|
||||
@@ -18,5 +18,11 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.appenumeration.crossuserpackagevisibility">
|
||||
<application android:testOnly="true">
|
||||
<activity android:name="com.android.appenumeration.testapp.DummyActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.android.appenumeration.action.CROSS_USER_TEST"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.server.backup.utils;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -250,9 +251,9 @@ public class BackupEligibilityRulesTest {
|
||||
/* flags */ ApplicationInfo.PRIVATE_FLAG_PRIVILEGED, CUSTOM_BACKUP_AGENT_NAME);
|
||||
BackupEligibilityRules eligibilityRules = getBackupEligibilityRules(
|
||||
OperationType.ADB_BACKUP);
|
||||
when(mPackageManager.getProperty(eq(PackageManager.PROPERTY_ALLOW_ADB_BACKUP),
|
||||
eq(TEST_PACKAGE_NAME))).thenReturn(getAdbBackupProperty(
|
||||
/* allowAdbBackup */ false));
|
||||
when(mPackageManager.getPropertyAsUser(eq(PackageManager.PROPERTY_ALLOW_ADB_BACKUP),
|
||||
eq(TEST_PACKAGE_NAME), isNull(), eq(mUserId)))
|
||||
.thenReturn(getAdbBackupProperty(/* allowAdbBackup */ false));
|
||||
|
||||
boolean isEligible = eligibilityRules.appIsEligibleForBackup(applicationInfo);
|
||||
|
||||
@@ -267,9 +268,9 @@ public class BackupEligibilityRulesTest {
|
||||
/* flags */ ApplicationInfo.PRIVATE_FLAG_PRIVILEGED, CUSTOM_BACKUP_AGENT_NAME);
|
||||
BackupEligibilityRules eligibilityRules = getBackupEligibilityRules(
|
||||
OperationType.ADB_BACKUP);
|
||||
when(mPackageManager.getProperty(eq(PackageManager.PROPERTY_ALLOW_ADB_BACKUP),
|
||||
eq(TEST_PACKAGE_NAME))).thenReturn(getAdbBackupProperty(
|
||||
/* allowAdbBackup */ true));
|
||||
when(mPackageManager.getPropertyAsUser(eq(PackageManager.PROPERTY_ALLOW_ADB_BACKUP),
|
||||
eq(TEST_PACKAGE_NAME), isNull(), eq(mUserId)))
|
||||
.thenReturn(getAdbBackupProperty(/* allowAdbBackup */ true));
|
||||
|
||||
boolean isEligible = eligibilityRules.appIsEligibleForBackup(applicationInfo);
|
||||
|
||||
|
||||
@@ -261,12 +261,12 @@ public class ActivityStarterTests extends WindowTestsBase {
|
||||
PRECONDITION_ACTIVITY_SUPPORTS_INTENT_EXCEPTION)) {
|
||||
doAnswer((inv) -> {
|
||||
throw new RemoteException();
|
||||
}).when(packageManager).activitySupportsIntent(
|
||||
eq(source.mActivityComponent), eq(intent), any());
|
||||
}).when(packageManager).activitySupportsIntentAsUser(
|
||||
eq(source.mActivityComponent), eq(intent), any(), anyInt());
|
||||
} else {
|
||||
doReturn(!containsConditions(preconditions, PRECONDITION_NO_VOICE_SESSION_SUPPORT))
|
||||
.when(packageManager).activitySupportsIntent(eq(source.mActivityComponent),
|
||||
eq(intent), any());
|
||||
.when(packageManager).activitySupportsIntentAsUser(
|
||||
eq(source.mActivityComponent), eq(intent), any(), anyInt());
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user