diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java index 70b2672f70b60..8a27acce03c35 100644 --- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java +++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java @@ -872,20 +872,22 @@ public class CompanionDeviceManagerService extends SystemService implements Bind } private void grantDeviceProfile(Association association) { - mRoleManager.addRoleHolderAsUser( - 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 grant device profile role " - + association.getDeviceProfile() - + " to " + association.getPackageName() - + " for user " + association.getUserId()); - } - }); + if (association.getDeviceProfile() != null) { + mRoleManager.addRoleHolderAsUser( + 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 grant device profile role " + + association.getDeviceProfile() + + " to " + association.getPackageName() + + " for user " + association.getUserId()); + } + }); + } } void onDeviceDisconnected(String address) {