Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 888bc2c1 authored by Rubin Xu's avatar Rubin Xu
Browse files

Catch IllegalStateException in DPM.isFinancedDevice

Bug: 380586088
Test: None
Flag: EXEMPT bugfix
Change-Id: I84e5acc080973a343e72bf148d587040bb190501
parent 0dbe03a2
Loading
Loading
Loading
Loading
+11 −3
Original line number Original line Diff line number Diff line
@@ -17644,9 +17644,17 @@ public class DevicePolicyManager {
            android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS
            android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS
    })
    })
    public boolean isFinancedDevice() {
    public boolean isFinancedDevice() {
        try {
            return isDeviceManaged()
            return isDeviceManaged()
                    && getDeviceOwnerType(getDeviceOwnerComponentOnAnyUser())
                    && getDeviceOwnerType(getDeviceOwnerComponentOnAnyUser())
                    == DEVICE_OWNER_TYPE_FINANCED;
                    == 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
    // TODO(b/315298076): revert ag/25574027 and update the doc