fix: 申请权限要放在最前面

This commit is contained in:
niushuai233 2022-10-26 22:50:41 +08:00
parent d77ec1fb1c
commit 8dfac50f51
3 changed files with 13 additions and 5 deletions

View File

@ -15,6 +15,7 @@ import java.util.List;
import cc.niushuai.project.devcontrol.BuildConfig;
import cc.niushuai.project.devcontrol.base.util.Global;
import cc.niushuai.project.devcontrol.base.util.Keys;
import cc.niushuai.project.devcontrol.base.util.XLog;
import cc.niushuai.project.devcontrol.db.DB;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.text.StrPool;
@ -25,12 +26,13 @@ public class App {
public static void init(Activity activity) {
// 申请权限
requestPermissions(activity);
// 初始化日志相关内容
initLog(activity);
// 检查root权限
checkRoot(activity);
// 申请权限
requestPermissions(activity);
// 初始化数据库
initDb(activity);
// 重建设备信息缓存
@ -47,10 +49,13 @@ public class App {
private static void checkRoot(Activity activity) {
String which_su = RuntimeUtil.execForStr("which su");
XLog.i(Keys.Tag.APP_INIT, "检查root权限... {}", which_su);
if (StrUtil.isNotEmpty(which_su)) {
Global.HAS_ROOT = true;
XLog.i(Keys.Tag.APP_INIT, "当前设备具有root权限, su路径: {}", which_su);
} else {
XLog.i(Keys.Tag.APP_INIT, "当前设备不具有root权限");
}
System.out.println("当前设备具有root权限");
}
/**

View File

@ -14,5 +14,7 @@ public interface Keys {
interface Tag {
String MY_OPEN_HELPER = "MyOpenHelper";
String APP_INIT = "AppInit";
}
}

View File

@ -9,6 +9,7 @@ import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
/**
@ -124,7 +125,7 @@ public class XLog {
private static String filterThr(String message, Object[] params) {
String format = StrUtil.format(message, params);
if (null != params) {
if (ArrayUtil.isNotEmpty(params)) {
Object lastParam = params[params.length - 1];
if (lastParam instanceof Throwable) {
// 最后一个元素如果为异常对象
@ -179,7 +180,7 @@ public class XLog {
public static void write(String tag, String message, int level) {
String logContent = concatFinalLog(tag, level, message);
FileUtil.appendUtf8String(logContent, currentAbsoluteLogPath());
FileUtil.appendUtf8String(logContent + System.lineSeparator(), currentAbsoluteLogPath());
}
/**