From d170c5c7f36db835dde03e9637c141313d8e35c5 Mon Sep 17 00:00:00 2001 From: Eugene Susla Date: Wed, 23 Dec 2020 18:14:15 -0800 Subject: [PATCH] Nullcheck device profile when re-granting on package change Test: presubmit Fixes: 176250389 Change-Id: I9c4e071b12335fdfc1177ab60e03002ae2704cc3 --- .../CompanionDeviceManagerService.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java index 04300c16fc966..f7be2800d04a6 100644 --- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java +++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java @@ -867,20 +867,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) {