From 77b0bb5295b26fcc4b0ac0f5f67ff15a1d06e8f9 Mon Sep 17 00:00:00 2001 From: shreyacsingh Date: Wed, 10 May 2023 15:11:33 +0000 Subject: [PATCH] Communicate right error code from DPMS to MP in response to STATUS_HEADLESS_SYSTEM_USER_MODE_NOT_SUPPORTED This status code occurs when an user attempts to provision an unsupported DPC into DO on a headless device Bug: 268168017 Test: manual Change-Id: If97998a628279ca4e7c2fba8633f5af1ae408000 --- .../devicepolicy/DevicePolicyManagerService.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index f6bc93ab2491a..bbd1f6a6aa987 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -10907,8 +10907,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { /* deviceOwnerUserId= */ deviceOwnerUserId, /* callingUserId*/ caller.getUserId(), isAdb(caller), hasIncompatibleAccountsOrNonAdb); if (code != STATUS_OK) { - throw new IllegalStateException(computeProvisioningErrorStringLocked(code, - deviceOwnerUserId, owner, showComponentOnError)); + final String provisioningErrorStringLocked = computeProvisioningErrorStringLocked(code, + deviceOwnerUserId, owner, showComponentOnError); + if (code == STATUS_HEADLESS_SYSTEM_USER_MODE_NOT_SUPPORTED) { + throw new ServiceSpecificException(code, provisioningErrorStringLocked); + } else { + throw new IllegalStateException(provisioningErrorStringLocked); + } } } @@ -10962,6 +10967,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { case STATUS_HAS_PAIRED: return "Not allowed to set the device owner because this device has already " + "paired."; + case STATUS_HEADLESS_SYSTEM_USER_MODE_NOT_SUPPORTED: + return "Cannot provision an unsupported DPC into DO on a" + + " headless device"; default: return "Unexpected @ProvisioningPreCondition: " + code; }