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 玩家中常说的“越狱”有一个更深层次的认识. ...
随机推荐
- fatal error LNK1104: 无法打开文件“LIBC.lib”错误(转)
原文转自 http://blog.csdn.net/qq1028850792/article/details/41546043 方法一: 用VS2005重新编译某个工程的发生了链接错误,现在把这个解决 ...
- RUNAS UAC
cookielib pip install wmi _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE', 0, _winreg.KEY_ALL ...
- python 实现经典算法
import time start_time = time.clock() list_ = [9, 2, 7, 4, 5, 6, 3, 8, 1] """ # 堆排序(通 ...
- VBA 学习
Sub abc() Dim i Dim coloumn coloumn = For i = To Dim currentValue currentValue = Val(ReplaceChar(She ...
- 用jmeter进行多用户并发压力测试
测试要求如下,多用户同时登陆web应用程序,并进行操作,查看在多用户操作下,程序的performence.恰好,jemter下有个CSV Data Set Config,它用来设定一组参数,以便在向程 ...
- [Git]Git 常用的操作命令
创建本地仓库 git init 获取远程仓库 git clone [url] 例如:git clone https://github.com/you/yourpro.git 创建远程仓库 添加一个新的 ...
- IntelliJ IDEA插件-翻译插件
说明:这个翻译插件应该是最好的了. 官网:https://github.com/YiiGuxing/TranslationPlugin 但是这个有个缺点就是使用收费的API,基于有道,截止今天使用的是 ...
- Jenkins的安装方法(Windows/Linux)
前提:要确定本机全部安装了JDK 一.先说官方的安装方式 打开网址:https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins,会留意 ...
- SimpleDateFormat关于时间类的一些常用处理
项目中经常会出现对时间类的一些处理,记录一下: 实例一:/** * 获取当前时间是星期几? * * @param args */ public static void main(String[] ar ...
- 从M个数中随机等可能的取出N个的问题
从0到m-1这m个数中随机取出n个(n<=m) 要求每个数被取到的可能性相等. 第一个方法是把这m个数丢到一个List里面 然后用nextInt(list.size())来产生随机数 然后把li ...