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

Commit 9bd2e1bb authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge "Adapter: move register callback to oneway call" into main

parents b489d8a7 73f4cef1
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -250,9 +250,9 @@ interface IBluetooth
    boolean removeActiveDevice(in int profiles, in AttributionSource attributionSource);

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    boolean registerBluetoothConnectionCallback(in IBluetoothConnectionCallback callback, in AttributionSource attributionSource);
    oneway void registerBluetoothConnectionCallback(in IBluetoothConnectionCallback callback, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    boolean unregisterBluetoothConnectionCallback(in IBluetoothConnectionCallback callback, in AttributionSource attributionSource);
    oneway void unregisterBluetoothConnectionCallback(in IBluetoothConnectionCallback callback, in AttributionSource attributionSource);

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    boolean canBondWithoutDialog(in BluetoothDevice device, in AttributionSource attributionSource);
+5 −6
Original line number Diff line number Diff line
@@ -3346,32 +3346,31 @@ public class AdapterService extends Service {
        }

        @Override
        public boolean registerBluetoothConnectionCallback(
        public void registerBluetoothConnectionCallback(
                IBluetoothConnectionCallback callback, AttributionSource source) {
            AdapterService service = getService();
            if (service == null
                    || !callerIsSystemOrActiveOrManagedUser(
                            service, TAG, "registerBluetoothConnectionCallback")
                    || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) {
                return false;
                return;
            }
            enforceBluetoothPrivilegedPermission(service);
            service.mBluetoothConnectionCallbacks.add(callback);
            return true;
        }

        @Override
        public boolean unregisterBluetoothConnectionCallback(
        public void unregisterBluetoothConnectionCallback(
                IBluetoothConnectionCallback callback, AttributionSource source) {
            AdapterService service = getService();
            if (service == null
                    || !callerIsSystemOrActiveOrManagedUser(
                            service, TAG, "unregisterBluetoothConnectionCallback")
                    || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) {
                return false;
                return;
            }
            enforceBluetoothPrivilegedPermission(service);
            return service.mBluetoothConnectionCallbacks.remove(callback);
            service.mBluetoothConnectionCallbacks.remove(callback);
        }

        @Override
+28 −27
Original line number Diff line number Diff line
@@ -4804,28 +4804,28 @@ public final class BluetoothAdapter {
        }

        synchronized (mBluetoothConnectionCallbackExecutorMap) {
            // If the callback map is empty, we register the service-to-app callback
            if (mBluetoothConnectionCallbackExecutorMap.containsKey(callback)) {
                throw new IllegalArgumentException("This callback has already been registered");
            }

            if (mBluetoothConnectionCallbackExecutorMap.isEmpty()) {
                // If the callback map is empty, we register the service-to-app callback
                mServiceLock.readLock().lock();
                try {
                    if (mService != null) {
                        if (!mService.registerBluetoothConnectionCallback(
                                mConnectionCallback, mAttributionSource)) {
                    if (mService == null) {
                        return false;
                    }
                    }
                    mService.registerBluetoothConnectionCallback(
                            mConnectionCallback, mAttributionSource);
                } catch (RemoteException e) {
                    Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
                    mBluetoothConnectionCallbackExecutorMap.remove(callback);
                    return false;
                } finally {
                    mServiceLock.readLock().unlock();
                }
            }

            // Adds the passed in callback to our map of callbacks to executors
            if (mBluetoothConnectionCallbackExecutorMap.containsKey(callback)) {
                throw new IllegalArgumentException("This callback has already been registered");
            }
            mBluetoothConnectionCallbackExecutorMap.put(callback, executor);
        }

@@ -4854,29 +4854,30 @@ public final class BluetoothAdapter {
        }

        synchronized (mBluetoothConnectionCallbackExecutorMap) {
            if (mBluetoothConnectionCallbackExecutorMap.remove(callback) != null) {
                return false;
            }
        }

        if (!mBluetoothConnectionCallbackExecutorMap.isEmpty()) {
            if (!mBluetoothConnectionCallbackExecutorMap.containsKey(callback)) {
                return true;
            }

            mBluetoothConnectionCallbackExecutorMap.remove(callback);

            if (mBluetoothConnectionCallbackExecutorMap.isEmpty()) {
                // If the callback map is empty, we unregister the service-to-app callback
                mServiceLock.readLock().lock();
                try {
            if (mService != null) {
                return mService.unregisterBluetoothConnectionCallback(
                        mConnectionCallback, mAttributionSource);
                    if (mService == null) {
                        return true;
                    }
                    mService.unregisterBluetoothConnectionCallback(
                            mConnectionCallback, mAttributionSource);
                } catch (RemoteException e) {
                    Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
                } finally {
                    mServiceLock.readLock().unlock();
                }
            }
        }

        return false;
        return true;
    }

    /**