一、执行ls -l /system/bin/ 查看一下用户和权限。

二、这些权限在哪里修改呢? 默认编译system/bin/可执行程序赋予权限的地方system\core\libcutils\fs_config.cpp 文件里面的android_files

三、使用实例,只有root和系统app权限才能执行某个命令,如上面的sn_writer命令,只有系统app和root权限才能运行。

- package com.giada.sn_writer;
-
- import androidx.appcompat.app.AppCompatActivity;
-
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
-
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
-
- public class MainActivity extends AppCompatActivity {
- private Button m_Button;
- private EditText m_EditText;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- m_Button=(Button)findViewById(R.id.button);
- m_EditText = (EditText) findViewById(R.id.textView);
-
- m_Button.setOnClickListener(new Button.OnClickListener() {
- public void onClick(View v)
- {
- String str = m_EditText.getText().toString();
- sn_writer_command("sn_writer write-key "+ str);
- // playRunTime("sn_writer write-key "+ str);
- }
- });
-
- }
- public static String sn_writer_command(String cmd) {
- try {
- //String keyCommand = "setprop " + propName;
- Runtime runtime = Runtime.getRuntime();
- Process proc = runtime.exec(cmd);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return cmd;
- }
-
- private String playRunTime(String cmd) throws Exception
- {
- // String cmd = "adb version";
- String ret = null;
- Process p = Runtime.getRuntime().exec(cmd);
- InputStream is = p.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
- String line; while ((line = reader.readLine()) != null)
- {
- //tv_result.append(line + "");
- ret = line;
- }
- p.waitFor();
- is.close();
- reader.close();
- p.destroy();
- return ret;
- }
-
- }
四、有价值的参考文章
[RK3288][Android6.0] 调试笔记 --- 修改默认system/bin/下可执行程序权限_KrisFei的博客-CSDN博客_android system/bin 权限