feat: 系统功能抽象

This commit is contained in:
2026-05-08 00:26:27 +08:00
parent b0ea6eff0a
commit 4dcb82b9f4
82 changed files with 4758 additions and 1019 deletions

View File

@@ -6,7 +6,8 @@ import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import androidx.multidex.MultiDex;
import com.alibaba.android.arouter.launcher.ARouter;
import com.arialyy.aria.core.Aria;
@@ -18,7 +19,11 @@ import com.ttstd.dialer.config.CommonConfig;
import com.ttstd.dialer.manager.AppManager;
import com.ttstd.dialer.manager.MapManager;
import com.ttstd.dialer.manager.WeatherManager;
import com.ttstd.dialer.mdm.DeviceManagerService;
import com.ttstd.dialer.network.OkHttpManager;
import com.ttstd.dialer.push.PushExecutor;
import com.ttstd.dialer.utils.Logger;
import com.ttstd.dialer.utils.NativeUtils;
import com.ttstd.dialer.utils.SystemUtils;
import com.ttstd.iconloader.IconCacheManager;
@@ -30,21 +35,30 @@ import cn.jpush.android.api.JPushInterface;
public class BaseApplication extends Application {
private static final String TAG = "BaseApplication";
private MMKV mMMKV;
/**
* ViewModel中因为经常旋转导致弱引用为空
*/
@SuppressLint("StaticFieldLeak")
private static Context context;
private static Context mAppContext;
public static Context getContext() {
return context;
return mAppContext;
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
@Override
public void onCreate() {
super.onCreate();
Log.e(TAG, "onCreate: ");
context = getApplicationContext();
Logger.e(TAG, "onCreate: ");
mAppContext = getApplicationContext();
if (!BuildConfig.DEBUG) {
catchException();
}
@@ -56,34 +70,20 @@ public class BaseApplication extends Application {
}
private void init() {
Log.e(TAG, "init: ");
Logger.e(TAG, "init: ");
Logger.e(TAG, "init: getNonce = " + NativeUtils.getNonce());
if (SystemUtils.isMainProcessName(this, android.os.Process.myPid())) {
Logger.initialize(this, BuildConfig.DEBUG);
Logger.setLogLevel(Logger.LogLevel.DEBUG); // 开发阶段记录所有日志
String rootDir = MMKV.initialize(this);
Log.e(TAG, "mmkv root: " + rootDir);
MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
Logger.e(TAG, "mmkv root: " + rootDir);
mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
/*jpush start*/
JPushInterface.setDebugMode(true);
// 调整点一调用启用推送业务功能代码前增加setAuth调用
boolean isPrivacyReady = true; // app根据是否已弹窗获取隐私授权来赋值
if (!isPrivacyReady) {
// JCore 5.0.4之前版本需要显式设置false
if (JCoreInterface.getJCoreSDKVersionInt() < 504) { // 5.0.4版本号对应504
JCollectionAuth.setAuth(context, false);
}
// 所有版本在未授权时都不应初始化SDK
return;
}
JPushInterface.init(this);
JPushInterface.setAlias(this, 0, SystemUtils.getSerial());
// 调整点二App用户同意了隐私政策授权并且开发者确定要开启推送服务后调用
// JCore 5.0.4+会自动处理授权状态可不需要显式设置true
JCollectionAuth.setAuth(context, true);
/*jpush end*/
DeviceManagerService.init(this);
OkHttpManager.init(this);
PushExecutor.init(this);
initJPush();
if (BuildConfig.DEBUG) { // 这两行必须写在init之前否则这些配置在init过程中将无效
ARouter.openLog(); // 打印日志
@@ -94,7 +94,7 @@ public class BaseApplication extends Application {
// 初始化 Toast 框架
Toaster.init(this);
Log.e(TAG, "slowInit: ");
Logger.e(TAG, "slowInit: ");
Aria.init(this);
CrashReport.initCrashReport(getApplicationContext(), "845e3ed68c", false);
CrashReport.setDeviceId(this, Build.MODEL);
@@ -103,8 +103,8 @@ public class BaseApplication extends Application {
AppManager.init(this);
MapManager.init(this);
MapManager.getInstance().initMap();
boolean manually = mmkv.decodeBool(CommonConfig.MANUALLY_SELECT_LOCATION, false);
Log.e(TAG, "init: manually location " + manually);
boolean manually = mMMKV.decodeBool(CommonConfig.MANUALLY_SELECT_LOCATION, false);
Logger.e(TAG, "init: manually location " + manually);
if (manually) {
} else {
@@ -115,12 +115,36 @@ public class BaseApplication extends Application {
}
}
private void initJPush() {
/*jpush start*/
JPushInterface.setDebugMode(true);
// 调整点一调用启用推送业务功能代码前增加setAuth调用
boolean isPrivacyReady = true; // app根据是否已弹窗获取隐私授权来赋值
if (!isPrivacyReady) {
// JCore 5.0.4之前版本需要显式设置false
if (JCoreInterface.getJCoreSDKVersionInt() < 504) { // 5.0.4版本号对应504
JCollectionAuth.setAuth(this, false);
}
// 所有版本在未授权时都不应初始化SDK
return;
}
JPushInterface.init(this);
JPushInterface.setAlias(this, 0, SystemUtils.getSerial());
// 调整点二App用户同意了隐私政策授权并且开发者确定要开启推送服务后调用
// JCore 5.0.4+会自动处理授权状态可不需要显式设置true
JCollectionAuth.setAuth(this, true);
/*jpush end*/
Logger.e(TAG, "initJPush: inited JPush");
}
private void catchException() {
Thread.setDefaultUncaughtExceptionHandler(
new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
Log.e("捕获异常子线程:", Thread.currentThread().getName() +
Logger.e("捕获异常子线程:", Thread.currentThread().getName() +
"在:" + e.getStackTrace()[0].getClassName());
}
}
@@ -133,7 +157,7 @@ public class BaseApplication extends Application {
try {
Looper.loop(); //会先执行这个方法,然后在执行下面的异常捕获方法!
} catch (Exception e) {
Log.e("捕获异常主线程:", Thread.currentThread().getName() + "在:" + e.getStackTrace()[0].getClassName());
Logger.e("捕获异常主线程:", Thread.currentThread().getName() + "在:" + e.getStackTrace()[0].getClassName());
e.printStackTrace();
}
}