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

Commit d2d8fa18 authored by William Escande's avatar William Escande
Browse files

Adapter: re-order init to prevent null exception

As soon as the callback are registered, the adapter can be notified.
There is a thin possibility that the bluetooth is being started at the
same time which would result in the callback being called before the
initialization is completed.

Since the initialization is only creating local variable except for the
registration, moving the registration to be the last init action would
solve this.

Note that this require a very fast callback call and a very slow init
altogether with a precise timing.
None of that are expect on a normal journey

Bug: 376735216
Fix: 376735216
Test: m .
Flag: Exempt, trivial fix
Change-Id: I6029fb30a7c4bf3be6d10b743684b6bbc41b5cb1
parent 13d80834
Loading
Loading
Loading
Loading
+9 −15
Original line number Original line Diff line number Diff line
@@ -1092,12 +1092,6 @@ public final class BluetoothAdapter {
    BluetoothAdapter(IBluetoothManager managerService, AttributionSource attributionSource) {
    BluetoothAdapter(IBluetoothManager managerService, AttributionSource attributionSource) {
        mManagerService = requireNonNull(managerService);
        mManagerService = requireNonNull(managerService);
        mAttributionSource = requireNonNull(attributionSource);
        mAttributionSource = requireNonNull(attributionSource);
        mServiceLock.writeLock().lock();
        try {
            mService = getBluetoothService(mManagerCallback);
        } finally {
            mServiceLock.writeLock().unlock();
        }


        Consumer<IBluetooth> registerQualityReportCallbackConsumer =
        Consumer<IBluetooth> registerQualityReportCallbackConsumer =
                (IBluetooth service) -> {
                (IBluetooth service) -> {
@@ -1165,6 +1159,13 @@ public final class BluetoothAdapter {
                new CallbackWrapper(
                new CallbackWrapper(
                        registerBluetoothConnectionCallbackConsumer,
                        registerBluetoothConnectionCallbackConsumer,
                        unregisterBluetoothConnectionCallbackConsumer);
                        unregisterBluetoothConnectionCallbackConsumer);

        mServiceLock.writeLock().lock();
        try {
            mService = registerBlueoothManagerCallback(mManagerCallback);
        } finally {
            mServiceLock.writeLock().unlock();
        }
    }
    }


    /**
    /**
@@ -4211,15 +4212,8 @@ public final class BluetoothAdapter {
        }
        }
    }
    }


    /**
    /** Registers a IBluetoothManagerCallback and returns the cached service proxy object. */
     * Registers a IBluetoothManagerCallback and returns the cached Bluetooth service proxy object.
    IBluetooth registerBlueoothManagerCallback(IBluetoothManagerCallback cb) {
     *
     * <p>TODO: rename this API to registerBlueoothManagerCallback or something? the current name
     * does not match what it does very well.
     *
     * <p>/ @UnsupportedAppUsage /*package
     */
    IBluetooth getBluetoothService(IBluetoothManagerCallback cb) {
        requireNonNull(cb);
        requireNonNull(cb);
        if (Flags.getProfileUseLock()) {
        if (Flags.getProfileUseLock()) {
            sServiceLock.writeLock().lock();
            sServiceLock.writeLock().lock();