private void waitDex2oatExit(String odex, Credentials credentials) {
try {
Log.d(TAG, "path=" + odex + ", uid=" + Os.getuid() +
", peer_uid=" + credentials.getUid() +
", peer_pid=" + credentials.getPid() +
", path_len=" + odex.length());
String command = "while [ -d \"/proc/" + credentials.getPid() + "\" ]; do sleep 1; done";
java.lang.Process process = Runtime.getRuntime().exec(new String[]{"/system/bin/sh", "-c", command});
process.waitFor(1, TimeUnit.HOURS);
String command2 = "sleep 3; PATH=$(magisk --path)/.magisk/busybox:$PATH; sed -i 's/--inline-max-code-units=0/ /g' '" + odex + "'";
java.lang.Process process2 = Runtime.getRuntime().exec(new String[]{"/system/bin/sh", "-c", command2});
new Thread(() -> {
try (var out = new BufferedReader(new InputStreamReader(process2.getInputStream()))) {
String line;
while ((line = out.readLine()) != null) {
Log.i(TAG, "dex2oat out: " + line);
}
} catch (IOException e) {
Log.e(TAG, "Failed to read dex2oat output", e);
}
}).start();
new Thread(() -> {
try (var err = new BufferedReader(new InputStreamReader(process2.getErrorStream()))) {
String line;
while ((line = err.readLine()) != null) {
Log.e(TAG, "dex2oat err: " + line);
}
} catch (IOException e) {
Log.e(TAG, "Failed to read dex2oat errput", e);
}
}).start();
process2.waitFor(30, TimeUnit.SECONDS);
Log.i(TAG, "dex2oat exit with code " + process2.exitValue());
} catch (Exception e) {
Log.e(TAG, "Failed to wait for dex2oat exit", e);
}
}