diff options
| -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 |