问题描述

越来越多的智能设备使用到了Firefly的开发板(http://dev.t-firefly.com/forum.php),有时候android应用开发必须要获取root权限(如重启设备、静默升级app),一般厂家都会提供获取root权限的方式,但是总有人不知道如何获取root。

请尊重原创,转载需要注明出处,大力哥的博客:https://blog.csdn.net/qq137722697

解决办法

Firefly论坛有一篇关于获取root权限的帖子(传送门),前提是设备要能连接到电脑,通过adb来操作。
1.设备连接到电脑,通过ADB调试;

2.下载附件root.tar和quick_root.tar,解压缩quick_root.tar(终端运行tar xf quick_root.tar)—>最好在电脑上解压

3.打开终端运行如下命令

adb remount
adb push root.tar system/usr/root.tar
adb push quick_root.sh system/usr/
adb shell 

接着运行

root@rk3288:/ # cd system/usr/
root@rk3288:/system/usr # chmod 777 quick_root.sh
root@rk3288:/system/usr # ./quick_root.sh 

会自动安装和配置相关文件,配置完成后会自动重启,重启后就已经获得ROOT权限了。

特殊情况

特殊情况总是有的,比如我接触到的一批设备是没有调试接口的,也就无法连接电脑(你可能会说可以用无线adb方式来连接,遗憾的是wifi功能已经被禁了,只能用有线)进行ADB调试;你可能想到了可以在android设备上面运行adb命令嘛,是的,可以的,google就提供了这么一个工具,下载地址传送门 ,该工具用法就跟电脑中使用adb一样。命令同上。

终极解决办法

有没有更简单的方式,比如一键获取root权限,有的,下面就是解决方案

一键获取Root权限工具RootUtils–>方式一: https://fir.im/7pw9
方式二:(扫描二维码)

用法:点击“获取Root权限”,稍等片刻,设备重启完成即可,真正的一键获取

下面来说说如何实现,博主真好,源码都公布了,还不点个赞(不想了解的就跳过了哈)

实现方法

只需要一行代码就搞定,不信你看

ShellUtils.execCommand("remount \n push file:///android_asset/root.tar system/usr/root.tar \npush file:///android_asset/quick_root.sh system/usr/\ncd system/usr/\nchmod 777 quick_root.sh\n./quick_root.sh ", false);

你逗我呢,ShellUtils又不是系统API肯定不止一行代码啦(杠精同志的话)

我们来看看这个方法实现了什么功能,其实就是执行了一条shell命令(每条命令以‘\n’结尾),即将assets文件夹下的root.tar和quick_root.sh复制到system/usr文件夹中,然后执行quick_root.sh脚本自动获取root。

第一步

所以第一步就是将root.tar和quick_root.sh放到assets文件夹下面(你放哪里都无所谓,只要app能读取到就行)

第二步

来看看ShellUtils是怎么实现的(此类出自网络,感谢作者)

package com.hdl.rootutils;import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;/*** Shell工具类* Created by HDL on 2018/8/6.*/public class ShellUtils {public static final String COMMAND_SU = "su";public static final String COMMAND_SH = "sh";public static final String COMMAND_EXIT = "exit\n";public static final String COMMAND_LINE_END = "\n";private ShellUtils() {throw new AssertionError();}/*** 查看是否有了root权限** @return*/public static boolean checkRootPermission() {return execCommand("echo root", true, false).result == 0;}/*** 执行shell命令,默认返回结果** @param command command* @return* @see ShellUtils#execCommand(String[], boolean, boolean)*/public static CommandResult execCommand(String command, boolean isRoot) {return execCommand(new String[]{command}, isRoot, true);}/*** 执行shell命令,默认返回结果** @param commands command list* @return* @see ShellUtils#execCommand(String[], boolean, boolean)*/public static CommandResult execCommand(List<String> commands, boolean isRoot) {return execCommand(commands == null ? null : commands.toArray(new String[]{}), isRoot, true);}/*** 执行shell命令,默认返回结果** @param commands command array* @return* @see ShellUtils#execCommand(String[], boolean, boolean)*/public static CommandResult execCommand(String[] commands, boolean isRoot) {return execCommand(commands, isRoot, true);}/*** execute shell command** @param command         command* @param isNeedResultMsg whether need result msg* @return* @see ShellUtils#execCommand(String[], boolean, boolean)*/public static CommandResult execCommand(String command, boolean isRoot, boolean isNeedResultMsg) {return execCommand(new String[]{command}, isRoot, isNeedResultMsg);}/*** execute shell commands** @param commands command list* @return* @see ShellUtils#execCommand(String[], boolean, boolean)*/public static CommandResult execCommand(List<String> commands, boolean isRoot, boolean isNeedResultMsg) {return execCommand(commands == null ? null : commands.toArray(new String[]{}), isRoot, isNeedResultMsg);}/*** execute shell commands*/public static CommandResult execCommand(String[] commands, boolean isRoot, boolean isNeedResultMsg) {int result = -1;if (commands == null || commands.length == 0) {return new CommandResult(result, null, null);}Process process = null;BufferedReader successResult = null;BufferedReader errorResult = null;StringBuilder successMsg = null;StringBuilder errorMsg = null;DataOutputStream os = null;try {process = Runtime.getRuntime().exec(isRoot ? COMMAND_SU : COMMAND_SH);os = new DataOutputStream(process.getOutputStream());for (String command : commands) {if (command == null) {continue;}// donnot use os.writeBytes(commmand), avoid chinese charset// erroros.write(command.getBytes());os.writeBytes(COMMAND_LINE_END);os.flush();}os.writeBytes(COMMAND_EXIT);os.flush();result = process.waitFor();// get command resultif (isNeedResultMsg) {successMsg = new StringBuilder();errorMsg = new StringBuilder();successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));String s;while ((s = successResult.readLine()) != null) {successMsg.append(s);}while ((s = errorResult.readLine()) != null) {errorMsg.append(s);}}} catch (IOException e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();} finally {try {if (os != null) {os.close();}if (successResult != null) {successResult.close();}if (errorResult != null) {errorResult.close();}} catch (IOException e) {e.printStackTrace();}if (process != null) {process.destroy();}}return new CommandResult(result, successMsg == null ? null : successMsg.toString(), errorMsg == null ? null : errorMsg.toString());}public static class CommandResult {/*** 运行结果**/public int result;/*** 运行成功结果**/public String successMsg;/*** 运行失败结果**/public String errorMsg;public CommandResult(int result) {this.result = result;}public CommandResult(int result, String successMsg, String errorMsg) {this.result = result;this.successMsg = successMsg;this.errorMsg = errorMsg;}}
}

下面是GIthub的地址,如果你觉得帮助到你了,来个star吧,更欢迎你fork新增更多实用功能。

https://github.com/huangdali/RootUtils

请尊重原创,转载需要注明出处,大力哥的博客:https://blog.csdn.net/qq137722697

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

  1. 三星 android 5.0 root,三星N9150 Android 5.0 (GALAXY Note Edge 双4G)ROOT教程,一键获取ROOT权限...

    三星N9150 Android 5.0 (GALAXY Note Edge 双4G)怎么ROOT?三星N9150 Android 5.0 (GALAXY Note Edge 双4G) ROOT工具选用 ...

  2. nubia android root权限,中兴NX402 (Nubia Z5 Mini Android 4.2)ROOT教程,一键获取ROOT权限

    中兴NX402 (Nubia Z5 Mini Android 4.2)怎么ROOT?中兴NX402 (Nubia Z5 Mini Android 4.2) ROOT工具选用哪些?如何避免中兴NX402 ...

  3. Android 模拟器一键获取root权限 一键安装Google play 服务

    最近要做一个集成地图的应用,最初准备使用高德地图或者百度地图,后来发现这两者均不适合我所开发的应用,因为是一个国际化的APP,最后决定使用Google地图.但是问题又来了,官方API写道在使用谷歌地图 ...

  4. nexus6 android 6.0 root,Nexus6 root教程_Nexus6一键获取root权限教程

    这一节主要是来说说有关Nexus6的root教程,这个手机还是真不好root呢,因为这个手机是5.0的安卓系统了,现在国内的很多一键root软件还无法对这个手机进行root呢,今天在这里分享的是国外的 ...

  5. flyme android 7 root,魅族Pro7如何获取root权限?利用系统自带root工具即可!

    ROOT大家都不会陌生,一般是指安卓手机获得最高管理权限.那么魅族PRO7怎么Root,今天小编主要详细介绍下魅族PRO7快速ROOT教程.值得一提的是,魅蓝手机ROOT比较简单,因为系统自带了ROO ...

  6. 魅蓝3 官方android系统,魅蓝3获取ROOT权限及刷入Android系统过程

    首先感谢制作魅蓝3  Android ROM的大神----眷恋阳阳 想必很多人跟我一样,在购买了魅蓝3之后发现系统是YunOS,且官方固件没有Android版本,魅族官方也没有给用户开放"获 ...

  7. 魅蓝3如何root_魅蓝3获取root权限及刷入Android过程

    首先感谢制作魅蓝3 Android ROM的大神----眷恋阳阳 想必很多人跟我一样,在购买了魅蓝3之后才发现系统是YunOS,且官方固件并没有Android版本,魅族官方也没有给用户开放" ...

  8. 魅蓝3如何root_魅蓝3获取ROOT权限及刷入Android系统过程

    首先感谢制作魅蓝3  Android ROM的大神----眷恋阳阳 想必很多人跟我一样,在购买了魅蓝3之后发现系统是YunOS,且官方固件没有Android版本,魅族官方也没有给用户开放"获 ...

  9. android apk 永久root,将android应用转成系统应用后,如何能使其直接获得ROOT权限

    可以试试一键root, 该软件目前适用于Android2.2-Android5.0系统的手机获取root权限.用一键root获取权限操作简单稳定,基本上适配所有Android手机,一键root目前已经 ...

最新文章

  1. pip安装itchat模块成功后annocanda中No module named 'itchat'
  2. 很实用但经常忘的小常识
  3. CodeFirst 的编程方式
  4. 7个步骤,帮您轻松实现云迁移
  5. ionic1 打包过程 常用命令行
  6. 统计学、数据分析、机器学习常用数据特征汇总
  7. js正则 匹配 正则表达式
  8. c语言 正号运算符 作用,C语言中,哪些运算符具有左结合性,哪些具有右结合性,帮忙总结下,...
  9. Oracle自制数据仓库,自治数据库:Oracle 的自治数据仓库云-ADWC体验
  10. Hive(一)——基础操作
  11. python怎么调用函数的返回值_python函数的返回值是什么
  12. Git 常用命令 和 安装
  13. 安武:被刷屏的德勤财务机器人(RPA)到底是什么?
  14. 用excel和python做数据分析的优缺点
  15. ug添加imachining变量_UG变量设置
  16. 【前端三剑客二】CSS手术刀剖析第一篇
  17. 河南省第十届ACM程序设计大赛参赛心得
  18. 【codeforces 894A】QAQ
  19. 连载:中国最早的一代官派留学生--留美幼童 (结尾)
  20. Arduino学习(六) 继电器实验

热门文章

  1. bzoj3054 Rainbow的信号(位运算+瞎搞)
  2. HTML——flex布局
  3. 【Oracle 实验 实验4 Oracle数据库模式对象管理】
  4. LINUXUNIX 中文著名网站
  5. vivoiqooz1鸿蒙系统,vivoiqooz1x参数配置详情_iqoo z1x详细参数跑分
  6. 流计算 Oceanus | Flink JVM 内存超限的分析方法总结
  7. vue中使用axios post上传头像/图片并实时显示到页面
  8. 360浏览器兼容问题html,该页面显示了360浏览器中的异常兼容性问题
  9. 各品类市场占有率——通过互联网大数据了解各品类的市场占有率
  10. 物联网家电第一股,想离开小米的云米现在有多少实力?