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

Commit 5f258d9d authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Gerrit Code Review
Browse files

Merge "Expose LE advertiser address for easier PTS tests (2/6)"

parents 08c0ee81 a9725a75
Loading
Loading
Loading
Loading
+22 −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;
@@ -1683,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 =
@@ -1845,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__);
@@ -2066,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},
+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);
+11 −0
Original line number Diff line number Diff line
@@ -584,6 +584,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();
@@ -1534,6 +1540,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);