[IOT-1547] add stop BLE scan API
authorjihwan.seo <jihwan.seo@samsung.com>
Tue, 15 Nov 2016 01:08:17 +0000 (10:08 +0900)
committerRick Bell <richard.s.bell@intel.com>
Mon, 28 Nov 2016 21:19:41 +0000 (21:19 +0000)
scanning should be stopped for saving battery when BLE is not using.

Change-Id: I0e12afb4f0961bd1fa4ec579b3e0412796cacf23
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14309
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Larry Sachs <larry.j.sachs@intel.com>
Reviewed-by: Rick Bell <richard.s.bell@intel.com>
android/android_api/base/jni/JniCaInterface.c
android/android_api/base/src/main/java/org/iotivity/ca/CaInterface.java
resource/csdk/connectivity/api/cautilinterface.h
resource/csdk/connectivity/util/inc/camanagerleinterface.h
resource/csdk/connectivity/util/src/camanager/bt_le_manager/android/caleconnectionmanager.c
resource/csdk/connectivity/util/src/cautilinterface.c

index c73ce51..e891a0e 100644 (file)
@@ -364,6 +364,15 @@ Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl(JNIEnv *env, jclass c
     CAUtilSetLEScanInterval(intervalTime, workignCount);
 }
 
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaInterface_stopLeScanImpl(JNIEnv *env, jclass clazz)
+{
+    LOGI("stopLeScan");
+    (void)env;
+    (void)clazz;
+    CAUtilStopLEScan();
+}
+
 JNIEXPORT jint JNICALL Java_org_iotivity_ca_CaInterface_setCipherSuiteImpl
   (JNIEnv *env, jclass clazz, jint cipherSuite, jint adapter)
 {
index 6924eb4..84ba56f 100644 (file)
@@ -186,13 +186,20 @@ public class CaInterface {
      *  @param intervalTime                  interval time(Seconds).
      *  @param workingCount                  working count with interval time.
      */
-
     public synchronized static void setLeScanIntervalTime(int intervalTime, int workingCount){
         CaInterface.setLeScanIntervalTimeImpl(intervalTime, workingCount);
     }
-
     private static native void setLeScanIntervalTimeImpl(int intervalTime, int workingCount);
 
+    /**
+     *  stop BLE scan.
+     *  if you want to start scan, it can be triggered by setLeScanIntervalTime or
+     *  other request API like findResource.
+     */
+    public synchronized static void stopLeScan(){
+        CaInterface.stopLeScanImpl();
+    }
+    private static native void stopLeScanImpl();
 
     public synchronized static int setCipherSuite(OicCipher cipher, OcConnectivityType connType){
         return CaInterface.setCipherSuiteImpl(cipher.getValue(), connType.getValue());
index d29af64..2a82bcb 100644 (file)
@@ -153,10 +153,15 @@ void CAUtilSetFoundDeviceListener(jobject listener);
  * @param[in]  intervalTime         interval time(Seconds).
  * @param[in]  workingCount         working cycle for selected interval time.
  *
- * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
+ * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
  */
 CAResult_t CAUtilSetLEScanInterval(jint intervalTime, jint workingCount);
 
+/**
+ * stop LE scan.
+ * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
+ */
+CAResult_t CAUtilStopLEScan();
 #endif
 
 #ifdef __cplusplus
index c15b05c..b5f2dad 100644 (file)
@@ -74,6 +74,11 @@ CAResult_t CAManagerLEClientTerminate(JNIEnv *env);
  */
 void CAManagerLESetScanInterval(jint intervalTime, jint workingCount);
 
+/**
+ * stop BLE scan.
+ */
+void CAManagerLEStopScan();
+
 #endif
 
 #ifdef __cplusplus
index fcecd59..70cdb80 100644 (file)
@@ -286,6 +286,12 @@ void CAManagerLESetScanInterval(jint interval, jint count)
     CALERestartScanWithInterval(interval, count, BLE_SCAN_ENABLE);
 }
 
+void CAManagerLEStopScan()
+{
+    OIC_LOG(DEBUG, TAG, "CAManagerLEStopScan");
+    CALERestartScanWithInterval(0, 0, BLE_SCAN_DISABLE);
+}
+
 JNIEXPORT void JNICALL
 Java_org_iotivity_ca_CaLeClientInterface_caManagerAdapterStateChangedCallback(
         JNIEnv *env, jobject obj, jint state)
index 9c357b0..95ae205 100644 (file)
@@ -274,4 +274,16 @@ CAResult_t CAUtilSetLEScanInterval(jint intervalTime, jint workingCount)
     return CA_NOT_SUPPORTED;
 #endif
 }
+
+CAResult_t CAUtilStopLEScan()
+{
+    OIC_LOG(DEBUG, TAG, "CAUtilStopLEScan");
+#ifdef LE_ADAPTER
+    CAManagerLEStopScan();
+    return CA_STATUS_OK;
+#else
+    OIC_LOG(DEBUG, TAG, "it is not supported");
+    return CA_NOT_SUPPORTED;
+#endif
+}
 #endif