Android 如何在Oreo中的我的应用程序中运行adb shell命令,如dumpsys?

Android 如何在Oreo中的我的应用程序中运行adb shell命令,如dumpsys?,android,android-studio,filesystems,gpu,android-8.0-oreo,Android,Android Studio,Filesystems,Gpu,Android 8.0 Oreo,我正在创建一个基本的基准应用程序,需要在上面显示设备的GPU总使用量。shell命令dumpsys gfxinfo在android oreo中显示信息。问题是我无法从我的应用程序运行此命令 请在下面找到我的Android清单: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http:/

我正在创建一个基本的基准应用程序,需要在上面显示设备的GPU总使用量。shell命令
dumpsys gfxinfo
在android oreo中显示信息。问题是我无法从我的应用程序运行此命令

请在下面找到我的Android清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
coreApp = "true"
package="com.vis.benchmark">
<!-- android:sharedUserId="android.uid.system" -->
 <uses-permission
    android:name="android.permission.PACKAGE_USAGE_STATS"
    tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".GFX_info"></activity>
</application>

java代码:

public class GFX_info extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_actest);
    TextView tv = findViewById(R.id.t4);
    String[] cmd = {"dumpsys gfxinfo"};
    Process prc;
    try {
        Log.d("PINFO","step 1");
        prc = Runtime.getRuntime().exec(cmd);
        Log.d("PINFO","step 2");
        OutputStream op = prc.getOutputStream();
        BufferedReader bf = new BufferedReader(new InputStreamReader((prc.getInputStream())));
        bf.markSupported();
        String line = bf.readLine();
        tv.setText(bf.readLine());
        for(int i = 0 ;i < 5 ; i++){
            tv.append(line);
            Log.d("GFX",line);
            line = bf.readLine();
        }

    } catch (IOException e) {
        e.printStackTrace();
        Log.d("PINFO","error");
    } }
public class GFX_info扩展appcompative活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_actest);
TextView tv=findViewById(R.id.t4);
字符串[]cmd={“dumpsys gfxinfo”};
处理中国;
试一试{
Log.d(“PINFO”,“步骤1”);
prc=Runtime.getRuntime().exec(cmd);
Log.d(“PINFO”,“步骤2”);
OutputStream op=prc.getOutputStream();
BufferedReader bf=新的BufferedReader(新的InputStreamReader((prc.getInputStream()));
bf.markSupported();
String line=bf.readLine();
tv.setText(bf.readLine());
对于(int i=0;i<5;i++){
追加(行);
Log.d(“GFX”,第行);
line=bf.readLine();
}
}捕获(IOE异常){
e、 printStackTrace();
Log.d(“PINFO”、“error”);
} }

在我的控制台中,我得到了第1步,然后是错误,所以它直到第2步才到达。

该命令可能需要root previlegies(
su
)@VladyslavMatviienko如何给出它?我不介意将其作为一个系统应用程序。