version:2.1 MTK

fix:优化获取设备类型逻辑,优化获取设备版本号
update:打包更新
This commit is contained in:
2022-04-25 18:21:25 +08:00
parent 11bad35331
commit 7a1a4fe5a5
24 changed files with 1118 additions and 212 deletions

View File

@@ -738,10 +738,10 @@ public class ApkUtils {
//桌面app
public static List<String> desktopAPP = new ArrayList<String>() {{
this.add("com.aoleyunos.dop1");
this.add("com.aoleyunos.dop2");
this.add("com.uiuios.jgy1");
this.add("com.uiuios.jgy2");
// this.add("com.aoleyunos.dop1");
// this.add("com.aoleyunos.dop2");
this.add("com.android.uiuios");
}};

View File

@@ -0,0 +1,69 @@
package com.aoleyun.sn.utils;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import com.google.gson.Gson;
import com.google.gson.JsonParser;
import java.io.Serializable;
public class FlowInfo implements Serializable {
private static final long serialVersionUID = 4948079364302374385L;
String packname;
Drawable icon;
String appname;
long upKb;
long downKb;
long[] stat;
public String getPackname() {
return packname;
}
public void setPackname(String packname) {
this.packname = packname;
}
public Drawable getIcon() {
return icon;
}
public void setIcon(Drawable icon) {
this.icon = icon;
}
public String getAppname() {
return appname;
}
public void setAppname(String appname) {
this.appname = appname;
}
public long getUpKb() {
return upKb;
}
public void setUpKb(long upKb) {
this.upKb = upKb;
}
public long getDownKb() {
return downKb;
}
public void setDownKb(long downKb) {
this.downKb = downKb;
}
public long[] getStat() {
return stat;
}
public void setStat(long[] stat) {
this.stat = stat;
}
}

View File

@@ -0,0 +1,84 @@
package com.aoleyun.sn.utils;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.TrafficStats;
import android.text.TextUtils;
import android.util.Log;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.List;
public class GetFlowUtil {
public static FlowInfo getAppFlowInfo(String pakageName, Context context) {
//获取到配置权限信息的应用程序
PackageManager pms = context.getPackageManager();
List<PackageInfo> packinfos = pms
.getInstalledPackages(PackageManager.GET_PERMISSIONS);
//存放具有Internet权限信息的应用
FlowInfo flowInfo = new FlowInfo();
for (PackageInfo packinfo : packinfos) {
String appName = packinfo.packageName;
if (!TextUtils.isEmpty(appName)) {
if (appName.equals(pakageName)) {
//用于封装具有Internet权限的应用程序信息
//封装应用信息
flowInfo.setPackname(packinfo.packageName);
flowInfo.setIcon(packinfo.applicationInfo.loadIcon(pms));
flowInfo.setAppname(packinfo.applicationInfo.loadLabel(pms).toString());
//获取到应用的uiduser id
int uid = packinfo.applicationInfo.uid;
//TrafficStats对象通过应用的uid来获取应用的下载、上传流量信息
//发送的 上传的流量byte
flowInfo.setUpKb(TrafficStats.getUidRxBytes(uid));
//下载的流量 byte
flowInfo.setDownKb(TrafficStats.getUidTxBytes(uid));
break;
}
}
}
return flowInfo;
}
private static long[] getStat(int uid) {
String line, line2;
long[] stats = new long[2];
try {
File fileSnd = new File("/proc/uid_stat/" + uid + "/tcp_snd");
File fileRcv = new File("/proc/uid_stat/" + uid + "/tcp_rcv");
BufferedReader br1 = new BufferedReader(new FileReader(fileSnd));
BufferedReader br2 = new BufferedReader(new FileReader(fileRcv));
while ((line = br1.readLine()) != null && (line2 = br2.readLine()) != null) {
stats[0] = Long.parseLong(line);
stats[1] = Long.parseLong(line2);
}
br1.close();
br2.close();
} catch (Exception e) {
e.printStackTrace();
Log.e("getStat: ", e.getMessage());
}
return stats;
}
//将字节数转化为MB
public static String byteToMB(long size) {
long kb = 1024;
long mb = kb * 1024;
long gb = mb * 1024;
if (size >= gb) {
return String.format("%.1f GB", (float) size / gb);
} else if (size >= mb) {
float f = (float) size / mb;
return String.format(f > 100 ? "%.0f MB" : "%.1f MB", f);
} else if (size > kb) {
float f = (float) size / kb;
return String.format(f > 100 ? "%.0f KB" : "%.1f KB", f);
} else {
return String.format("%d B", size);
}
}
}

View File

@@ -53,7 +53,6 @@ import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.aoleyun.sn.BuildConfig;
import com.aoleyun.sn.base.BaseApplication;
import com.aoleyun.sn.bean.AppListInfo;
import com.aoleyun.sn.bean.Appground;
import com.aoleyun.sn.bean.BaseResponse;
@@ -108,16 +107,21 @@ public class JGYUtils {
private Context mContext;
private ContentResolver crv;
public static int MTKPlatform = 1;
public static int ZhanruiPlatform = 2;
public static int UnknowPlatform = 0;
public static String MTKTag = "MTK";
public static String ZhanruiTag = "展锐cube";
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 CacheHelper cacheHelper;
static {
System.loadLibrary("jgy");
}
@@ -147,6 +151,74 @@ public class JGYUtils {
public static native String getAuthorization();
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);
@@ -1591,67 +1663,6 @@ public class JGYUtils {
}
}
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 {
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 {
getAppPlatformCallback.AppPlatform(UnknowPlatform);
}
}
public String getAppPlatform() {
String platform = BuildConfig.platform;
if ("MTK".equalsIgnoreCase(platform)) {
return MTKTag;
} else if ("ZhanRui".equalsIgnoreCase(platform)) {
return ZhanruiTag;
} else {
return Other;
}
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void cleanBackgroundMemory() {
ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
@@ -1885,8 +1896,16 @@ public class JGYUtils {
private String Launcher3 = "com.android.launcher3";
private String Launcher3Class = "com.android.launcher3.Launcher";
public void checkDefaultDesktop(String pkg) {
String desktopPkg = (String) SPUtils.get(mContext, "default_launcher", "");
if (desktopPkg.equalsIgnoreCase(pkg)) {
setDefaultDesktop(pkg);
}
}
//设置默认桌面
public void setDefaultDesktop(String pkg) {
Log.e(TAG, "setDefaultDesktop: " + pkg);
if (TextUtils.isEmpty(pkg)) {
openLauncher3();
} else {
@@ -2069,4 +2088,47 @@ public class JGYUtils {
wakeUpAppstore();
wakeUpNotify();
}
public static String getModel() {
Log.e(TAG, "MANUFACTURER=" + Build.MANUFACTURER);
Log.e(TAG, "BRAND=" + Build.BRAND);
Log.e(TAG, "MODEL=" + Build.MODEL);
Log.e(TAG, "VERSION.RELEASE=" + Build.VERSION.RELEASE);
Log.e(TAG, "VERSION.SDK_INT=" + Build.VERSION.SDK_INT);
Log.e(TAG, "DEVICE=" + Build.DEVICE);
Log.e(TAG, "HOST=" + Build.HOST);
Log.e(TAG, "ID=" + Build.ID);
Log.e(TAG, "TIME=" + Build.TIME);
Log.e(TAG, "TYPE=" + Build.TYPE);
Log.e(TAG, "PRODUCT=" + Build.PRODUCT);
Log.e(TAG, "BOARD=" + Build.BOARD);
Log.e(TAG, "DISPLAY=" + Build.DISPLAY);
Log.e(TAG, "FINGERPRINT=" + Build.FINGERPRINT);
Log.e(TAG, "HARDWARE=" + Build.HARDWARE);
Log.e(TAG, "BOOTLOADER=" + Build.BOOTLOADER);
Log.e(TAG, "TAGS=" + Build.TAGS);
Log.e(TAG, "UNKNOWN=" + Build.UNKNOWN);
Log.e(TAG, "USER=" + Build.USER);
return Build.MODEL;
}
private static String MTK_HARDWARE = "mtk";
private static String UNISOC_HARDWARE = "ums";
private static String AIHUA_BRAND = "AS";
private static String CUBE_BRAND = "ALLDOCUBE";
public static String getHardware() {
return Build.HARDWARE;
}
public static boolean isAihuaDevice() {
return getHardware().startsWith(MTK_HARDWARE) && Build.BRAND.startsWith(AIHUA_BRAND);
}
public static boolean isCubeDevice() {
return getHardware().startsWith(UNISOC_HARDWARE) && Build.BRAND.equalsIgnoreCase(CUBE_BRAND);
}
}

View File

@@ -115,8 +115,8 @@ public class SysSettingUtils {
// ToastTool.show("qch_call_forbid::"+setting_call+"----setting_phones::"+setting_phones+"----"+qch_white_list_Array+"---"+qch_call_forbid);
Log.e(TAG, "qch_white_list_Array:" + qch_white_list_Array + "---" + qch_white_list_Array);
boolean qch_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_sdcard_forbid_on", state);
Log.e(TAG, "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on);
boolean aole_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), "aole_sdcard_forbid_on", state);
Log.e(TAG, "aole_sdcard_forbid_on:" + aole_sdcard_forbid_on);
} catch (Exception e) {
Log.e(TAG, "setPhoneList: " + e.getMessage());
}
@@ -146,8 +146,8 @@ public class SysSettingUtils {
}
//存储卡
int setting_memory = changeNum(jsonObject.getInteger("setting_memory"));
boolean qch_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_sdcard_forbid_on", setting_memory);
Log.e(TAG, "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on);
boolean aole_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), "aole_sdcard_forbid_on", setting_memory);
Log.e(TAG, "aole_sdcard_forbid_on:" + aole_sdcard_forbid_on);
} catch (Exception e) {
Log.e(TAG, "setPhoneList: " + e.getMessage());
}
@@ -180,26 +180,36 @@ public class SysSettingUtils {
//Midi模式usb_midi
String setting_usb = jsonObject.getString("setting_usb");
if (!BuildConfig.DEBUG) {
SuperPower mService = (SuperPower) context.getSystemService("mdm");
boolean aole_usb_choose = Settings.System.putString(context.getContentResolver(), "aole_usb_choose", setting_usb);
Log.e("setUSBstate", "aole_usb_choose---------" + aole_usb_choose);
String usbStatus = "";
switch (setting_usb) {
case "usb_charge":
mService.setUSBDataDisabled(true);
usbStatus = "aole_action_usb_usb_charge";
break;
case "usb_mtp":
mService.setUSBDataDisabled(false);
usbStatus = "aole_action_usb_usb_mtp";
break;
case "usb_midi":
usbStatus = "aole_action_usb_usb_midi";
break;
if (JGYUtils.isCubeDevice()) {
SuperPower mService = (SuperPower) context.getSystemService("mdm");
switch (setting_usb) {
case "usb_charge":
mService.setUSBDataDisabled(true);
break;
case "usb_mtp":
mService.setUSBDataDisabled(false);
break;
default:
}
} else {
boolean aole_usb_choose = Settings.System.putString(context.getContentResolver(), "aole_usb_choose", setting_usb);
Log.e("setUSBstate", "aole_usb_choose---------" + aole_usb_choose);
String usbStatus = "aole_action_usb_usb_charge";
switch (setting_usb) {
case "usb_charge":
usbStatus = "aole_action_usb_usb_charge";
break;
case "usb_mtp":
usbStatus = "aole_action_usb_usb_mtp";
break;
case "usb_midi":
usbStatus = "aole_action_usb_usb_midi";
break;
default:
}
Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings");
context.sendBroadcast(usbIntent);
}
Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings");
context.sendBroadcast(usbIntent);
}
}
@@ -597,21 +607,21 @@ public class SysSettingUtils {
}
private static void setCanReset(Context context, int state) {
boolean qch_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_restore_forbid_on", 0);
Log.e(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on);
boolean aole_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "aole_restore_forbid_on", 0);
Log.e(TAG, "aole_restore_forbid_on:" + aole_restore_forbid_on);
//默认打开
}
//qch_restore_forbid_on=1禁止恢复出厂设置
//qch_restore_forbid_on=0允许恢复出厂设置
//aole_restore_forbid_on=1禁止恢复出厂设置
//aole_restore_forbid_on=0允许恢复出厂设置
private static void setCanReset(Context context, JSONObject jsonObject) {
int mode = jsonObject.getInteger("qch_restore");
if (mode == 1) {
boolean qch_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_restore_forbid_on", 0);
Log.e(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on);
boolean aole_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "aole_restore_forbid_on", 0);
Log.e(TAG, "aole_restore_forbid_on:" + aole_restore_forbid_on);
} else {
boolean qch_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_restore_forbid_on", 1);
Log.e(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on);
boolean aole_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "aole_restore_forbid_on", 1);
Log.e(TAG, "aole_restore_forbid_on:" + aole_restore_forbid_on);
}
}

View File

@@ -172,11 +172,12 @@ public class Utils {
}
public static String getAndroid10MAC(Context context) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
return getMacAddress(context);
} else {
return getAndroid7MAC();
}
// if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
// return getMacAddress(context);
// } else {
// return getAndroid7MAC();
// }
return getAllMacAddress(context);
}
/**
@@ -284,6 +285,95 @@ public class Utils {
return builder.toString();
}
/**
* 获取MAC地址
*
* @param context
* @return
*/
public static String getAllMacAddress(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return getMacDefault(context);
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
return getMacAddressM();
} else {
return getMacFromHardware();
}
}
/**
* Android 6.0 之前不包括6.0
*
* @param context
* @return
*/
private static String getMacDefault(Context context) {
String mac = "未获取到设备Mac地址";
if (context == null) {
return mac;
}
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = null;
try {
info = wifi.getConnectionInfo();
} catch (Exception e) {
e.printStackTrace();
}
if (info == null) {
return mac;
}
mac = info.getMacAddress();
if (!TextUtils.isEmpty(mac)) {
mac = mac.toUpperCase(Locale.ENGLISH);
}
return mac;
}
/**
* Android 6.0(包括) - Android 7.0(不包括)
*
* @return
*/
private static String getMacAddressM() {
String mac = "未获取到设备Mac地址";
try {
mac = new BufferedReader(new FileReader("/sys/class/net/wlan0/address")).readLine();
} catch (IOException e) {
e.printStackTrace();
}
return mac;
}
/**
* 遍历循环所有的网络接口,找到接口是 wlan0
*
* @return
*/
private static String getMacFromHardware() {
try {
List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface nif : all) {
if (!nif.getName().equalsIgnoreCase("wlan0")) {
continue;
}
byte[] macBytes = nif.getHardwareAddress();
StringBuilder res1 = new StringBuilder();
for (byte b : macBytes) {
res1.append(String.format("%02X:", b));
}
if (res1 != null) {
res1.deleteCharAt(res1.length() - 1);
}
return res1.toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return "未获取到设备Mac地址";
}
// MD5 设备地址标识
public static String getMD5(Context context) {
@@ -1593,17 +1683,33 @@ public class Utils {
return Formatter.formatFileSize(context, availableSize);
}
/**
* 获取自定义版本号 或者版本号
* @return
*/
public static String getCustomVersion() {
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
return Utils.getProperty("ro.build.display.id", "获取失败");
} else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.CubePlatform) {
return Utils.getProperty("ro.build.display.id", "获取失败");
} else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.MTKPlatform) {
return Utils.getProperty("ro.build.display.id", "获取失败");
} else {
return Utils.getProperty("ro.custom.build.version", "获取失败");
}
}
/**
* 获取系统版本号
* @return
*/
public static String getRomVersion() {
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
return getProperty("ro.build.id", "获取失败");
}else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.CubePlatform) {
return Utils.getProperty("ro.build.id", "获取失败");
} else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.MTKPlatform) {
return Utils.getProperty("ro.build.id", "获取失败");
} else {
return getProperty("ro.build.display.id", "获取失败");
}
@@ -1719,6 +1825,69 @@ public class Utils {
}
}
/**
* 当前充电电流 mA
* <p>
* adb shell "cat /sys/class/power_supply/battery/BatteryAverageCurrent"
*/
public static int getCurrentChargingCurrent() {
int result = 0;
BufferedReader br = null;
try {
String line;
br = new BufferedReader(new FileReader("/sys/class/power_supply/battery/BatteryAverageCurrent"));
if ((line = br.readLine()) != null) {
result = Integer.parseInt(line);
}
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
/**
* 当前充电电压 uV
* <p>
* adb shell "cat /sys/class/power_supply/battery/batt_vol"
*/
public static int getCurrentChargingVoltage() {
int result = 0;
BufferedReader br = null;
try {
String line;
br = new BufferedReader(new FileReader("/sys/class/power_supply/battery/batt_vol"));
if ((line = br.readLine()) != null) {
result = Integer.parseInt(line);
}
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
}