Skip to content

Commit 320a294

Browse files
committed
Extend the timeouts in the binary updater to prevent premature failures
1 parent 8532328 commit 320a294

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/com/noshufou/android/su/service/UpdaterService.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,14 @@ public void run() {
361361
BufferedReader is = new BufferedReader(new InputStreamReader(
362362
new DataInputStream(process.getInputStream())));
363363

364-
stepSuccess = executeCommand(os, is, mSuToolsPath, "touch /data/sutest");
364+
// Long timeout here in case the user has to respond to the prompt
365+
stepSuccess = executeCommand(os, is, 2000, mSuToolsPath, "id");
365366
currentStep.finish(stepSuccess);
366367

367368
// remount system partition
368369
if (mCancelled || !stepSuccess) return;
369370
currentStep = currentStep.increment(UPDATER_STEPS);
370-
executeCommand(os, is, mSuToolsPath, "mount -o remount,rw /system");
371-
stepSuccess = executeCommand(os, is, mSuToolsPath, "touch /system/su");
372-
executeCommand(os, is, mSuToolsPath, "rm /system/sutest");
371+
stepSuccess = executeCommand(os, is, mSuToolsPath, "mount -o remount,rw /system");
373372
currentStep.finish(stepSuccess);
374373

375374
// Copy su to /system
@@ -387,12 +386,12 @@ public void run() {
387386
// Ops check
388387
if (mCancelled || !stepSuccess) return;
389388
currentStep = currentStep.increment(UPDATER_STEPS);
390-
os.writeBytes("/system/su\n");
391389
Process process2 = Runtime.getRuntime().exec("/system/su");
392390
DataOutputStream os2 = new DataOutputStream(process2.getOutputStream());
393391
BufferedReader is2 = new BufferedReader(new InputStreamReader(
394392
new DataInputStream(process2.getInputStream())));
395-
stepSuccess = executeCommand(os2, is2, mSuToolsPath, "id");
393+
// Another long timeout since there may be a prompt again
394+
stepSuccess = executeCommand(os2, is2, 2000, mSuToolsPath, "id");
396395
currentStep.finish(stepSuccess);
397396
if (stepSuccess) os2.writeBytes("exit\n");
398397

@@ -499,7 +498,7 @@ private boolean downloadFile(String urlStr, String localName, String md5) {
499498

500499
private boolean executeCommand(DataOutputStream os, BufferedReader is, String... commands)
501500
throws IOException {
502-
return executeCommand(os, is, 200, commands);
501+
return executeCommand(os, is, 400, commands);
503502
}
504503

505504
private boolean executeCommand(DataOutputStream os, BufferedReader is, int timeout,
@@ -511,6 +510,8 @@ private boolean executeCommand(DataOutputStream os, BufferedReader is, int timeo
511510
}
512511
command.append("\n");
513512
os.writeBytes(command.toString());
513+
os.flush();
514+
Log.d(TAG, command.toString());
514515
if (is != null) {
515516
for (int i = 0; i < timeout; i++) {
516517
if (is.ready()) break;
@@ -521,11 +522,15 @@ private boolean executeCommand(DataOutputStream os, BufferedReader is, int timeo
521522
}
522523
}
523524
if (is.ready()) {
524-
return is.readLine().equals("0");
525+
String result = is.readLine();
526+
Log.d(TAG, result);
527+
return result.equals("0");
525528
} else {
529+
Log.d(TAG, "timeout");
526530
return false;
527531
}
528532
} else {
533+
Log.d(TAG, "null input stream");
529534
return false;
530535
}
531536
}

0 commit comments

Comments
 (0)