-[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.1","enabled":true,"outputFile":"IcL02WorkService_V57_202012041649_release.apk","fullName":"IcL02WorkServiceRelease","baseName":"IcL02WorkService-release"},"path":"IcL02WorkService_V57_202012041649_release.apk","properties":{}}]
\ No newline at end of file
+[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.1","enabled":true,"outputFile":"IcL02WorkService_V57_202012161210_release.apk","fullName":"IcL02WorkServiceRelease","baseName":"IcL02WorkService-release"},"path":"IcL02WorkService_V57_202012161210_release.apk","properties":{}}]
\ No newline at end of file
android:process=":remote">
<intent-filter>
<action android:name="com.ic.action.WORK_SERVICE" />
+ <!--掌育通过startService的方式来测量体温/心率-->
+ <action android:name="com.jx.lanucher.action.temperature" />
+ <action android:name="com.jx.lanucher.action.heartrate" />
</intent-filter>
</service>
super.onDestroy();
IcLog.i(TAG, "WorkService onDestroy");
bloodProcess = null;
-
mApp = null;
EventBus.getDefault().unregister(this);
-
unregisterReceiver(mIntentReceiver);
-
if (coreService != null) {
coreService.onUnBindCoreService(getApplicationContext());
coreService = null;
--- /dev/null
+package com.ic.work.domain;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class TemperatureItem implements Parcelable {
+
+ private String bodyTemp/*体温*/;
+ private String cpuTemp/*cpu温度*/;
+ private String evnTemp/*环境温度*/;
+ private String gpuTemp/*gpu温度*/;
+ private String chargeTemp/*充电版温度*/;
+ private String boardTemp/*主板温度*/;
+ private String paTemp/*射频的温度*/;
+
+ public TemperatureItem(String bodyTemp, String cpuTemp, String evnTemp, String gpuTemp, String chargeTemp, String boardTemp, String paTemp) {
+ this.bodyTemp = bodyTemp;
+ this.cpuTemp = cpuTemp;
+ this.evnTemp = evnTemp;
+ this.gpuTemp = gpuTemp;
+ this.chargeTemp = chargeTemp;
+ this.boardTemp = boardTemp;
+ this.paTemp = paTemp;
+ }
+
+ protected TemperatureItem(Parcel in) {
+ bodyTemp = in.readString();
+ cpuTemp = in.readString();
+ evnTemp = in.readString();
+ gpuTemp = in.readString();
+ chargeTemp = in.readString();
+ boardTemp = in.readString();
+ paTemp = in.readString();
+ }
+
+ public static final Creator<TemperatureItem> CREATOR = new Creator<TemperatureItem>() {
+ @Override
+ public TemperatureItem createFromParcel(Parcel in) {
+ return new TemperatureItem(in);
+ }
+
+ @Override
+ public TemperatureItem[] newArray(int size) {
+ return new TemperatureItem[size];
+ }
+ };
+
+ public String getBodyTemp() {
+ return bodyTemp;
+ }
+
+ public void setBodyTemp(String bodyTemp) {
+ this.bodyTemp = bodyTemp;
+ }
+
+ public String getCpuTemp() {
+ return cpuTemp;
+ }
+
+ public void setCpuTemp(String cpuTemp) {
+ this.cpuTemp = cpuTemp;
+ }
+
+ public String getEvnTemp() {
+ return evnTemp;
+ }
+
+ public void setEvnTemp(String evnTemp) {
+ this.evnTemp = evnTemp;
+ }
+
+ public String getGpuTemp() {
+ return gpuTemp;
+ }
+
+ public void setGpuTemp(String gpuTemp) {
+ this.gpuTemp = gpuTemp;
+ }
+
+ public String getChargeTemp() {
+ return chargeTemp;
+ }
+
+ public void setChargeTemp(String chargeTemp) {
+ this.chargeTemp = chargeTemp;
+ }
+
+ public String getBoardTemp() {
+ return boardTemp;
+ }
+
+ public void setBoardTemp(String boardTemp) {
+ this.boardTemp = boardTemp;
+ }
+
+ public String getPaTemp() {
+ return paTemp;
+ }
+
+ public void setPaTemp(String paTemp) {
+ this.paTemp = paTemp;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(bodyTemp);
+ dest.writeString(cpuTemp);
+ dest.writeString(evnTemp);
+ dest.writeString(gpuTemp);
+ dest.writeString(chargeTemp);
+ dest.writeString(boardTemp);
+ dest.writeString(paTemp);
+ }
+}
package com.ic.work.hardware;
+import com.ic.work.domain.TemperatureItem;
import com.ic.work.event.TaskFinishedEvent;
import com.ic.work.event.TemperatureResultCompleteEvent;
import com.ic.work.event.TemperatureResultEvent;
import com.ic.work.utils.HardwareUtils;
import com.ic.work.utils.IcLog;
+import com.ic.work.utils.TemperatureUtil;
import org.greenrobot.eventbus.EventBus;
-import java.math.BigDecimal;
-
public class TemperatureRunnable implements Runnable {
private static final String TAG = "TemperatureRunnable";
- private final static double room_temperature = 26.0;
@Override
public void run() {
- double testValue;
- double animal;
- double tempout;
double lastTempOut = 0.0;
double lastBodyTemp = 0.0;
double lastWristTemp = 0.0;
IcLog.i(TAG, "TemperatureRunnable :" + state[0] + " state[1]:" + state[1]);
if (state[0]) { //have temp
try {
-// if(HardwareUtils.isTemperatureDevOpened()){
IcLog.i(TAG, "getNdkTemperatureValue enableTemperature");
HardwareUtils.disablePedometer();
if (HardwareUtils.enableTemperature()) {
IcLog.i(TAG, "getNdkTemperatureValue enableTemperature");
Thread.sleep(1000);
}
-// }
while (true) {
- testValue = HardwareUtils.getNdkTemperatureValue();
- tempout = HardwareUtils.getNdkTemperatureOutValue();
- if (tempout < 0 || tempout > 60)
- tempout = 0;
- if (tempout > 0) {
- animal = HardwareUtils.getBodyTempFromWristTemp(testValue, tempout);
- } else {
- animal = HardwareUtils.getBodyTempFromWristTemp(testValue, room_temperature);
+ lastWristTemp = HardwareUtils.getNdkTemperatureOutValue();
+ TemperatureItem temperatureItem = TemperatureUtil.doTempTest();
+ if (temperatureItem != null) {
+ lastBodyTemp = Double.parseDouble(temperatureItem.getBodyTemp());
+ lastTempOut = Double.parseDouble(temperatureItem.getEvnTemp());
+ //获取
+ EventBus.getDefault().post(new TemperatureResultEvent(lastWristTemp,
+ lastBodyTemp, lastTempOut));
}
- IcLog.i(TAG, "getNdkTemperatureValue Value:" + testValue + " TempOut:" + tempout + " bodyTemp:" + animal);
- //if (tempout > 50 || tempout < 10 || testValue < 10 || testValue > 50) {
- // 提交
- //if (tempout > 50 || tempout < 10 || testValue < 10 || testValue > 50) {
- IcLog.i(TAG, "getNdkTemperatureValue TempOut or Wirst Value out of range skip send it ! ");
- //} else {
- lastBodyTemp = animal;
- lastWristTemp = testValue;
- lastTempOut = tempout;
- EventBus.getDefault().post(new TemperatureResultEvent(testValue, animal, tempout));
//}
try {
Thread.sleep(1000);
if (delay_times_in_seconds <= 0)
break;
}
- HardwareUtils.disableTemperature();
} catch (InterruptedException e) {
IcLog.e(TAG, "TemperatureRunnable :", e);
} finally {
EventBus.getDefault().post(new TemperatureResultCompleteEvent(lastWristTemp, lastBodyTemp, lastTempOut));
}
-
- public static double div(double value1, int value2, int scale) {
- //如果精确范围小于0,抛出异常信息
- if (scale < 0) {
- return room_temperature;
- }
- BigDecimal b1 = BigDecimal.valueOf(value1);
- BigDecimal b2 = BigDecimal.valueOf(value2);
- return b1.divide(b2, scale).doubleValue();
- }
}
import android.util.Log;
-import com.ic.work.BuildConfig;
-
/**
* @author RyanLee
* @date 2018/2/2
public class IcLog {
private static final String DOT = ".";
- private static boolean isDebug = BuildConfig.DEBUG;
+ private static boolean isDebug = true;
private static String tagHead = "";
public static void v(String tag, String msg) {
}
}
- public static void e(String tag, String msg,Throwable e) {
+ public static void e(String tag, String msg, Throwable e) {
if (isDebug) {
- Log.e(mergeHeadTag(tag), msg,e);
+ Log.e(mergeHeadTag(tag), msg, e);
}
}
--- /dev/null
+package com.ic.work.utils;
+
+import android.util.Log;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public class ShellUtil {
+ /**
+ * 执行命令并且输出结果
+ */
+ public static String execRootCmd(String cmd) {
+ String result = "";
+ DataOutputStream dos = null;
+ DataInputStream dis = null;
+
+ try {
+ Process p = Runtime.getRuntime().exec(cmd);// 经过Root处理的android系统即有su命令
+ dos = new DataOutputStream(p.getOutputStream());
+ dis = new DataInputStream(p.getInputStream());
+ String line;
+ while ((line = dis.readLine()) != null) {
+ Log.d("result", line);
+ result += line;
+ }
+ p.waitFor();
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (dos != null) {
+ try {
+ dos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (dis != null) {
+ try {
+ dis.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return result;
+ }
+}
--- /dev/null
+package com.ic.work.utils;
+
+import android.text.TextUtils;
+import android.util.Log;
+
+import com.ic.jni.ICJniUtils;
+import com.ic.work.domain.TemperatureItem;
+
+public class TemperatureUtil {
+ private static String TAG = "TemperatureUtil";
+
+ private static double temp_value_orig = 0.0f;
+ private static double tempOut_value = 0.0f;
+
+ public static double get_tempOut_value_origin() {
+ tempOut_value = ICJniUtils.getTemperatureOrigin();
+ Log.i(TAG, "测量环境温度 原始值 " + tempOut_value);
+ return tempOut_value;
+ }
+
+ public static double get_temp_value_adjusted() {
+ temp_value_orig = ICJniUtils.getTemperature();
+ Log.i(TAG, "测量体温 原始值 " + temp_value_orig);
+ return temp_value_orig;
+ }
+
+
+ public static void enableTemp() {
+ if (ICJniUtils.isTemperatureDevAvailable() > ICJniUtils.TempSensorType.TEMPSENSOR_TYPE_NONE.ordinal()) {
+
+ ICJniUtils.disablePedometer();
+ ICJniUtils.enableTemperature();
+ mSleep(1000);
+ }
+
+ }
+
+ public static void disableTemp() {
+ if (ICJniUtils.isTemperatureDevAvailable() > ICJniUtils.TempSensorType.TEMPSENSOR_TYPE_NONE.ordinal()) {
+ ICJniUtils.disableTemperature();
+ ICJniUtils.enablePedometer();
+ }
+ }
+
+ public static void mSleep(int ms) {
+ try {
+ Thread.yield();
+ Thread.sleep(ms);
+ } catch (Exception e) {
+ // Log.e(TAG,e.getMessage(),e);
+ }
+ }
+
+
+ //thermal_zone0
+ public static final String CMD_CPU_TEM = "cat /sys/class/thermal/thermal_zone0/temp";
+ public static final String CMD_CPU_TYPE = "cat /sys/class/thermal/thermal_zone0/type";
+ //thermal_zone1
+ public static final String CMD_GPU_TEM = "cat /sys/class/thermal/thermal_zone1/temp";
+ public static final String CMD_GPU_TYPE = "cat /sys/class/thermal/thermal_zone1/type";
+ //thermal_zone2
+ public static final String CMD_CHARGE_TEM = "cat /sys/class/thermal/thermal_zone2/temp";
+ public static final String CMD_CHARGE_TYPE = "cat /sys/class/thermal/thermal_zone2/type";
+ //thermal_zone3
+ public static final String CMD_PA_TEM = "cat /sys/class/thermal/thermal_zone3/temp";
+ public static final String CMD_PA_TYPE = "cat /sys/class/thermal/thermal_zone3/type";
+ //thermal_zone4
+ public static final String CMD_BOARD_TEM = "cat /sys/class/thermal/thermal_zone4/temp";
+ public static final String CMD_BOARD_TYPE = "cat /sys/class/thermal/thermal_zone4/type";
+
+
+ /**
+ * 这里获取到CPU温度,主板温度,体温,外温的数据,然后写到log里,后面转成数据表,再转成函数表达式。
+ */
+ public static TemperatureItem doTempTest() {
+ if (ICJniUtils.isTemperatureDevAvailable() > ICJniUtils.TempSensorType.TEMPSENSOR_TYPE_NONE.ordinal()) {
+
+ double bodyTemp/*体温*/ = 0.0f;
+ double cpuTemp/*cpu温度*/ = 0.0f;
+ double evnTemp/*环境温度*/ = 0.0f;
+ double gpuTemp/*gpu温度*/ = 0.0f;
+ double chargeTemp/*充电板的温度*/ = 0.0f;
+ double paTemp/*射频的温度*/ = 0.0f;
+ double boardTemp/*主板的温度*/ = 0.0f;
+ try {
+ String cpuTempType = ShellUtil.execRootCmd(CMD_CPU_TYPE);
+ String cpuTempStr = ShellUtil.execRootCmd(CMD_CPU_TEM);
+ String gpuTempType = ShellUtil.execRootCmd(CMD_GPU_TYPE);
+ String gpuTempStr = ShellUtil.execRootCmd(CMD_GPU_TEM);
+ String chargeTempType = ShellUtil.execRootCmd(CMD_CHARGE_TYPE);
+ String chargeTempStr = ShellUtil.execRootCmd(CMD_CHARGE_TEM);
+ String paTempType = ShellUtil.execRootCmd(CMD_PA_TYPE);
+ String paTempStr = ShellUtil.execRootCmd(CMD_PA_TEM);
+ String boardTempType = ShellUtil.execRootCmd(CMD_BOARD_TYPE);
+ String boardTempStr = ShellUtil.execRootCmd(CMD_BOARD_TEM);
+ //cpuTempType == > cpu-thmzone cpuTempStr == > 45295 gpuTempType == > gpu-thmzone gpuTempStr == > 43910
+ Log.d(TAG, " cpuTempType == > " + cpuTempType +
+ " cpuTempStr == > " + cpuTempStr +
+ "\n | " +
+ " gpuTempType == > " + gpuTempType +
+ " gpuTempStr == > " + gpuTempStr
+ + "\n | "
+ + "chargeTempType == > " + chargeTempType +
+ " chargeTempStr == > " + chargeTempStr
+ + "\n | "
+ + "paTempType == > " + paTempType +
+ " paTempStr == > " + paTempStr
+ + "\n | "
+ + "boardTempType == > " + boardTempType +
+ " boardTempStr == > " + boardTempStr
+ );
+ //数据处理一下
+ cpuTemp = Integer.parseInt(cpuTempStr) / 1000.0f;
+ gpuTemp = Integer.parseInt(gpuTempStr) / 1000.0f;
+ chargeTemp = Integer.parseInt(chargeTempStr) / 1000.0f;
+ paTemp = Integer.parseInt(paTempStr) / 1000.0f;
+ boardTemp = Integer.parseInt(boardTempStr) / 1000.0f;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ evnTemp = get_tempOut_value_origin();
+ bodyTemp = get_temp_value_adjusted();
+ //对数据进行处理=======================================================start
+ // 环境温度计算公式:
+ // Ut=St-(0.6205x-22.049),St为传感器温度,其中x主板温度,x∈[38,56]
+ // 体温计算公式:
+ // Ut = St-(Bt*0.4533-15.294) St为传感器温度,Bt为板子温度 Bt∈[38,56]
+ // 系数不要抽成常量,以后如果有更好的公式可以替换。
+ // 以上公式通过数据分析出来的,此公式仅适用于S123的产品,公式跟产品结构有关系
+ //TODO:以上重要,所以同时对外可支持配置,如果没有配置不进行数据处理,直接返回原数值
+ //TODO:配置格式:
+ // PRODUCT_PROPERTY_OVERRIDES += persist.sys.envTempAlgSlope=系数(斜率)
+ // PRODUCT_PROPERTY_OVERRIDES += persist.sys.envTempAlgDy=Y轴偏移值
+ //========================================================================//
+ //环境温度的斜率和Y轴偏移值
+ String envSlope = IcSystemProperty.getSystemProperties("persist.sys.envAlgSlope", "");
+ String envDy = IcSystemProperty.getSystemProperties("persist.sys.envAlgDy", "");
+ IcLog.d(TAG, "envSlope == > " + envSlope + " envDy == > " + envDy);
+ double resultEnvTemp = evnTemp;
+ if (!TextUtils.isEmpty(envDy) && !TextUtils.isEmpty(envSlope)) {
+ //进行换算
+ IcLog.d(TAG, "env temp with board temp...");
+ resultEnvTemp = evnTemp - (Float.parseFloat(envSlope) * boardTemp + Float.parseFloat(envDy));
+ }
+
+ String bodySlope = IcSystemProperty.getSystemProperties("persist.sys.bodyAlgSlope", "");
+ String bodyDy = IcSystemProperty.getSystemProperties("persist.sys.bodyAlgDy", "");
+ IcLog.d(TAG, "bodySlope == > " + bodySlope + " bodyDy == > " + bodyDy);
+ double resultBodyTemp = bodyTemp;
+ if (!TextUtils.isEmpty(bodyDy) && !TextUtils.isEmpty(bodySlope)) {
+ IcLog.d(TAG, "body temp with board temp...");
+ resultBodyTemp = bodyTemp - (Float.parseFloat(bodySlope) * boardTemp + Float.parseFloat(bodyDy));
+ }
+
+ //=======================================================================end
+ IcLog.d(TAG, "evnTemp == > " + evnTemp + " resultEnvTemp = > " + resultEnvTemp);
+ IcLog.d(TAG, "bodyTemp == > " + bodyTemp + " resultBodyTemp = > " + resultBodyTemp);
+ if (resultBodyTemp < 0) {
+ return null;
+ }
+ try {
+ //发送消息给launcher显示
+ TemperatureItem temperatureItem = new TemperatureItem(
+ String.format("%.01f", resultBodyTemp),
+ String.format("%.01f", cpuTemp),
+ String.format("%.01f", resultEnvTemp),
+ String.format("%.01f", gpuTemp),
+ String.format("%.01f", chargeTemp),
+ String.format("%.01f", boardTemp),
+ String.format("%.01f", paTemp));
+ return temperatureItem;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+}