diff options
| author | 2023-04-24 14:19:00 +0000 | |
|---|---|---|
| committer | 2023-04-24 14:19:00 +0000 | |
| commit | d2f17f294d5cb6c40afec55b9a8efd2e4e739f65 (patch) | |
| tree | 2b1c4eb39615848e0923619d321f7d1be2c7f3cf | |
| parent | 32e686255e0cf346433d980777cd0937601d5a02 (diff) | |
Headless fixes for cross profile apps.
Test: btest a.d.c.CrossProfileAppsTest
Bug: 278891585
Change-Id: I6430752702d3b08a6d6c08659e3c7ac40ad5e5c9
| -rw-r--r-- | core/java/android/app/admin/DevicePolicyManager.java | 1 | ||||
| -rw-r--r-- | services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java | 18 |
2 files changed, 14 insertions, 5 deletions
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 7b6835792370..27f5545d8f03 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -9599,6 +9599,7 @@ public class DevicePolicyManager { } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } catch (IllegalArgumentException ex) { + Log.e(TAG, "IllegalArgumentException checking isPackageSuspended", ex); throw new NameNotFoundException(packageName); } } diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 7156f6c4c917..c689b26b6300 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -7513,6 +7513,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { boolean success = false; try { if (getCurrentForegroundUserId() == userId) { + // TODO: We need to special case headless here as we can't switch to the system user mInjector.getIActivityManager().switchUser(UserHandle.USER_SYSTEM); } @@ -7520,7 +7521,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!success) { Slogf.w(LOG_TAG, "Couldn't remove user " + userId); } else if (isManagedProfile(userId) && !wipeSilently) { - sendWipeProfileNotification(wipeReasonForUser); + sendWipeProfileNotification(wipeReasonForUser, + UserHandle.of(getProfileParentId(userId))); } } catch (RemoteException re) { // Shouldn't happen @@ -7868,7 +7870,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { }); } - private void sendWipeProfileNotification(String wipeReasonForUser) { + private void sendWipeProfileNotification(String wipeReasonForUser, UserHandle user) { Notification notification = new Notification.Builder(mContext, SystemNotificationChannels.DEVICE_ADMIN) .setSmallIcon(android.R.drawable.stat_sys_warning) @@ -7877,7 +7879,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { .setColor(mContext.getColor(R.color.system_notification_accent_color)) .setStyle(new Notification.BigTextStyle().bigText(wipeReasonForUser)) .build(); - mInjector.getNotificationManager().notify(SystemMessage.NOTE_PROFILE_WIPED, notification); + mInjector.getNotificationManager().notifyAsUser( + /* tag= */ null, SystemMessage.NOTE_PROFILE_WIPED, notification, user); } private String getWorkProfileDeletedTitle() { @@ -16895,6 +16898,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } else { granted = PackageManager.PERMISSION_GRANTED; } + } } } @@ -19998,6 +20002,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Objects.requireNonNull(who, "ComponentName is null"); Objects.requireNonNull(packageNames, "Package names is null"); final CallerIdentity caller = getCallerIdentity(who); @@ -20014,9 +20019,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { saveSettingsLocked(caller.getUserId()); } logSetCrossProfilePackages(who, packageNames); - final CrossProfileApps crossProfileApps = mContext.getSystemService(CrossProfileApps.class); + final CrossProfileApps crossProfileApps = + mContext.createContextAsUser( + caller.getUserHandle(), /* flags= */ 0) + .getSystemService(CrossProfileApps.class); mInjector.binderWithCleanCallingIdentity( - () -> crossProfileApps.resetInteractAcrossProfilesAppOps( + () -> crossProfileApps.resetInteractAcrossProfilesAppOps( previousCrossProfilePackages, new HashSet<>(packageNames))); } |