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

Commit 640b0b54 authored by Ömer Faruk Yılmaz's avatar Ömer Faruk Yılmaz
Browse files

Fix missing GattService variable linkage

When scanManagerRefactor flag is enabled, `startGattProfileService()` is
never called and hence, the variable `mGattService` was never assigned.
Fixing that, fix the connecting issue as `getBluetoothGatt()` now no
longer returns null.

See go/scan-manager-refactor for more details.

Bug: 313335632
Bug: 267361243
Bug: 327503826
Bug: 343116685
Flag: com.android.bluetooth.flags.scan_manager_refactor
Test: m com.android.btservices
Change-Id: Ief870e097c643c60ff3249b1bf1e66e394285125
parent 52ce81f5
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -1997,6 +1997,9 @@ public class AdapterService extends Service {
        mLeAudioService = LeAudioService.getLeAudioService();
        mBassClientService = BassClientService.getBassClientService();
        mBatteryService = BatteryService.getBatteryService();
        if (Flags.scanManagerRefactor()) {
            mGattService = GattService.getGattService();
        }
    }

    @BluetoothAdapter.RfcommListenerResult
@@ -4197,10 +4200,7 @@ public class AdapterService extends Service {
        @Override
        public IBinder getBluetoothGatt() {
            AdapterService service = getService();
            if (service == null) {
                return null;
            }
            return service.getBluetoothGatt();
            return service == null ? null : service.getBluetoothGatt();
        }

        @Override
@@ -5912,10 +5912,7 @@ public class AdapterService extends Service {
    }

    IBinder getBluetoothGatt() {
        if (mGattService == null) {
            return null;
        }
        return ((ProfileService) mGattService).getBinder();
        return mGattService == null ? null : mGattService.getBinder();
    }

    IBinder getBluetoothScan() {
+39 −0
Original line number Diff line number Diff line
@@ -140,6 +140,9 @@ public class GattService extends ProfileService {
    public final TransitionalScanHelper mTransitionalScanHelper =
            new TransitionalScanHelper(this, this::isTestModeEnabled);

    /** This is only used when Flags.scanManagerRefactor() is true. */
    private static GattService sGattService;

    /** List of our registered advertisers. */
    static class AdvertiserMap extends ContextMap<IAdvertisingSetCallback, Void> {}

@@ -200,6 +203,11 @@ public class GattService extends ProfileService {
    @Override
    public void start() {
        Log.d(TAG, "start()");

        if (Flags.scanManagerRefactor() && sGattService != null) {
            throw new IllegalStateException("start() called twice");
        }

        Settings.Global.putInt(
                getContentResolver(), "bluetooth_sanitized_exposure_notification_supported", 1);

@@ -220,11 +228,24 @@ public class GattService extends ProfileService {

        mActivityManager = getSystemService(ActivityManager.class);
        mPackageManager = mAdapterService.getPackageManager();

        if (Flags.scanManagerRefactor()) {
            setGattService(this);
        }
    }

    @Override
    public void stop() {
        Log.d(TAG, "stop()");
        if (Flags.scanManagerRefactor() && sGattService != null) {
            Log.w(TAG, "stop() called before start()");
            return;
        }

        if (Flags.scanManagerRefactor()) {
            setGattService(null);
        }

        mTransitionalScanHelper.stop();
        mAdvertiserMap.clear();
        mClientMap.clear();
@@ -253,6 +274,24 @@ public class GattService extends ProfileService {
        mTransitionalScanHelper.cleanup();
    }

    /** This is only used when Flags.scanManagerRefactor() is true. */
    public static synchronized GattService getGattService() {
        if (sGattService == null) {
            Log.w(TAG, "getGattService(): service is null");
            return null;
        }
        if (!sGattService.isAvailable()) {
            Log.w(TAG, "getGattService(): service is not available");
            return null;
        }
        return sGattService;
    }

    private static synchronized void setGattService(GattService instance) {
        Log.d(TAG, "setGattService(): set to: " + instance);
        sGattService = instance;
    }

    TransitionalScanHelper getTransitionalScanHelper() {
        return mTransitionalScanHelper;
    }