Files
Launcher3-Q-Aoleyun/src/com/aoleyun/os/uiuiutils/JGYUtils.java
Fanhuitong f3564fb0f5 version:zhanrui 6.4.1
fix:
update:更换图标,修改主页
2023-09-28 15:07:02 +08:00

270 lines
9.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.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 final int UnknowPlatform = 0;
public static final int MTKPlatform = 1;
public static final int CubePlatform = 2;
public static final int ZhanruiPlatform = 3;
public static final int MTK11Platform = 5;
public static final int TeclastP20sPlatform = 6;
public static final int AH6016Platform = 9;
public static final int ZR6016Platform = 10;
public static final String Other = "其他";
public static final String MTKTag = "MTK";
public static final String CubeTag = "展锐cube";
public static final String ZhanruiTag = "展锐";
public static final String MTK11Tag = "MTK11";
public static final String TeclastP20sTag = "P20S";
public static final String AH6016Tag = "AH6016";
public static final String ZR6016Tag = "ZR6016";
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 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 if ("MTK11".equalsIgnoreCase(platform)) {
Log.i(TAG, "checkAppPlatform: " + "MTK11");
return MTK11Platform;
} else if (TeclastP20sTag.equalsIgnoreCase(platform)) {
Log.i(TAG, "checkAppPlatform: " + "P20S");
return TeclastP20sPlatform;
} else if (AH6016Tag.equalsIgnoreCase(platform)) {
Log.i(TAG, "checkAppPlatform: " + "AH6016Tag");
return AH6016Platform;
} else if (ZR6016Tag.equalsIgnoreCase(platform)) {
Log.i(TAG, "checkAppPlatform: " + "ZR6016");
return ZR6016Platform;
} else {
Log.i(TAG, "checkAppPlatform: " + "没有数据");
return UnknowPlatform;
}
}
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 if (MTK11Tag.equalsIgnoreCase(platform)) {
getAppPlatformCallback.AppPlatform(MTK11Platform);
} else if (TeclastP20sTag.equalsIgnoreCase(platform)) {
getAppPlatformCallback.AppPlatform(TeclastP20sPlatform);
} else if (AH6016Tag.equalsIgnoreCase(platform)) {
getAppPlatformCallback.AppPlatform(AH6016Platform);
} else if (ZR6016Tag.equalsIgnoreCase(platform)) {
getAppPlatformCallback.AppPlatform(ZR6016Platform);
} else {
getAppPlatformCallback.AppPlatform(UnknowPlatform);
}
}
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();
}
}
public static boolean isUnlocked(Context context) {
int locked = Settings.System.getInt(context.getContentResolver(), "qch_unlock_ipad", 0);
int aihuaUnlock = Settings.System.getInt(context.getContentResolver(), "Aihua_unlock_state", 0);
return locked == 1 || aihuaUnlock == 1;
}
public static boolean isDisable(Context context, String pkg) {
String aole_disable_app_list = Settings.Global.getString(context.getContentResolver(), "aole_disable_app_list");
if (TextUtils.isEmpty(aole_disable_app_list)) {
return false;
} else {
HashSet<String> appSet = new HashSet<>(Arrays.asList(aole_disable_app_list.split(",")));
return appSet.contains(pkg);
}
}
}