diff --git a/app/src/main/java/xzr/konabess/ChipInfo.java b/app/src/main/java/xzr/konabess/ChipInfo.java index 87fc2fc..33b8a83 100644 --- a/app/src/main/java/xzr/konabess/ChipInfo.java +++ b/app/src/main/java/xzr/konabess/ChipInfo.java @@ -18,6 +18,7 @@ public enum type { waipio_singleBin, cape_singleBin, kalama, + diwali, unknown } @@ -31,7 +32,7 @@ public static boolean shouldIgnoreVoltTable(type type) { return type == ChipInfo.type.lahaina || type == ChipInfo.type.lahaina_singleBin || type == ChipInfo.type.shima || type == ChipInfo.type.yupik || type == ChipInfo.type.waipio_singleBin || type == ChipInfo.type.cape_singleBin - || type == ChipInfo.type.kalama; + || type == ChipInfo.type.kalama || type == ChipInfo.type.diwali; } public static boolean checkChipGeneral(type input) { @@ -78,6 +79,8 @@ public static String name2chipdesc(type t, Activity activity) { return activity.getResources().getString(R.string.sd8g1p_singlebin); case kalama: return activity.getResources().getString(R.string.sd8g2); + case diwali: + return activity.getResources().getString(R.string.sd7g1); } return activity.getResources().getString(R.string.unknown); } @@ -108,6 +111,8 @@ else if (ChipInfo.which == type.cape_singleBin) return rpmh_levels_cape.levels; else if (ChipInfo.which == type.kalama) return rpmh_levels_kalama.levels; + else if (ChipInfo.which == type.diwali) + return rpmh_levels_diwali.levels; return new int[]{}; } @@ -135,13 +140,16 @@ else if (ChipInfo.which == type.cape_singleBin) return rpmh_levels_cape.level_str; else if (ChipInfo.which == type.kalama) return rpmh_levels_kalama.level_str; + else if (ChipInfo.which == type.diwali) + return rpmh_levels_diwali.level_str; return new String[]{}; } } private static class rpmh_levels_kona { - public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, 336, 352, 384, 400, 416}; + public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, + 336, 352, 384, 400, 416}; public static final String[] level_str = { "RETENTION", "MIN_SVS", @@ -206,7 +214,8 @@ private static class rpmh_levels_msmnile { } private static class rpmh_levels_lahaina { - public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, 336, 352, 384, 400, 416, 432, 448, 464}; + public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, + 336, 352, 384, 400, 416, 432, 448, 464}; public static final String[] level_str = { "RETENTION", "MIN_SVS", @@ -232,7 +241,8 @@ private static class rpmh_levels_lahaina { } private static class rpmh_levels_lahaina_singleBin { - public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, 336, 352, 384, 400, 416}; + public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, + 336, 352, 384, 400, 416}; public static final String[] level_str = { "RETENTION", "MIN_SVS", @@ -255,7 +265,8 @@ private static class rpmh_levels_lahaina_singleBin { } private static class rpmh_levels_lito { - public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, 336, 352, 384, 400, 416}; + public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, + 336, 352, 384, 400, 416}; public static final String[] level_str = { "RETENTION", "MIN_SVS", @@ -278,7 +289,8 @@ private static class rpmh_levels_lito { } private static class rpmh_levels_lagoon { - public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, 336, 352, 384, 400, 416}; + public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, + 336, 352, 384, 400, 416}; public static final String[] level_str = { "RETENTION", "MIN_SVS", @@ -301,7 +313,8 @@ private static class rpmh_levels_lagoon { } private static class rpmh_levels_shima { - public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, 336, 352, 384, 400, 416}; + public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, + 336, 352, 384, 400, 416}; public static final String[] level_str = { "RETENTION", "MIN_SVS", @@ -324,7 +337,8 @@ private static class rpmh_levels_shima { } private static class rpmh_levels_yupik { - public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, 336, 352, 384, 400, 416}; + public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, + 336, 352, 384, 400, 416}; public static final String[] level_str = { "RETENTION", "MIN_SVS", @@ -347,7 +361,8 @@ private static class rpmh_levels_yupik { } private static class rpmh_levels_waipio { - public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, 336, 352, 384, 400, 416}; + public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, + 336, 352, 384, 400, 416}; public static final String[] level_str = { "RETENTION", "MIN_SVS", @@ -370,7 +385,32 @@ private static class rpmh_levels_waipio { } private static class rpmh_levels_cape { - public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, 336, 352, 384, 400, 416}; + public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, + 336, 352, 384, 400, 416}; + public static final String[] level_str = { + "RETENTION", + "MIN_SVS", + "LOW_SVS_D1", + "LOW_SVS", + "LOW_SVS_L1", + "LOW_SVS_L2", + "SVS", + "SVS_L0", + "SVS_L1", + "SVS_L2", + "NOM", + "NOM_L1", + "NOM_L2", + "NOM_L3", + "TURBO", + "TURBO_L0", + "TURBO_L1" + }; + } + + private static class rpmh_levels_diwali { + public static final int[] levels = {16, 48, 56, 64, 80, 96, 128, 144, 192, 224, 256, 320, + 336, 352, 384, 400, 416}; public static final String[] level_str = { "RETENTION", "MIN_SVS", @@ -393,7 +433,8 @@ private static class rpmh_levels_cape { } private static class rpmh_levels_kalama { - public static final int[] levels = {16, 48, 52, 56, 60, 64, 72, 80, 96, 128, 144, 192, 224, 256, 288, 320, 336, 384, 400, 416, 432, 448, 464, 480}; + public static final int[] levels = {16, 48, 52, 56, 60, 64, 72, 80, 96, 128, 144, 192, + 224, 256, 288, 320, 336, 384, 400, 416, 432, 448, 464, 480}; public static final String[] level_str = { "RETENTION", "MIN_SVS", diff --git a/app/src/main/java/xzr/konabess/GpuTableEditor.java b/app/src/main/java/xzr/konabess/GpuTableEditor.java index e26f323..6a74910 100644 --- a/app/src/main/java/xzr/konabess/GpuTableEditor.java +++ b/app/src/main/java/xzr/konabess/GpuTableEditor.java @@ -47,7 +47,8 @@ public static void init() throws IOException { lines_in_dts = new ArrayList<>(); bins = new ArrayList<>(); bin_position = -1; - BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(KonaBessCore.dts_path))); + BufferedReader bufferedReader = + new BufferedReader(new FileReader(new File(KonaBessCore.dts_path))); String s; while ((s = bufferedReader.readLine()) != null) { lines_in_dts.add(s); @@ -82,7 +83,8 @@ public static void decode() throws Exception { || ChipInfo.which == ChipInfo.type.lagoon || ChipInfo.which == ChipInfo.type.shima || ChipInfo.which == ChipInfo.type.yupik - || ChipInfo.which == ChipInfo.type.kalama) + || ChipInfo.which == ChipInfo.type.kalama + || ChipInfo.which == ChipInfo.type.diwali) && this_line.contains("qcom,gpu-pwrlevels-")) { start = i; if (bin_position < 0) @@ -106,7 +108,8 @@ public static void decode() throws Exception { || ChipInfo.which == ChipInfo.type.lagoon || ChipInfo.which == ChipInfo.type.shima || ChipInfo.which == ChipInfo.type.yupik - || ChipInfo.which == ChipInfo.type.kalama)) { + || ChipInfo.which == ChipInfo.type.kalama + || ChipInfo.which == ChipInfo.type.diwali)) { end = i; if (end >= start) { decode_bin(lines_in_dts.subList(start, end + 1)); @@ -215,7 +218,8 @@ public static List genTable() { || ChipInfo.which == ChipInfo.type.lagoon || ChipInfo.which == ChipInfo.type.shima || ChipInfo.which == ChipInfo.type.yupik - || ChipInfo.which == ChipInfo.type.kalama) { + || ChipInfo.which == ChipInfo.type.kalama + || ChipInfo.which == ChipInfo.type.diwali) { for (int bin_id = 0; bin_id < bins.size(); bin_id++) { lines.add("qcom,gpu-pwrlevels-" + bins.get(bin_id).id + " {"); lines.addAll(bins.get(bin_id).header); @@ -267,10 +271,12 @@ private static String generateSubtitle(String line) throws Exception { if ("qcom,level".equals(raw_name) || "qcom,cx-level".equals(raw_name)) { return GpuVoltEditor.levelint2str(DtsHelper.decode_int_line(line).value); } - return DtsHelper.shouldUseHex(line) ? DtsHelper.decode_hex_line(line).value : DtsHelper.decode_int_line(line).value + ""; + return DtsHelper.shouldUseHex(line) ? DtsHelper.decode_hex_line(line).value : + DtsHelper.decode_int_line(line).value + ""; } - private static void generateALevel(Activity activity, int last, int levelid, LinearLayout page) throws Exception { + private static void generateALevel(Activity activity, int last, int levelid, + LinearLayout page) throws Exception { ((MainActivity) activity).onBackPressedListener = new MainActivity.onBackPressedListener() { @Override public void onBackPressed() { @@ -291,7 +297,8 @@ public void onBackPressed() { for (String line : bins.get(last).levels.get(levelid).lines) { items.add(new ParamAdapter.item() {{ - title = KonaBessStr.convert_level_params(DtsHelper.decode_hex_line(line).name, activity); + title = KonaBessStr.convert_level_params(DtsHelper.decode_hex_line(line).name, + activity); subtitle = generateSubtitle(line); }}); } @@ -302,15 +309,21 @@ public void onBackPressed() { generateLevels(activity, last, page); return; } - String raw_name = DtsHelper.decode_hex_line(bins.get(last).levels.get(levelid).lines.get(position - 1)).name; - String raw_value = DtsHelper.shouldUseHex(bins.get(last).levels.get(levelid).lines.get(position - 1)) - ? DtsHelper.decode_hex_line(bins.get(last).levels.get(levelid).lines.get(position - 1)).value - : DtsHelper.decode_int_line(bins.get(last).levels.get(levelid).lines.get(position - 1)).value + ""; + String raw_name = + DtsHelper.decode_hex_line(bins.get(last).levels.get(levelid).lines.get(position - 1)).name; + String raw_value = + DtsHelper.shouldUseHex(bins.get(last).levels.get(levelid).lines.get(position - 1)) + ? + DtsHelper.decode_hex_line(bins.get(last).levels.get(levelid).lines.get(position - 1)).value + : + DtsHelper.decode_int_line(bins.get(last).levels.get(levelid).lines.get(position - 1)).value + ""; if (raw_name.equals("qcom,level") || raw_name.equals("qcom,cx-level")) { try { Spinner spinner = new Spinner(activity); - spinner.setAdapter(new ArrayAdapter(activity, android.R.layout.simple_dropdown_item_1line, ChipInfo.rpmh_levels.level_str())); + spinner.setAdapter(new ArrayAdapter(activity, + android.R.layout.simple_dropdown_item_1line, + ChipInfo.rpmh_levels.level_str())); spinner.setSelection(GpuVoltEditor.levelint2int(Integer.parseInt(raw_value))); new AlertDialog.Builder(activity) @@ -321,9 +334,11 @@ public void onBackPressed() { try { bins.get(last).levels.get(levelid).lines.set( position - 1, - DtsHelper.encodeIntOrHexLine(raw_name, ChipInfo.rpmh_levels.levels()[spinner.getSelectedItemPosition()] + "")); + DtsHelper.encodeIntOrHexLine(raw_name, + ChipInfo.rpmh_levels.levels()[spinner.getSelectedItemPosition()] + "")); generateALevel(activity, last, levelid, page); - Toast.makeText(activity, R.string.save_success, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, R.string.save_success, + Toast.LENGTH_SHORT).show(); } catch (Exception exception) { DialogUtil.showError(activity, R.string.save_failed); exception.printStackTrace(); @@ -337,7 +352,8 @@ public void onBackPressed() { } } else { EditText editText = new EditText(activity); - editText.setInputType(DtsHelper.shouldUseHex(raw_name) ? InputType.TYPE_CLASS_TEXT : InputType.TYPE_CLASS_NUMBER); + editText.setInputType(DtsHelper.shouldUseHex(raw_name) ? + InputType.TYPE_CLASS_TEXT : InputType.TYPE_CLASS_NUMBER); editText.setText(raw_value); new AlertDialog.Builder(activity) .setTitle(activity.getResources().getString(R.string.edit) + " \"" + items.get(position).title + "\"") @@ -347,9 +363,11 @@ public void onBackPressed() { try { bins.get(last).levels.get(levelid).lines.set( position - 1, - DtsHelper.encodeIntOrHexLine(raw_name, editText.getText().toString())); + DtsHelper.encodeIntOrHexLine(raw_name, + editText.getText().toString())); generateALevel(activity, last, levelid, page); - Toast.makeText(activity, R.string.save_success, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, R.string.save_success, + Toast.LENGTH_SHORT).show(); } catch (Exception e) { DialogUtil.showError(activity, R.string.save_failed); } @@ -515,7 +533,8 @@ public static int min_level_chip_offset() throws Exception { || ChipInfo.which == ChipInfo.type.shima || ChipInfo.which == ChipInfo.type.yupik || ChipInfo.which == ChipInfo.type.waipio_singleBin || ChipInfo.which == ChipInfo.type.cape_singleBin - || ChipInfo.which == ChipInfo.type.kalama) + || ChipInfo.which == ChipInfo.type.kalama + || ChipInfo.which == ChipInfo.type.diwali) return 1; if (ChipInfo.which == ChipInfo.type.kona || ChipInfo.which == ChipInfo.type.kona_singleBin || ChipInfo.which == ChipInfo.type.msmnile || ChipInfo.which == ChipInfo.type.msmnile_singleBin @@ -728,7 +747,8 @@ public void run() { decode(); patch_throttle_level(); } catch (Exception e) { - activity.runOnUiThread(() -> DialogUtil.showError(activity, R.string.getting_freq_table_failed)); + activity.runOnUiThread(() -> DialogUtil.showError(activity, + R.string.getting_freq_table_failed)); } activity.runOnUiThread(() -> { diff --git a/app/src/main/java/xzr/konabess/GpuVoltEditor.java b/app/src/main/java/xzr/konabess/GpuVoltEditor.java index d91443a..5d221a3 100644 --- a/app/src/main/java/xzr/konabess/GpuVoltEditor.java +++ b/app/src/main/java/xzr/konabess/GpuVoltEditor.java @@ -52,7 +52,8 @@ public static void init() throws IOException { lines_in_dts = new ArrayList<>(); opps = new ArrayList<>(); opp_position = -1; - BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(KonaBessCore.dts_path))); + BufferedReader bufferedReader = + new BufferedReader(new FileReader(new File(KonaBessCore.dts_path))); String s; while ((s = bufferedReader.readLine()) != null) { lines_in_dts.add(s); @@ -215,7 +216,8 @@ public void onBackPressed() { .setView(editText) .setPositiveButton(R.string.save, (dialog, which) -> { try { - opps.get(voltn).frequency = Long.parseLong(editText.getText().toString()); + opps.get(voltn).frequency = + Long.parseLong(editText.getText().toString()); generateAVolt(activity, page, voltn); } catch (Exception e) { DialogUtil.showError(activity, R.string.save_failed); @@ -227,7 +229,9 @@ public void onBackPressed() { if (position == 2) { try { Spinner spinner = new Spinner(activity); - spinner.setAdapter(new ArrayAdapter(activity, android.R.layout.simple_dropdown_item_1line, ChipInfo.rpmh_levels.level_str())); + spinner.setAdapter(new ArrayAdapter(activity, + android.R.layout.simple_dropdown_item_1line, + ChipInfo.rpmh_levels.level_str())); spinner.setSelection(levelint2int(opps.get(voltn).volt)); new AlertDialog.Builder(activity) @@ -235,7 +239,8 @@ public void onBackPressed() { .setView(spinner) .setMessage(R.string.editvolt_msg) .setPositiveButton(R.string.save, (dialog, which) -> { - opps.get(voltn).volt = ChipInfo.rpmh_levels.levels()[spinner.getSelectedItemPosition()]; + opps.get(voltn).volt = + ChipInfo.rpmh_levels.levels()[spinner.getSelectedItemPosition()]; try { generateAVolt(activity, page, voltn); } catch (Exception e) { @@ -354,7 +359,8 @@ public void run() { init(); decode(); } catch (Exception e) { - activity.runOnUiThread(() -> DialogUtil.showError(activity, R.string.getting_volt_failed)); + activity.runOnUiThread(() -> DialogUtil.showError(activity, + R.string.getting_volt_failed)); } activity.runOnUiThread(() -> { diff --git a/app/src/main/java/xzr/konabess/KonaBessCore.java b/app/src/main/java/xzr/konabess/KonaBessCore.java index 131aa27..2b0c073 100644 --- a/app/src/main/java/xzr/konabess/KonaBessCore.java +++ b/app/src/main/java/xzr/konabess/KonaBessCore.java @@ -33,9 +33,11 @@ private enum dtb_types { public static void cleanEnv(Context context) throws IOException { Process process = new ProcessBuilder("sh").start(); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(process.getInputStream())); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(process.getOutputStream()); - outputStreamWriter.write("rm -rf " + context.getFilesDir().getAbsolutePath() + "/*\nexit\n"); + outputStreamWriter.write("rm -rf " + context.getFilesDir().getAbsolutePath() + "/*\nexit" + + "\n"); outputStreamWriter.flush(); while (bufferedReader.readLine() != null) { } @@ -58,7 +60,8 @@ public static void setupEnv(Context context) throws IOException { public static void reboot() throws IOException { Process process = new ProcessBuilder("su").redirectErrorStream(true).start(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter((process.getOutputStream())); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(process.getInputStream())); outputStreamWriter.write("svc power reboot\n"); outputStreamWriter.write("exit\n"); outputStreamWriter.flush(); @@ -109,9 +112,11 @@ public static void getBootImage(Context context) throws IOException { private static void getRealBootImage(Context context) throws IOException { Process process = new ProcessBuilder("su").redirectErrorStream(true).start(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter((process.getOutputStream())); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(process.getInputStream())); outputStreamWriter.write("dd if=/dev/block/bootdevice/by-name/boot" + getCurrent("slot") + " of=" + context.getFilesDir().getAbsolutePath() + "/boot.img\n"); - outputStreamWriter.write("chmod 644 " + context.getFilesDir().getAbsolutePath() + "/boot.img\n"); + outputStreamWriter.write("chmod 644 " + context.getFilesDir().getAbsolutePath() + "/boot" + + ".img\n"); outputStreamWriter.write("exit\n"); outputStreamWriter.flush(); while (bufferedReader.readLine() != null) { @@ -130,9 +135,12 @@ private static void getRealBootImage(Context context) throws IOException { private static void getVendorBootImage(Context context) throws IOException { Process process = new ProcessBuilder("su").redirectErrorStream(true).start(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter((process.getOutputStream())); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); - outputStreamWriter.write("dd if=/dev/block/bootdevice/by-name/vendor_boot" + getCurrent("slot") + " of=" + context.getFilesDir().getAbsolutePath() + "/boot.img\n"); - outputStreamWriter.write("chmod 644 " + context.getFilesDir().getAbsolutePath() + "/boot.img\n"); + BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(process.getInputStream())); + outputStreamWriter.write("dd if=/dev/block/bootdevice/by-name/vendor_boot" + getCurrent( + "slot") + " of=" + context.getFilesDir().getAbsolutePath() + "/boot.img\n"); + outputStreamWriter.write("chmod 644 " + context.getFilesDir().getAbsolutePath() + "/boot" + + ".img\n"); outputStreamWriter.write("exit\n"); outputStreamWriter.flush(); while (bufferedReader.readLine() != null) { @@ -151,8 +159,10 @@ private static void getVendorBootImage(Context context) throws IOException { public static void writeBootImage(Context context) throws IOException { Process process = new ProcessBuilder("su").redirectErrorStream(true).start(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter((process.getOutputStream())); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); - outputStreamWriter.write("dd if=" + context.getFilesDir().getAbsolutePath() + "/boot_new.img of=/dev/block/bootdevice/by-name/" + boot_name + getCurrent("slot") + "\n"); + BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(process.getInputStream())); + outputStreamWriter.write("dd if=" + context.getFilesDir().getAbsolutePath() + "/boot_new" + + ".img of=/dev/block/bootdevice/by-name/" + boot_name + getCurrent("slot") + "\n"); outputStreamWriter.write("exit\n"); outputStreamWriter.flush(); while (bufferedReader.readLine() != null) { @@ -165,8 +175,10 @@ public static void writeBootImage(Context context) throws IOException { public static void backupBootImage(Context context) throws IOException { Process process = new ProcessBuilder("sh").redirectErrorStream(true).start(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter((process.getOutputStream())); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); - outputStreamWriter.write("cp -f " + context.getFilesDir().getAbsolutePath() + "/boot.img " + Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + boot_name + ".img\n"); + BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(process.getInputStream())); + outputStreamWriter.write("cp -f " + context.getFilesDir().getAbsolutePath() + "/boot.img " + + Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + boot_name + ".img\n"); outputStreamWriter.write("exit\n"); outputStreamWriter.flush(); while (bufferedReader.readLine() != null) { @@ -187,25 +199,30 @@ public static void checkDevice(Context context) throws IOException { dtbs = new ArrayList<>(); for (int i = 0; i < dtb_num; i++) { if (checkChip(context, i, "kona v2.1") - || KonaBessCore.getCurrent("device").equals("OP4A79") && checkChip(context, i, "kona v2")) { + || KonaBessCore.getCurrent("device").equals("OP4A79") && checkChip(context, i + , "kona v2")) { dtb dtb = new dtb(); dtb.id = i; - dtb.type = checkSingleBin(context, i) ? ChipInfo.type.kona_singleBin : ChipInfo.type.kona; + dtb.type = checkSingleBin(context, i) ? ChipInfo.type.kona_singleBin : + ChipInfo.type.kona; dtbs.add(dtb); } else if (checkChip(context, i, "SM8150 v2")) { dtb dtb = new dtb(); dtb.id = i; - dtb.type = checkSingleBin(context, i) ? ChipInfo.type.msmnile_singleBin : ChipInfo.type.msmnile; + dtb.type = checkSingleBin(context, i) ? ChipInfo.type.msmnile_singleBin : + ChipInfo.type.msmnile; dtbs.add(dtb); } else if (checkChip(context, i, "Lahaina V2.1")) { dtb dtb = new dtb(); dtb.id = i; - dtb.type = checkSingleBin(context, i) ? ChipInfo.type.lahaina_singleBin : ChipInfo.type.lahaina; + dtb.type = checkSingleBin(context, i) ? ChipInfo.type.lahaina_singleBin : + ChipInfo.type.lahaina; dtbs.add(dtb); } else if (checkChip(context, i, "Lahaina v2.1")) { dtb dtb = new dtb(); dtb.id = i; - dtb.type = checkSingleBin(context, i) ? ChipInfo.type.lahaina_singleBin : ChipInfo.type.lahaina; + dtb.type = checkSingleBin(context, i) ? ChipInfo.type.lahaina_singleBin : + ChipInfo.type.lahaina; dtbs.add(dtb); } else if (checkChip(context, i, "Lito SoC")) { dtb dtb = new dtb(); @@ -248,6 +265,11 @@ public static void checkDevice(Context context) throws IOException { dtb.id = i; dtb.type = ChipInfo.type.kalama; dtbs.add(dtb); + } else if (checkChip(context, i, "Diwali SoC")) { + dtb dtb = new dtb(); + dtb.id = i; + dtb.type = ChipInfo.type.diwali; + dtbs.add(dtb); } } } @@ -260,7 +282,8 @@ public static void chooseTarget(dtb dtb, Activity activity) { private static boolean checkSingleBin(Context context, int index) throws IOException { Process process = new ProcessBuilder("sh").start(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter((process.getOutputStream())); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(process.getInputStream())); outputStreamWriter.write("cat " + context.getFilesDir().getAbsolutePath() + "/" + index + ".dts | grep 'qcom,gpu-pwrlevels {'\n"); outputStreamWriter.write("exit\n"); outputStreamWriter.flush(); @@ -278,7 +301,8 @@ private static boolean checkChip(Context context, int index, String chip) throws boolean result = false; Process process = new ProcessBuilder("sh").start(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter((process.getOutputStream())); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(process.getInputStream())); outputStreamWriter.write("cat " + context.getFilesDir().getAbsolutePath() + "/" + index + ".dts | grep model | grep '" + chip + "'\n"); outputStreamWriter.write("exit\n"); outputStreamWriter.flush(); @@ -294,7 +318,8 @@ private static boolean checkChip(Context context, int index, String chip) throws private static void unpackBootImage(Context context) throws IOException { Process process = new ProcessBuilder("sh").redirectErrorStream(true).start(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(process.getOutputStream()); - BufferedReader bufferedReader = new BufferedReader((new InputStreamReader(process.getInputStream()))); + BufferedReader bufferedReader = + new BufferedReader((new InputStreamReader(process.getInputStream()))); outputStreamWriter.write("cd " + context.getFilesDir().getAbsolutePath() + "\n"); outputStreamWriter.write("./magiskboot unpack boot.img\n"); outputStreamWriter.write("exit\n"); @@ -332,7 +357,8 @@ private static void unpackBootImage(Context context) throws IOException { private static void dtb2dts(Context context, int index) throws IOException { Process process = new ProcessBuilder("sh").redirectErrorStream(true).start(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(process.getOutputStream()); - BufferedReader bufferedReader = new BufferedReader((new InputStreamReader(process.getInputStream()))); + BufferedReader bufferedReader = + new BufferedReader((new InputStreamReader(process.getInputStream()))); outputStreamWriter.write("cd " + context.getFilesDir().getAbsolutePath() + "\n"); outputStreamWriter.write("./dtc -I dtb -O dts " + index + ".dtb -o " + index + ".dts\n"); outputStreamWriter.write("rm -f " + index + ".dtb\n"); @@ -420,7 +446,8 @@ else if (dtb_type == dtb_types.both) { private static void dts2dtb(Context context, int index) throws IOException { Process process = new ProcessBuilder("sh").redirectErrorStream(true).start(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(process.getOutputStream()); - BufferedReader bufferedReader = new BufferedReader((new InputStreamReader(process.getInputStream()))); + BufferedReader bufferedReader = + new BufferedReader((new InputStreamReader(process.getInputStream()))); outputStreamWriter.write("cd " + context.getFilesDir().getAbsolutePath() + "\n"); outputStreamWriter.write("./dtc -I dts -O dtb " + index + ".dts -o " + index + ".dtb\n"); outputStreamWriter.write("exit\n"); @@ -441,7 +468,8 @@ private static void dts2dtb(Context context, int index) throws IOException { private static void dtb2bootImage(Context context) throws IOException { Process process = new ProcessBuilder("sh").redirectErrorStream(true).start(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(process.getOutputStream()); - BufferedReader bufferedReader = new BufferedReader((new InputStreamReader(process.getInputStream()))); + BufferedReader bufferedReader = + new BufferedReader((new InputStreamReader(process.getInputStream()))); outputStreamWriter.write("cd " + context.getFilesDir().getAbsolutePath() + "\n"); if (dtb_type == dtb_types.both) outputStreamWriter.write("cp dtb kernel_dtb\n"); @@ -512,7 +540,8 @@ public static int getDtbIndex() throws IOException { private static List getCmdline() throws IOException { Process process = new ProcessBuilder("su").start(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter((process.getOutputStream())); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(process.getInputStream())); outputStreamWriter.write("cat /proc/cmdline\n"); outputStreamWriter.write("exit\n"); outputStreamWriter.flush(); diff --git a/app/src/main/java/xzr/konabess/KonaBessStr.java b/app/src/main/java/xzr/konabess/KonaBessStr.java index 243f68a..a79d741 100644 --- a/app/src/main/java/xzr/konabess/KonaBessStr.java +++ b/app/src/main/java/xzr/konabess/KonaBessStr.java @@ -31,6 +31,8 @@ else if (ChipInfo.which == ChipInfo.type.cape_singleBin) return convert_bins_cape_singleBin(which, activity); else if (ChipInfo.which == ChipInfo.type.kalama) return convert_bins_kalama(which, activity); + else if (ChipInfo.which == ChipInfo.type.diwali) + return convert_bins_diwali(which, activity); throw new Exception(); } @@ -150,6 +152,14 @@ public static String convert_bins_kalama(int which, Activity activity) { return activity.getResources().getString(R.string.unknown_table) + which; } + public static String convert_bins_diwali(int which, Activity activity) { + switch (which) { + case 3: + return activity.getResources().getString(R.string.sd7g1); + } + return activity.getResources().getString(R.string.unknown_table) + which; + } + public static String convert_level_params(String input, Activity activity) { input = input.replace("qcom,", ""); if (input.equals("gpu-freq")) diff --git a/app/src/main/java/xzr/konabess/MainActivity.java b/app/src/main/java/xzr/konabess/MainActivity.java index 0e23681..c6e8031 100644 --- a/app/src/main/java/xzr/konabess/MainActivity.java +++ b/app/src/main/java/xzr/konabess/MainActivity.java @@ -60,7 +60,8 @@ public void onBackPressed() { public static void runWithStoragePermission(Activity activity, Thread what) { MainActivity.permission_worker = what; if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - activity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); + activity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, + 0); } else { what.start(); permission_worker = null; @@ -94,7 +95,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } @Override - public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, String[] permissions, + int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (permission_worker != null) { @@ -157,18 +159,24 @@ void showMainView() { .setTitle(R.string.help) .setMessage(KonaBessStr.generic_help(this)) .setPositiveButton(R.string.ok, null) - .setNeutralButton(R.string.about, (dialog, which) -> new AlertDialog.Builder(MainActivity.this) - .setTitle(R.string.about) - .setMessage(getResources().getString(R.string.author) + " xzr467706992 (LibXZR)\n" + getResources().getString(R.string.release_at) + " www.akr-developers.com\n") - .setPositiveButton(R.string.ok, null) - .setNegativeButton("Github", (dialog1, which1) -> MainActivity.this.startActivity(new Intent() {{ - setAction(Intent.ACTION_VIEW); - setData(Uri.parse("https://github.com/xzr467706992/KonaBess")); - }})) - .setNeutralButton(R.string.visit_akr, (dialog1, which1) -> MainActivity.this.startActivity(new Intent() {{ - setAction(Intent.ACTION_VIEW); - setData(Uri.parse("https://www.akr-developers.com/d/441")); - }})).create().show()) + .setNeutralButton(R.string.about, + (dialog, which) -> new AlertDialog.Builder(MainActivity.this) + .setTitle(R.string.about) + .setMessage(getResources().getString(R.string.author) + " " + + "xzr467706992 (LibXZR)\n" + getResources().getString(R.string.release_at) + " www.akr-developers.com\n") + .setPositiveButton(R.string.ok, null) + .setNegativeButton("Github", + (dialog1, which1) -> MainActivity.this.startActivity(new Intent() {{ + setAction(Intent.ACTION_VIEW); + setData(Uri.parse("https://github" + + ".com/xzr467706992/KonaBess")); + }})) + .setNeutralButton(R.string.visit_akr, + (dialog1, which1) -> MainActivity.this.startActivity(new Intent() {{ + setAction(Intent.ACTION_VIEW); + setData(Uri.parse("https://www.akr-developers" + + ".com/d/441")); + }})).create().show()) .create().show()); } @@ -246,7 +254,8 @@ public void run() { runOnUiThread(() -> { waiting.dismiss(); if (is_err) - DialogUtil.showDetailedError(MainActivity.this, R.string.repack_failed, error); + DialogUtil.showDetailedError(MainActivity.this, R.string.repack_failed, + error); }); if (is_err) return; @@ -275,7 +284,8 @@ public void run() { try { KonaBessCore.reboot(); } catch (IOException e) { - DialogUtil.showError(MainActivity.this, R.string.failed_reboot); + DialogUtil.showError(MainActivity.this, + R.string.failed_reboot); } }) .setNegativeButton(R.string.no, null) @@ -327,7 +337,8 @@ public void run() { runOnUiThread(() -> { waiting.dismiss(); if (is_err) - DialogUtil.showDetailedError(MainActivity.this, R.string.unpack_failed, error); + DialogUtil.showDetailedError(MainActivity.this, R.string.unpack_failed, + error); }); if (is_err) return; @@ -348,7 +359,8 @@ public void run() { runOnUiThread(() -> { waiting.dismiss(); if (is_err) - DialogUtil.showDetailedError(MainActivity.this, R.string.failed_checking_platform, error); + DialogUtil.showDetailedError(MainActivity.this, + R.string.failed_checking_platform, error); }); if (is_err) return; @@ -369,7 +381,8 @@ public void run() { for (KonaBessCore.dtb dtb : KonaBessCore.dtbs) { items.add(new ParamAdapter.item() {{ title = dtb.id + " " + ChipInfo.name2chipdesc(dtb.type, MainActivity.this); - subtitle = dtb.id == dtb_index ? MainActivity.this.getString(R.string.possible_dtb) : ""; + subtitle = dtb.id == dtb_index ? + MainActivity.this.getString(R.string.possible_dtb) : ""; }}); } listView.setAdapter(new ParamAdapter(items, MainActivity.this)); diff --git a/app/src/main/java/xzr/konabess/TableIO.java b/app/src/main/java/xzr/konabess/TableIO.java index a9b26b2..ae37cf7 100644 --- a/app/src/main/java/xzr/konabess/TableIO.java +++ b/app/src/main/java/xzr/konabess/TableIO.java @@ -49,10 +49,12 @@ private static class json_keys { private static boolean decodeAndWriteData(JSONObject jsonObject) throws Exception { if (!ChipInfo.checkChipGeneral(ChipInfo.type.valueOf(jsonObject.getString(json_keys.CHIP)))) return true; - ArrayList freq = new ArrayList<>(Arrays.asList(jsonObject.getString(json_keys.FREQ).split("\n"))); + ArrayList freq = + new ArrayList<>(Arrays.asList(jsonObject.getString(json_keys.FREQ).split("\n"))); GpuTableEditor.writeOut(GpuTableEditor.genBack(freq)); if (!ChipInfo.shouldIgnoreVoltTable(ChipInfo.which)) { - ArrayList volt = new ArrayList<>(Arrays.asList(jsonObject.getString(json_keys.VOLT).split("\n"))); + ArrayList volt = + new ArrayList<>(Arrays.asList(jsonObject.getString(json_keys.VOLT).split("\n"))); //Init again because the dts file has been updated GpuVoltEditor.init(); GpuVoltEditor.decode(); @@ -106,7 +108,9 @@ private static void import_edittext(Activity activity) { new AlertDialog.Builder(activity) .setTitle(R.string.import_data) .setView(editText) - .setPositiveButton(R.string.confirm, (dialog, which) -> new showDecodeDialog(activity, editText.getText().toString()).start()) + .setPositiveButton(R.string.confirm, + (dialog, which) -> new showDecodeDialog(activity, + editText.getText().toString()).start()) .setNegativeButton(R.string.cancel, null) .create().show(); } @@ -115,7 +119,8 @@ private static abstract class ConfirmExportCallback { public abstract void onConfirm(String desc); } - private static void showExportDialog(Activity activity, ConfirmExportCallback confirmExportCallback) { + private static void showExportDialog(Activity activity, + ConfirmExportCallback confirmExportCallback) { EditText editText = new EditText(activity); editText.setHint(R.string.input_introduction_here); @@ -123,7 +128,8 @@ private static void showExportDialog(Activity activity, ConfirmExportCallback co .setTitle(R.string.export_data) .setMessage(R.string.export_data_msg) .setView(editText) - .setPositiveButton(R.string.confirm, (dialog, which) -> confirmExportCallback.onConfirm(editText.getText().toString())) + .setPositiveButton(R.string.confirm, + (dialog, which) -> confirmExportCallback.onConfirm(editText.getText().toString())) .setNegativeButton(R.string.cancel, null) .create().show(); } @@ -131,7 +137,8 @@ private static void showExportDialog(Activity activity, ConfirmExportCallback co private static void export_cpy(Activity activity, String desc) { // TODO: clipboard try { - DialogUtil.showDetailedInfo(activity, R.string.export_done, R.string.export_done_msg, "konabess://" + getConfig(desc)); + DialogUtil.showDetailedInfo(activity, R.string.export_done, R.string.export_done_msg, + "konabess://" + getConfig(desc)); } catch (Exception e) { DialogUtil.showError(activity, R.string.error_occur); } @@ -149,7 +156,8 @@ public exportToFile(Activity activity, String desc) { public void run() { error = false; - File out = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/konabess-" + new SimpleDateFormat("MMddHHmmss").format(new Date()) + ".txt"); + File out = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + + "/konabess-" + new SimpleDateFormat("MMddHHmmss").format(new Date()) + ".txt"); try { BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(out)); bufferedWriter.write("konabess://" + getConfig(desc)); @@ -159,7 +167,8 @@ public void run() { } activity.runOnUiThread(() -> { if (!error) - Toast.makeText(activity, activity.getResources().getString(R.string.success_export_to) + " " + out.getAbsolutePath(), Toast.LENGTH_LONG).show(); + Toast.makeText(activity, + activity.getResources().getString(R.string.success_export_to) + " " + out.getAbsolutePath(), Toast.LENGTH_LONG).show(); else Toast.makeText(activity, R.string.failed_export, Toast.LENGTH_SHORT).show(); }); @@ -189,7 +198,8 @@ public void run() { try { new AlertDialog.Builder(activity) .setTitle(R.string.going_import) - .setMessage(jsonObject.getString(json_keys.DESCRIPTION) + "\n" + activity.getResources().getString(R.string.compatible_chip) + ChipInfo.name2chipdesc(jsonObject.getString(json_keys.CHIP), activity)) + .setMessage(jsonObject.getString(json_keys.DESCRIPTION) + "\n" + + activity.getResources().getString(R.string.compatible_chip) + ChipInfo.name2chipdesc(jsonObject.getString(json_keys.CHIP), activity)) .setPositiveButton(R.string.confirm, (dialog, which) -> { waiting_import.show(); new Thread(() -> { @@ -201,9 +211,13 @@ public void run() { activity.runOnUiThread(() -> { waiting_import.dismiss(); if (!error) - Toast.makeText(activity, R.string.success_import, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, + R.string.success_import, + Toast.LENGTH_SHORT).show(); else - Toast.makeText(activity, R.string.failed_incompatible, Toast.LENGTH_LONG).show(); + Toast.makeText(activity, + R.string.failed_incompatible, + Toast.LENGTH_LONG).show(); }); }).start(); }) @@ -241,11 +255,13 @@ public void run() { waiting_import.show(); }); try { - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(activity.getContentResolver().openInputStream(uri))); + BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(activity.getContentResolver().openInputStream(uri))); new showDecodeDialog(activity, bufferedReader.readLine()).start(); bufferedReader.close(); } catch (Exception e) { - activity.runOnUiThread(() -> Toast.makeText(activity, R.string.unable_get_target_file, Toast.LENGTH_SHORT).show()); + activity.runOnUiThread(() -> Toast.makeText(activity, + R.string.unable_get_target_file, Toast.LENGTH_SHORT).show()); } } } @@ -289,7 +305,8 @@ public void onBackPressed() { showExportDialog(activity, new ConfirmExportCallback() { @Override public void onConfirm(String desc) { - MainActivity.runWithStoragePermission(activity, new exportToFile(activity, desc)); + MainActivity.runWithStoragePermission(activity, new exportToFile(activity + , desc)); } }); } else if (position == 2) { @@ -336,7 +353,8 @@ public void run() { GpuVoltEditor.decode(); } } catch (Exception e) { - activity.runOnUiThread(() -> DialogUtil.showError(activity, R.string.failed_getting_freq_voltage)); + activity.runOnUiThread(() -> DialogUtil.showError(activity, + R.string.failed_getting_freq_voltage)); } activity.runOnUiThread(() -> { diff --git a/app/src/main/java/xzr/konabess/utils/DialogUtil.java b/app/src/main/java/xzr/konabess/utils/DialogUtil.java index 8eb49ae..f1f3035 100644 --- a/app/src/main/java/xzr/konabess/utils/DialogUtil.java +++ b/app/src/main/java/xzr/konabess/utils/DialogUtil.java @@ -43,7 +43,8 @@ public static void showDetailedError(Activity activity, int err, String detail) showDetailedError(activity, activity.getResources().getString(err), detail); } - public static void showDetailedInfo(Activity activity, String title, String what, String detail) { + public static void showDetailedInfo(Activity activity, String title, String what, + String detail) { what += "\n" + activity.getResources().getString(R.string.long_press_to_copy); ScrollView scrollView = new ScrollView(activity); TextView textView = new TextView(activity); @@ -58,7 +59,8 @@ public static void showDetailedInfo(Activity activity, String title, String what } public static void showDetailedInfo(Activity activity, int title, int what, String detail) { - showDetailedInfo(activity, activity.getResources().getString(title), activity.getResources().getString(what), detail); + showDetailedInfo(activity, activity.getResources().getString(title), + activity.getResources().getString(what), detail); } public static AlertDialog getWaitDialog(Context context, int id) { diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 80d2bd2..d5063d5 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -124,4 +124,5 @@ Snapdragon 8+Gen1 Snapdragon 8Gen2 Snapdragon 8Gen2 for Galaxy + Snapdragon 7Gen1 diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index f6d0913..f1c108b 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -123,4 +123,5 @@ 骁龙8+Gen1 骁龙8Gen2 骁龙8Gen2 for Galaxy + 骁龙7Gen1 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3d9e7e6..405bbb1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -123,4 +123,5 @@ Snapdragon 8+Gen1 Snapdragon 8Gen2 Snapdragon 8Gen2 for Galaxy + Snapdragon 7Gen1 \ No newline at end of file