Get minimum CPU frequency. - Android Hardware

Android examples for Hardware:CPU Frequency

Description

Get minimum CPU frequency.

Demo Code


//package com.java2s;
import java.io.*;

public class Main {
    private static final String CMD_CAT = "/system/bin/cat";
    private static final String CPU_FREQ_MIN_PATH = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq";
    private static long CPU_MIN_frequency = 0;

    /**/* w  ww. j  av a  2 s  . co m*/
     * Get minimum frequency.
     */
    public static long getMinfrequency() {
        if (CPU_MIN_frequency > 0) {
            return CPU_MIN_frequency;
        }
        try {
            CPU_MIN_frequency = Long.parseLong(getCMDOutputString(
                    new String[] { CMD_CAT, CPU_FREQ_MIN_PATH }).trim());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return CPU_MIN_frequency;
    }

    /**
     * Get command output string.
     */
    public static String getCMDOutputString(String[] args) {
        try {
            ProcessBuilder cmd = new ProcessBuilder(args);
            Process process = cmd.start();
            InputStream in = process.getInputStream();
            StringBuilder sb = new StringBuilder();
            byte[] re = new byte[64];
            int len;
            while ((len = in.read(re)) != -1) {
                sb.append(new String(re, 0, len));
            }
            in.close();
            process.destroy();
            return sb.toString();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return null;
    }
}

Related Tutorials