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

Commit 23cc1b07 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6379507 from c14806197cb453e8e26558adf8c02db9567c036a to mainline-release

Change-Id: I2ddc68634a691db6c6321d47e2ac69e6f6637ead
parents bc0fcef4 10a6ecd8
Loading
Loading
Loading
Loading
+9 −23
Original line number Diff line number Diff line
@@ -979,14 +979,17 @@ public final class BluetoothAdapter {
                8, BLUETOOTH_GET_STATE_CACHE_PROPERTY) {
                @Override
                protected Integer recompute(Void query) {
                    // This function must be called while holding the
                    // mServiceLock, and with mService not null. The public
                    // getState() method makes this guarantee.
                    try {
                        mServiceLock.readLock().lock();
                        if (mService != null) {
                            return mService.getState();
                        }
                    } catch (RemoteException e) {
                        throw e.rethrowFromSystemServer();
                        Log.e(TAG, "", e);
                    } finally {
                        mServiceLock.readLock().unlock();
                    }
                    return BluetoothAdapter.STATE_OFF;
                }
            };

@@ -1013,24 +1016,7 @@ public final class BluetoothAdapter {
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    @AdapterState
    public int getState() {
        int state = BluetoothAdapter.STATE_OFF;

        try {
            mServiceLock.readLock().lock();
            // The test for mService must either be outside the cache, or
            // the cache must be invalidated when mService changes.
            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();
        }
        int state = mBluetoothGetStateCache.query(null);

        // Consider all internal states as OFF
        if (state == BluetoothAdapter.STATE_BLE_ON || state == BluetoothAdapter.STATE_BLE_TURNING_ON
+30 −40
Original line number Diff line number Diff line
@@ -119,8 +119,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
    private static final int MESSAGE_DISABLE = 2;
    private static final int MESSAGE_HANDLE_ENABLE_DELAYED = 3;
    private static final int MESSAGE_HANDLE_DISABLE_DELAYED = 4;
    private static final int MESSAGE_REGISTER_ADAPTER = 20;
    private static final int MESSAGE_UNREGISTER_ADAPTER = 21;
    private static final int MESSAGE_REGISTER_STATE_CHANGE_CALLBACK = 30;
    private static final int MESSAGE_UNREGISTER_STATE_CHANGE_CALLBACK = 31;
    private static final int MESSAGE_BLUETOOTH_SERVICE_CONNECTED = 40;
@@ -642,10 +640,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
            Slog.w(TAG, "Callback is null in registerAdapter");
            return null;
        }
        Message msg = mHandler.obtainMessage(MESSAGE_REGISTER_ADAPTER);
        msg.obj = callback;
        mHandler.sendMessage(msg);

        synchronized (mCallbacks) {
            mCallbacks.register(callback);
        }
        return mBluetooth;
    }

@@ -655,9 +652,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
            return;
        }
        mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        Message msg = mHandler.obtainMessage(MESSAGE_UNREGISTER_ADAPTER);
        msg.obj = callback;
        mHandler.sendMessage(msg);
        synchronized (mCallbacks) {
            mCallbacks.unregister(callback);
        }
    }

    public void registerStateChangeCallback(IBluetoothStateChangeCallback callback) {
@@ -1559,6 +1556,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
     * Inform BluetoothAdapter instances that Adapter service is up
     */
    private void sendBluetoothServiceUpCallback() {
        synchronized (mCallbacks) {
            try {
                int n = mCallbacks.beginBroadcast();
                Slog.d(TAG, "Broadcasting onBluetoothServiceUp() to " + n + " receivers.");
@@ -1573,11 +1571,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                mCallbacks.finishBroadcast();
            }
        }
    }

    /**
     * Inform BluetoothAdapter instances that Adapter service is down
     */
    private void sendBluetoothServiceDownCallback() {
        synchronized (mCallbacks) {
            try {
                int n = mCallbacks.beginBroadcast();
                Slog.d(TAG, "Broadcasting onBluetoothServiceDown() to " + n + " receivers.");
@@ -1592,6 +1592,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                mCallbacks.finishBroadcast();
            }
        }
    }

    public String getAddress() {
        mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
@@ -1917,17 +1918,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                                mContext.getPackageName());
                    }
                    break;

                case MESSAGE_REGISTER_ADAPTER: {
                    IBluetoothManagerCallback callback = (IBluetoothManagerCallback) msg.obj;
                    mCallbacks.register(callback);
                    break;
                }
                case MESSAGE_UNREGISTER_ADAPTER: {
                    IBluetoothManagerCallback callback = (IBluetoothManagerCallback) msg.obj;
                    mCallbacks.unregister(callback);
                    break;
                }
                case MESSAGE_REGISTER_STATE_CHANGE_CALLBACK: {
                    IBluetoothStateChangeCallback callback =
                            (IBluetoothStateChangeCallback) msg.obj;