@@ -45,6 +45,13 @@ public void run() {
45
45
return ;
46
46
}
47
47
48
+ if (!rootAvailable ()) {
49
+ MainActivity ._appendLog (activity .getResources ().getString (R .string .unable_flash_root ), activity );
50
+ MainActivity .cur_status = MainActivity .status .error ;
51
+ ((MainActivity ) activity ).update_title ();
52
+ return ;
53
+ }
54
+
48
55
try {
49
56
copy ();
50
57
} catch (IOException ioException ) {
@@ -82,7 +89,7 @@ public void run() {
82
89
is_error = true ;
83
90
}
84
91
if (is_error ) {
85
- MainActivity ._appendLog (activity .getResources ().getString (R .string .unable_flash_root ), activity );
92
+ MainActivity ._appendLog (activity .getResources ().getString (R .string .unable_flash_error ), activity );
86
93
MainActivity .cur_status = MainActivity .status .error ;
87
94
((MainActivity ) activity ).update_title ();
88
95
return ;
@@ -106,6 +113,15 @@ public void run() {
106
113
((MainActivity ) activity ).update_title ();
107
114
}
108
115
116
+ boolean rootAvailable () {
117
+ try {
118
+ String ret = runWithNewProcessReturn (true , "id" );
119
+ return ret != null && ret .contains ("root" );
120
+ } catch (IOException e ) {
121
+ return false ;
122
+ }
123
+ }
124
+
109
125
void copy () throws IOException {
110
126
InputStream inputStream = activity .getContentResolver ().openInputStream (uri );
111
127
FileOutputStream fileOutputStream = new FileOutputStream (new File (file_path ));
@@ -160,6 +176,10 @@ void reboot() throws IOException {
160
176
}
161
177
162
178
void runWithNewProcessNoReturn (boolean su , String cmd ) throws IOException {
179
+ runWithNewProcessReturn (su , cmd );
180
+ }
181
+
182
+ String runWithNewProcessReturn (boolean su , String cmd ) throws IOException {
163
183
Process process = null ;
164
184
if (su ) {
165
185
process = new ProcessBuilder ("su" ).redirectErrorStream (true ).start ();
@@ -171,11 +191,16 @@ void runWithNewProcessNoReturn(boolean su, String cmd) throws IOException {
171
191
outputStreamWriter .write (cmd + "\n " );
172
192
outputStreamWriter .write ("exit\n " );
173
193
outputStreamWriter .flush ();
174
- while (bufferedReader .readLine () != null ) {
194
+ String tmp ;
195
+ StringBuilder ret = new StringBuilder ();
196
+ while ((tmp = bufferedReader .readLine ()) != null ) {
197
+ ret .append (tmp );
198
+ ret .append ("\n " );
175
199
}
176
200
outputStreamWriter .close ();
177
201
bufferedReader .close ();
178
202
process .destroy ();
203
+ return ret .toString ();
179
204
}
180
205
181
206
}
0 commit comments