update aidl api.
authorTrillGates <williamtrillgates@gmail.com>
Thu, 20 May 2021 06:47:46 +0000 (14:47 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Thu, 20 May 2021 06:47:46 +0000 (14:47 +0800)
app/src/main/aidl/com/ic/work/IHeartRateSensorCallback.aidl
app/src/main/aidl/com/ic/work/IHeartRateSensorService.aidl
app/src/main/aidl/com/ic/work/ITempSensorService.aidl
app/src/main/java/com/ic/work/SensorDataService.java
app/src/main/java/com/ic/work/hardware/BloodInfoHelper.java

index f695844..103950c 100644 (file)
@@ -10,4 +10,5 @@ interface IHeartRateSensorCallback {
      oneway void onHeartRateUpdate(in HeartRate heartRate);
      oneway void onGettingData();
      oneway void onWaiting();
+     oneway void onNoWear();
 }
\ No newline at end of file
index 70a7dd5..9afcc4f 100644 (file)
@@ -6,5 +6,5 @@ import com.ic.work.IHeartRateSensorCallback;
 interface IHeartRateSensorService {
     void registerCallback(in IHeartRateSensorCallback callback,in String callbackTag);
     void unRegisterCallback(in IHeartRateSensorCallback callback);
-    oneway void getHeartRateInfo(int from,in String callbackTag);
+    oneway void getHeartRateInfo(in int from,in String callbackTag);
 }
\ No newline at end of file
index 4941edd..824107c 100644 (file)
@@ -5,5 +5,5 @@ import com.ic.work.ITempSensorCallback;
 interface ITempSensorService {
     void registerCallback(in ITempSensorCallback callback,in String callbackTag);
     void unRegisterCallback(in ITempSensorCallback callback);
-    oneway void getTemperatureInfo(int from,in String callbackTag);
+    oneway void getTemperatureInfo(in int from,in String callbackTag);
 }
\ No newline at end of file
index a0ed976..58bbd7a 100644 (file)
@@ -674,4 +674,22 @@ public class SensorDataService extends Service implements TemperatureHelper.Temp
     public void onHeartRateTestFinished() {
         checkContinue();
     }
+
+    @Override
+    public void onNoWear() {
+        synchronized (mLock) {
+            int i = heartRateCallbacks.beginBroadcast();
+            IcLog.d(TAG, "onNoWear size == > " + i);
+            try {
+                while (i > 0) {
+                    i--;
+                    heartRateCallbacks.getBroadcastItem(i).onNoWear();
+                }
+            } catch (RemoteException e) {
+                e.printStackTrace();
+            } finally {
+                heartRateCallbacks.finishBroadcast();
+            }
+        }
+    }
 }
index 1320910..dd9de46 100644 (file)
@@ -72,7 +72,7 @@ public class BloodInfoHelper implements SensorEventListener {
             mHeartRate = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
             boolean ret = mSensorManager.registerListener(this, mHeartRate, SensorManager.SENSOR_DELAY_FASTEST);
             Log.d(TAG, "ret == > " + ret);
-            isWear=false;
+            isWear = false;
             ndkHeart = 0;
             ndkHigh = 0;
             ndkLow = 0;
@@ -88,6 +88,7 @@ public class BloodInfoHelper implements SensorEventListener {
             checkBloodOther();
         }
     }
+
     private Sensor mHeartRate = null;
     private int ndkHeart = 0;
     private int ndkHigh = 0;
@@ -138,7 +139,7 @@ public class BloodInfoHelper implements SensorEventListener {
                     if (noWearCount <= 20) {
                         ppgLooper.postDelayed(this, 1000);
                     } else {
-                        handleResult();
+                        handleNoWearResult();
                     }
                 } else {
                     noWearCount = 0;
@@ -148,7 +149,23 @@ public class BloodInfoHelper implements SensorEventListener {
             }
         });
     }
-    private void doPPGtest(){
+
+    private void handleNoWearResult() {
+        if (mListener != null) {
+            mListener.onNoWear();
+            mListener.onHeartRateTestFinished();
+        }
+        try {
+            IcLog.d(TAG, "disable ppg..");
+            HardwareUtils.onNdkDisablePPG();
+        } catch (Exception e) {
+            IcLog.e(TAG, "Stop Get Heart Value", e);
+        }
+        IcLog.d(TAG, "total use time == checkBloodStartTime > "
+                + (System.currentTimeMillis() - checkBloodStartTime));
+    }
+
+    private void doPPGtest() {
         if (ndkHeart > 0) {
             if (oxygen <= 0) oxygen = randomOxygenValue();
             if (mListener != null) {
@@ -163,6 +180,7 @@ public class BloodInfoHelper implements SensorEventListener {
             IcLog.d(TAG, "invalidateTime == > " + invalidateTime);
         }
     }
+
     //- 数据测试结果为0,如果连续20个数据为0,那么就结束此次测试
     //- 有数据以后,连续测上10次,就可以返回结果了
     private void doTest() {
@@ -176,7 +194,7 @@ public class BloodInfoHelper implements SensorEventListener {
                 ndkLow = HardwareUtils.getNdkLowBloodValue();
                 oxygen = HardwareUtils.getNdkOxygenValue();
                 doPPGtest();
-                if ( checkCount > 10 ||  invalidateTime > 30) {
+                if (checkCount > 10 || invalidateTime > 30) {
                     handleResultOtherBlood();
                 } else {
                     //继续测试
@@ -203,18 +221,17 @@ public class BloodInfoHelper implements SensorEventListener {
         }
         IcLog.d(TAG, "total use time == checkBloodStartTime > " + (System.currentTimeMillis() - checkBloodStartTime));
     }
+
     private void handleResult() {
         if (mListener != null) {
             mListener.onHeartRateResult(ndkHigh, ndkLow, ndkHeart, oxygen);
-        }
-        if (mListener != null) {
             mListener.onHeartRateTestFinished();
         }
 
         try {
             IcLog.d(TAG, "disable ppg..");
-            if(mHeartRate!=null)
-                mSensorManager.unregisterListener(this,mHeartRate);
+            if (mHeartRate != null)
+                mSensorManager.unregisterListener(this, mHeartRate);
         } catch (Exception e) {
             IcLog.e(TAG, "Stop Get Heart Value", e);
         }
@@ -248,15 +265,15 @@ public class BloodInfoHelper implements SensorEventListener {
                     + "Weared= " + values[4]
             );
 
-            ndkHeart = (int)values[0];//调用底层函数保证状态更新。
-            ndkHigh = (int)values[1];
-            ndkLow = (int)values[2];
-            oxygen = (int)values[3];
-            isWear = ((int)values[4] == 2);
-           // isPPGTesting = true;// (ICJniUtils.isPPGStarted() == 1);
+            ndkHeart = (int) values[0];//调用底层函数保证状态更新。
+            ndkHigh = (int) values[1];
+            ndkLow = (int) values[2];
+            oxygen = (int) values[3];
+            isWear = ((int) values[4] == 2);
+            // isPPGTesting = true;// (ICJniUtils.isPPGStarted() == 1);
             doPPGtest();
             /*[0]---心率;[1]---血压高压;[2]---血压低压;[3]---血氧;[4]---佩戴检测(1--脱手,2--上手);*/
-            if ( checkCount > 10 ||  invalidateTime > 30) {
+            if (checkCount > 10 || invalidateTime > 30) {
                 handleResult();
             }
         } else {
@@ -280,6 +297,8 @@ public class BloodInfoHelper implements SensorEventListener {
         //没有佩戴之类的,总之,走不到结果那里,如果不结束的话,状态会错乱
         void onHeartRateTestFinished();
 
+        void onNoWear();
+
     }