add board temperature api.
authorTrillGates <williamtrillgates@gmail.com>
Fri, 24 Sep 2021 03:35:12 +0000 (11:35 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Fri, 24 Sep 2021 03:35:12 +0000 (11:35 +0800)
app/src/main/aidl/com/ic/work/IExInfoCallback.aidl [new file with mode: 0644]
app/src/main/aidl/com/ic/work/IExInfoService.aidl [new file with mode: 0644]
app/src/main/java/com/ic/work/TemperatureListenerReceiver.java [new file with mode: 0644]
app/src/main/java/com/ic/work/utils/AlarmManagerUtil.java [new file with mode: 0644]
app/src/main/java/com/ic/work/utils/TempFileUtils.java
app/src/main/java/com/ic/work/utils/TemperatureUtil.java

diff --git a/app/src/main/aidl/com/ic/work/IExInfoCallback.aidl b/app/src/main/aidl/com/ic/work/IExInfoCallback.aidl
new file mode 100644 (file)
index 0000000..3a11009
--- /dev/null
@@ -0,0 +1,9 @@
+// IExInfoCallback.aidl
+package com.ic.work;
+
+interface IExInfoCallback {
+     //获取主板温度的回调方法
+     void onBoardTemperatureLoaded(in float tempearture);
+     //高温警告的回调方法
+     void onBoardTemperatureTooHigh(in float limit);
+}
\ No newline at end of file
diff --git a/app/src/main/aidl/com/ic/work/IExInfoService.aidl b/app/src/main/aidl/com/ic/work/IExInfoService.aidl
new file mode 100644 (file)
index 0000000..c01c34e
--- /dev/null
@@ -0,0 +1,13 @@
+// IExInfoService.aidl
+package com.ic.work;
+
+interface IExInfoService {
+  //获取主板温度
+  void getBoardTemperature();
+  //设置主办温度的阀值和测试周期
+  //如果没有设置测试周期,越接近阀值温度,测试越频繁,离阀值温度越远
+  //测试不那么频繁
+  void setBoardTempCheckCycle(in int second);
+  //如果没有设置,默认是50度
+  void setBoardTempTopLimit(in float temp);
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/ic/work/TemperatureListenerReceiver.java b/app/src/main/java/com/ic/work/TemperatureListenerReceiver.java
new file mode 100644 (file)
index 0000000..588807f
--- /dev/null
@@ -0,0 +1,16 @@
+package com.ic.work;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+/**
+ * 这个是监听获取 温度的周期Alarm
+ */
+public class TemperatureListenerReceiver extends BroadcastReceiver {
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        //TODO:
+    }
+}
diff --git a/app/src/main/java/com/ic/work/utils/AlarmManagerUtil.java b/app/src/main/java/com/ic/work/utils/AlarmManagerUtil.java
new file mode 100644 (file)
index 0000000..0b9841f
--- /dev/null
@@ -0,0 +1,120 @@
+package com.ic.work.utils;
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+
+import java.util.Calendar;
+import java.util.Date;
+
+public class AlarmManagerUtil {
+
+    public static final String ALARM_ACTION = "com.ic.alarm.action.BOARD_TEMPERATURE_CHECK";
+
+    public static void setAlarmTime(Context context, long timeInMillis, Intent intent) {
+        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+        PendingIntent sender = PendingIntent.getBroadcast(context, intent.getIntExtra("id", 0),
+                intent, PendingIntent.FLAG_CANCEL_CURRENT);
+        int interval = (int) intent.getLongExtra("intervalMillis", 0);
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+            am.setWindow(AlarmManager.RTC_WAKEUP, timeInMillis, interval, sender);
+        }
+    }
+
+    public static void cancelAlarm(Context context, String action, int id) {
+        Intent intent = new Intent(action);
+        PendingIntent pi = PendingIntent.getBroadcast(context, id, intent, PendingIntent
+                .FLAG_CANCEL_CURRENT);
+        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+        am.cancel(pi);
+    }
+
+    /**
+     * @param flag            周期性时间间隔的标志,flag = 0 表示一次性的闹钟, flag = 1 表示每天提醒的闹钟(1天的时间间隔),flag = 2
+     *                        表示按周每周提醒的闹钟(一周的周期性时间间隔)
+     * @param hour            时
+     * @param minute          分
+     * @param id              闹钟的id
+     * @param week            week=0表示一次性闹钟或者按天的周期性闹钟,非0 的情况下是几就代表以周为周期性的周几的闹钟
+     * @param tips            闹钟提示信息
+     * @param soundOrVibrator 2表示声音和震动都执行,1表示只有铃声提醒,0表示只有震动提醒
+     */
+    public static void setAlarm(Context context, int flag, int hour, int minute, int id, int
+            week, String tips, int soundOrVibrator, String action, long intervalMillis) {
+        ICLogger.d("flag ==> " + flag + " hour ==> " + hour + " minute ==> " +
+                minute + " week ==> " + week + " tips==> " +
+                tips + " soundOrVibrator==> " + soundOrVibrator + " intervalMillis==> " + intervalMillis);
+        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(new Date());
+        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get
+                (Calendar.DAY_OF_MONTH), hour, minute, 0);
+        if (flag == 1) {
+            intervalMillis = 24 * 60 * 60 * 1000;
+        } else if (flag == 2) {
+            intervalMillis = 24 * 60 * 60 * 1000 * 7;
+        }
+        Intent intent = new Intent(action);
+        intent.putExtra("intervalMillis", intervalMillis);
+        intent.putExtra("msg", tips);
+        intent.putExtra("id", id);
+        intent.putExtra("soundOrVibrator", soundOrVibrator);
+        PendingIntent sender = PendingIntent.getBroadcast(context, id, intent, PendingIntent
+                .FLAG_UPDATE_CURRENT);
+        ICLogger.d("intervalMillis ==> " + intervalMillis);
+        //4.4以上的
+        long targetTime = calMethod(week, calendar.getTimeInMillis());
+        ICLogger.d("targetTime ==> " + targetTime);
+        am.setExact(AlarmManager.RTC, targetTime, sender);
+    }
+
+
+    /**
+     * @param weekFlag 传入的是周几
+     * @param dateTime 传入的是时间戳(设置当天的年月日+从选择框拿来的时分秒)
+     * @return 返回起始闹钟时间的时间戳
+     */
+    private static long calMethod(int weekFlag, long dateTime) {
+        long time = 0;
+        //weekflag == 0表示是按天为周期性的时间间隔或者是一次行的,weekfalg非0时表示每周几的闹钟并以周为时间间隔
+        if (weekFlag != 0) {
+            Calendar c = Calendar.getInstance();
+            int week = c.get(Calendar.DAY_OF_WEEK);
+            if (1 == week) {
+                week = 7;
+            } else if (2 == week) {
+                week = 1;
+            } else if (3 == week) {
+                week = 2;
+            } else if (4 == week) {
+                week = 3;
+            } else if (5 == week) {
+                week = 4;
+            } else if (6 == week) {
+                week = 5;
+            } else if (7 == week) {
+                week = 6;
+            }
+            if (weekFlag == week) {
+                if (dateTime > System.currentTimeMillis()) {
+                    time = dateTime;
+                } else {
+                    time = dateTime + 7 * 24 * 3600 * 1000;
+                }
+            } else if (weekFlag > week) {
+                time = dateTime + (weekFlag - week) * 24 * 3600 * 1000;
+            } else {
+                time = dateTime + (weekFlag - week + 7) * 24 * 3600 * 1000;
+            }
+        } else {
+            if (dateTime > System.currentTimeMillis()) {
+                time = dateTime;
+            } else {
+                time = dateTime + 24 * 3600 * 1000;
+            }
+        }
+        return time;
+    }
+}
index 3e1f5a7..0c89d79 100644 (file)
@@ -14,7 +14,6 @@ public class TempFileUtils {
         if (TextUtils.isEmpty(file)) {
             return null;
         }
-
         BufferedReader bf = null;
         try {
             FileInputStream fis = new FileInputStream(file);
index a16e331..d75794b 100644 (file)
@@ -29,7 +29,6 @@ public class TemperatureUtil {
         return ICJniUtils.getBodyTempFromWristTemp(wristtemp, envtemp);
     }
 
-
     //thermal_zone0
     public static final String CMD_CPU_TEM = "/sys/class/thermal/thermal_zone0/temp";
     public static final String CMD_CPU_TYPE = "/sys/class/thermal/thermal_zone0/type";