+++ /dev/null
-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;
- }
-}
//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";
/**
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 +
--- /dev/null
+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;
+ }
+}