hjw
2026-04-28 08a3fefb4e20177a8c1d450dd271927c1ddd1f1e
app/src/main/java/com/jwipc/nodka_reboot_under/utils/Utils.java
....@@ -1,6 +1,7 @@
11 package com.jwipc.nodka_reboot_under.utils;
22
33 import java.io.BufferedReader;
4
+import java.io.DataInputStream;
45 import java.io.DataOutputStream;
56 import java.io.File;
67 import java.io.FileNotFoundException;
....@@ -11,24 +12,18 @@
1112 import java.lang.reflect.Method;
1213 import java.util.ArrayList;
1314 import java.util.Calendar;
14
-import java.util.List;
1515
1616 import android.app.ActivityManager;
1717 import android.content.Context;
18
-import android.content.Intent;
1918 import android.content.SharedPreferences;
2019 import android.content.SharedPreferences.Editor;
21
-import android.hardware.spirit.AlarmPowerItem;
2220 import android.hardware.spirit.AlarmPowerManager;
2321 import android.jwipc.spirit.SpiritAlarmManager;
24
-import android.net.ConnectivityManager;
25
-import android.net.NetworkInfo;
26
-import android.net.NetworkInfo.DetailedState;
22
+import android.os.Build;
2723 import android.os.PowerManager;
28
-import android.os.RemoteException;
2924 import android.text.format.DateFormat;
30
-import android.util.Log;
3125
26
+import com.jwipc.nodka_reboot_under.MyApplication;
3227
3328 public class Utils {
3429
....@@ -67,8 +62,7 @@
6762 Thread thread_set_time_reboot = null;
6863 Thread thread_STOP_WATCH_DOG = null;
6964 Thread thread_AlarmPower_Repeat_Poweroff = null;
70
-
71
-
65
+
7266
7367
7468 public Utils(Context context) {
....@@ -80,7 +74,6 @@
8074 sharedPreferences = context.getSharedPreferences(shapre, context.MODE_PRIVATE);
8175 editor = sharedPreferences.edit();
8276 }
83
-
8477
8578 public void shut_Down()
8679 {
....@@ -250,26 +243,30 @@
250243 return;
251244 }
252245
253
-
254
- AlarmPowerManager mAlarmPowerManager = new AlarmPowerManager();
255
-
256
- mAlarmPowerManager.removeAllalarmPower();
257
-
246
+ if (isSpiritVersion()) {
247
+ new AlarmPowerManager().removeAllalarmPower();
248
+ setFileState("0", "/sys/class/minix-rtc/MCURTCDATA");
249
+ } else {
250
+ MyApplication.getApplication().getAndroidAPI().alarm_removeAllalarmPower();
251
+ setFileState("0", "/sys/class/minix-rtc/minix_RTC_DATA");
252
+ }
253
+
258254 editor.putString(repeat_alarm_poweron_time, "");
259255 editor.putString(repeat_alarm_poweroff_time, "");
260256 editor.commit();
261
-
262
- setFileState("0", "/sys/class/minix-rtc/MCURTCDATA");
263
-
257
+
264258 if(active)
265259 {
266260 if(repeat.equals("true"))
267261 {
268
- SpiritAlarmManager mSpiritAlarmManager = new SpiritAlarmManager();
269
- mSpiritAlarmManager.setSpiritAlarmWithDay(1, hms_on[0], hms_on[1]);
270
-
271
- setFileState("1", "/sys/class/minix-rtc/MCURTCDATA");
272
-
262
+ if (isSpiritVersion()) {
263
+ new SpiritAlarmManager().setSpiritAlarmWithDay(1, hms_on[0], hms_on[1]);
264
+ setFileState("1", "/sys/class/minix-rtc/MCURTCDATA");
265
+ } else {
266
+ MyApplication.getApplication().getAndroidAPI().alarm_setSpiritAlarmWithDay(1, hms_on[0], hms_on[1]);
267
+ setFileState("1", "/sys/class/minix-rtc/minix_RTC_DATA");
268
+ }
269
+
273270 editor.putString(repeat_alarm_poweron_time, hms_on[0]+":"+hms_on[1]+":"+0);
274271 editor.putString(repeat_alarm_poweroff_time, hms_off[0]+":"+hms_off[1]+":"+0);
275272 editor.commit();
....@@ -284,22 +281,37 @@
284281 editor.commit();
285282
286283 Calendar calendar = Calendar.getInstance();
287
-
288
- // 改接口 setSpiritAlarmWithDay()
289
- mAlarmPowerManager.CreatOneAlarmPower(calendar.get(Calendar.YEAR)+"",
290
- calendar.get(Calendar.MONTH)+1+"",
291
- calendar.get(Calendar.DAY_OF_MONTH)+"",
292
- hms_on[0]+"",
293
- hms_on[1]+"",
294
- hms_on[2]+"",
295
- hms_off[0]+"",
296
- hms_off[1]+"",
297
- hms_off[2]+"",
298
- hms_on[0]>12? "0":"1",
299
- hms_off[0]>12? "0":"1");
300
-
301
- mAlarmPowerManager.updateAlarmPowerActive(0, active+"");
302
-
284
+
285
+ if (isSpiritVersion()) {
286
+ // 改接口 setSpiritAlarmWithDay()
287
+ new AlarmPowerManager().CreatOneAlarmPower(calendar.get(Calendar.YEAR)+"",
288
+ calendar.get(Calendar.MONTH)+1+"",
289
+ calendar.get(Calendar.DAY_OF_MONTH)+"",
290
+ hms_on[0]+"",
291
+ hms_on[1]+"",
292
+ hms_on[2]+"",
293
+ hms_off[0]+"",
294
+ hms_off[1]+"",
295
+ hms_off[2]+"",
296
+ hms_on[0]>12? "0":"1",
297
+ hms_off[0]>12? "0":"1");
298
+
299
+ new AlarmPowerManager().updateAlarmPowerActive(0, active+"");
300
+ } else {
301
+ MyApplication.getApplication().getAndroidAPI().alarm_creatOneAlarmPower(calendar.get(Calendar.YEAR)+"",
302
+ calendar.get(Calendar.MONTH)+1+"",
303
+ calendar.get(Calendar.DAY_OF_MONTH)+"",
304
+ hms_on[0]+"",
305
+ hms_on[1]+"",
306
+ hms_on[2]+"",
307
+ hms_off[0]+"",
308
+ hms_off[1]+"",
309
+ hms_off[2]+"",
310
+ hms_on[0]>12? "0":"1",
311
+ hms_off[0]>12? "0":"1");
312
+
313
+ MyApplication.getApplication().getAndroidAPI().alarm_updateAlarmPowerActive(0, active+"");
314
+ }
303315 }
304316 }
305317 }
....@@ -666,8 +678,70 @@
666678
667679 return re;
668680 }
681
+
682
+ public String getRootCmdSilent(String cmd) {
683
+ DataOutputStream dos = null;
684
+ DataInputStream dis = null;
685
+ Process process = null;
686
+ try {
687
+ process = Runtime.getRuntime().exec("su");
688
+ dos = new DataOutputStream(process.getOutputStream());
689
+ dis = new DataInputStream(process.getInputStream());
690
+ dos.write(cmd.getBytes());
691
+ dos.flush();
692
+ dos.close();
693
+ process.waitFor();
694
+ return getStrFromDataInPutStream(dis);
695
+ } catch (Exception e) {
696
+ e.printStackTrace();
697
+ return null;
698
+ } finally {
699
+ if (dos != null) {
700
+ try {
701
+ dos.close();
702
+ } catch (IOException e) {
703
+ e.printStackTrace();
704
+ }
705
+ }
706
+ if (dis != null) {
707
+ try {
708
+ dis.close();
709
+ } catch (IOException e) {
710
+ e.printStackTrace();
711
+ }
712
+ }
713
+ if (process != null) {
714
+ process.destroy();
715
+ }
716
+ }
717
+ }
718
+
719
+ private String getStrFromDataInPutStream(DataInputStream dos) {
720
+ if (null == dos) {
721
+ return "";
722
+ }
723
+ int BUFFER_SIZE = 512;
724
+ byte[] buffer = new byte[BUFFER_SIZE];
725
+ StringBuilder result = new StringBuilder();
726
+ try {
727
+ while (true) {
728
+ int read = dos.read(buffer);
729
+ if (read > 0) {
730
+ result.append(new String(buffer, 0, read));
731
+ }
732
+ if (read < BUFFER_SIZE) {
733
+ break;
734
+ }
735
+ }
736
+ } catch (Exception e) {
737
+ e.printStackTrace();
738
+ }
739
+ return result.toString();
740
+ }
669741
670
-
671
-
672
-
742
+ public boolean isSpiritVersion() {
743
+ return Build.VERSION.SDK_INT <= 25;
744
+ }
745
+
746
+
673747 }