Merge "Merge "Failing setPackagesSuspended if user has a DO / PO" into pi-dev am: 694f60005e" into pi-dev-plus-aosp
am: fecb262029
Change-Id: I58139151f963f6a45493615d07e9b7e4a5417456
This commit is contained in:
@@ -13640,25 +13640,15 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
// install reason correctly.
|
||||
return installReason;
|
||||
}
|
||||
|
||||
final IDevicePolicyManager dpm = IDevicePolicyManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
|
||||
if (dpm != null) {
|
||||
ComponentName owner = null;
|
||||
try {
|
||||
owner = dpm.getDeviceOwnerComponent(true /* callingUserOnly */);
|
||||
if (owner == null) {
|
||||
owner = dpm.getProfileOwner(UserHandle.getUserId(installerUid));
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
if (owner != null && owner.getPackageName().equals(installerPackageName)) {
|
||||
// If the install is being performed by a device or profile owner, the install
|
||||
// reason should be enterprise policy.
|
||||
return PackageManager.INSTALL_REASON_POLICY;
|
||||
}
|
||||
final String ownerPackage = mProtectedPackages.getDeviceOwnerOrProfileOwnerPackage(
|
||||
UserHandle.getUserId(installerUid));
|
||||
if (ownerPackage != null && ownerPackage.equals(installerPackageName)) {
|
||||
// If the install is being performed by a device or profile owner, the install
|
||||
// reason should be enterprise policy.
|
||||
return PackageManager.INSTALL_REASON_POLICY;
|
||||
}
|
||||
|
||||
|
||||
if (installReason == PackageManager.INSTALL_REASON_POLICY) {
|
||||
// If the install is being performed by a regular app (i.e. neither system app nor
|
||||
// device or profile owner), we have no reason to believe that the app is acting on
|
||||
@@ -14055,7 +14045,11 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
throw new IllegalArgumentException("CallingPackage " + callingPackage + " does not"
|
||||
+ " belong to calling app id " + UserHandle.getAppId(callingUid));
|
||||
}
|
||||
|
||||
if (!PLATFORM_PACKAGE_NAME.equals(callingPackage)
|
||||
&& mProtectedPackages.getDeviceOwnerOrProfileOwnerPackage(userId) != null) {
|
||||
throw new UnsupportedOperationException("Cannot suspend/unsuspend packages. User "
|
||||
+ userId + " has an active DO or PO");
|
||||
}
|
||||
if (ArrayUtils.isEmpty(packageNames)) {
|
||||
return packageNames;
|
||||
}
|
||||
|
||||
@@ -88,6 +88,13 @@ public class ProtectedPackages {
|
||||
return false;
|
||||
}
|
||||
|
||||
public synchronized String getDeviceOwnerOrProfileOwnerPackage(int userId) {
|
||||
if (mDeviceOwnerUserId == userId) {
|
||||
return mDeviceOwnerPackage;
|
||||
}
|
||||
return mProfileOwnerPackages.get(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if a given package is protected. Otherwise, returns {@code false}.
|
||||
*
|
||||
|
||||
@@ -73,6 +73,9 @@ import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker
|
||||
import static com.android.server.devicepolicy.TransferOwnershipMetadataManager.ADMIN_TYPE_DEVICE_OWNER;
|
||||
import static com.android.server.devicepolicy.TransferOwnershipMetadataManager.ADMIN_TYPE_PROFILE_OWNER;
|
||||
|
||||
|
||||
import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
|
||||
|
||||
import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
|
||||
import static org.xmlpull.v1.XmlPullParser.END_TAG;
|
||||
import static org.xmlpull.v1.XmlPullParser.TEXT;
|
||||
@@ -9194,8 +9197,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
|
||||
long id = mInjector.binderClearCallingIdentity();
|
||||
try {
|
||||
return mIPackageManager.setPackagesSuspendedAsUser(
|
||||
packageNames, suspended, null, null, null, "android", callingUserId);
|
||||
return mIPackageManager.setPackagesSuspendedAsUser(packageNames, suspended,
|
||||
null, null, null, PLATFORM_PACKAGE_NAME, callingUserId);
|
||||
} catch (RemoteException re) {
|
||||
// Shouldn't happen.
|
||||
Slog.e(LOG_TAG, "Failed talking to the package manager", re);
|
||||
|
||||
Reference in New Issue
Block a user