OSDN Git Service

Bluetooth 5 move timeout parameter (2/2)
authorJakub Pawlowski <jpawlowski@google.com>
Fri, 17 Mar 2017 18:23:38 +0000 (11:23 -0700)
committerJakub Pawlowski <jpawlowski@google.com>
Fri, 17 Mar 2017 22:23:45 +0000 (22:23 +0000)
Timeout is not a parameter, it is a property of enabling the
advertising. Move it into more proper place.

Test: manual
Bug: 30622771
Change-Id: Ib688f183bf71fe429da6b9c3c8eb3591e9c6ec1d

jni/com_android_bluetooth_gatt.cpp
src/com/android/bluetooth/gatt/AdvertiseManager.java
src/com/android/bluetooth/gatt/GattService.java

index 38fa55e..91e026c 100644 (file)
@@ -1567,8 +1567,8 @@ static void advertiseCleanupNative(JNIEnv* env, jobject object) {
   }
 }
 
-static AdvertiseParameters parseParams(JNIEnv* env, jobject i, bool isScannable,
-                                       int* timeout) {
+static AdvertiseParameters parseParams(JNIEnv* env, jobject i,
+                                       bool isScannable) {
   AdvertiseParameters p;
 
   jclass clazz = env->GetObjectClass(i);
@@ -1590,8 +1590,6 @@ static AdvertiseParameters parseParams(JNIEnv* env, jobject i, bool isScannable,
   uint32_t interval = env->CallIntMethod(i, methodId);
   methodId = env->GetMethodID(clazz, "getTxPowerLevel", "()I");
   int8_t txPowerLevel = env->CallIntMethod(i, methodId);
-  methodId = env->GetMethodID(clazz, "getTimeout", "()I");
-  *timeout = env->CallIntMethod(i, methodId);
 
   uint16_t props = 0;
   if (isConnectable) props |= 0x01;
@@ -1661,7 +1659,8 @@ static void startAdvertisingSetNative(JNIEnv* env, jobject object,
                                       jobject parameters, jbyteArray adv_data,
                                       jbyteArray scan_resp,
                                       jobject periodic_parameters,
-                                      jbyteArray periodic_data, jint reg_id) {
+                                      jbyteArray periodic_data, jint timeout,
+                                      jint reg_id) {
   if (!sGattIf) return;
 
   jbyte* scan_resp_data = env->GetByteArrayElements(scan_resp, NULL);
@@ -1670,12 +1669,13 @@ static void startAdvertisingSetNative(JNIEnv* env, jobject object,
                                      scan_resp_data + scan_resp_len);
   env->ReleaseByteArrayElements(scan_resp, scan_resp_data, JNI_ABORT);
 
-  int timeout;
   AdvertiseParameters params =
-      parseParams(env, parameters, (scan_resp_len != 0), &timeout);
+      parseParams(env, parameters, (scan_resp_len != 0));
   PeriodicAdvertisingParameters periodicParams =
       parsePeriodicParams(env, periodic_parameters);
 
+  int timeout_s = (int)timeout / 1000;
+
   jbyte* adv_data_data = env->GetByteArrayElements(adv_data, NULL);
   uint16_t adv_data_len = (uint16_t)env->GetArrayLength(adv_data);
   std::vector<uint8_t> data_vec(adv_data_data, adv_data_data + adv_data_len);
@@ -1689,7 +1689,7 @@ static void startAdvertisingSetNative(JNIEnv* env, jobject object,
 
   sGattIf->advertiser->StartAdvertisingSet(
       base::Bind(&ble_advertising_set_started_cb, reg_id), params, data_vec,
-      scan_resp_vec, periodicParams, periodic_data_vec, timeout,
+      scan_resp_vec, periodicParams, periodic_data_vec, timeout_s,
       base::Bind(ble_advertising_set_timeout_cb));
 }
 
@@ -1733,7 +1733,7 @@ static JNINativeMethod sAdvertiseMethods[] = {
     {"cleanupNative", "()V", (void*)advertiseCleanupNative},
     {"startAdvertisingSetNative",
      "(Landroid/bluetooth/le/AdvertisingSetParameters;[B[BLandroid/bluetooth/"
-     "le/PeriodicAdvertisingParameters;[BI)V",
+     "le/PeriodicAdvertisingParameters;[BII)V",
      (void*)startAdvertisingSetNative},
     {"stopAdvertisingSetNative", "(I)V", (void*)stopAdvertisingSetNative},
 };
index 019b237..19c939f 100644 (file)
@@ -178,7 +178,7 @@ class AdvertiseManager {
 
     void startAdvertisingSet(AdvertisingSetParameters parameters, AdvertiseData advertiseData,
             AdvertiseData scanResponse, PeriodicAdvertisingParameters periodicParameters,
-            AdvertiseData periodicData, IAdvertisingSetCallback callback) {
+            AdvertiseData periodicData, int timeout, IAdvertisingSetCallback callback) {
         AdvertisingSetDeathRecipient deathRecipient = new AdvertisingSetDeathRecipient(callback);
         IBinder binder = toBinder(callback);
         try {
@@ -196,8 +196,8 @@ class AdvertiseManager {
         mAdvertisers.put(binder, new AdvertiserInfo(cb_id, deathRecipient, callback));
 
         logd("startAdvertisingSet() - reg_id=" + cb_id + ", callback: " + binder);
-        startAdvertisingSetNative(
-                parameters, adv_data, scan_response, periodicParameters, periodic_data, cb_id);
+        startAdvertisingSetNative(parameters, adv_data, scan_response, periodicParameters,
+                periodic_data, timeout, cb_id);
     }
 
     void stopAdvertisingSet(IAdvertisingSetCallback callback) {
@@ -237,7 +237,8 @@ class AdvertiseManager {
     private native void cleanupNative();
     private native void startAdvertisingSetNative(AdvertisingSetParameters parameters,
             byte[] advertiseData, byte[] scanResponse,
-            PeriodicAdvertisingParameters periodicParameters, byte[] periodicData, int reg_id);
+            PeriodicAdvertisingParameters periodicParameters, byte[] periodicData, int timeout,
+            int reg_id);
 
     private native void stopAdvertisingSetNative(int advertiser_id);
 }
index 34bf395..3ca5363 100644 (file)
@@ -546,11 +546,11 @@ public class GattService extends ProfileService {
         public void startAdvertisingSet(AdvertisingSetParameters parameters,
                 AdvertiseData advertiseData, AdvertiseData scanResponse,
                 PeriodicAdvertisingParameters periodicParameters, AdvertiseData periodicData,
-                IAdvertisingSetCallback callback) {
+                int timeout, IAdvertisingSetCallback callback) {
             GattService service = getService();
             if (service == null) return;
             service.startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
-                    periodicData, callback);
+                    periodicData, timeout, callback);
         }
 
         public void stopAdvertisingSet(IAdvertisingSetCallback callback) {
@@ -559,7 +559,7 @@ public class GattService extends ProfileService {
             service.stopAdvertisingSet(callback);
         }
 
-        public void enableAdverisingSet(int advertiserId, boolean enable) {
+        public void enableAdverisingSet(int advertiserId, boolean enable, int timeout) {
             GattService service = getService();
             if (service == null) return;
             // TODO: implement
@@ -1421,11 +1421,11 @@ public class GattService extends ProfileService {
      *************************************************************************/
     void startAdvertisingSet(AdvertisingSetParameters parameters, AdvertiseData advertiseData,
             AdvertiseData scanResponse, PeriodicAdvertisingParameters periodicParameters,
-            AdvertiseData periodicData, IAdvertisingSetCallback callback) {
+            AdvertiseData periodicData, int timeout, IAdvertisingSetCallback callback) {
         enforceAdminPermission();
 
         mAdvertiseManager.startAdvertisingSet(parameters, advertiseData, scanResponse,
-                periodicParameters, periodicData, callback);
+                periodicParameters, periodicData, timeout, callback);
     }
 
     void stopAdvertisingSet(IAdvertisingSetCallback callback) {