Files
Launcher3-Q-Aoleyun/src/com/aoleyun/os/uiuiutils/JGYUtils.java
Godfather 6bd36a3afb version:4.5
fix:
update:优化aihua版本
2022-04-25 21:10:34 +08:00

262 lines
8.6 KiB
Java

package com.aoleyun.os.uiuiutils;
import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import com.android.server.BootReceiver;
import com.aoleyun.os.BuildConfig;
import com.aoleyun.os.comm.JGYActions;
import com.aoleyun.os.model.LoaderTask;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashSet;
public class JGYUtils {
private static final String TAG = JGYUtils.class.getSimpleName();
@SuppressLint("StaticFieldLeak")
private static JGYUtils sInstance;
private Context mContext;
private ContentResolver mResolver;
public static int UnknowPlatform = 0;
public static int MTKPlatform = 1;
// TODO: 2022/4/23 标签替换未完成
public static int CubePlatform = 2;
public static int ZhanruiPlatform = 3;
public static String Other = "其他";
public static String MTKTag = "MTK";
// TODO: 2022/4/23 标签替换未完成
public static String CubeTag = "展锐cube";
public static String ZhanruiTag = "展锐";
private JGYUtils(Context context) {
if (context == null) {
throw new RuntimeException("Context is NULL");
}
this.mContext = context;
this.mResolver = context.getContentResolver();
}
public static void init(Context context) {
if (sInstance == null) {
sInstance = new JGYUtils(context);
}
}
public static JGYUtils getInstance() {
if (sInstance == null) {
throw new IllegalStateException("You must be init JGYUtils first");
}
return sInstance;
}
public int checkSNPlatform(String sn) {
String secondChars = sn.substring(1, 2);
if ("N".equalsIgnoreCase(secondChars)) {//MTK平台
return MTKPlatform;
} else if ("R".equalsIgnoreCase(secondChars)) {//展锐平台
return ZhanruiPlatform;
} else {
Log.e(TAG, "checkSNPlatform: " + "sn: " + sn + "没有对应平台");
return UnknowPlatform;
}
}
public int checkAppPlatform() {
String platform = BuildConfig.platform;
if ("MTK".equalsIgnoreCase(platform)) {
Log.i(TAG, "checkAppPlatform: " + "MTK平台");
return MTKPlatform;
} else if ("ZhanRui".equalsIgnoreCase(platform)) {
Log.i(TAG, "checkAppPlatform: " + "展锐平台");
return ZhanruiPlatform;
} else if ("ZhanRuiCube".equalsIgnoreCase(platform)) {
Log.i(TAG, "checkAppPlatform: " + "酷比平台");
return CubePlatform;
} else {
Log.i(TAG, "checkAppPlatform: " + "没有数据");
return UnknowPlatform;
}
}
public boolean isSamePlatform(String platform) {
String AppPlatform = BuildConfig.platform;
if ("ZhanRui".equals(AppPlatform)) {
return ZhanruiTag.equals(platform);
} else {
return AppPlatform.equals(platform);
}
}
public interface GetAppPlatformCallback {
void AppPlatform(int platform);
}
public void getAppPlatform(GetAppPlatformCallback getAppPlatformCallback) {
String platform = BuildConfig.platform;
if ("MTK".equalsIgnoreCase(platform)) {
getAppPlatformCallback.AppPlatform(MTKPlatform);
} else if ("ZhanRui".equalsIgnoreCase(platform)) {
getAppPlatformCallback.AppPlatform(ZhanruiPlatform);
} else if ("ZhanRuiCube".equalsIgnoreCase(platform)) {
getAppPlatformCallback.AppPlatform(CubePlatform);
} else {
getAppPlatformCallback.AppPlatform(UnknowPlatform);
}
}
public String getAppPlatform() {
String platform = BuildConfig.platform;
if ("MTK".equalsIgnoreCase(platform)) {
return MTKTag;
} else if ("ZhanRui".equalsIgnoreCase(platform)) {
return ZhanruiTag;
} else if ("ZhanRuiCube".equalsIgnoreCase(platform)) {
return CubeTag;
} else {
return Other;
}
}
public static boolean isOfficialVersion() {
String channelValue = JGYUtils.getInstance().getStringMetaData();
return "official".equals(channelValue);
}
public static boolean isNewlyVersion() {
String channelValue = JGYUtils.getInstance().getStringMetaData();
return "beta".equals(channelValue);
}
public static boolean isBetaVersion() {
String channelValue = JGYUtils.getInstance().getStringMetaData();
return "beta".equals(channelValue);
}
/**
* 从Manifest中获取meta-data值
* https://blog.csdn.net/yue_233/article/details/91453451
*
* @return
*/
public String getStringMetaData() {
ApplicationInfo appInfo = null;
try {
appInfo = mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
String value = appInfo.metaData.getString("CHANNEL_VALUE");
return value;
}
public static String getCustomVersion() {
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
return getProperty("ro.build.display.id", "获取失败");
} else {
return getProperty("ro.custom.build.version", "获取失败");
}
}
public static String getRomVersion() {
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
return getProperty("ro.build.id", "获取失败");
} else {
return getProperty("ro.build.display.id", "获取失败");
}
}
/**
* 获取系统配置信息
*
* @param key
* @param defaultValue
* @return
*/
public static String getProperty(String key, String defaultValue) {
String value = defaultValue;
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class, String.class);
value = (String) (get.invoke(c, key, "unknown"));
} catch (Exception e) {
e.printStackTrace();
} finally {
return value;
}
}
public boolean isEnforceApp(String pkg) {
String appString = Settings.System.getString(mResolver, "qch_force_app");
if (TextUtils.isEmpty(appString)) return false;
Log.e("isEnforceApp", "appString: " + appString);
HashSet<String> appSet = new HashSet<>(Arrays.asList(appString.split(",")));
appSet.addAll(LoaderTask.showApp);
return appSet.contains(pkg);
}
public boolean getDeviceIsLocked() {
int locked = Settings.System.getInt(mContext.getContentResolver(), JGYActions.ACTION_QCH_UNLOCK_IPAD, JGYActions.FRAME_CODE_LOCKED);
return locked == JGYActions.FRAME_CODE_LOCKED;
}
public static final String PACKAGE_DEVICEINFO = "com.aoleyun.sn";
public static final String PACKAGE_APPSTORE = "com.aoleyun.appstore";
public static final String CLASS_DEVICEINFO = "com.aoleyun.sn.receiver.BootReceiver";
public static final String CLASS_APPSTORE = "com.aoleyun.appstore.receiver.BootReceiver";
public static final String BOOT_COMPLETED = "aoleyun.intent.action.BOOT_COMPLETED";
public void wakeUpDeviceInfo() {
//启动设备信息
Intent bootIntent = new Intent(BOOT_COMPLETED);
bootIntent.setComponent(new ComponentName(PACKAGE_DEVICEINFO, CLASS_DEVICEINFO));
mContext.sendBroadcast(bootIntent);
}
public void wakeUpAppstore() {
//启动应用市场
Intent bootIntent = new Intent(BOOT_COMPLETED);
bootIntent.setComponent(new ComponentName(PACKAGE_APPSTORE, CLASS_APPSTORE));
mContext.sendBroadcast(bootIntent);
}
public void cleanLauncher3Cache() {
try {
new CacheUtils().cleanApplicationUserData(mContext, "com.android.launcher3");
} catch (Exception e) {
Log.e(TAG, "onReceive: " + e.getMessage());
e.printStackTrace();
}
}
public void cleanAoleLauncher3Cache() {
try {
new CacheUtils().cleanApplicationUserData(mContext, "com.aoleyun.os");
} catch (Exception e) {
Log.e(TAG, "onReceive: " + e.getMessage());
e.printStackTrace();
}
}
}