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

Commit c8aa1c5c authored by Lee Shombert's avatar Lee Shombert Committed by Automerger Merge Worker
Browse files

Merge "Fix exception handling in getState() binder cache" into rvc-dev am:...

Merge "Fix exception handling in getState() binder cache" into rvc-dev am: 6e17bc7f am: 3bfe58bd am: 303cf242

Change-Id: I159305c3c8b4c05198c94bc9c94e2e1bf6206361
parents 3c6d3414 303cf242
Loading
Loading
Loading
Loading
+28 −10
Original line number Diff line number Diff line
@@ -980,16 +980,10 @@ public final class BluetoothAdapter {
                @Override
                protected Integer recompute(Void query) {
                    try {
                        mServiceLock.readLock().lock();
                        if (mService != null) {
                        return mService.getState();
                        }
                    } catch (RemoteException e) {
                        Log.e(TAG, "", e);
                    } finally {
                        mServiceLock.readLock().unlock();
                        throw e.rethrowFromSystemServer();
                    }
                    return BluetoothAdapter.STATE_OFF;
                }
            };

@@ -1003,6 +997,30 @@ public final class BluetoothAdapter {
        PropertyInvalidatedCache.invalidateCache(BLUETOOTH_GET_STATE_CACHE_PROPERTY);
    }

    /**
     * Fetch the current bluetooth state.  If the service is down, return
     * OFF.
     */
    @AdapterState
    private int getStateInternal() {
        int state = BluetoothAdapter.STATE_OFF;
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                state = mBluetoothGetStateCache.query(null);
            }
        } catch (RuntimeException e) {
            if (e.getCause() instanceof RemoteException) {
                Log.e(TAG, "", e.getCause());
            } else {
                throw e;
            }
        } finally {
            mServiceLock.readLock().unlock();
        }
        return state;
    }

    /**
     * Get the current state of the local Bluetooth adapter.
     * <p>Possible return values are
@@ -1016,7 +1034,7 @@ public final class BluetoothAdapter {
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    @AdapterState
    public int getState() {
        int state = mBluetoothGetStateCache.query(null);
        int state = getStateInternal();

        // Consider all internal states as OFF
        if (state == BluetoothAdapter.STATE_BLE_ON || state == BluetoothAdapter.STATE_BLE_TURNING_ON
@@ -1054,7 +1072,7 @@ public final class BluetoothAdapter {
    @UnsupportedAppUsage(publicAlternatives = "Use {@link #getState()} instead to determine "
            + "whether you can use BLE & BT classic.")
    public int getLeState() {
        int state = mBluetoothGetStateCache.query(null);
        int state = getStateInternal();

        if (VDBG) {
            Log.d(TAG, "getLeState() returning " + BluetoothAdapter.nameForState(state));