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;
....@@ -688,6 +689,66 @@
688689
689690 return re;
690691 }
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
+ }
691752
692753 public boolean isSpiritVersion() {
693754 return Build.VERSION.SDK_INT <= 25;