static jmethodID method_onNotify;
static jmethodID method_onRegisterForNotifications;
static jmethodID method_onReadRemoteRssi;
-static jmethodID method_onAdvertiseCallback;
static jmethodID method_onConfigureMTU;
static jmethodID method_onScanFilterConfig;
static jmethodID method_onScanFilterParamsConfigured;
method_onRegisterForNotifications = env->GetMethodID(clazz, "onRegisterForNotifications", "(IIII)V");
method_onReadRemoteRssi = env->GetMethodID(clazz, "onReadRemoteRssi", "(ILjava/lang/String;II)V");
method_onConfigureMTU = env->GetMethodID(clazz, "onConfigureMTU", "(III)V");
- method_onAdvertiseCallback = env->GetMethodID(clazz, "onAdvertiseCallback", "(I)V");
method_onScanFilterConfig = env->GetMethodID(clazz, "onScanFilterConfig", "(IIIII)V");
method_onScanFilterParamsConfigured = env->GetMethodID(clazz, "onScanFilterParamsConfigured", "(IIII)V");
method_onScanFilterEnableDisabled = env->GetMethodID(clazz, "onScanFilterEnableDisabled", "(III)V");
sGattIf->client->read_remote_rssi(clientif, &bda);
}
-
-void btgattc_advertise_cb(uint8_t status)
-{
- CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
- sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAdvertiseCallback, status);
-}
-
-static void gattAdvertiseNative(JNIEnv *env, jobject object, jboolean start)
-{
- if (!sGattIf) return;
- sGattIf->advertiser->Enable(start, base::Bind(&btgattc_advertise_cb));
-}
-
-static void gattSetAdvDataNative(JNIEnv *env, jobject object,
- jboolean setScanRsp, 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(setScanRsp, std::move(data_vec));
-}
-
static void gattSetScanParametersNative(JNIEnv* env, jobject object,
jint client_if, jint scan_interval_unit,
jint scan_window_unit)
{
if (!sGattIf) return;
- sGattIf->advertiser->MultiAdvEnable(
+ sGattIf->advertiser->Enable(
advertiser_id, enable,
base::Bind(&ble_advertiser_enable_cb, enable, advertiser_id), timeout_s,
base::Bind(&ble_advertiser_enable_cb, false, advertiser_id));
{
if (!sGattIf) return;
- sGattIf->advertiser->MultiAdvSetParameters(
+ sGattIf->advertiser->SetParameters(
advertiser_id, min_interval, max_interval, adv_type, chnl_map, tx_power,
base::Bind(&ble_advertiser_set_params_cb, advertiser_id));
}
vector<uint8_t> data_vec(data_data, data_data + data_len);
env->ReleaseByteArrayElements(data, data_data, JNI_ABORT);
- sGattIf->advertiser->MultiAdvSetInstData(
+ sGattIf->advertiser->SetData(
advertiser_id, set_scan_rsp, std::move(data_vec),
base::Bind(&ble_advertiser_setadv_data_cb, advertiser_id));
}
{"gattClientSetParamsNative", "(IIIIII)V", (void *) gattClientSetAdvParamsNative},
{"gattClientSetAdvDataNative", "(IZ[B)V", (void *) gattClientSetAdvDataNative},
{"gattClientEnableAdvNative", "(IZI)V", (void *) gattClientEnableAdvNative},
- {"gattSetAdvDataNative", "(Z[B)V", (void *) gattSetAdvDataNative},
- {"gattAdvertiseNative", "(Z)V", (void *) gattAdvertiseNative},
};
// JNI functions defined in ScanManager class.
return service.isMultiAdvertisementSupported();
}
- public boolean isPeripheralModeSupported() {
- AdapterService service = getService();
- if (service == null) return false;
- return service.isPeripheralModeSupported();
- }
-
public boolean isOffloadedFilteringSupported() {
AdapterService service = getService();
if (service == null) return false;
return mAdapterProperties.getNumOfOffloadedScanFilterSupported();
}
- public boolean isPeripheralModeSupported() {
- return getResources().getBoolean(R.bool.config_bluetooth_le_peripheral_mode_supported);
- }
-
public int getOffloadedScanResultStorage() {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
return mAdapterProperties.getOffloadedScanResultStorage();
// Returns maximum advertise instances supported by controller.
int maxAdvertiseInstances() {
- // Note numOfAdvtInstances includes the standard advertising instance.
- // TODO: remove - 1 once the stack is able to include standard instance for multiple
- // advertising.
- if (mAdapterService.isMultiAdvertisementSupported()) {
- return mAdapterService.getNumOfAdvertisementInstancesSupported() - 1;
- }
- if (mAdapterService.isPeripheralModeSupported()) {
- return 1;
- }
- return 0;
+ return mAdapterService.getNumOfAdvertisementInstancesSupported();
}
}
private static final int ADVERTISING_EVENT_TYPE_SCANNABLE = 2;
private static final int ADVERTISING_EVENT_TYPE_NON_CONNECTABLE = 3;
- // TODO: Extract advertising logic into interface as we have multiple implementations now.
boolean startAdverising(AdvertiseClient client) {
- if (!mAdapterService.isMultiAdvertisementSupported() &&
- !mAdapterService.isPeripheralModeSupported()) {
- return false;
- }
- if (mAdapterService.isMultiAdvertisementSupported()) {
- return startMultiAdvertising(client);
- }
- return startSingleAdvertising(client);
- }
-
- boolean startMultiAdvertising(AdvertiseClient client) {
- logd("starting multi advertising");
+ logd("starting advertising");
resetCountDownLatch();
setAdvertisingParameters(client);
if (!waitForCallback()) {
return true;
}
- boolean startSingleAdvertising(AdvertiseClient client) {
- logd("starting single advertising");
- resetCountDownLatch();
- enableAdvertising(client, true);
- if (!waitForCallback()) {
- return false;
- }
- setAdvertisingData(client, client.advertiseData, false);
- if (client.scanResponse != null) {
- setAdvertisingData(client, client.scanResponse, true);
- }
- return true;
- }
-
void stopAdvertising(AdvertiseClient client) {
- if (mAdapterService.isMultiAdvertisementSupported()) {
- gattClientEnableAdvNative(client.advertiserId, false, 0);
- } else {
- gattAdvertiseNative(false);
- try {
- mService.onAdvertiseInstanceEnabled(
- AdvertiseCallback.ADVERTISE_SUCCESS, client.advertiserId, false);
- } catch (RemoteException e) {
- Log.d(TAG, "failed onAdvertiseInstanceDisabled", e);
- }
- }
+ gattClientEnableAdvNative(client.advertiserId, false, 0);
}
private void resetCountDownLatch() {
int maxAdvertiseUnit = minAdvertiseUnit + ADVERTISING_INTERVAL_DELTA_UNIT;
int advertiseEventType = getAdvertisingEventType(client);
int txPowerLevel = getTxPowerLevel(client.settings);
- if (mAdapterService.isMultiAdvertisementSupported()) {
- gattClientSetParamsNative(
+
+ // if only legacy advertising is supported, the TX power settings wont take effect
+ gattClientSetParamsNative(
advertiserId,
minAdvertiseUnit, maxAdvertiseUnit,
advertiseEventType,
ADVERTISING_CHANNEL_ALL,
txPowerLevel);
- } else {
- //there is no method to set parameters if multi advertising not enabled
- }
}
private void enableAdvertising(AdvertiseClient client, boolean enable) {
int advertiserId = client.advertiserId;
int advertiseTimeoutSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(
client.settings.getTimeout());
- if (mAdapterService.isMultiAdvertisementSupported()) {
- gattClientEnableAdvNative(advertiserId, enable, advertiseTimeoutSeconds);
- } else {
- gattAdvertiseNative(enable);
- }
+ gattClientEnableAdvNative(advertiserId, enable, advertiseTimeoutSeconds);
}
private static final int DEVICE_NAME_MAX = 18;
}
byte [] data_out = advertiseDataToBytes(data);
-
- if (mAdapterService.isMultiAdvertisementSupported()) {
- gattClientSetAdvDataNative(client.advertiserId, isScanResponse, data_out);
- } else {
- gattSetAdvDataNative(isScanResponse, data_out);
- }
+ gattClientSetAdvDataNative(client.advertiserId, isScanResponse, data_out);
}
// Convert settings tx power level to stack tx power level.
private native void gattClientEnableAdvNative(int advertiserId,
boolean enable, int timeout_s);
-
- private native void gattSetAdvDataNative(boolean setScanRsp, byte[] data);
-
- private native void gattAdvertiseNative(boolean start);
}
private void logd(String s) {
}
}
- // Callback for standard advertising instance.
- void onAdvertiseCallback(int status) {
- if (DBG) Log.d(TAG, "onAdvertiseCallback status=" + status);
- mAdvertiseManager.callbackDone(0 /* advertiser_id */, status);
- }
-
// Followings are callbacks for Bluetooth LE Advertise operations.
// Start advertising flow is
// register advertiser -> onAdvertiserRegistered