获取android中GPU当前和最大频率的值

问题描述 投票:0回答:1

我能够获得 GPU 最大频率 /sys/class/kgsl/kgsl-3d0/max_gpuclk 对我来说是 840000000

但是当我尝试从此 /sys/class/kgsl/kgsl-3d0/gpuclk 获取 GPU 当前频率时,我收到错误此错误 -> gpuinfo java.io.FileNotFoundException: /sys/class/kgsl/kgsl-3d0/gpuclk :打开失败:EACCES(权限被拒绝)

我已尝试允许所有权限。

try {
        Log.d(
            "GPU Info",
            "gpuinfo test max" + getGPUFreq("/sys/class/kgsl/kgsl-3d0/max_gpuclk")
        )
        Log.d(
            "GPU Info",
            "gpuinfo test curr" + getGPUFreq("/sys/class/kgsl/kgsl-3d0/gpuclk")
        )
        val gpuFile = File("/sys/class/kgsl/kgsl-3d0/gpuclk")
        if (gpuFile.exists()) {
            val fis = FileInputStream(gpuFile)
            val reader = BufferedReader(InputStreamReader(fis))
            var line: String
            while (reader.readLine().also { line = it } != null) {
                // 'line' contains the content of the file
                // You can process or display the content as needed
                // For example, you can log it:
                Log.d("GPU Info", "gpuinfo$line")
            }

            // Close the resources when done
            reader.close()
            fis.close()
        } else {
            // Handle the case where the file does not exist
            Log.d("GPU Info", "gpuinfo he file does not exist")
        }
    } catch (e: java.lang.Exception) {
        // Handle exceptions appropriately
        e.printStackTrace()
        Log.d("GPU Info", "gpuinfo $e")
    }




 fun getGPUFreq(path: String): Int? {
    return readIntegerFile(path)
}

private fun readIntegerFile(path: String): Int? {
    var ret = 0
    try {
        val reader = RandomAccessFile(path, "r")
        ret = try {
            val line = reader.readLine()
            line.toInt()
        } finally {
            reader.close()
        }
    } catch (ex: Exception) {
        ex.printStackTrace()
    }
    return ret
}
java android android-studio gpu
1个回答
0
投票

这篇文章来自 读取 CPU 使用情况时出错:/proc/stat(权限被拒绝) 指出:

  • 在 Android API 级别 26+ 上,Google 不允许在非系统应用程序的情况下访问某些文件。
© www.soinside.com 2019 - 2024. All rights reserved.