.. | .. |
---|
1 | 1 | package com.jwipc.nodka_reboot_under.utils; |
---|
2 | 2 | |
---|
3 | 3 | import java.io.BufferedReader; |
---|
| 4 | +import java.io.DataInputStream; |
---|
4 | 5 | import java.io.DataOutputStream; |
---|
5 | 6 | import java.io.File; |
---|
6 | 7 | import java.io.FileNotFoundException; |
---|
.. | .. |
---|
24 | 25 | import android.net.ConnectivityManager; |
---|
25 | 26 | import android.net.NetworkInfo; |
---|
26 | 27 | import android.net.NetworkInfo.DetailedState; |
---|
| 28 | +import android.os.Build; |
---|
27 | 29 | import android.os.PowerManager; |
---|
28 | 30 | import android.os.RemoteException; |
---|
29 | 31 | import android.text.format.DateFormat; |
---|
30 | 32 | 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; |
---|
31 | 37 | |
---|
32 | 38 | |
---|
33 | 39 | public class Utils { |
---|
.. | .. |
---|
67 | 73 | Thread thread_set_time_reboot = null; |
---|
68 | 74 | Thread thread_STOP_WATCH_DOG = null; |
---|
69 | 75 | Thread thread_AlarmPower_Repeat_Poweroff = null; |
---|
70 | | - |
---|
71 | | - |
---|
| 76 | + |
---|
72 | 77 | |
---|
73 | 78 | |
---|
74 | 79 | public Utils(Context context) { |
---|
.. | .. |
---|
80 | 85 | sharedPreferences = context.getSharedPreferences(shapre, context.MODE_PRIVATE); |
---|
81 | 86 | editor = sharedPreferences.edit(); |
---|
82 | 87 | } |
---|
83 | | - |
---|
84 | 88 | |
---|
85 | 89 | public void shut_Down() |
---|
86 | 90 | { |
---|
.. | .. |
---|
250 | 254 | return; |
---|
251 | 255 | } |
---|
252 | 256 | |
---|
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 | + |
---|
258 | 265 | editor.putString(repeat_alarm_poweron_time, ""); |
---|
259 | 266 | editor.putString(repeat_alarm_poweroff_time, ""); |
---|
260 | 267 | editor.commit(); |
---|
261 | | - |
---|
262 | | - setFileState("0", "/sys/class/minix-rtc/MCURTCDATA"); |
---|
263 | | - |
---|
| 268 | + |
---|
264 | 269 | if(active) |
---|
265 | 270 | { |
---|
266 | 271 | if(repeat.equals("true")) |
---|
267 | 272 | { |
---|
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 | + |
---|
273 | 281 | editor.putString(repeat_alarm_poweron_time, hms_on[0]+":"+hms_on[1]+":"+0); |
---|
274 | 282 | editor.putString(repeat_alarm_poweroff_time, hms_off[0]+":"+hms_off[1]+":"+0); |
---|
275 | 283 | editor.commit(); |
---|
.. | .. |
---|
284 | 292 | editor.commit(); |
---|
285 | 293 | |
---|
286 | 294 | 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 | + } |
---|
303 | 326 | } |
---|
304 | 327 | } |
---|
305 | 328 | } |
---|
.. | .. |
---|
666 | 689 | |
---|
667 | 690 | return re; |
---|
668 | 691 | } |
---|
| 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 | + } |
---|
669 | 752 | |
---|
670 | | - |
---|
671 | | - |
---|
672 | | - |
---|
| 753 | + public boolean isSpiritVersion() { |
---|
| 754 | + return Build.VERSION.SDK_INT <= 25; |
---|
| 755 | + } |
---|
| 756 | + |
---|
| 757 | + |
---|
673 | 758 | } |
---|