package ZtlApi;

import com.google.android.exoplayer2.C;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CpuInfo {
    boolean bexit = false;
    public int cpuTemp;
    BaseDev curDev = null;
    DevType devType = DevType.dt_3288_5_1;
    Eventhandler eventhandler = null;
    public int gpuFreq;
    public int gpuMaxFreq;
    public String gpuName;
    public int gpuTemp;
    public int gpu_utilisation;
    public List<SubCore> mCores = new ArrayList();
    public int memFree;
    public int memTotal;
    public float usage;

    enum DevType {
        dt_3288_5_1,
        dt_3288_7_1,
        dt_3399,
        dt_3328,
        dt_3128,
        dt_3368,
        dt_A33,
        dt_A64
    }

    public interface Eventhandler {
        void OnInitOK(CpuInfo cpuInfo);

        void OnUpdate();
    }

    public static class SubCore {
        public int cur_freq;
        public String governor;
        public int max_freq;
        DevType mdevType;
        public int min_freq;
        public String name;
        public Object tag;

        public String formatFreq() {
            int i = this.cur_freq / 1000;
            int i2 = this.max_freq / 1000;
            int i3 = this.min_freq / 1000;
            if (i == 0 && (this.mdevType == DevType.dt_A33 || this.mdevType == DevType.dt_A64)) {
                return "休眠";
            }
            return String.format("%d/(%d-%d)Mhz", new Object[]{Integer.valueOf(i), Integer.valueOf(i3), Integer.valueOf(i2)});
        }

        public void Init(DevType devType) {
            this.mdevType = devType;
            String onelinevalue = CpuInfo.getOnelinevalue(String.format("/sys/devices/system/cpu/%s/cpufreq/cpuinfo_max_freq", new Object[]{this.name}));
            if (onelinevalue != null) {
                this.max_freq = Integer.valueOf(onelinevalue).intValue();
            } else {
                this.max_freq = 0;
            }
            String onelinevalue2 = CpuInfo.getOnelinevalue(String.format("/sys/devices/system/cpu/%s/cpufreq/cpuinfo_min_freq", new Object[]{this.name}));
            if (onelinevalue2 != null) {
                this.min_freq = Integer.valueOf(onelinevalue2).intValue();
            } else {
                this.min_freq = 0;
            }
            if (devType == DevType.dt_A33 || devType == DevType.dt_A64) {
                ZtlManager GetInstance = ZtlManager.GetInstance();
                GetInstance.execRootCmdSilent("chmod 777 " + String.format("/sys/devices/system/cpu/%s/cpufreq/scaling_governor", new Object[]{this.name}));
            }
            this.governor = CpuInfo.getOnelinevalue(String.format("/sys/devices/system/cpu/%s/cpufreq/scaling_governor", new Object[]{this.name}));
        }

        public void Speedup() {
            ZtlManager.GetInstance().execRootCmdSilent(String.format("echo \"performance\" > /sys/devices/system/cpu/%s/cpufreq/scaling_governor", new Object[]{this.name}));
        }

        public static String[] getFreq() {
            return CpuInfo.getOnelinevalue("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies").split(" ");
        }

        public void SetFreq(String str) {
            ZtlManager.GetInstance().execRootCmdSilent(String.format("echo \"userspace\" > /sys/devices/system/cpu/%s/cpufreq/scaling_governor", new Object[]{this.name}));
            ZtlManager.GetInstance().execRootCmdSilent(String.format("echo %s > /sys/devices/system/cpu/%s/cpufreq/scaling_setspeed", new Object[]{str, this.name}));
        }

        public void Restore() {
            ZtlManager.GetInstance().execRootCmdSilent(String.format("echo \"interactive\" > /sys/devices/system/cpu/%s/cpufreq/scaling_governor", new Object[]{this.name}));
        }

        public static boolean isExist(String str) {
            return new File(str).exists();
        }

        public void Update(boolean z) {
            if (isExist(String.format("/sys/devices/system/cpu/%s/cpufreq/scaling_cur_freq", new Object[]{this.name}))) {
                String onelinevalue = CpuInfo.getOnelinevalue(String.format("/sys/devices/system/cpu/%s/cpufreq/scaling_cur_freq", new Object[]{this.name}));
                if (onelinevalue != null) {
                    this.cur_freq = Integer.valueOf(onelinevalue).intValue();
                } else {
                    this.cur_freq = 0;
                }
            } else {
                this.cur_freq = 0;
            }
            if (z) {
                this.governor = CpuInfo.getOnelinevalue(String.format("/sys/devices/system/cpu/%s/cpufreq/scaling_governor", new Object[]{this.name}));
            }
        }
    }

    abstract class BaseDev {
        public String gpu_base_path = "";
        public String temp_base_path = "";

        /* access modifiers changed from: package-private */
        public abstract int getCPUTemp();

        /* access modifiers changed from: package-private */
        public abstract int getGPUCurfreq();

        /* access modifiers changed from: package-private */
        public abstract int getGPUMaxFreq();

        /* access modifiers changed from: package-private */
        public abstract String getGPUName();

        /* access modifiers changed from: package-private */
        public abstract int getGPUTemp();

        /* access modifiers changed from: package-private */
        public abstract int getGPUUtilisation();

        /* access modifiers changed from: package-private */
        public abstract void speedUp();

        BaseDev() {
        }
    }

    class BD3288_51 extends BaseDev {
        int gpuFreq0 = 0;

        /* access modifiers changed from: package-private */
        public void speedUp() {
        }

        BD3288_51() {
            super();
            this.gpu_base_path = "/sys/bus/platform/devices/ffa30000.gpu/";
            this.temp_base_path = "/sys/bus/platform/drivers/tsadc/ff280000.tsadc/";
        }

        /* access modifiers changed from: package-private */
        public String getGPUName() {
            return CpuInfo.getOnelinevalue(this.gpu_base_path + "gpuinfo");
        }

        /* access modifiers changed from: package-private */
        public int getGPUMaxFreq() {
            List<String> lines = CpuInfo.getLines(this.gpu_base_path + "clock", 2);
            if (lines != null && lines.size() >= 2) {
                String[] split = lines.get(1).split(",");
                String str = split[split.length - 1];
                if (str.contains("KHz")) {
                    return Integer.valueOf(str.replace("possible_freqs :", "").trim().split(" ")[0]).intValue();
                }
            }
            return 0;
        }

        /* access modifiers changed from: package-private */
        public int getCPUTemp() {
            String onelinevalue = CpuInfo.getOnelinevalue(this.temp_base_path + "temp1_input");
            if (onelinevalue != null) {
                return Integer.valueOf(onelinevalue).intValue();
            }
            return -1;
        }

        /* access modifiers changed from: package-private */
        public int getGPUTemp() {
            String onelinevalue = CpuInfo.getOnelinevalue(this.temp_base_path + "temp2_input");
            if (onelinevalue != null) {
                return Integer.valueOf(onelinevalue).intValue();
            }
            return -1;
        }

        /* access modifiers changed from: package-private */
        public int getGPUUtilisation() {
            List<String> lines = CpuInfo.getLines(this.gpu_base_path + "dvfs", 3);
            int i = 0;
            if (lines.size() >= 3) {
                String str = lines.get(1);
                if (str.contains("gpu_utilisation")) {
                    i = Integer.valueOf(str.replace("gpu_utilisation :", "").trim()).intValue();
                }
                String str2 = lines.get(2);
                if (str2.contains("current_gpu_clk_freq")) {
                    this.gpuFreq0 = Integer.valueOf(str2.replace("current_gpu_clk_freq : ", "").replace("MHz", "").trim()).intValue();
                }
            } else if (lines.size() >= 2) {
                String str3 = lines.get(1);
                if (str3.contains("current_gpu_clk_freq")) {
                    this.gpuFreq0 = Integer.valueOf(str3.replace("current_gpu_clk_freq : ", "").replace("MHz", "").trim()).intValue();
                }
            }
            return i;
        }

        /* access modifiers changed from: package-private */
        public int getGPUCurfreq() {
            return this.gpuFreq0;
        }
    }

    class BD3288_71 extends BaseDev {
        int gpuFreq0 = 0;

        /* access modifiers changed from: package-private */
        public void speedUp() {
        }

        BD3288_71() {
            super();
            this.gpu_base_path = "/sys/bus/platform/devices/ffa30000.gpu/";
            this.temp_base_path = "/sys/bus/platform/drivers/tsadc/ff280000.tsadc/";
        }

        /* access modifiers changed from: package-private */
        public String getGPUName() {
            return CpuInfo.getOnelinevalue(this.gpu_base_path + "gpuinfo");
        }

        /* access modifiers changed from: package-private */
        public int getGPUMaxFreq() {
            String[] split = CpuInfo.getOnelinevalue(this.gpu_base_path + "devfreq/ffa30000.gpu/available_frequencies").split(" ");
            return (int) (Long.valueOf(split[split.length - 1]).longValue() / 1000);
        }

        /* access modifiers changed from: package-private */
        public int getCPUTemp() {
            String onelinevalue = CpuInfo.getOnelinevalue("/sys/class/thermal/thermal_zone0/temp");
            if (onelinevalue != null) {
                return Integer.valueOf(onelinevalue).intValue() / 1000;
            }
            return -1;
        }

        /* access modifiers changed from: package-private */
        public int getGPUTemp() {
            String onelinevalue = CpuInfo.getOnelinevalue("/sys/class/thermal/thermal_zone1/temp");
            if (onelinevalue != null) {
                return Integer.valueOf(onelinevalue).intValue() / 1000;
            }
            return -1;
        }

        /* access modifiers changed from: package-private */
        public int getGPUUtilisation() {
            String onelinevalue = CpuInfo.getOnelinevalue(this.gpu_base_path + "utilisation");
            if (onelinevalue != null) {
                return Integer.valueOf(onelinevalue).intValue();
            }
            return -1;
        }

        /* access modifiers changed from: package-private */
        public int getGPUCurfreq() {
            String onelinevalue = CpuInfo.getOnelinevalue(this.gpu_base_path + "devfreq/ffa30000.gpu/cur_freq");
            if (onelinevalue != null) {
                return (int) (Long.valueOf(onelinevalue).longValue() / C.MICROS_PER_SECOND);
            }
            return -1;
        }
    }

    class BD3399 extends BaseDev {
        /* access modifiers changed from: package-private */
        public int getCPUTemp() {
            return -1;
        }

        /* access modifiers changed from: package-private */
        public int getGPUTemp() {
            return -1;
        }

        BD3399() {
            super();
            this.gpu_base_path = "/sys/bus/platform/devices/ff9a0000.gpu/";
            this.temp_base_path = "/sys/class/thermal/thermal_zone0/temp/";
        }

        /* access modifiers changed from: package-private */
        public void speedUp() {
            ZtlManager.GetInstance().execRootCmdSilent(String.format("echo \"performance\" > /sys/bus/platform/devices/ff9a0000.gpu/devfreq/ff9a0000.gpu/governor", new Object[0]));
        }

        /* access modifiers changed from: package-private */
        public String getGPUName() {
            return CpuInfo.getOnelinevalue(this.gpu_base_path + "gpuinfo");
        }

        /* access modifiers changed from: package-private */
        public int getGPUMaxFreq() {
            String[] split = CpuInfo.getOnelinevalue(this.gpu_base_path + "devfreq/ff9a0000.gpu/available_frequencies").split(" ");
            return (int) (Long.valueOf(split[split.length - 1]).longValue() / 1000);
        }

        /* access modifiers changed from: package-private */
        public int getGPUUtilisation() {
            String onelinevalue = CpuInfo.getOnelinevalue(this.gpu_base_path + "utilisation");
            if (onelinevalue != null) {
                return Integer.valueOf(onelinevalue).intValue();
            }
            return -1;
        }

        /* access modifiers changed from: package-private */
        public int getGPUCurfreq() {
            String onelinevalue = CpuInfo.getOnelinevalue(this.gpu_base_path + "devfreq/ff9a0000.gpu/cur_freq");
            if (onelinevalue != null) {
                return (int) (Long.valueOf(onelinevalue).longValue() / C.MICROS_PER_SECOND);
            }
            return -1;
        }
    }

    class BD3328 extends BD3399 {
        /* access modifiers changed from: package-private */
        public String getGPUName() {
            return "";
        }

        /* access modifiers changed from: package-private */
        public int getGPUTemp() {
            return -1;
        }

        /* access modifiers changed from: package-private */
        public void speedUp() {
        }

        BD3328() {
            super();
            this.gpu_base_path = "/sys/bus/platform/devices/ff300000.gpu/";
            this.temp_base_path = "/sys/class/thermal/thermal_zone0/temp/";
        }

        /* access modifiers changed from: package-private */
        public int getCPUTemp() {
            return super.getCPUTemp() / 1000;
        }

        /* access modifiers changed from: package-private */
        public int getGPUUtilisation() {
            return (super.getGPUUtilisation() / 256) * 100;
        }

        /* access modifiers changed from: package-private */
        public int getGPUMaxFreq() {
            List<String> lines = CpuInfo.getLines(this.gpu_base_path + "available_frequencies", 10);
            return (int) (Long.valueOf(lines.get(lines.size() - 1)).longValue() / 1000);
        }

        /* access modifiers changed from: package-private */
        public int getGPUCurfreq() {
            String onelinevalue = CpuInfo.getOnelinevalue(this.gpu_base_path + "clock");
            if (onelinevalue != null) {
                return (int) (Long.valueOf(onelinevalue).longValue() / C.MICROS_PER_SECOND);
            }
            return -1;
        }
    }

    class BD3128 extends BD3328 {
        /* access modifiers changed from: package-private */
        public int getCPUTemp() {
            return -1;
        }

        /* access modifiers changed from: package-private */
        public String getGPUName() {
            return "Mali-400MP2";
        }

        /* access modifiers changed from: package-private */
        public int getGPUTemp() {
            return -1;
        }

        /* access modifiers changed from: package-private */
        public void speedUp() {
        }

        BD3128() {
            super();
            this.gpu_base_path = "/sys/bus/platform/devices/10091000.gpu/";
        }

        /* access modifiers changed from: package-private */
        public int getGPUMaxFreq() {
            ZtlManager GetInstance = ZtlManager.GetInstance();
            GetInstance.execRootCmdSilent("chmod 777 " + this.gpu_base_path + "available_frequencies");
            ZtlManager GetInstance2 = ZtlManager.GetInstance();
            GetInstance2.execRootCmdSilent("chmod 777 " + this.gpu_base_path + "clock");
            StringBuilder sb = new StringBuilder();
            sb.append(this.gpu_base_path);
            sb.append("available_frequencies");
            List<String> lines = CpuInfo.getLines(sb.toString(), 10);
            return (int) (Long.valueOf(lines.get(lines.size() - 1)).longValue() / 1000);
        }
    }

    class BD3368 extends BaseDev {
        /* access modifiers changed from: package-private */
        public String getGPUName() {
            return "PowerVR G6110";
        }

        /* access modifiers changed from: package-private */
        public void speedUp() {
        }

        BD3368() {
            super();
            this.gpu_base_path = "/sys/devices/platform/ffa30000.rogue-g6110/devfreq/ffa30000.rogue-g6110/";
        }

        /* access modifiers changed from: package-private */
        public int getCPUTemp() {
            String onelinevalue = CpuInfo.getOnelinevalue("/sys/class/thermal/thermal_zone0/temp");
            if (onelinevalue != null) {
                return Integer.valueOf(onelinevalue).intValue() / 1000;
            }
            return -1;
        }

        /* access modifiers changed from: package-private */
        public int getGPUTemp() {
            String onelinevalue = CpuInfo.getOnelinevalue("/sys/class/thermal/thermal_zone1/temp");
            if (onelinevalue != null) {
                return Integer.valueOf(onelinevalue).intValue() / 1000;
            }
            return -1;
        }

        /* access modifiers changed from: package-private */
        public int getGPUMaxFreq() {
            String[] split = CpuInfo.getOnelinevalue(this.gpu_base_path + "available_frequencies").split(" ");
            return (int) (Long.valueOf(split[split.length - 1]).longValue() / 1000);
        }

        /* access modifiers changed from: package-private */
        public int getGPUUtilisation() {
            String onelinevalue = CpuInfo.getOnelinevalue(this.gpu_base_path + "load");
            if (onelinevalue != null) {
                return Integer.valueOf(onelinevalue.substring(0, onelinevalue.indexOf(64))).intValue();
            }
            return -1;
        }

        /* access modifiers changed from: package-private */
        public int getGPUCurfreq() {
            String onelinevalue = CpuInfo.getOnelinevalue(this.gpu_base_path + "cur_freq");
            if (onelinevalue != null) {
                return (int) (Long.valueOf(onelinevalue).longValue() / C.MICROS_PER_SECOND);
            }
            return -1;
        }
    }

    class BDA33 extends BaseDev {
        /* access modifiers changed from: package-private */
        public int getCPUTemp() {
            return -1;
        }

        /* access modifiers changed from: package-private */
        public int getGPUCurfreq() {
            return -1;
        }

        /* access modifiers changed from: package-private */
        public String getGPUName() {
            return "Mali-400 MP2";
        }

        /* access modifiers changed from: package-private */
        public int getGPUTemp() {
            return -1;
        }

        /* access modifiers changed from: package-private */
        public int getGPUUtilisation() {
            return -1;
        }

        /* access modifiers changed from: package-private */
        public void speedUp() {
        }

        BDA33() {
            super();
        }

        /* access modifiers changed from: package-private */
        public int getGPUMaxFreq() {
            String onelinevalue = CpuInfo.getOnelinevalue("/sys/kernel/debug/clk/hosc/pll_gpu/gpu/clk_rate");
            if (onelinevalue != null) {
                return (int) (Long.valueOf(onelinevalue).longValue() / 1000);
            }
            return -1;
        }
    }

    class BDA64 extends BaseDev {
        /* access modifiers changed from: package-private */
        public int getGPUCurfreq() {
            return -1;
        }

        /* access modifiers changed from: package-private */
        public String getGPUName() {
            return "Mali-400 MP2";
        }

        /* access modifiers changed from: package-private */
        public int getGPUUtilisation() {
            return -1;
        }

        /* access modifiers changed from: package-private */
        public void speedUp() {
        }

        BDA64() {
            super();
        }

        /* access modifiers changed from: package-private */
        public int getCPUTemp() {
            String onelinevalue = CpuInfo.getOnelinevalue("/sys/class/thermal/thermal_zone0/temp");
            if (onelinevalue != null) {
                return Integer.valueOf(onelinevalue).intValue();
            }
            return -1;
        }

        /* access modifiers changed from: package-private */
        public int getGPUTemp() {
            String onelinevalue = CpuInfo.getOnelinevalue("/sys/bus/platform/drivers/mali-utgard/1c40000.gpu/dvfs/tempctrl");
            String trim = onelinevalue.substring(onelinevalue.indexOf("temperature:")).replace("temperature: ", "").trim();
            if (trim != null) {
                return Integer.valueOf(trim).intValue();
            }
            return -1;
        }

        /* access modifiers changed from: package-private */
        public int getGPUMaxFreq() {
            String trim = CpuInfo.getOnelinevalue("/sys/bus/platform/drivers/mali-utgard/1c40000.gpu/dvfs/android").replace("MHz", "").trim();
            if (trim != null) {
                return (int) (Long.valueOf(trim).longValue() * 1000);
            }
            return -1;
        }
    }

    public void setCPUFreq(String str) {
        for (int i = 0; i < this.mCores.size(); i++) {
            this.mCores.get(i).SetFreq(str);
        }
    }

    public void Init(Eventhandler eventhandler2) {
        this.eventhandler = eventhandler2;
        String[] cpuCount = getCpuCount();
        ZtlManager.GetInstance();
        String deviceVersion = ZtlManager.getDeviceVersion();
        if (deviceVersion.contains("3399")) {
            this.devType = DevType.dt_3399;
            this.curDev = new BD3399();
        } else if (deviceVersion.contains("3288")) {
            String systemVersion = ZtlManager.GetInstance().getSystemVersion();
            if (systemVersion.contains("5.1")) {
                this.devType = DevType.dt_3288_5_1;
                this.curDev = new BD3288_51();
            } else if (systemVersion.contains("7.1")) {
                this.devType = DevType.dt_3288_7_1;
                this.curDev = new BD3288_71();
            }
        } else if (deviceVersion.contains("3328")) {
            this.devType = DevType.dt_3328;
            this.curDev = new BD3328();
        } else if (deviceVersion.contains("3126c") || deviceVersion.contains("3128")) {
            this.devType = DevType.dt_3128;
            this.curDev = new BD3128();
        } else if (deviceVersion.contains("3368")) {
            this.devType = DevType.dt_3368;
            this.curDev = new BD3368();
        } else if (deviceVersion.contains("A33")) {
            this.devType = DevType.dt_A33;
            this.curDev = new BDA33();
        } else if (deviceVersion.contains("A64")) {
            this.devType = DevType.dt_A64;
            this.curDev = new BDA64();
        }
        if (this.curDev == null) {
            this.curDev = new BD3288_51();
        }
        for (int i = 0; i < cpuCount.length; i++) {
            SubCore subCore = new SubCore();
            subCore.name = cpuCount[i];
            subCore.Init(this.devType);
            if ((this.devType == DevType.dt_A33 || this.devType == DevType.dt_A64) && i >= 1) {
                subCore.min_freq = this.mCores.get(0).min_freq;
                subCore.max_freq = this.mCores.get(0).max_freq;
                subCore.governor = this.mCores.get(0).governor;
            }
            this.mCores.add(subCore);
        }
        this.gpuName = this.curDev.getGPUName();
        this.gpuMaxFreq = this.curDev.getGPUMaxFreq();
        String onelinevalue = getOnelinevalue("/proc/meminfo");
        if (onelinevalue.contains("MemTotal")) {
            this.memTotal = Integer.valueOf(onelinevalue.replace("MemTotal:", "").trim().split(" ")[0]).intValue();
        }
        Eventhandler eventhandler3 = this.eventhandler;
        if (eventhandler3 != null) {
            eventhandler3.OnInitOK(this);
        }
    }

    public void SpeedUp() {
        for (int i = 0; i < this.mCores.size(); i++) {
            this.mCores.get(i).Speedup();
        }
        BaseDev baseDev = this.curDev;
        if (baseDev != null) {
            baseDev.speedUp();
        }
    }

    public void Restore() {
        for (int i = 0; i < this.mCores.size(); i++) {
            this.mCores.get(i).Restore();
        }
    }

    public void close() {
        this.bexit = true;
    }

    /* access modifiers changed from: package-private */
    public float getRate() {
        Map<String, String> cPUUsageSnap = getCPUUsageSnap();
        long parseLong = Long.parseLong(cPUUsageSnap.get("user")) + Long.parseLong(cPUUsageSnap.get("nice")) + Long.parseLong(cPUUsageSnap.get("system")) + Long.parseLong(cPUUsageSnap.get("idle")) + Long.parseLong(cPUUsageSnap.get("iowait")) + Long.parseLong(cPUUsageSnap.get("irq")) + Long.parseLong(cPUUsageSnap.get("softirq"));
        long parseLong2 = Long.parseLong(cPUUsageSnap.get("idle"));
        try {
            Thread.sleep(360);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Map<String, String> cPUUsageSnap2 = getCPUUsageSnap();
        long parseLong3 = ((((((Long.parseLong(cPUUsageSnap2.get("user")) + Long.parseLong(cPUUsageSnap2.get("nice"))) + Long.parseLong(cPUUsageSnap2.get("system"))) + Long.parseLong(cPUUsageSnap2.get("idle"))) + Long.parseLong(cPUUsageSnap2.get("iowait"))) + Long.parseLong(cPUUsageSnap2.get("irq"))) + Long.parseLong(cPUUsageSnap2.get("softirq"))) - parseLong;
        return (float) (((parseLong3 - (Long.parseLong(cPUUsageSnap2.get("idle")) - parseLong2)) * 100) / parseLong3);
    }

    static Map<String, String> getCPUUsageSnap() {
        String[] strArr;
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream("/proc/stat")));
            String readLine = bufferedReader.readLine();
            bufferedReader.close();
            strArr = readLine.split(" ");
        } catch (IOException e) {
            e.printStackTrace();
            strArr = null;
        }
        HashMap hashMap = new HashMap();
        hashMap.put("user", strArr[2]);
        hashMap.put("nice", strArr[3]);
        hashMap.put("system", strArr[4]);
        hashMap.put("idle", strArr[5]);
        hashMap.put("iowait", strArr[6]);
        hashMap.put("irq", strArr[7]);
        hashMap.put("softirq", strArr[8]);
        return hashMap;
    }

    public static String[] getCpuCount() {
        char charAt;
        ArrayList arrayList = new ArrayList();
        for (File file : new File("/sys/devices/system/cpu").listFiles()) {
            if (file.getName().contains("cpu") && (charAt = file.getName().charAt(3)) >= '0' && charAt <= '9') {
                arrayList.add(file.getName());
            }
        }
        return (String[]) arrayList.toArray(new String[arrayList.size()]);
    }

    static String getOnelinevalue(String str) {
        List<String> lines = getLines(str, 1);
        if (lines != null) {
            return lines.get(0);
        }
        return null;
    }

    static List<String> getLines(String str, int i) {
        ArrayList arrayList = new ArrayList();
        try {
            FileReader fileReader = new FileReader(str);
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            int i2 = 0;
            while (true) {
                if (i2 >= i) {
                    break;
                }
                String readLine = bufferedReader.readLine();
                if (readLine == null) {
                    break;
                }
                i2++;
                arrayList.add(readLine);
            }
            fileReader.close();
            return arrayList;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    static String getSpecail(String str, String str2) {
        try {
            FileReader fileReader = new FileReader(str);
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            String readLine = bufferedReader.readLine();
            while (readLine != null) {
                if (!readLine.contains(str2)) {
                    readLine = bufferedReader.readLine();
                    if (readLine == null) {
                        break;
                    }
                } else {
                    return readLine;
                }
            }
            fileReader.close();
            return null;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e2) {
            e2.printStackTrace();
            return null;
        }
    }
}
