diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java index 04300c16fc966..a7ce4e7a6d63b 100644 --- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java +++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java @@ -612,20 +612,25 @@ public class CompanionDeviceManagerService extends SystemService implements Bind + " for " + association + " - profile still present in " + otherAssociationWithDeviceProfile); } else { - mRoleManager.removeRoleHolderAsUser( - association.getDeviceProfile(), - association.getPackageName(), - RoleManager.MANAGE_HOLDERS_FLAG_DONT_KILL_APP, - UserHandle.of(association.getUserId()), - getContext().getMainExecutor(), - success -> { - if (!success) { - Log.e(LOG_TAG, "Failed to revoke device profile role " - + association.getDeviceProfile() - + " to " + association.getPackageName() - + " for user " + association.getUserId()); - } - }); + long identity = Binder.clearCallingIdentity(); + try { + mRoleManager.removeRoleHolderAsUser( + association.getDeviceProfile(), + association.getPackageName(), + RoleManager.MANAGE_HOLDERS_FLAG_DONT_KILL_APP, + UserHandle.of(association.getUserId()), + getContext().getMainExecutor(), + success -> { + if (!success) { + Log.e(LOG_TAG, "Failed to revoke device profile role " + + association.getDeviceProfile() + + " to " + association.getPackageName() + + " for user " + association.getUserId()); + } + }); + } finally { + Binder.restoreCallingIdentity(identity); + } } } }