From 2f405e5ce7e27ffe217df9421c4aac87128b329b Mon Sep 17 00:00:00 2001 From: thatmidcoder393 <73651803+ThatMG393@users.noreply.github.com> Date: Tue, 14 Jan 2025 18:05:09 +0800 Subject: [PATCH 1/6] misc[devenv[: Add devcontainer for quick cloud editing --- .devcontainer/devcontainer.json | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..b321ef782 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,25 @@ +{ + "name": "Java", + "image": "mcr.microsoft.com/devcontainers/base:bullseye", + "features": { + "ghcr.io/devcontainers/features/java:1": { + "version": "21.0.5", + "installMaven": "false", + "installGradle": "true", + "jdkDistro": "graal" + }, + "ghcr.io/devcontainers/features/desktop-lite:1": {} + }, + "forwardPorts": [ + 6080 + ], + "portsAttributes": { + "6080": { + "label": "desktop", + "onAutoForward": "notify" + } + }, + "runArgs": [ + "--shm-size=1g" + ] +} From cb3a8a26d1b73d67230d7e113c7200d14d290928 Mon Sep 17 00:00:00 2001 From: thatmidcoder393 <73651803+ThatMG393@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:54:35 +0000 Subject: [PATCH 2/6] feat[SystemInfo]: fix cpu fetching on Android --- .../java/net/vulkanmod/vulkan/SystemInfo.java | 80 +++++++++++++++++-- 1 file changed, 75 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/vulkanmod/vulkan/SystemInfo.java b/src/main/java/net/vulkanmod/vulkan/SystemInfo.java index d64417c40..fd21216fd 100644 --- a/src/main/java/net/vulkanmod/vulkan/SystemInfo.java +++ b/src/main/java/net/vulkanmod/vulkan/SystemInfo.java @@ -1,12 +1,82 @@ package net.vulkanmod.vulkan; -import oshi.hardware.CentralProcessor; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Stream; public class SystemInfo { - public static final String cpuInfo; + public static final String cpuInfo = getCPUNameSafely(); + public static String getCPUNameSafely() { + String tmp = getCPUNameFromProc(); + if (tmp == null) { + tmp = getCPUNameFromProp(); + if (tmp == null) { + return "Unknown CPU"; + } + } - static { - CentralProcessor centralProcessor = new oshi.SystemInfo().getHardware().getProcessor(); - cpuInfo = String.format("%s", centralProcessor.getProcessorIdentifier().getName()).replaceAll("\\s+", " "); + return tmp; + } + + private static String getCPUNameFromProc() { + try (Stream lines = Files.lines(Paths.get("/proc/cpuinfo"))) { + return lines.filter(line -> line.startsWith("Hardware") || line.startsWith("model name")) + .reduce((f, s) -> f.startsWith("H") ? f : s) + .map(line -> { + String value = line.split(":")[1].strip(); + return value.startsWith("H") ? value + " (SoC)" : value; + }).orElse(null); + } catch (IOException e) { + return null; + } + } + + private static String getCPUNameFromProp() { + Set manufacturer = shellExec("getprop ro.soc.manufacturer"); + Set model = shellExec("getprop ro.soc.model"); + + if (manufacturer.size() == 0) { + // manu is null but model not null -> model. ex: "MT6833V/NZA" + if (model.size() >= 1) return model.iterator().next(); + } else { + // manu not null but model is null -> manu + " CPU". ex: "Mediatek CPU" + if (model.size() == 0) return manufacturer.iterator().next() + " CPU"; + // best case scenario + // manu not null and model not null -> manu + model. ex: "Mediatek MT6833V/NZA" + else return manufacturer.iterator().next() + " " + model.iterator().next(); + } + + // worst case scenario + // manu is null and model is null + return null; + } + + private static Set shellExec(String commands) { + Set lines = new HashSet<>(); + + // idk + String[] args = { + "sh", "-c", "\"" + commands + "\"" + }; + + try { + ProcessBuilder procBuilder = new ProcessBuilder(args); + procBuilder.redirectErrorStream(true); + + Process proc = procBuilder.start(); + try ( + BufferedReader stdin = new BufferedReader(new InputStreamReader(proc.getInputStream())); + ) { + String tmp = null; + while ((tmp = stdin.readLine()) != null) lines.add(tmp.strip()); + } catch (IOException e1) { } + } catch (IOException e) { } + + return lines; } } From 2e28730524301e40f0461d385f563f320755c835 Mon Sep 17 00:00:00 2001 From: thatmidcoder393 <73651803+ThatMG393@users.noreply.github.com> Date: Wed, 15 Jan 2025 20:20:46 +0800 Subject: [PATCH 3/6] fix[SystemInfo]: refine the CPU fetcher --- .../java/net/vulkanmod/vulkan/SystemInfo.java | 103 ++++++++---------- 1 file changed, 43 insertions(+), 60 deletions(-) diff --git a/src/main/java/net/vulkanmod/vulkan/SystemInfo.java b/src/main/java/net/vulkanmod/vulkan/SystemInfo.java index fd21216fd..5a2b49b4d 100644 --- a/src/main/java/net/vulkanmod/vulkan/SystemInfo.java +++ b/src/main/java/net/vulkanmod/vulkan/SystemInfo.java @@ -1,82 +1,65 @@ package net.vulkanmod.vulkan; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashSet; -import java.util.Set; -import java.util.stream.Stream; +import net.vulkanmod.Initializer; +import java.io.*; +import java.nio.file.*; +import java.util.*; public class SystemInfo { + private static final String UNKNOWN_CPU = "Unknown CPU"; + private static final String PROC_CPUINFO = "/proc/cpuinfo"; + private static final String SOC_MANUFACTURER_PROP = "/system/bin/getprop ro.soc.manufacturer"; + private static final String SOC_MODEL_PROP = "/system/bin/getprop ro.soc.model"; + public static final String cpuInfo = getCPUNameSafely(); - public static String getCPUNameSafely() { - String tmp = getCPUNameFromProc(); - if (tmp == null) { - tmp = getCPUNameFromProp(); - if (tmp == null) { - return "Unknown CPU"; - } - } - return tmp; + public static String getCPUNameSafely() { + return Optional.ofNullable(getCPUNameFromProc()) + .orElseGet(() -> Optional.ofNullable(getCPUNameFromProp()) + .orElse(UNKNOWN_CPU)); } private static String getCPUNameFromProc() { - try (Stream lines = Files.lines(Paths.get("/proc/cpuinfo"))) { - return lines.filter(line -> line.startsWith("Hardware") || line.startsWith("model name")) - .reduce((f, s) -> f.startsWith("H") ? f : s) + try { + return Files.lines(Paths.get(PROC_CPUINFO)) + .filter(line -> line.startsWith("Hardware") || line.startsWith("model name")) + .findFirst() .map(line -> { - String value = line.split(":")[1].strip(); - return value.startsWith("H") ? value + " (SoC)" : value; + String value = line.split(":", 2)[1].strip(); + return line.startsWith("Hardware") ? value + " (SoC)" : value; }).orElse(null); } catch (IOException e) { + Initializer.LOGGER.warn("Failed to read CPU info from proc", e); return null; } } private static String getCPUNameFromProp() { - Set manufacturer = shellExec("getprop ro.soc.manufacturer"); - Set model = shellExec("getprop ro.soc.model"); - - if (manufacturer.size() == 0) { - // manu is null but model not null -> model. ex: "MT6833V/NZA" - if (model.size() >= 1) return model.iterator().next(); - } else { - // manu not null but model is null -> manu + " CPU". ex: "Mediatek CPU" - if (model.size() == 0) return manufacturer.iterator().next() + " CPU"; - // best case scenario - // manu not null and model not null -> manu + model. ex: "Mediatek MT6833V/NZA" - else return manufacturer.iterator().next() + " " + model.iterator().next(); - } - - // worst case scenario - // manu is null and model is null - return null; + String manufacturer = executeCommand(SOC_MANUFACTURER_PROP); + String model = executeCommand(SOC_MODEL_PROP); + + if (manufacturer == null) return model != null ? model : null; + else return model != null ? manufacturer + " " + model + : manufacturer + " CPU"; } - private static Set shellExec(String commands) { - Set lines = new HashSet<>(); - - // idk - String[] args = { - "sh", "-c", "\"" + commands + "\"" - }; - + private static String executeCommand(String command) { try { - ProcessBuilder procBuilder = new ProcessBuilder(args); - procBuilder.redirectErrorStream(true); - - Process proc = procBuilder.start(); - try ( - BufferedReader stdin = new BufferedReader(new InputStreamReader(proc.getInputStream())); - ) { - String tmp = null; - while ((tmp = stdin.readLine()) != null) lines.add(tmp.strip()); - } catch (IOException e1) { } - } catch (IOException e) { } - - return lines; + Process process = new ProcessBuilder(command.split(" ")).start(); + try (BufferedReader reader = new BufferedReader( + new InputStreamReader(process.getInputStream()))) { + + if (process.waitFor() != 0) { + Initializer.LOGGER.warn("Command failed: " + command); + return null; + } + + return reader.readLine(); + } + } catch (IOException | InterruptedException e) { + Initializer.LOGGER.warn("Failed to execute command: " + command, e); + Thread.currentThread().interrupt(); + return null; + } } } From 4abcdf67c73effa1af39af32fd4e77102e91c848 Mon Sep 17 00:00:00 2001 From: thatmidcoder393 <73651803+ThatMG393@users.noreply.github.com> Date: Wed, 15 Jan 2025 20:22:14 +0800 Subject: [PATCH 4/6] fix[SystemInfo]: changed an output string --- src/main/java/net/vulkanmod/vulkan/SystemInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/vulkanmod/vulkan/SystemInfo.java b/src/main/java/net/vulkanmod/vulkan/SystemInfo.java index 5a2b49b4d..b0b8a2309 100644 --- a/src/main/java/net/vulkanmod/vulkan/SystemInfo.java +++ b/src/main/java/net/vulkanmod/vulkan/SystemInfo.java @@ -40,7 +40,7 @@ private static String getCPUNameFromProp() { if (manufacturer == null) return model != null ? model : null; else return model != null ? manufacturer + " " + model - : manufacturer + " CPU"; + : "A " + manufacturer + " CPU"; } private static String executeCommand(String command) { From 8c2ef9c5098cab23990578b169f15355e6426e22 Mon Sep 17 00:00:00 2001 From: thatmidcoder393 <73651803+ThatMG393@users.noreply.github.com> Date: Wed, 15 Jan 2025 21:21:02 +0800 Subject: [PATCH 5/6] change[SystemInfo]: made `getprop` method the main method instead of as fallback --- src/main/java/net/vulkanmod/vulkan/SystemInfo.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/vulkanmod/vulkan/SystemInfo.java b/src/main/java/net/vulkanmod/vulkan/SystemInfo.java index b0b8a2309..e7c5a918a 100644 --- a/src/main/java/net/vulkanmod/vulkan/SystemInfo.java +++ b/src/main/java/net/vulkanmod/vulkan/SystemInfo.java @@ -6,7 +6,6 @@ import java.util.*; public class SystemInfo { - private static final String UNKNOWN_CPU = "Unknown CPU"; private static final String PROC_CPUINFO = "/proc/cpuinfo"; private static final String SOC_MANUFACTURER_PROP = "/system/bin/getprop ro.soc.manufacturer"; private static final String SOC_MODEL_PROP = "/system/bin/getprop ro.soc.model"; @@ -14,9 +13,9 @@ public class SystemInfo { public static final String cpuInfo = getCPUNameSafely(); public static String getCPUNameSafely() { - return Optional.ofNullable(getCPUNameFromProc()) - .orElseGet(() -> Optional.ofNullable(getCPUNameFromProp()) - .orElse(UNKNOWN_CPU)); + return Optional.ofNullable(getCPUNameFromProp()) + .orElseGet(() -> Optional.ofNullable(getCPUNameFromProc()) + .orElse("Unknown CPU")); } private static String getCPUNameFromProc() { From 0dcb9f5f54a2d320b09a698ed1047be01a113354 Mon Sep 17 00:00:00 2001 From: ThatMG393 Date: Wed, 29 Jan 2025 07:18:11 +0800 Subject: [PATCH 6/6] chore[devenv]: Remove .devcontainer --- .devcontainer/devcontainer.json | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index b321ef782..000000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "Java", - "image": "mcr.microsoft.com/devcontainers/base:bullseye", - "features": { - "ghcr.io/devcontainers/features/java:1": { - "version": "21.0.5", - "installMaven": "false", - "installGradle": "true", - "jdkDistro": "graal" - }, - "ghcr.io/devcontainers/features/desktop-lite:1": {} - }, - "forwardPorts": [ - 6080 - ], - "portsAttributes": { - "6080": { - "label": "desktop", - "onAutoForward": "notify" - } - }, - "runArgs": [ - "--shm-size=1g" - ] -}