From: kfl_614 Date: Wed, 16 Dec 2020 08:52:38 +0000 (+0800) Subject: switch shell to file reader. X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=e498d66dbfec9deab52cabcb6efd9b2effeb7370;p=protocol_srv.git switch shell to file reader. --- diff --git a/app/src/main/java/com/enqualcomm/support/utils/ShellUtil.java b/app/src/main/java/com/enqualcomm/support/utils/ShellUtil.java deleted file mode 100644 index ea04e0da..00000000 --- a/app/src/main/java/com/enqualcomm/support/utils/ShellUtil.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.enqualcomm.support.utils; - -import android.util.Log; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class ShellUtil { - /** - * 执行命令并且输出结果 - */ - public static String execRootCmd(String cmd) { - String result = ""; - DataOutputStream dos = null; - DataInputStream dis = null; - - try { - Process p = Runtime.getRuntime().exec(cmd);// 经过Root处理的androi:qd系统即有su命令 - dos = new DataOutputStream(p.getOutputStream()); - dis = new DataInputStream(p.getInputStream()); - String line; - while ((line = dis.readLine()) != null) { - Log.d("result", line); - result += line; - } - p.waitFor(); - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (dos != null) { - try { - dos.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - if (dis != null) { - try { - dis.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - return result; - } -} diff --git a/app/src/main/java/com/enqualcomm/support/utils/TempAlgUtil.java b/app/src/main/java/com/enqualcomm/support/utils/TempAlgUtil.java index 436e0d08..749f0d8e 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/TempAlgUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/TempAlgUtil.java @@ -51,20 +51,20 @@ public class TempAlgUtil { //thermal_zone0 - public static final String CMD_CPU_TEM = "cat /sys/class/thermal/thermal_zone0/temp"; - public static final String CMD_CPU_TYPE = "cat /sys/class/thermal/thermal_zone0/type"; + public static final String CMD_CPU_TEM = "/sys/class/thermal/thermal_zone0/temp"; + public static final String CMD_CPU_TYPE = "/sys/class/thermal/thermal_zone0/type"; //thermal_zone1 - public static final String CMD_GPU_TEM = "cat /sys/class/thermal/thermal_zone1/temp"; - public static final String CMD_GPU_TYPE = "cat /sys/class/thermal/thermal_zone1/type"; + public static final String CMD_GPU_TEM = "/sys/class/thermal/thermal_zone1/temp"; + public static final String CMD_GPU_TYPE = "/sys/class/thermal/thermal_zone1/type"; //thermal_zone2 - public static final String CMD_CHARGE_TEM = "cat /sys/class/thermal/thermal_zone2/temp"; - public static final String CMD_CHARGE_TYPE = "cat /sys/class/thermal/thermal_zone2/type"; + public static final String CMD_CHARGE_TEM = "/sys/class/thermal/thermal_zone2/temp"; + public static final String CMD_CHARGE_TYPE = "/sys/class/thermal/thermal_zone2/type"; //thermal_zone3 - public static final String CMD_PA_TEM = "cat /sys/class/thermal/thermal_zone3/temp"; - public static final String CMD_PA_TYPE = "cat /sys/class/thermal/thermal_zone3/type"; + public static final String CMD_PA_TEM = "/sys/class/thermal/thermal_zone3/temp"; + public static final String CMD_PA_TYPE = "/sys/class/thermal/thermal_zone3/type"; //thermal_zone4 - public static final String CMD_BOARD_TEM = "cat /sys/class/thermal/thermal_zone4/temp"; - public static final String CMD_BOARD_TYPE = "cat /sys/class/thermal/thermal_zone4/type"; + public static final String CMD_BOARD_TEM = "/sys/class/thermal/thermal_zone4/temp"; + public static final String CMD_BOARD_TYPE = "/sys/class/thermal/thermal_zone4/type"; /** @@ -81,16 +81,16 @@ public class TempAlgUtil { double paTemp/*射频的温度*/ = 0.0f; double boardTemp/*主板的温度*/ = 0.0f; try { - String cpuTempType = ShellUtil.execRootCmd(CMD_CPU_TYPE); - String cpuTempStr = ShellUtil.execRootCmd(CMD_CPU_TEM); - String gpuTempType = ShellUtil.execRootCmd(CMD_GPU_TYPE); - String gpuTempStr = ShellUtil.execRootCmd(CMD_GPU_TEM); - String chargeTempType = ShellUtil.execRootCmd(CMD_CHARGE_TYPE); - String chargeTempStr = ShellUtil.execRootCmd(CMD_CHARGE_TEM); - String paTempType = ShellUtil.execRootCmd(CMD_PA_TYPE); - String paTempStr = ShellUtil.execRootCmd(CMD_PA_TEM); - String boardTempType = ShellUtil.execRootCmd(CMD_BOARD_TYPE); - String boardTempStr = ShellUtil.execRootCmd(CMD_BOARD_TEM); + String cpuTempType = TempFileUtils.readFile(CMD_CPU_TYPE); + String cpuTempStr = TempFileUtils.readFile(CMD_CPU_TEM); + String gpuTempType = TempFileUtils.readFile(CMD_GPU_TYPE); + String gpuTempStr = TempFileUtils.readFile(CMD_GPU_TEM); + String chargeTempType = TempFileUtils.readFile(CMD_CHARGE_TYPE); + String chargeTempStr = TempFileUtils.readFile(CMD_CHARGE_TEM); + String paTempType = TempFileUtils.readFile(CMD_PA_TYPE); + String paTempStr = TempFileUtils.readFile(CMD_PA_TEM); + String boardTempType = TempFileUtils.readFile(CMD_BOARD_TYPE); + String boardTempStr = TempFileUtils.readFile(CMD_BOARD_TEM); //cpuTempType == > cpu-thmzone cpuTempStr == > 45295 gpuTempType == > gpu-thmzone gpuTempStr == > 43910 Log.d(TAG, " cpuTempType == > " + cpuTempType + " cpuTempStr == > " + cpuTempStr + diff --git a/app/src/main/java/com/enqualcomm/support/utils/TempFileUtils.java b/app/src/main/java/com/enqualcomm/support/utils/TempFileUtils.java new file mode 100644 index 00000000..9695d407 --- /dev/null +++ b/app/src/main/java/com/enqualcomm/support/utils/TempFileUtils.java @@ -0,0 +1,38 @@ +package com.enqualcomm.support.utils; + +import android.text.TextUtils; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; + +public class TempFileUtils { + /** + * 执行命令并且输出结果 + */ + public static String readFile(String file) { + if (TextUtils.isEmpty(file)) { + return null; + } + + BufferedReader bf = null; + try { + FileInputStream fis = new FileInputStream(file); + InputStreamReader isr = new InputStreamReader(fis); + bf = new BufferedReader(isr); + String result = bf.readLine(); + return result; + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (bf != null) { + try { + bf.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + return null; + } +}