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

Commit 578d3f6a authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'bt5-cherry-pickerry-3' into oc-dev

* changes:
  Expose LE advertiser address for easier PTS tests (2/6)
  Read by UUID for PTS tests (2/5)
parents 0a885175 abe554f0
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -190,6 +190,7 @@ static jmethodID method_onServerConnUpdate;
 * Advertiser callback methods
 */
static jmethodID method_onAdvertisingSetStarted;
static jmethodID method_onOwnAddressRead;
static jmethodID method_onAdvertisingEnabled;
static jmethodID method_onAdvertisingDataSet;
static jmethodID method_onScanResponseDataSet;
@@ -1083,6 +1084,17 @@ static void gattClientReadCharacteristicNative(JNIEnv* env, jobject object,
  sGattIf->client->read_characteristic(conn_id, handle, authReq);
}

static void gattClientReadUsingCharacteristicUuidNative(
    JNIEnv* env, jobject object, jint conn_id, jlong uuid_lsb, jlong uuid_msb,
    jint s_handle, jint e_handle, jint authReq) {
  if (!sGattIf) return;

  bt_uuid_t uuid;
  set_uuid(uuid.uu, uuid_msb, uuid_lsb);
  sGattIf->client->read_using_characteristic_uuid(conn_id, &uuid, s_handle,
                                                  e_handle, authReq);
}

static void gattClientReadDescriptorNative(JNIEnv* env, jobject object,
                                           jint conn_id, jint handle,
                                           jint authReq) {
@@ -1672,6 +1684,8 @@ static void gattServerSendResponseNative(JNIEnv* env, jobject object,
static void advertiseClassInitNative(JNIEnv* env, jclass clazz) {
  method_onAdvertisingSetStarted =
      env->GetMethodID(clazz, "onAdvertisingSetStarted", "(IIII)V");
  method_onOwnAddressRead =
      env->GetMethodID(clazz, "onOwnAddressRead", "(IILjava/lang/String;)V");
  method_onAdvertisingEnabled =
      env->GetMethodID(clazz, "onAdvertisingEnabled", "(IZI)V");
  method_onAdvertisingDataSet =
@@ -1834,6 +1848,24 @@ static void stopAdvertisingSetNative(JNIEnv* env, jobject object,
  sGattIf->advertiser->Unregister(advertiser_id);
}

static void getOwnAddressCb(uint8_t advertiser_id, uint8_t address_type,
                            bt_bdaddr_t address) {
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;

  ScopedLocalRef<jstring> addr(sCallbackEnv.get(),
                               bdaddr2newjstr(sCallbackEnv.get(), &address));
  sCallbackEnv->CallVoidMethod(mAdvertiseCallbacksObj, method_onOwnAddressRead,
                               advertiser_id, address_type, addr.get());
}

static void getOwnAddressNative(JNIEnv* env, jobject object,
                                jint advertiser_id) {
  if (!sGattIf) return;
  sGattIf->advertiser->GetOwnAddress(
      advertiser_id, base::Bind(&getOwnAddressCb, advertiser_id));
}

static void callJniCallback(jmethodID method, uint8_t advertiser_id,
                            uint8_t status) {
  CallbackEnv sCallbackEnv(__func__);
@@ -2055,6 +2087,7 @@ static JNINativeMethod sAdvertiseMethods[] = {
     "(Landroid/bluetooth/le/AdvertisingSetParameters;[B[BLandroid/bluetooth/"
     "le/PeriodicAdvertisingParameters;[BIII)V",
     (void*)startAdvertisingSetNative},
    {"getOwnAddressNative", "(I)V", (void*)getOwnAddressNative},
    {"stopAdvertisingSetNative", "(I)V", (void*)stopAdvertisingSetNative},
    {"enableAdvertisingSetNative", "(IZII)V",
     (void*)enableAdvertisingSetNative},
@@ -2142,6 +2175,8 @@ static JNINativeMethod sMethods[] = {
    {"gattClientGetGattDbNative", "(I)V", (void*)gattClientGetGattDbNative},
    {"gattClientReadCharacteristicNative", "(III)V",
     (void*)gattClientReadCharacteristicNative},
    {"gattClientReadUsingCharacteristicUuidNative", "(IJJIII)V",
     (void*)gattClientReadUsingCharacteristicUuidNative},
    {"gattClientReadDescriptorNative", "(III)V",
     (void*)gattClientReadDescriptorNative},
    {"gattClientWriteCharacteristicNative", "(IIII[B)V",
+19 −0
Original line number Diff line number Diff line
@@ -202,6 +202,24 @@ class AdvertiseManager {
                periodic_data, duration, maxExtAdvEvents, cb_id);
    }

    void onOwnAddressRead(int advertiser_id, int addressType, String address)
            throws RemoteException {
        logd("onOwnAddressRead() advertiser_id=" + advertiser_id);

        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiser_id);
        if (entry == null) {
            Log.i(TAG, "onOwnAddressRead() - bad advertiser_id " + advertiser_id);
            return;
        }

        IAdvertisingSetCallback callback = entry.getValue().callback;
        callback.onOwnAddressRead(advertiser_id, addressType, address);
    }

    void getOwnAddress(int advertiserId) {
        getOwnAddressNative(advertiserId);
    }

    void stopAdvertisingSet(IAdvertisingSetCallback callback) {
        IBinder binder = toBinder(callback);
        if (DBG) Log.d(TAG, "stopAdvertisingSet() " + binder);
@@ -361,6 +379,7 @@ class AdvertiseManager {
            byte[] advertiseData, byte[] scanResponse,
            PeriodicAdvertisingParameters periodicParameters, byte[] periodicData, int duration,
            int maxExtAdvEvents, int reg_id);
    private native void getOwnAddressNative(int advertiserId);
    private native void stopAdvertisingSetNative(int advertiser_id);
    private native void enableAdvertisingSetNative(
            int advertiserId, boolean enable, int duration, int maxExtAdvEvents);
+50 −0
Original line number Diff line number Diff line
@@ -219,6 +219,13 @@ public class GattService extends ProfileService {
        return true;
    }

    boolean permissionCheck(UUID uuid) {
        if (isRestrictedCharUuid(uuid) && (0 != checkCallingOrSelfPermission(BLUETOOTH_PRIVILEGED)))
            return false;
        else
            return true;
    }

    boolean permissionCheck(int connId, int handle) {
        List<BluetoothGattService> db = gattClientDatabases.get(connId);
        if (db == null) return true;
@@ -460,6 +467,14 @@ public class GattService extends ProfileService {
            service.readCharacteristic(clientIf, address, handle, authReq);
        }

        public void readUsingCharacteristicUuid(int clientIf, String address, ParcelUuid uuid,
                int startHandle, int endHandle, int authReq) {
            GattService service = getService();
            if (service == null) return;
            service.readUsingCharacteristicUuid(
                    clientIf, address, uuid.getUuid(), startHandle, endHandle, authReq);
        }

        public void writeCharacteristic(int clientIf, String address, int handle,
                             int writeType, int authReq, byte[] value) {
            GattService service = getService();
@@ -603,6 +618,12 @@ public class GattService extends ProfileService {
            service.stopAdvertisingSet(callback);
        }

        public void getOwnAddress(int advertiserId) {
            GattService service = getService();
            if (service == null) return;
            service.getOwnAddress(advertiserId);
        }

        public void enableAdvertisingSet(
                int advertiserId, boolean enable, int duration, int maxExtAdvEvents) {
            GattService service = getService();
@@ -1708,6 +1729,11 @@ public class GattService extends ProfileService {
        mAdvertiseManager.stopAdvertisingSet(callback);
    }

    void getOwnAddress(int advertiserId) {
        enforcePrivilegedPermission();
        mAdvertiseManager.getOwnAddress(advertiserId);
    }

    void enableAdvertisingSet(int advertiserId, boolean enable, int duration, int maxExtAdvEvents) {
        enforceAdminPermission();
        mAdvertiseManager.enableAdvertisingSet(advertiserId, enable, duration, maxExtAdvEvents);
@@ -1871,6 +1897,27 @@ public class GattService extends ProfileService {
        gattClientReadCharacteristicNative(connId, handle, authReq);
    }

    void readUsingCharacteristicUuid(
            int clientIf, String address, UUID uuid, int startHandle, int endHandle, int authReq) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");

        if (VDBG) Log.d(TAG, "readUsingCharacteristicUuid() - address=" + address);

        Integer connId = mClientMap.connIdByAddress(clientIf, address);
        if (connId == null) {
            Log.e(TAG, "readUsingCharacteristicUuid() - No connection for " + address + "...");
            return;
        }

        if (!permissionCheck(uuid)) {
            Log.w(TAG, "readUsingCharacteristicUuid() - permission check failed!");
            return;
        }

        gattClientReadUsingCharacteristicUuidNative(connId, uuid.getLeastSignificantBits(),
                uuid.getMostSignificantBits(), startHandle, endHandle, authReq);
    }

    void writeCharacteristic(int clientIf, String address, int handle, int writeType,
                             int authReq, byte[] value) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
@@ -2646,6 +2693,9 @@ public class GattService extends ProfileService {

    private native void gattClientReadCharacteristicNative(int conn_id, int handle, int authReq);

    private native void gattClientReadUsingCharacteristicUuidNative(
            int conn_id, long uuid_msb, long uuid_lsb, int s_handle, int e_handle, int authReq);

    private native void gattClientReadDescriptorNative(int conn_id, int handle, int authReq);

    private native void gattClientWriteCharacteristicNative(int conn_id,