Catch SecurityException for bluetooth_address setting.

This commit is contained in:
akwizgran
2023-09-12 17:12:13 +01:00
parent 09a9a00af6
commit 05b9dd699e

View File

@@ -64,11 +64,16 @@ public class AndroidUtils {
} }
// Return the address from settings if it's valid and not fake // Return the address from settings if it's valid and not fake
if (SDK_INT < 33) { if (SDK_INT < 33) {
try {
address = Settings.Secure.getString(ctx.getContentResolver(), address = Settings.Secure.getString(ctx.getContentResolver(),
"bluetooth_address"); "bluetooth_address");
if (isValidBluetoothAddress(address)) { if (isValidBluetoothAddress(address)) {
return new Pair<>(address, "settings"); return new Pair<>(address, "settings");
} }
} catch (SecurityException e) {
// Some custom ROMs throw this exception on SDK_INT < 33.
// Fall through
}
} }
// Try to get the address via reflection // Try to get the address via reflection
address = getBluetoothAddressByReflection(adapter); address = getBluetoothAddressByReflection(adapter);