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

Commit 9b335980 authored by Scott Warner's avatar Scott Warner
Browse files

Handle change from boolean to int preference

Commit 02bf7ae9 changed the type of the
phonebook access preference from boolean to int, which throws a
ClassCastException and disconnects from the device.
This changes the preference type from a boolean to an integer if this
would happen

Change-Id: I37bc1f4eec52cd05a04d370bfcecb473c0eff374
parent a182008a
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -1768,7 +1768,21 @@ public class AdapterService extends Service {
        if (!pref.contains(device.getAddress())) {
            return BluetoothDevice.ACCESS_UNKNOWN;
        }
        try {
            return pref.getInt(device.getAddress(), BluetoothDevice.ACCESS_UNKNOWN);
        } catch (ClassCastException e) {
            // Handle and change old boolean preferences to the int-based values
            boolean currentPref = pref.getBoolean(device.getAddress(), false);
            int newPref = currentPref ?
                BluetoothDevice.ACCESS_ALLOWED : BluetoothDevice.ACCESS_REJECTED;

            SharedPreferences.Editor editor = pref.edit();
            editor.putInt(device.getAddress(), newPref);
            if (editor.commit()) {
                return newPref;
            }
            return BluetoothDevice.ACCESS_UNKNOWN;
        }
    }

    boolean setPhonebookAccessPermission(BluetoothDevice device, int value) {