From 8dfac50f51adfd4f676a97e8da5b55bb05759a89 Mon Sep 17 00:00:00 2001 From: niushuai233 Date: Wed, 26 Oct 2022 22:50:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=B3=E8=AF=B7=E6=9D=83=E9=99=90?= =?UTF-8?q?=E8=A6=81=E6=94=BE=E5=9C=A8=E6=9C=80=E5=89=8D=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cc/niushuai/project/devcontrol/base/App.java | 11 ++++++++--- .../niushuai/project/devcontrol/base/util/Keys.java | 2 ++ .../niushuai/project/devcontrol/base/util/XLog.java | 5 +++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/App.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/App.java index 5921c8d..02872a2 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/App.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/App.java @@ -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权限"); } /** diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/Keys.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/Keys.java index d7dd4a9..98e3abc 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/Keys.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/Keys.java @@ -14,5 +14,7 @@ public interface Keys { interface Tag { String MY_OPEN_HELPER = "MyOpenHelper"; + + String APP_INIT = "AppInit"; } } diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/XLog.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/XLog.java index c14163e..a46e5a7 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/XLog.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/XLog.java @@ -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()); } /**