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

Commit 69574b75 authored by William Escande's avatar William Escande
Browse files

Le callback: Pass gattService from app directly

This allow to avoid getting the gattService in async from the framework
context and ensure the gattService is not null.

Bug: 318461868
Test: m com.android.btservices
Flag: EXEMPT, no logical change only passing back a variable instead of
      getting it later Talked offline with Hallstrom about the flagging
      need
Change-Id: I1bd114564742253a86d6eced1f0db16ee59dad57
parent 1dd09249
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ package android.bluetooth.le;
 * @hide
 */
oneway interface IAdvertisingSetCallback {
  void onAdvertisingSetStarted(in int advertiserId, in int tx_power, in int status);
  void onAdvertisingSetStarted(in IBinder gattBinder, in int advertiserId, in int tx_power, in int status);
  void onOwnAddressRead(in int advertiserId, in int addressType, in String address);
  void onAdvertisingSetStopped(in int advertiserId);
  void onAdvertisingEnabled(in int advertiserId, in boolean enable, in int status);
+2 −1
Original line number Diff line number Diff line
@@ -111,7 +111,8 @@ public abstract class ProfileService extends ContextWrapper {
        mBinder = initBinder();
    }

    IBinder getBinder() {
    /** return the binder of the profile */
    public IBinder getBinder() {
        requireNonNull(mBinder, "Binder is null. onCreate need to be called first");
        return mBinder;
    }
+7 −4
Original line number Diff line number Diff line
@@ -184,7 +184,8 @@ public class AdvertiseManager {
            AppAdvertiseStats.recordAdvertiseErrorCount(LE_ADV_ERROR_ON_START_COUNT);
        }

        callback.onAdvertisingSetStarted(advertiserId, txPower, status);
        IBinder gattBinder = mService.getBinder();
        callback.onAdvertisingSetStarted(gattBinder, advertiserId, txPower, status);
    }

    void onAdvertisingEnabled(int advertiserId, boolean enable, int status) throws Exception {
@@ -221,8 +222,9 @@ public class AdvertiseManager {
                        != AdvertisingSetParameters.ADDRESS_TYPE_RANDOM_NON_RESOLVABLE) {
            Log.w(TAG, "Cannot advertise an isolated GATT server using a resolvable address");
            try {
                IBinder gattBinder = mService.getBinder();
                callback.onAdvertisingSetStarted(
                        0x00, 0x00, AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR);
                        gattBinder, 0x00, 0x00, AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR);
            } catch (RemoteException exception) {
                Log.e(TAG, "Failed to callback:" + Log.getStackTraceString(exception));
            }
@@ -279,8 +281,9 @@ public class AdvertiseManager {
        } catch (IllegalArgumentException e) {
            try {
                binder.unlinkToDeath(deathRecipient, 0);
                callback.onAdvertisingSetStarted(0x00, 0x00,
                        AdvertiseCallback.ADVERTISE_FAILED_DATA_TOO_LARGE);
                IBinder gattBinder = mService.getBinder();
                callback.onAdvertisingSetStarted(
                        gattBinder, 0x00, 0x00, AdvertiseCallback.ADVERTISE_FAILED_DATA_TOO_LARGE);
            } catch (RemoteException exception) {
                Log.e(TAG, "Failed to callback:" + Log.getStackTraceString(exception));
            }
+3 −2
Original line number Diff line number Diff line
@@ -50,13 +50,14 @@ public final class AdvertisingSet {
    private int mAdvertiserId;
    private AttributionSource mAttributionSource;

    /* package */ AdvertisingSet(
    AdvertisingSet(
            IBluetoothGatt gatt,
            int advertiserId,
            BluetoothAdapter bluetoothAdapter,
            AttributionSource attributionSource) {
        mAdvertiserId = advertiserId;
        mAttributionSource = attributionSource;
        mGatt = requireNonNull(bluetoothAdapter.getBluetoothGatt(), "Failed to get Bluetooth gatt");
        mGatt = requireNonNull(gatt, "Bluetooth gatt cannot be null");
    }

    /* package */ void setAdvertiserId(int advertiserId) {
+4 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.bluetooth.annotations.RequiresBluetoothAdvertisePermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission;
import android.content.AttributionSource;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.ParcelUuid;
import android.os.RemoteException;
@@ -750,7 +751,8 @@ public final class BluetoothLeAdvertiser {
    IAdvertisingSetCallback wrap(AdvertisingSetCallback callback, Handler handler) {
        return new IAdvertisingSetCallback.Stub() {
            @Override
            public void onAdvertisingSetStarted(int advertiserId, int txPower, int status) {
            public void onAdvertisingSetStarted(
                    IBinder gattBinder, int advertiserId, int txPower, int status) {
                handler.post(
                        () -> {
                            if (status != AdvertisingSetCallback.ADVERTISE_SUCCESS) {
@@ -761,6 +763,7 @@ public final class BluetoothLeAdvertiser {

                            AdvertisingSet advertisingSet =
                                    new AdvertisingSet(
                                            IBluetoothGatt.Stub.asInterface(gattBinder),
                                            advertiserId,
                                            mBluetoothAdapter,
                                            mAttributionSource);