android推断手机是否root
关于推断手机是否已经root的方法。假设app有一些特殊功能须要root权限,则须要推断是否root。
比方一些市场下载完app后自己主动安装。
/**
* @author Kevin Kowalewski
*
*/
public class Root { private static String LOG_TAG = Root.class.getName(); public boolean isDeviceRooted() {
if (checkRootMethod1()){return true;}
if (checkRootMethod2()){return true;}
if (checkRootMethod3()){return true;}
return false;
} public boolean checkRootMethod1(){
String buildTags = android.os.Build.TAGS; if (buildTags != null && buildTags.contains("test-keys")) {
return true;
}
return false;
} public boolean checkRootMethod2(){
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
return true;
}
} catch (Exception e) { } return false;
} public boolean checkRootMethod3() {
if (new ExecShell().executeCommand(SHELL_CMD.check_su_binary) != null){
return true;
}else{
return false;
}
}
} /**
* @author Kevin Kowalewski
*
*/
public class ExecShell { private static String LOG_TAG = ExecShell.class.getName(); public static enum SHELL_CMD {
check_su_binary(new String[] {"/system/xbin/which","su"}),
; String[] command; SHELL_CMD(String[] command){
this.command = command;
}
} public ArrayList<String> executeCommand(SHELL_CMD shellCmd){
String line = null;
ArrayList<String> fullResponse = new ArrayList<String>();
Process localProcess = null; try {
localProcess = Runtime.getRuntime().exec(shellCmd.command);
} catch (Exception e) {
return null;
//e.printStackTrace();
} BufferedWriter out = new BufferedWriter(new OutputStreamWriter(localProcess.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(localProcess.getInputStream())); try {
while ((line = in.readLine()) != null) {
Log.d(LOG_TAG, "--> Line received: " + line);
fullResponse.add(line);
}
} catch (Exception e) {
e.printStackTrace();
} Log.d(LOG_TAG, "--> Full response was: " + fullResponse); return fullResponse;
} }
代码来自stackoverflow。向作者致敬。
方法2:
The RootTools library offers simple methods to check for root:
一个开源项目:http://code.google.com/p/roottools/
RootTools.isRootAvailable()推断是否root
RootTools.isAccessGiven()返回true那么手机已经root而且app也被授予root权限。
另外:据那片帖子的一个回贴人说使用
String commandToExecute = "su";
executeShellCommand(commandToExecute);
private boolean executeShellCommand(String command){
Process process = null;
try{
process = Runtime.getRuntime().exec(command);
return true;
} catch (Exception e) {
return false;
} finally{
if(process != null){
try{
process.destroy();
}catch (Exception e) {
}
}
}
}
会引起很严重的性能问题,将手机系统拖的很慢,当应用多次启动后会创建出许多个僵死的进程耗用内存。
參考http://stackoverflow.com/questions/1101380/determine-if-running-on-a-rooted-device
To sum up; I have no advice for you to determine if device is rooted or not. But if I were you I would not use Runtime.getRuntime().exec().
By the way; RootTools.isRootAvailable() causes same problem.
The RootTools library offers simple methods to check for root:
android推断手机是否root的更多相关文章
- Android 判定手机是否root
Android获取手机root的状态 package com.app.demo; import java.io.File; import android.app.Activity; import an ...
- [Android] 安卓手机不用root删除自带app
声明:本文档仅供测试,因删除引起的一切问题,本人概不负责 声明:本文档仅供测试,因删除引起的一切问题,本人概不负责 声明:本文档仅供测试,因删除引起的一切问题,本人概不负责 转载请注明出处:https ...
- android 推断手机是否支持前置摄像头
话不多说 直接上代码, @SuppressLint("NewApi") public static boolean isSupportFrontCamera() { if (!ha ...
- 【Android】不弹root请求框检测手机是否root
由于项目需要root安装软件,并且希望在合适的时候引导用户去开启root安装,故需要检测手机是否root. 最基本的判断如下,直接运行一个底层命令.(参考https://github.com/Trin ...
- Android手机一键Root原理分析
图/文 非虫 一直以来,刷机与Root是Android手机爱好者最热衷的事情.即使国行手机的用户也不惜冒着失去保修的风险对Root手机乐此不疲.就在前天晚上,一年一度的Google I/O大会拉开了帷 ...
- 【转】Android检查手机是否被root
目前来说Android平台并没有提供能够root检查的工具.但是我们可以通过两种方式来判断 手机里面是否有su文件 这个su文件是不是能够执行 但是这两种检查方式都存在缺点. 第一种存在误测和漏测的情 ...
- Android使得手机拍照功能的发展(源共享)
Android系统调用手机拍照功能有两种方法来直接调用手机自带摄像头还有一个就是要当心自己的节拍. 例Camera360 强大的一个在每个操作系统都有一个手机摄影软件:您可以捕捉不同风格,不同特效的照 ...
- Android 获取手机信息
private void initData() { TelephonyManager mTm = (TelephonyManager) getActivity().getSystemService(C ...
- Android 上SuperUser获取ROOT权限原理解析
Android 上SuperUser获取ROOT权限原理解析 一. 概述 本文介绍了android中获取root权限的方法以及原理,让大家对android 玩家中常说的“越狱”有一个更深层次的认识. ...
随机推荐
- 嵌入式Linux上通过boa服务器实现cgi/html的web上网【转】
转自:http://blog.csdn.net/tianmohust/article/details/6595996 版权声明:本文为博主原创文章,未经博主允许不得转载. 嵌入式Linux上通过boa ...
- ftp服务器搭建(windows)+实现ftp图片上传对接
ftp服务器搭建(windows): vsftpd简介: vsftpd是“very secure FTP daemon”的缩写,是一个完全免费的.开放源代码的ftp服务器软件. 下载地址: http: ...
- 开始gentoo之旅
买了一台i7笔记本,dell 15游戏匣7559,老笔记本dell n4030装了gentoo. 用了两天,先用着,再慢慢学内核编译.
- 我和阿里云RDS的故事
于阿里云的RDS性能无法满足我们公司系统的要求,数据库偶尔出现莫名的查询慢(索引等做了全面优化)经过好多次投诉,情况还是没有改善.由于是类金融的系统,对这种情况是不能接受的.相信系统数据有5G以上有人 ...
- 通过过滤器和增强request对象解决get提交请求服务器端乱码。
1.表单用get方式提交 <%@ page language="java" contentType="text/html; charset=UTF-8" ...
- pycharm配置pep8
可以使用外部工具,来检查代码是否符合pep8的风格: 1)下载 autopep8,这个简单,pip3 install pep8 2)在pychamr中配置: A)file-setting..-tool ...
- org.hibernate.HibernateException: Unable to get the default Bean Validation factor
org.hibernate.HibernateException: Unable to get the default Bean Validation factor这个异常需要在hibernate.c ...
- 【原创】Talend ETL Job日志框架——基于P&G项目的一些思考和优化
一.背景 接触talend也挺长一段时间了,在P&G项目中每天都是使用它开发job,做ETL,也看了前辈开发的很多ETL Job,学到不少.也接触了TAC(talend administrat ...
- Mysql优化的方法
一.表的优化: 1: 定长与变长分离 如 time.手机号等,每一单元值占的字节是固定的. 核心且常用字段,宜建成定长,放在一张表,查询速度会很快 而varchar, text,blob,这种变长字段 ...
- javascript原型理解一种
http://www.jianshu.com/p/15ac7393bc1f 这个系列值得好好学习的.. // 声明构造函数 function Person(name, age) { this.name ...