| .. | .. |
|---|
| 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; |
|---|
| .. | .. |
|---|
| 11 | 12 | import java.lang.reflect.Method; |
|---|
| 12 | 13 | import java.util.ArrayList; |
|---|
| 13 | 14 | import java.util.Calendar; |
|---|
| 14 | | -import java.util.List; |
|---|
| 15 | 15 | |
|---|
| 16 | 16 | import android.app.ActivityManager; |
|---|
| 17 | 17 | import android.content.Context; |
|---|
| 18 | | -import android.content.Intent; |
|---|
| 19 | 18 | import android.content.SharedPreferences; |
|---|
| 20 | 19 | import android.content.SharedPreferences.Editor; |
|---|
| 21 | | -import android.hardware.spirit.AlarmPowerItem; |
|---|
| 22 | 20 | import android.hardware.spirit.AlarmPowerManager; |
|---|
| 23 | 21 | import android.jwipc.spirit.SpiritAlarmManager; |
|---|
| 24 | | -import android.net.ConnectivityManager; |
|---|
| 25 | | -import android.net.NetworkInfo; |
|---|
| 26 | | -import android.net.NetworkInfo.DetailedState; |
|---|
| 27 | 22 | import android.os.Build; |
|---|
| 28 | 23 | import android.os.PowerManager; |
|---|
| 29 | | -import android.os.RemoteException; |
|---|
| 30 | 24 | import android.text.format.DateFormat; |
|---|
| 31 | | -import android.util.Log; |
|---|
| 32 | 25 | |
|---|
| 33 | 26 | import com.jwipc.nodka_reboot_under.MyApplication; |
|---|
| 34 | | -import com.nodka.api.NodkaAPI; |
|---|
| 35 | | -import com.nodka.api.NodkaNative; |
|---|
| 36 | | - |
|---|
| 37 | 27 | |
|---|
| 38 | 28 | public class Utils { |
|---|
| 39 | 29 | |
|---|
| .. | .. |
|---|
| 257 | 247 | new AlarmPowerManager().removeAllalarmPower(); |
|---|
| 258 | 248 | setFileState("0", "/sys/class/minix-rtc/MCURTCDATA"); |
|---|
| 259 | 249 | } else { |
|---|
| 260 | | - MyApplication.getApplication().getNodkaAPI().alarm_removeAllalarmPower(); |
|---|
| 250 | + MyApplication.getApplication().getAndroidAPI().alarm_removeAllalarmPower(); |
|---|
| 261 | 251 | setFileState("0", "/sys/class/minix-rtc/minix_RTC_DATA"); |
|---|
| 262 | 252 | } |
|---|
| 263 | 253 | |
|---|
| .. | .. |
|---|
| 273 | 263 | new SpiritAlarmManager().setSpiritAlarmWithDay(1, hms_on[0], hms_on[1]); |
|---|
| 274 | 264 | setFileState("1", "/sys/class/minix-rtc/MCURTCDATA"); |
|---|
| 275 | 265 | } else { |
|---|
| 276 | | - MyApplication.getApplication().getNodkaAPI().alarm_setSpiritAlarmWithDay(1, hms_on[0], hms_on[1]); |
|---|
| 266 | + MyApplication.getApplication().getAndroidAPI().alarm_setSpiritAlarmWithDay(1, hms_on[0], hms_on[1]); |
|---|
| 277 | 267 | setFileState("1", "/sys/class/minix-rtc/minix_RTC_DATA"); |
|---|
| 278 | 268 | } |
|---|
| 279 | 269 | |
|---|
| .. | .. |
|---|
| 308 | 298 | |
|---|
| 309 | 299 | new AlarmPowerManager().updateAlarmPowerActive(0, active+""); |
|---|
| 310 | 300 | } else { |
|---|
| 311 | | - MyApplication.getApplication().getNodkaAPI().alarm_creatOneAlarmPower(calendar.get(Calendar.YEAR)+"", |
|---|
| 301 | + MyApplication.getApplication().getAndroidAPI().alarm_creatOneAlarmPower(calendar.get(Calendar.YEAR)+"", |
|---|
| 312 | 302 | calendar.get(Calendar.MONTH)+1+"", |
|---|
| 313 | 303 | calendar.get(Calendar.DAY_OF_MONTH)+"", |
|---|
| 314 | 304 | hms_on[0]+"", |
|---|
| .. | .. |
|---|
| 320 | 310 | hms_on[0]>12? "0":"1", |
|---|
| 321 | 311 | hms_off[0]>12? "0":"1"); |
|---|
| 322 | 312 | |
|---|
| 323 | | - MyApplication.getApplication().getNodkaAPI().alarm_updateAlarmPowerActive(0, active+""); |
|---|
| 313 | + MyApplication.getApplication().getAndroidAPI().alarm_updateAlarmPowerActive(0, active+""); |
|---|
| 324 | 314 | } |
|---|
| 325 | 315 | } |
|---|
| 326 | 316 | } |
|---|
| .. | .. |
|---|
| 688 | 678 | |
|---|
| 689 | 679 | return re; |
|---|
| 690 | 680 | } |
|---|
| 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 | + } |
|---|
| 691 | 741 | |
|---|
| 692 | 742 | public boolean isSpiritVersion() { |
|---|
| 693 | 743 | return Build.VERSION.SDK_INT <= 25; |
|---|