Catch security exception on isOemUnlockAllowed

As of Android 15, devices with FRP active will throw an exception when loading developer options attempts to update the OEM unlock state, which causes the app to crash.  This CL just catches the exception and reports that OEM unlock is not, in fact, settable.

A full fix should probably tell the user that OEM unlock may not be set because FRP is active, rather than just quietly failing and logging the situation, but because GMS Core is soon going to begin blocking access to the Android UI when FRP is active, meaning that developer options won't even be reachable and the user will be informed about FRP state by GMS Core, the effort that would require isn't justified.

Note that this CL does not add a test for this change because it is not possible for CTS to put the device in FRP-active state to test the relevant case.  Manual testing is required.

Test: SettingsUnitTests
Flag: EXEMPT bugfix
Bug: 405023810
Change-Id: Ic43de93a4208bbc17f2e287d52f9baf281cd678c
This commit is contained in:
Shawn Willden
2025-03-21 15:38:19 -07:00
parent 081fab1330
commit fb2d3b7abb

View File

@@ -236,7 +236,13 @@ public class OemUnlockPreferenceController extends DeveloperOptionsPreferenceCon
@VisibleForTesting
boolean isOemUnlockedAllowed() {
try {
return mOemLockManager.isOemUnlockAllowed();
} catch (SecurityException e) {
// This exception is thrown if the device is not allowed to check (or change) the OEM
// unlock setting because Factory Reset Protection is active.
Log.e(TAG, "Failed to check OEM unlock allowed", e);
return false;
}
}
}