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

Commit 1844d2d8 authored by William Escande's avatar William Escande Committed by Automerger Merge Worker
Browse files

Adapter: registerBluetoothConnection am: a38c9f19

parents 2b19dd87 a38c9f19
Loading
Loading
Loading
Loading
+28 −31
Original line number Diff line number Diff line
@@ -3762,23 +3762,10 @@ public final class BluetoothAdapter {
                                }
                            }
                        }
                        synchronized (mBluetoothConnectionCallbackExecutorMap) {
                            if (!mBluetoothConnectionCallbackExecutorMap.isEmpty()) {
                                try {
                                    mService.registerBluetoothConnectionCallback(
                                            mConnectionCallback, mAttributionSource);
                                } catch (RemoteException e) {
                                    Log.e(
                                            TAG,
                                            "onBluetoothServiceUp: Failed to register "
                                                    + "bluetooth connection callback",
                                            e);
                                }
                            }
                        }
                    } finally {
                        mServiceLock.readLock().unlock();
                    }
                    registerBluetoothConnectionCallbackIfNeeded();
                }

                public void onBluetoothServiceDown() {
@@ -4630,7 +4617,7 @@ public final class BluetoothAdapter {
    }

    @SuppressLint("AndroidFrameworkBluetoothPermission")
    private final IBluetoothConnectionCallback mConnectionCallback =
    private final IBluetoothConnectionCallback mBluetoothConnectionCallback =
            new IBluetoothConnectionCallback.Stub() {
                @Override
                public void onDeviceConnected(BluetoothDevice device) {
@@ -4686,27 +4673,37 @@ public final class BluetoothAdapter {
            }

            if (mBluetoothConnectionCallbackExecutorMap.isEmpty()) {
                // If the callback map is empty, we register the service-to-app callback
                registerBluetoothConnectionCallback();
            }

            mBluetoothConnectionCallbackExecutorMap.put(callback, executor);
        }

        return true;
    }

    private void registerBluetoothConnectionCallback() {
        mServiceLock.readLock().lock();
        try {
            if (mService == null) {
                        return false;
                return;
            }
            mService.registerBluetoothConnectionCallback(
                            mConnectionCallback, mAttributionSource);
                    mBluetoothConnectionCallback, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
                    return false;
        } finally {
            mServiceLock.readLock().unlock();
        }
    }

            // Adds the passed in callback to our map of callbacks to executors
            mBluetoothConnectionCallbackExecutorMap.put(callback, executor);
    private void registerBluetoothConnectionCallbackIfNeeded() {
        synchronized (mBluetoothConnectionCallbackExecutorMap) {
            if (mBluetoothConnectionCallbackExecutorMap.isEmpty()) {
                return;
            }
            registerBluetoothConnectionCallback();
        }

        return true;
    }

    /**
@@ -4745,7 +4742,7 @@ public final class BluetoothAdapter {
                        return true;
                    }
                    mService.unregisterBluetoothConnectionCallback(
                            mConnectionCallback, mAttributionSource);
                            mBluetoothConnectionCallback, mAttributionSource);
                } catch (RemoteException e) {
                    Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
                } finally {