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;
....@@ -24,10 +25,15 @@
2425 import android.net.ConnectivityManager;
2526 import android.net.NetworkInfo;
2627 import android.net.NetworkInfo.DetailedState;
28
+import android.os.Build;
2729 import android.os.PowerManager;
2830 import android.os.RemoteException;
2931 import android.text.format.DateFormat;
3032 import android.util.Log;
33
+
34
+import com.jwipc.nodka_reboot_under.MyApplication;
35
+import com.nodka.api.NodkaAPI;
36
+import com.nodka.api.NodkaNative;
3137
3238
3339 public class Utils {
....@@ -67,8 +73,7 @@
6773 Thread thread_set_time_reboot = null;
6874 Thread thread_STOP_WATCH_DOG = null;
6975 Thread thread_AlarmPower_Repeat_Poweroff = null;
70
-
71
-
76
+
7277
7378
7479 public Utils(Context context) {
....@@ -80,7 +85,6 @@
8085 sharedPreferences = context.getSharedPreferences(shapre, context.MODE_PRIVATE);
8186 editor = sharedPreferences.edit();
8287 }
83
-
8488
8589 public void shut_Down()
8690 {
....@@ -250,26 +254,30 @@
250254 return;
251255 }
252256
253
-
254
- AlarmPowerManager mAlarmPowerManager = new AlarmPowerManager();
255
-
256
- mAlarmPowerManager.removeAllalarmPower();
257
-
257
+ if (isSpiritVersion()) {
258
+ new AlarmPowerManager().removeAllalarmPower();
259
+ setFileState("0", "/sys/class/minix-rtc/MCURTCDATA");
260
+ } else {
261
+ MyApplication.getApplication().getNodkaAPI().alarm_removeAllalarmPower();
262
+ setFileState("0", "/sys/class/minix-rtc/minix_RTC_DATA");
263
+ }
264
+
258265 editor.putString(repeat_alarm_poweron_time, "");
259266 editor.putString(repeat_alarm_poweroff_time, "");
260267 editor.commit();
261
-
262
- setFileState("0", "/sys/class/minix-rtc/MCURTCDATA");
263
-
268
+
264269 if(active)
265270 {
266271 if(repeat.equals("true"))
267272 {
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
-
273
+ if (isSpiritVersion()) {
274
+ new SpiritAlarmManager().setSpiritAlarmWithDay(1, hms_on[0], hms_on[1]);
275
+ setFileState("1", "/sys/class/minix-rtc/MCURTCDATA");
276
+ } else {
277
+ MyApplication.getApplication().getNodkaAPI().alarm_setSpiritAlarmWithDay(1, hms_on[0], hms_on[1]);
278
+ setFileState("1", "/sys/class/minix-rtc/minix_RTC_DATA");
279
+ }
280
+
273281 editor.putString(repeat_alarm_poweron_time, hms_on[0]+":"+hms_on[1]+":"+0);
274282 editor.putString(repeat_alarm_poweroff_time, hms_off[0]+":"+hms_off[1]+":"+0);
275283 editor.commit();
....@@ -284,22 +292,37 @@
284292 editor.commit();
285293
286294 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
-
295
+
296
+ if (isSpiritVersion()) {
297
+ // 改接口 setSpiritAlarmWithDay()
298
+ new AlarmPowerManager().CreatOneAlarmPower(calendar.get(Calendar.YEAR)+"",
299
+ calendar.get(Calendar.MONTH)+1+"",
300
+ calendar.get(Calendar.DAY_OF_MONTH)+"",
301
+ hms_on[0]+"",
302
+ hms_on[1]+"",
303
+ hms_on[2]+"",
304
+ hms_off[0]+"",
305
+ hms_off[1]+"",
306
+ hms_off[2]+"",
307
+ hms_on[0]>12? "0":"1",
308
+ hms_off[0]>12? "0":"1");
309
+
310
+ new AlarmPowerManager().updateAlarmPowerActive(0, active+"");
311
+ } else {
312
+ MyApplication.getApplication().getNodkaAPI().alarm_creatOneAlarmPower(calendar.get(Calendar.YEAR)+"",
313
+ calendar.get(Calendar.MONTH)+1+"",
314
+ calendar.get(Calendar.DAY_OF_MONTH)+"",
315
+ hms_on[0]+"",
316
+ hms_on[1]+"",
317
+ hms_on[2]+"",
318
+ hms_off[0]+"",
319
+ hms_off[1]+"",
320
+ hms_off[2]+"",
321
+ hms_on[0]>12? "0":"1",
322
+ hms_off[0]>12? "0":"1");
323
+
324
+ MyApplication.getApplication().getNodkaAPI().alarm_updateAlarmPowerActive(0, active+"");
325
+ }
303326 }
304327 }
305328 }
....@@ -666,8 +689,70 @@
666689
667690 return re;
668691 }
692
+
693
+ public String getRootCmdSilent(String cmd) {
694
+ DataOutputStream dos = null;
695
+ DataInputStream dis = null;
696
+ Process process = null;
697
+ try {
698
+ process = Runtime.getRuntime().exec("su");
699
+ dos = new DataOutputStream(process.getOutputStream());
700
+ dis = new DataInputStream(process.getInputStream());
701
+ dos.write(cmd.getBytes());
702
+ dos.flush();
703
+ dos.close();
704
+ process.waitFor();
705
+ return getStrFromDataInPutStream(dis);
706
+ } catch (Exception e) {
707
+ e.printStackTrace();
708
+ return null;
709
+ } finally {
710
+ if (dos != null) {
711
+ try {
712
+ dos.close();
713
+ } catch (IOException e) {
714
+ e.printStackTrace();
715
+ }
716
+ }
717
+ if (dis != null) {
718
+ try {
719
+ dis.close();
720
+ } catch (IOException e) {
721
+ e.printStackTrace();
722
+ }
723
+ }
724
+ if (process != null) {
725
+ process.destroy();
726
+ }
727
+ }
728
+ }
729
+
730
+ private String getStrFromDataInPutStream(DataInputStream dos) {
731
+ if (null == dos) {
732
+ return "";
733
+ }
734
+ int BUFFER_SIZE = 512;
735
+ byte[] buffer = new byte[BUFFER_SIZE];
736
+ StringBuilder result = new StringBuilder();
737
+ try {
738
+ while (true) {
739
+ int read = dos.read(buffer);
740
+ if (read > 0) {
741
+ result.append(new String(buffer, 0, read));
742
+ }
743
+ if (read < BUFFER_SIZE) {
744
+ break;
745
+ }
746
+ }
747
+ } catch (Exception e) {
748
+ e.printStackTrace();
749
+ }
750
+ return result.toString();
751
+ }
669752
670
-
671
-
672
-
753
+ public boolean isSpiritVersion() {
754
+ return Build.VERSION.SDK_INT <= 25;
755
+ }
756
+
757
+
673758 }