Android系统获取GPU、屏幕信息

源码下载

https://github.com/sufadi/AndroidCpuTools

1.GPU 电压和频率

C:\Users\fadi.su>adb shell cat /proc/gpufreq/gpufreq_opp_dump
[0] freq = 450000, volt = 115000, idx = 0
[1] freq = 400000, volt = 111875, idx = 1
[2] freq = 350000, volt = 108750, idx = 2
[3] freq = 290000, volt = 105000, idx = 3

    public static List getGpuFreqVolt() {
        List result = new ArrayList<>();

        try {
            String line;
            BufferedReader br = new BufferedReader(new FileReader("/proc/gpufreq/gpufreq_opp_dump"));
            while ((line = br.readLine()) != null) {
                result.add(line);
            }
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return result;
    }

2.GPU 供应商和版本信息

        final RendererUtil mRendererUtil = new RendererUtil();
        GLSurfaceView mGLSurfaceView = (GLSurfaceView) mView.findViewById(R.id.surfaceView);
        mGLSurfaceView.setEGLContextClientVersion(1);
        mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 0, 0);
        mGLSurfaceView.setRenderer(mRendererUtil);
        mGLSurfaceView.post(new Runnable() {
            @Override
            public void run() {
                result.add(getString(R.string.gl_vendor) + mRendererUtil.gl_vendor);
                result.add(getString(R.string.gl_renderer) + mRendererUtil.gl_renderer);
                result.add(getString(R.string.gl_version) + mRendererUtil.gl_version);
                result.add(getString(R.string.gl_extensions) + mRendererUtil.gl_extensions);
                mHandler.sendEmptyMessage(UPDATE_UI);
            }
        });

package com.fadisu.cpurun.util;

import android.opengl.GLSurfaceView;
import android.util.Log;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

public class RendererUtil implements GLSurfaceView.Renderer {

    //GPU 渲染器
    public String gl_renderer;

    //GPU 供应商
    public String gl_vendor;

    //GPU 版本
    public String gl_version;

    //GPU  扩展名
    public String gl_extensions;

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig eglConfig) {
        gl_renderer = gl.glGetString(GL10.GL_RENDERER);
        gl_vendor = gl.glGetString(GL10.GL_VENDOR);
        gl_version = gl.glGetString(GL10.GL_VERSION);
        gl_extensions = gl.glGetString(GL10.GL_EXTENSIONS);
        Log.d("suhuazhi", "onSurfaceCreated = " + gl_renderer);
    }

    @Override
    public void onSurfaceChanged(GL10 gl10, int i, int i1) {

    }

    @Override
    public void onDrawFrame(GL10 gl10) {

    }
}

3.GPU 获取屏幕

public class ScreenInfo {

    // 英寸
    public double size;

    public String sizeStr;

    // 高
    public int heightPixels;

    // 宽
    public int widthPixels;

    public String screenRealMetrics;

    // 显示器的逻辑密度
    public float density;

    // 屏幕密度为点每英寸
    public int densityDpi;

    public String densityDpiStr;

    // 显示在显示器的字体的定标因子
    public float scaledDensity;

    // 每在 X 维屏幕英寸的确切物理像素
    public float xdpi;

    // 每在 Y 维屏幕英寸的确切物理像素
    public float ydpi;

    //在屏幕中显示的参考密度
    public int density_default;

    @Override
    public String toString() {
        return "ScreenInfo{" +
                "size=" + size +
                ", sizeStr='" + sizeStr + '\'' +
                ", heightPixels=" + heightPixels +
                ", screenRealMetrics='" + screenRealMetrics + '\'' +
                ", widthPixels=" + widthPixels +
                ", density=" + density +
                ", densityDpi=" + densityDpi +
                ", densityDpiStr='" + densityDpiStr + '\'' +
                ", scaledDensity=" + scaledDensity +
                ", xdpi=" + xdpi +
                ", ydpi=" + ydpi +
                ", density_default=" + density_default +
                '}';
    }
}

   /**
     * 屏幕分辨率
     *
     * @param mContext
     * @return
     */
    public static ScreenInfo getScreenInfo(Context mContext) {
        ScreenInfo result = new ScreenInfo();
        int widthPixels;
        int heightPixels;

        WindowManager w = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);

        Display d = w.getDefaultDisplay();
        DisplayMetrics metrics = new DisplayMetrics();
        d.getMetrics(metrics);
        // since SDK_INT = 1;
        widthPixels = metrics.widthPixels;
        heightPixels = metrics.heightPixels;
        // includes window decorations (statusbar bar/menu bar)
        if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17) {
            try {
                widthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(d);
                heightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(d);
            } catch (Exception ignored) {
                ignored.printStackTrace();
            }
        }
        // includes window decorations (statusbar bar/menu bar)
        if (Build.VERSION.SDK_INT >= 17) {
            try {
                Point realSize = new Point();
                Display.class.getMethod("getRealSize", Point.class).invoke(d, realSize);
                widthPixels = realSize.x;
                heightPixels = realSize.y;
            } catch (Exception ignored) {
                ignored.printStackTrace();
            }
        }

        result.widthPixels = widthPixels;
        result.heightPixels = heightPixels;
        result.screenRealMetrics = widthPixels + " X " + heightPixels;
        result.density = metrics.density;
        result.density_default = metrics.DENSITY_DEFAULT;
        result.densityDpi = metrics.densityDpi;
        result.densityDpiStr = metrics.densityDpi + " dpi";
        result.scaledDensity = metrics.scaledDensity;
        result.xdpi = metrics.xdpi;
        result.ydpi = metrics.ydpi;
        result.size = (Math.sqrt(Math.pow(widthPixels, 2) + Math.pow(heightPixels, 2)) / metrics.densityDpi);
        result.sizeStr = String.format("%.2f", result.size) + mContext.getResources().getString(R.string.sys_inches_unit);

        return result;
    }

4.运行结果

Android系统获取GPU、屏幕信息_第1张图片

你可能感兴趣的:(Android系统获取GPU、屏幕信息)