Skip to content

Commit

Permalink
KonaBessCore: Use props to detect dtb idx
Browse files Browse the repository at this point in the history
Seems more compatible.
  • Loading branch information
libxzr committed Apr 24, 2024
1 parent 4ba3390 commit 70155bc
Showing 1 changed file with 5 additions and 27 deletions.
32 changes: 5 additions & 27 deletions app/src/main/java/xzr/konabess/KonaBessCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import xzr.konabess.utils.AssetsUtil;

Expand Down Expand Up @@ -543,33 +541,13 @@ public static void dts2bootImage(Context context) throws IOException {
dtb2bootImage(context);
}

public static int getDtbIndex() throws IOException {
public static int getDtbIndex() {
int ret = -1;
for (String line : getCmdline()) {
if (line.startsWith("androidboot.dtb_idx")) {
try {
for (int i = line.length() - 1; i >= 0; i--) {
ret = Integer.parseInt(line.substring(i));
}
} catch (Exception ignored) {
}
}
try {
ret = Integer.parseInt(SystemProperties.get("ro.boot.dtb_idx", null));
} catch (Exception ignored) {

}
return ret;
}

private static List<String> getCmdline() throws IOException {
Process process = new ProcessBuilder("su").start();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter((process.getOutputStream()));
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader(process.getInputStream()));
outputStreamWriter.write("cat /proc/cmdline\n");
outputStreamWriter.write("exit\n");
outputStreamWriter.flush();
String s = bufferedReader.readLine();
outputStreamWriter.close();
bufferedReader.close();
process.destroy();
return s != null ? Arrays.asList(s.split(" ")) : new ArrayList<>();
}
}

0 comments on commit 70155bc

Please sign in to comment.