if (!mHaveRoot) {
int ret = execRootCmdSilent(“echo test”); // 通过执行测试命令来检测
if (ret != -1) {
Log.i(TAG, “have root!”);
mHaveRoot = true;
} else {
Log.i(TAG, “not root!”);
}
} else {
Log.i(TAG, “mHaveRoot = true, have root!”);
}
return mHaveRoot;
}
// 执行命令并且输出结果
public static String execRootCmd(String cmd) {
String result = “”;
DataOutputStream dos = null;
DataInputStream dis = null;
try {
Process p = Runtime.getRuntime().exec(“su”);// 经过Root处理的android系统即有su命令
dos = new DataOutputStream(p.getOutputStream());
dis = new DataInputStream(p.getInputStream());
Log.i(TAG, cmd);
dos.writeBytes(cmd + “\n”);
dos.flush();
dos.writeBytes(“exit\n”);
dos.flush();
String line = null;
while ((line = dis.readLine()) != null) {
Log.d(“result”, line);
result += line;
}
p.waitFor();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (dos != null) {
try {
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (dis != null) {
try {
dis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
// 执行命令但不关注结果输出
public static int execRootCmdSilent(String cmd) {
int result = -1;
DataOutputStream dos = null;
try {
Process p = Runtime.getRuntime().exec(“su”);
dos = new DataOutputStream(p.getOutputStream());
Log.i(TAG, cmd);
dos.writeBytes(cmd + “\n”);
dos.flush();
dos.writeBytes(“exit\n”);
dos.flush();
p.waitFor();
result = p.exitValue();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (dos != null) {
try {
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
}
相关文件:SystemPartition.java,获取/system分区设备节点,并支持重新mount /system为可读写:
[java]
package org.ckl.root;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import android.util.Log;
public class SystemPartition {
private static final String TAG = “SystemMount”;
private static String TMP_PATH = “/sdcard/mount.txt”;
private static String mMountPiont = null;
private static boolean mWriteable = false;
private SystemPartition() {
Log.i(TAG, “new SystemMount()”);
}
private static class SystemPartitionHolder {
private static SystemPartition instance = new SystemPartition();
}
public SystemPartition getInstance() {
return SystemPartitionHolder.instance;
}
public static String getSystemMountPiont() {
DataInputStream dis = null;
if (mMountPiont == null) {
try {
RootCmd.execRootCmd("mount > " + TMP_PATH);
// Runtime.getRuntime().exec("mount > " + TMP_PATH);
dis = new DataInputStream(new FileInputStream(TMP_PATH));
String line = null;
int index = -1;
while ( (line = dis.readLine()) != null ) {
index = line.indexOf(" /system ");
if (index > 0) {
mMountPiont = line.substring(0, index);
if (line.indexOf(" rw") > 0) {
mWriteable = true;
Log.i(TAG, “/system is writeable !”);
} else {
mWriteable = false;
Log.i(TAG, “/system is readonly !”);
}
break;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (dis != null) {
try {
dis.close();
} catch (IOException e1) {
e1.printStackTrace();
}
dis = null;
}
File f = new File(TMP_PATH);
if (f.exists()) {
f.delete();
}
}
}
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
总结
最后对于程序员来说,要学习的知识内容、技术有太多太多,要想不被环境淘汰就只有不断提升自己,从来都是我们去适应环境,而不是环境来适应我们!
这里附上上述的技术体系图相关的几十套腾讯、头条、阿里、美团等公司2021年的面试题,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。
相信它会给大家带来很多收获:
当程序员容易,当一个优秀的程序员是需要不断学习的,从初级程序员到高级程序员,从初级架构师到资深架构师,或者走向管理,从技术经理到技术总监,每个阶段都需要掌握不同的能力。早早确定自己的职业方向,才能在工作和能力提升中甩开同龄人。
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
:**
[外链图片转存中…(img-CARb4WqO-1712829162383)]
[外链图片转存中…(img-bPHEJIaQ-1712829162384)]
当程序员容易,当一个优秀的程序员是需要不断学习的,从初级程序员到高级程序员,从初级架构师到资深架构师,或者走向管理,从技术经理到技术总监,每个阶段都需要掌握不同的能力。早早确定自己的职业方向,才能在工作和能力提升中甩开同龄人。
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
[外链图片转存中…(img-LOkofY3m-1712829162384)]