用法:

1 Runtime.getRuntime().exec("su , tinymix"); 要连在一起写,或者写一脚本

public void onClick(View v) {
      
        Log.d("test by Wade", "su test start");
        Process p = null;
        try {
            p = Runtime.getRuntime().exec("su , tinymix");

String data = null;
            /**/
            BufferedReader ie = new BufferedReader(new InputStreamReader(p.getErrorStream()));
            BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String error = null;
            while ((error = ie.readLine()) != null
                    && !error.equals("null")) {
                data += error + "\n";
            }
            String line = null;
            while ((line = in.readLine()) != null
                    && !line.equals("null")) {
                data += line + "\n";
            }

// Log.v("ls", data);
            Log.d("test by Wade", "su test 111"  + data );

/**/
            p = Runtime.getRuntime().exec("ls /data/data");
            BufferedReader ie1 = new BufferedReader(new InputStreamReader(p.getErrorStream()));
            BufferedReader in1 = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String error1 = null;
            while ((error1 = ie1.readLine()) != null
                    && !error1.equals("null")) {
                data += error1 + "\n";
            }
            String line1 = null;
            while ((line1 = in1.readLine()) != null
                    && !line1.equals("null")) {
                data += line1 + "\n";
            }

// Log.v("ls", data);
            Log.d("test by Wade", "su test 222" + data);

} catch (IOException e) {
            Log.d("test by Wade", "error at IOException" );
            e.printStackTrace();
        }
    }

2 log ,可以看出在同一个Runtime里,能执行成功。再写另外一个 runtime 是不行的,如另外一个 ls /data/data

D/Wade_arm_net_set(  176): ni= 512
D/Wade_arm_net_set(  176): internet not ok
W/gralloc (  155):  Debugmem The fd=57, in vmalloc !!!! Ishwc=0
W/AudioTrack(  460): AUDIO_OUTPUT_FLAG_FAST denied by client
D/test by Wade(10715): su test start
W/AppOps  (  460): Bad call: specified package media under uid 1000 but it is really 1013
I/su      (10759): type=1400 audit(0.0:62): avc: denied { setgid } for capability=6 scontext=u:r:untrusted_app:s0 tcontext=u:r:untrusted_app:s0 tclass=capability permissive=1
I/su      (10759): type=1400 audit(0.0:63): avc: denied { setuid } for capability=7 scontext=u:r:untrusted_app:s0 tcontext=u:r:untrusted_app:s0 tclass=capability permissive=1
I/tinymix (10759): type=1400 audit(0.0:64): avc: denied { dac_override } for capability=1 scontext=u:r:untrusted_app:s0 tcontext=u:r:untrusted_app:s0 tclass=capability permissive=1
D/test by Wade(10715): su test 111nullsu: uid 10052 not allowed to su by wade
D/test by Wade(10715): Mixer name: 'RK_ES8323'
D/test by Wade(10715): Number of controls: 29
D/test by Wade(10715): ctl      type    num     name                                     value
D/test by Wade(10715): 0        ENUM    1       3D Mode                                  2
D/test by Wade(10715): 1        INT     1       ALC Capture Target Volume                12
D/test by Wade(10715): 2        INT     1       ALC Capture Max PGA                      5
D/test by Wade(10715): 3        INT     1       ALC Capture Min PGA                      2
D/test by Wade(10715): 4        ENUM    1       ALC Capture Function                     Stereo
D/test by Wade(10715): 5        BOOL    1       ALC Capture ZC Switch                    Off
D/test by Wade(10715): 6        INT     1       ALC Capture Hold Time                    0
D/test by Wade(10715): 7        INT     1       ALC Capture Decay Time                   0
D/test by Wade(10715): 8        INT     1       ALC Capture Attack Time                  5
D/test by Wade(10715): 9        INT     1       ALC Capture NG Threshold                 10
D/test by Wade(10715): 10       ENUM    1       ALC Capture NG Type                      Mute ADC Output
D/test by Wade(10715): 11       BOOL    1       ALC Capture NG Switch                    On
D/test by Wade(10715): 12       BOOL    1       ZC Timeout Switch                        Off
D/test by Wade(10715): 13       INT     2       Capture Digital Volume                   255 255
D/test by Wade(10715): 14       BOOL    1       Capture Mute                             Off
D/test by Wade(10715): 15       INT     1       Left Channel Capture Volume              8
D/test by Wade(10715): 16       INT     1       Right Channel Capture Volume             8
D/test by Wade(10715): 17       ENUM    1       Playback De-emphasis                     None
D/test by Wade(10715): 18       ENUM    1       Capture Polarity                         Normal
D/test by Wade(10715): 19       INT     2       PCM Volume                               255 255
D/test by Wade(10715): 20       INT     1       Left Mixer Left Bypass Volume            0
D/test by Wade(10715): 21       INT     1       Right Mixer Right Bypass Volume          0
D/test by Wade(10715): 22       INT     2       Output 1 Playback Volume                 21 21
D/test by Wade(10715): 23       INT     2       Output 2 Playback Volume                 30 30
D/test by Wade(10715): 24       BOOL    1       Right Mixer Right Playback Switch        On
D/test by Wade(10715): 25       BOOL    1       Right Mixer Right Bypass Switch          Off
D/test by Wade(10715): 26       BOOL    1       Left Mixer Left Playback Switch          On
D/test by Wade(10715): 27       BOOL    1       Left Mixer Left Bypass Switch            Off
D/test by Wade(10715): 28       ENUM    1       Route                                    Stereo
D/test by Wade(10715): su test 222nullsu: uid 10052 not allowed to su by wade
D/test by Wade(10715): Mixer name: 'RK_ES8323'
D/test by Wade(10715): Number of controls: 29
D/test by Wade(10715): ctl      type    num     name                                     value
D/test by Wade(10715): 0        ENUM    1       3D Mode                                  2
D/test by Wade(10715): 1        INT     1       ALC Capture Target Volume                12
D/test by Wade(10715): 2        INT     1       ALC Capture Max PGA                      5
D/test by Wade(10715): 3        INT     1       ALC Capture Min PGA                      2
D/test by Wade(10715): 4        ENUM    1       ALC Capture Function                     Stereo
D/test by Wade(10715): 5        BOOL    1       ALC Capture ZC Switch                    Off
D/test by Wade(10715): 6        INT     1       ALC Capture Hold Time                    0
D/test by Wade(10715): 7        INT     1       ALC Capture Decay Time                   0
D/test by Wade(10715): 8        INT     1       ALC Capture Attack Time                  5
D/test by Wade(10715): 9        INT     1       ALC Capture NG Threshold                 10
D/test by Wade(10715): 10       ENUM    1       ALC Capture NG Type                      Mute ADC Output
D/test by Wade(10715): 11       BOOL    1       ALC Capture NG Switch                    On
D/test by Wade(10715): 12       BOOL    1       ZC Timeout Switch                        Off
D/test by Wade(10715): 13       INT     2       Capture Digital Volume                   255 255
D/test by Wade(10715): 14       BOOL    1       Capture Mute                             Off
D/test by Wade(10715): 15       INT     1       Left Channel Capture Volume              8
D/test by Wade(10715): 16       INT     1       Right Channel Capture Volume             8
D/test by Wade(10715): 17       ENUM    1       Playback De-emphasis                     None
D/test by Wade(10715): 18       ENUM    1       Capture Polarity                         Normal
D/test by Wade(10715): 19       INT     2       PCM Volume                               255 255
D/test by Wade(10715): 20       INT     1       Left Mixer Left Bypass Volume            0
D/test by Wade(10715): 21       INT     1       Right Mixer Right Bypass Volume          0
D/test by Wade(10715): 22       INT     2       Output 1 Playback Volume                 21 21
D/test by Wade(10715): 23       INT     2       Output 2 Playback Volume                 30 30
D/test by Wade(10715): 24       BOOL    1       Right Mixer Right Playback Switch        On
D/test by Wade(10715): 25       BOOL    1       Right Mixer Right Bypass Switch          Off
D/test by Wade(10715): 26       BOOL    1       Left Mixer Left Playback Switch          On
D/test by Wade(10715): 27       BOOL    1       Left Mixer Left Bypass Switch            Off
D/test by Wade(10715): 28       ENUM    1       Route                                    Stereo
D/test by Wade(10715): opendir failed, Permission denied
D/DisplayManager(10715): getDisplayInfo: displayId=0, info=DisplayInfo{"鍐呯疆灞忓箷", uniqueId "local:0", app 1280 x 800, real 1280 x 800, largest app 1280 x 1280, smallest app 800 x 800, 113.95901 fps, supportedRefreshRates [113.95901], rotation 0, density 160 (160.15764 x 160.0) dpi, layerStack 0, appVsyncOff 0, presDeadline 9775085, type BUILT_IN, state ON, FLAG_SECURE, FLAG_SUPPORTS_PROTECTED_BUFFERS}
W/AppOps  (  460): Bad call: specified package media under uid 1000 but it is really 1013
D/AudioHardwareTiny(  170): start_output_stream
D/AudioHardwareTiny(  170): Device     : 0x80400
D/AudioHardwareTiny(  170): SampleRate : 44100
D/AudioHardwareTiny(  170): Channels   : 2
D/AudioHardwareTiny(  170): Formate    : 0
D/AudioHardwareTiny(  170): PreiodSize : 2048
W/gralloc (  155):  Debugmem The fd=32, in vmalloc !!!! Ishwc=0
D/ViewRootImpl(10715): onAttachToWindow register content observer attrs=WM.LayoutParams{(0,64)(wrapxwrap)mPosX=0mPosY=0mHScale=1.0mVScale=1.0 align=UNDEFINE taskId=-1 gr=#51 ty=2005 fl=#98 compatible=true pfl=0x80 fmt=-3 wanim=0x1030004 surfaceInsets=Rect(0, 0 - 0, 0)packageName=com.practice.sensortoken=null}
D/ViewRootImpl(10715): 131<<<<<< BACK FROM relayoutWM.LayoutParams{(0,64)(wrapxwrap)mPosX=0mPosY=0mHScale=1.0mVScale=1.0 align=UNDEFINE taskId=-1 gr=#51 sim=#20 ty=2005 fl=#98 compatible=true pfl=0x80 fmt=-3 wanim=0x1030004 surfaceInsets=Rect(0, 0 - 0, 0)packageName=com.practice.sensortoken=null}
W/gralloc (  155):  Debugmem The fd=56, in vmalloc !!!! Ishwc=0
D/ViewRootImpl(10715): 131<<<<<< BACK FROM relayoutnull
W/gralloc (  155):  Debugmem The fd=69, in vmalloc !!!! Ishwc=0
W/AppOps  (  460): Bad call: specified package media under uid 1000 but it is really 1013
D/ViewRootImpl(10715): onDetachedFromWindow ungister contentObserver
D/Wade_arm_net_set(  176): ni= 512
D/Wade_arm_net_set(  176): internet not ok
D/AudioHardwareTiny(  170): close device
W/AppOps  (  460): Bad call: specified package media under uid 1000 but it is really 1013
^C
C:\Users\pc>

3 代码修改 
diff --git a/system/extras/su/su.c b/system/extras/su/su.c
index 8365379..5388470 100644
--- a/system/extras/su/su.c
+++ b/system/extras/su/su.c
@@ -108,8 +108,8 @@ int main(int argc, char **argv)
     /* Until we have something better, only root and the shell can use su. */
     myuid = getuid();
     if (myuid != AID_ROOT && myuid != AID_SHELL) {
-        fprintf(stderr,"su: uid %d not allowed to su\n", myuid);
-        return 1;
+        fprintf(stderr,"su: uid %d not allowed to su by wade\n", myuid);
+        //return 1;
     }
 
     if(argc < 2) {
 
diff --git a/frameworks/base/cmds/app_process/app_main.cpp b/frameworks/base/cmds/app_process/app_main.cpp
index 1bb28c3..a92a561 100644
--- a/frameworks/base/cmds/app_process/app_main.cpp
+++ b/frameworks/base/cmds/app_process/app_main.cpp
@@ -185,6 +185,7 @@ static const char ZYGOTE_NICE_NAME[] = "zygote";
 
 int main(int argc, char* const argv[])
 {
+    /*
     if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0) {
         // Older kernels don't understand PR_SET_NO_NEW_PRIVS and return
         // EINVAL. Don't die on such kernels.
@@ -192,7 +193,7 @@ int main(int argc, char* const argv[])
             LOG_ALWAYS_FATAL("PR_SET_NO_NEW_PRIVS failed: %s", strerror(errno));
             return 12;
         }
-    }
+    } */
 
     AppRuntime runtime(argv[0], computeArgBlockSize(argc, argv));
     // Process command line arguments
diff --git a/frameworks/base/core/jni/com_android_internal_os_Zygote.cpp b/frameworks/base/core/jni/com_android_interna
index 3af968d..6236438 100644
--- a/frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
+++ b/frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
@@ -208,6 +208,7 @@ static void EnableKeepCapabilities(JNIEnv* env) {
 }
 
 static void DropCapabilitiesBoundingSet(JNIEnv* env) {
+    /*
   for (int i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {
     int rc = prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
     if (rc == -1) {
@@ -219,7 +220,7 @@ static void DropCapabilitiesBoundingSet(JNIEnv* env) {
         RuntimeAbort(env);
       }
     }
-  }
+  } */
 }

diff --git a/system/core/include/private/android_filesystem_config.h b/system/core/include/private/android_filesystem_c
index 7a4c943..2b987e1 100644
--- a/system/core/include/private/android_filesystem_config.h
+++ b/system/core/include/private/android_filesystem_config.h
@@ -245,7 +245,7 @@ static const struct fs_path_config android_files[] = {
 
     /* the following five files are INTENTIONALLY set-uid, but they
      * are NOT included on user builds. */
-    { 04750, AID_ROOT,      AID_SHELL,     0, "system/xbin/su" },
+    { 06755, AID_ROOT,      AID_SHELL,     0, "system/xbin/su" },
        { 06755, AID_ROOT,      AID_ROOT,      0, "system/xbin/vm" },
     { 06755, AID_ROOT,      AID_ROOT,      0, "system/xbin/librank" },
     { 06755, AID_ROOT,      AID_ROOT,      0, "system/xbin/procrank" },

4 参考文章 
https://blog.csdn.net/kangear/article/details/51872653
https://blog.csdn.net/kangear/article/details/51868077

一些记录:
写一个app 查看 id
root@nanopi2:/ # ps | grep com.example.helloroot
u0_a50    1283  121   1233532 40640 ffffffff b6e791c4 S com.example.helloroot
root@nanopi2:/ #

其中u0_a50就是HelloRoot的Application user id了,这个id在下面步骤中会用到;

切换到u0_a50用户下并运行su命令
root@nanopi2:/ # su u0_a50
root@nanopi2:/ $ id
uid=10050(u0_a50) gid=10050(u0_a50) groups=1003(graphics),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats) context=u:r:su:s0
# 以u0_a50身份运行su命令,正常情况下会再切到root权限下,相当于该APP在调用su命令了。
root@nanopi2:/ $ su
root@nanopi2:/ #

rk3288 android5.1 java 层使用 su 获取 root 权限相关推荐

  1. Deepin su 获取root权限失败,显示鉴定故障解决方法

  2. Android WIFI密码查看器实例(在获取Root权限下查看系统文件)

    Android WIFI密码查看器实例 实现原理:使用shell命令查看保存WIFI密码的系统文件 涉及的知识 界面展示 基本的Shell命令 shell查看WIFI密码 ShellUtil的使用 正 ...

  3. 【android工具篇】Firefly-RK系列(eg:RK3288 RK3368)一键获取root权限工具RootUtils

    问题描述 越来越多的智能设备使用到了Firefly的开发板(http://dev.t-firefly.com/forum.php),有时候android应用开发必须要获取root权限(如重启设备.静默 ...

  4. java root权限_Android应用获取Root权限

    在项目的过程中,有可能会要实现类似360优化大师.安卓优化大师的软件搬家.静默安装等需要root权限的功能,或者类似SET_PREFERRED_APPLICATIONS.MOVE_PACKAGE 等需 ...

  5. java获取root权限_apk如何获取root权限

    展开全部 在apk中,有时候需要root权限,例如通过apk更新系统库等system的文件等,避免升级固件,或者e68a8432313133353236313431303231363533313333 ...

  6. Android 命令su,获取Android的ROOT权限其实很简单,只要在Runtime下执行命令su就可以了。复制代码 代码如下:// 获取ROOT权限public void...

    获取Android的ROOT权限其实很简单,只要在Runtime下执行命令"su"就可以了. // 获取ROOT权限 public void get_root(){ if (is_ ...

  7. n918st能刷Android5吗?,中兴 N918st(V5S 双4G版)获取Root权限服务含精简系统方案

    安卓手机一旦获取Root权限就好像拥有了全世界 独家系统精简方案,优化系统流畅度,还你如初的感受. 刷前须知: 使用本服务前,请保证手机未进行刷机或root权限 使用本服务不会清除手机数据,但建议备份 ...

  8. linux通过java获取root权限_通过可写文件获取Linux root权限的5种方法

    Linux系统中,全部都是以文件形式存在的,包括目录.设备都是有权限的,共有读.写.可执行三种.管理员为文件设置好权限后,应该要考虑哪些Linux用户会被允许和限制上述的三个权限. 通过可写脚本进行r ...

  9. ADB工具 获取ROOT权限及复制文件方法

    adb push d:\tm3_sqlit.db data/zouhao/tm3_sqlit.db adb pull data/zouhao/tm3_sqlit.db d:\tm3_sqlit.db ...

最新文章

  1. mysql sql 事务写作_mysql中的事务
  2. sql的加减乘除运算_实现四则运算的一条sql语句
  3. when is Lessifier triggered to be loaded
  4. 2017.3.22-morning
  5. 【前端就业课 第一阶段】HTML5 零基础到实战(五)基础元素
  6. JAVA编程心得-Eclipse/MyEclipse 中文乱码解决办法
  7. 用行为树的方式思考问题
  8. [转载] 列表、元组及通用序列操作
  9. Hadoop配置项整理(hdfs-site.xml)
  10. 高德,百度,Google地图定位偏移以及坐标系转换
  11. SpringBoot:Could not autowire there is more than one bean of xx type
  12. 基于MINA构建简单高性能的NIO应用-优化指南
  13. 这么多牛逼的Java常用Json库,万万没想到它的性能最好!
  14. 【Python技能树共建】验证码实操2案例
  15. 北京二手房价10月微涨 业内:坚持限购就不会大涨
  16. 51单片机——人体红外感应报警
  17. 跟小静读CLR via C#-开篇及目录
  18. like not like 优化 2
  19. CSS实现按钮点击后根据背景色加深效果
  20. MUX VLAN详解与配置实例

热门文章

  1. 华为方舟编译器是黑科技?
  2. 资深架构师谈云原生生态的基石Kubernetes
  3. 程序员如何一键“Get”高清壁纸?
  4. 如何使用 SpringCloud 搭建服务注册中心?
  5. @Python 程序员,如何实现狂拽酷炫的 3D 编程技术?
  6. 你是如何离编程越来越远的?
  7. python游戏房间_Python House冒险-如果已经进入一个房间,如何给出不同的输出
  8. mysql读写分离错_MySQL主从同步、读写分离配置步骤、问题解决
  9. mysql重置密码报错,吐血整理
  10. git reset --hard HEAD 后恢复暂存区文件