diff options
| author | 2025-02-11 17:22:08 +0000 | |
|---|---|---|
| committer | 2025-02-20 11:35:01 +0000 | |
| commit | 888bc2c19ddff16409e17385bcc004dc7abffdfc (patch) | |
| tree | db64b46f1d7e6fee33a86d09c07b602ef33bd75f | |
| parent | 0dbe03a2c035cd7a40df95106d73a2167ed31b8d (diff) | |
Catch IllegalStateException in DPM.isFinancedDevice
Bug: 380586088
Test: None
Flag: EXEMPT bugfix
Change-Id: I84e5acc080973a343e72bf148d587040bb190501
| -rw-r--r-- | core/java/android/app/admin/DevicePolicyManager.java | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 08719fc549f8..671d7c153c30 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -17644,9 +17644,17 @@ public class DevicePolicyManager { android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS }) public boolean isFinancedDevice() { - return isDeviceManaged() - && getDeviceOwnerType(getDeviceOwnerComponentOnAnyUser()) - == DEVICE_OWNER_TYPE_FINANCED; + try { + return isDeviceManaged() + && getDeviceOwnerType(getDeviceOwnerComponentOnAnyUser()) + == DEVICE_OWNER_TYPE_FINANCED; + } catch (IllegalStateException e) { + // getDeviceOwnerType() will throw IllegalStateException if the device does not have a + // DO. This can happen under a race condition when the DO is removed after + // isDeviceManaged() (so it still returns true) but before getDeviceOwnerType(). + // In this case, the device should not be considered a financed device. + return false; + } } // TODO(b/315298076): revert ag/25574027 and update the doc |