static jmethodID method_onScanFilterParamsConfigured;
static jmethodID method_onScanFilterEnableDisabled;
static jmethodID method_onAdvertiserRegistered;
-static jmethodID method_onMultiAdvSetParams;
-static jmethodID method_onMultiAdvSetAdvData;
+static jmethodID method_onAdvertiserStarted;
static jmethodID method_onMultiAdvEnable;
static jmethodID method_onClientCongestion;
static jmethodID method_onBatchScanStorageConfigured;
status, advertiser_id, UUID_PARAMS(&uuid));
}
-void ble_advertiser_set_params_cb(uint8_t advertiser_id, uint8_t status)
-{
- CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
- sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onMultiAdvSetParams, status, advertiser_id);
-}
-
-void ble_advertiser_setadv_data_cb(uint8_t advertiser_id, uint8_t status)
+void ble_advertiser_enable_cb(bool enable, uint8_t advertiser_id, uint8_t status)
{
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onMultiAdvSetAdvData, status, advertiser_id);
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onMultiAdvEnable, status, advertiser_id, enable);
}
-void ble_advertiser_enable_cb(bool enable, uint8_t advertiser_id, uint8_t status)
+void ble_advertiser_start_cb(uint8_t advertiser_id, uint8_t status)
{
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onMultiAdvEnable, status, advertiser_id, enable);
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAdvertiserStarted,
+ status, advertiser_id);
}
/**
method_onScanFilterParamsConfigured = env->GetMethodID(clazz, "onScanFilterParamsConfigured", "(IIII)V");
method_onScanFilterEnableDisabled = env->GetMethodID(clazz, "onScanFilterEnableDisabled", "(III)V");
method_onAdvertiserRegistered = env->GetMethodID(clazz, "onAdvertiserRegistered", "(IIJJ)V");
- method_onMultiAdvSetParams = env->GetMethodID(clazz, "onAdvertiseParamsSet", "(II)V");
- method_onMultiAdvSetAdvData = env->GetMethodID(clazz, "onAdvertiseDataSet", "(II)V");
+ method_onAdvertiserStarted = env->GetMethodID(clazz, "onAdvertiserStarted", "(II)V");
method_onMultiAdvEnable = env->GetMethodID(clazz, "onAdvertiseInstanceEnabled", "(IIZ)V");
method_onClientCongestion = env->GetMethodID(clazz, "onClientCongestion", "(IZ)V");
method_onBatchScanStorageConfigured = env->GetMethodID(clazz, "onBatchScanStorageConfigured", "(II)V");
sGattIf->advertiser->RegisterAdvertiser(base::Bind(&ble_advertiser_register_cb, uuid));
}
+static void startAdvertiserNative(JNIEnv *env, jobject object, jint advertiser_id,
+ jint min_interval, jint max_interval, jint adv_type, jint chnl_map,
+ jint tx_power, jbyteArray adv_data, jbyteArray scan_resp, jint timeout_s) {
+ if (!sGattIf) return;
+
+ AdvertiseParameters params;
+ params.min_interval = min_interval;
+ params.max_interval = max_interval;
+ params.adv_type = adv_type;
+ params.channel_map = chnl_map;
+ params.tx_power = tx_power;
+
+ jbyte* adv_data_data = env->GetByteArrayElements(adv_data, NULL);
+ uint16_t adv_data_len = (uint16_t) env->GetArrayLength(adv_data);
+ vector<uint8_t> data_vec(adv_data_data, adv_data_data + adv_data_len);
+ env->ReleaseByteArrayElements(adv_data, adv_data_data, JNI_ABORT);
+
+ jbyte* scan_resp_data = env->GetByteArrayElements(scan_resp, NULL);
+ uint16_t scan_resp_len = (uint16_t) env->GetArrayLength(scan_resp);
+ vector<uint8_t> scan_resp_vec(scan_resp_data, scan_resp_data + scan_resp_len);
+ env->ReleaseByteArrayElements(scan_resp, scan_resp_data, JNI_ABORT);
+
+ sGattIf->advertiser->StartAdvertising(advertiser_id,
+ base::Bind(&ble_advertiser_start_cb, advertiser_id),
+ params, data_vec, scan_resp_vec, timeout_s,
+ base::Bind(&ble_advertiser_enable_cb, false,
+ advertiser_id));
+}
static void unregisterAdvertiserNative(JNIEnv* env, jobject object, jint advertiser_id)
{
if (!sGattIf) return;
base::Bind(&ble_advertiser_enable_cb, false, advertiser_id));
}
-static void gattClientSetAdvParamsNative(JNIEnv* env, jobject object, jint advertiser_id,
- jint min_interval, jint max_interval, jint adv_type, jint chnl_map, jint tx_power)
-{
- if (!sGattIf) return;
-
- sGattIf->advertiser->SetParameters(
- advertiser_id, min_interval, max_interval, adv_type, chnl_map, tx_power,
- base::Bind(&ble_advertiser_set_params_cb, advertiser_id));
-}
-
-static void gattClientSetAdvDataNative(JNIEnv* env, jobject object, jint advertiser_id,
- jboolean set_scan_rsp, jbyteArray data)
-{
- if (!sGattIf) return;
- jbyte* data_data = env->GetByteArrayElements(data, NULL);
- uint16_t data_len = (uint16_t) env->GetArrayLength(data);
- vector<uint8_t> data_vec(data_data, data_data + data_len);
- env->ReleaseByteArrayElements(data, data_data, JNI_ABORT);
-
- sGattIf->advertiser->SetData(
- advertiser_id, set_scan_rsp, std::move(data_vec),
- base::Bind(&ble_advertiser_setadv_data_cb, advertiser_id));
-}
-
static void gattClientConfigBatchScanStorageNative(JNIEnv* env, jobject object, jint client_if,
jint max_full_reports_percent, jint max_trunc_reports_percent,
jint notify_threshold_level_percent)
static JNINativeMethod sAdvertiseMethods[] = {
{"registerAdvertiserNative", "(JJ)V", (void *) registerAdvertiserNative},
{"unregisterAdvertiserNative", "(I)V", (void *) unregisterAdvertiserNative},
- {"gattClientSetParamsNative", "(IIIIII)V", (void *) gattClientSetAdvParamsNative},
- {"gattClientSetAdvDataNative", "(IZ[B)V", (void *) gattClientSetAdvDataNative},
{"gattClientEnableAdvNative", "(IZI)V", (void *) gattClientEnableAdvNative},
+ {"startAdvertiserNative", "(IIIIII[B[BI)V", (void *) startAdvertiserNative},
};
// JNI functions defined in ScanManager class.
boolean startAdverising(AdvertiseClient client) {
logd("starting advertising");
+
+ int advertiserId = client.advertiserId;
+ int minAdvertiseUnit = (int) getAdvertisingIntervalUnit(client.settings);
+ int maxAdvertiseUnit = minAdvertiseUnit + ADVERTISING_INTERVAL_DELTA_UNIT;
+ int advertiseEventType = getAdvertisingEventType(client);
+ int txPowerLevel = getTxPowerLevel(client.settings);
+
+ byte [] adv_data = advertiseDataToBytes(client.advertiseData);
+ byte [] scan_resp_data = advertiseDataToBytes(client.scanResponse);
+
+ int advertiseTimeoutSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(
+ client.settings.getTimeout());
+
resetCountDownLatch();
- setAdvertisingParameters(client);
- if (!waitForCallback()) {
- return false;
- }
- resetCountDownLatch();
- setAdvertisingData(client, client.advertiseData, false);
- if (!waitForCallback()) {
- return false;
- }
- if (client.scanResponse != null) {
- resetCountDownLatch();
- setAdvertisingData(client, client.scanResponse, true);
- if (!waitForCallback()) {
- return false;
- }
- }
- resetCountDownLatch();
- enableAdvertising(client, true);
+
+ startAdvertiserNative(advertiserId, minAdvertiseUnit, maxAdvertiseUnit,
+ advertiseEventType, ADVERTISING_CHANNEL_ALL, txPowerLevel, adv_data,
+ scan_resp_data, advertiseTimeoutSeconds);
if (!waitForCallback()) {
return false;
}
}
}
- private void setAdvertisingParameters(AdvertiseClient client) {
- int advertiserId = client.advertiserId;
- int minAdvertiseUnit = (int) getAdvertisingIntervalUnit(client.settings);
- int maxAdvertiseUnit = minAdvertiseUnit + ADVERTISING_INTERVAL_DELTA_UNIT;
- int advertiseEventType = getAdvertisingEventType(client);
- int txPowerLevel = getTxPowerLevel(client.settings);
-
- // if only legacy advertising is supported, the TX power settings wont take effect
- gattClientSetParamsNative(
- advertiserId,
- minAdvertiseUnit, maxAdvertiseUnit,
- advertiseEventType,
- ADVERTISING_CHANNEL_ALL,
- txPowerLevel);
- }
-
- private void enableAdvertising(AdvertiseClient client, boolean enable) {
- int advertiserId = client.advertiserId;
- int advertiseTimeoutSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(
- client.settings.getTimeout());
- gattClientEnableAdvNative(advertiserId, enable, advertiseTimeoutSeconds);
- }
-
private static final int DEVICE_NAME_MAX = 18;
private static final int COMPLETE_LIST_16_BIT_SERVICE_UUIDS = 0X03;
private static final int MANUFACTURER_SPECIFIC_DATA = 0XFF;
private byte[] advertiseDataToBytes(AdvertiseData data) {
+
+ if (data == null)
+ return new byte[0];
+
// Flags are added by lower layers of the stack, only if needed;
// no need to add them here.
return ret.toByteArray();
}
- private void setAdvertisingData(AdvertiseClient client, AdvertiseData data,
- boolean isScanResponse) {
- if (data == null) {
- return;
- }
-
- byte [] data_out = advertiseDataToBytes(data);
- gattClientSetAdvDataNative(client.advertiserId, isScanResponse, data_out);
- }
-
// Convert settings tx power level to stack tx power level.
private int getTxPowerLevel(AdvertiseSettings settings) {
switch (settings.getTxPowerLevel()) {
private native void unregisterAdvertiserNative(int advertiserId);
- private native void gattClientSetParamsNative(int advertiserId,
- int min_interval, int max_interval, int adv_type, int chnl_map, int tx_power);
-
- private native void gattClientSetAdvDataNative(int advertiserId,
- boolean set_scan_rsp, byte[] data);
-
private native void gattClientEnableAdvNative(int advertiserId,
boolean enable, int timeout_s);
+
+ private native void startAdvertiserNative(int advertiserId,
+ int min_interval, int max_interval, int adv_type, int chnl_map, int tx_power,
+ byte[] adv_data, byte[] scan_resp_data, int timeout_s);
+
}
private void logd(String s) {