是否有Root权限
2016-04-27 11:11
316 查看
Process process = null; DataOutputStream os = null; BufferedInputStream br = null; try { String cmd = "ls /data/app"; // 切换到root帐号 process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(cmd + "\n"); os.writeBytes("exit\n"); os.flush(); br = new BufferedInputStream(process.getErrorStream()); StringBuffer text = new StringBuffer(); int ch; while ((ch = br.read()) != -1) { text.append((char) ch); } int exitValue = process.waitFor(); String ret = text.toString(); boolean permission = false; if (ret == null || ret.trim().length() == 0) { permission = true; } if (exitValue == 0) { if (Build.VERSION.SDK_INT == 23) { return true; } if (permission) { return true; } return false; } else { return false; } } catch (Exception e) { e.printStackTrace(); return false; } finally { try { if (os != null) { os.close(); } if (br != null) { br.close(); } process.destroy(); } catch (Exception e) { e.printStackTrace(); } }
相关文章推荐
- mysql table checksum
- Qt入门之信号与槽机制
- Mybatis之传多个参数方法总结
- Nio
- Struts2-S2-032远程命令执行EXP
- 数据结构和算法 c#– 1.单项链表
- Redis复制与可扩展集群搭建
- ClassNotFoundException和NoClassDefFoundError的区别
- 在string.xml显示%
- 2016年4月27
- 左右按钮轮播代码
- eclipse中svn的使用:Failed to run the WC DB work queue associated with 'E:\NewEclip
- mysql 远程登录
- 关于UITextView上部出现空白一步解决
- c++内存分配方式
- 子网掩码与子网划分两个分别是什么意思
- awda
- centos6.x 安装subversion svn
- centos7.x firewalld
- CVE-2015-7547 分析代码bug