version:1.4

update:2021-10-21 10:14:40
fix:
add:增加浏览器桌面检测升级,修复重复请求
This commit is contained in:
2021-12-03 14:33:03 +08:00
parent 768519e14e
commit 34fa9fcdb7
70 changed files with 3189 additions and 1503 deletions

View File

@@ -2,6 +2,8 @@ package com.aoleyun.sn.utils;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
@@ -29,6 +31,7 @@ import android.os.BatteryManager;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.os.SystemClock;
import android.provider.Settings;
import androidx.annotation.RequiresApi;
@@ -47,6 +50,7 @@ import android.widget.EditText;
import android.widget.Toast;
import com.alibaba.fastjson.JSONObject;
import com.aoleyun.sn.network.HTTPInterface;
import com.arialyy.aria.core.Aria;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.PathUtils;
@@ -88,9 +92,11 @@ import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import io.reactivex.Observable;
@@ -634,16 +640,16 @@ public class Utils {
return "";
}
//获取教管易版本号
public static synchronized String getAPPVersionName(Context context) {
//获取App版本号
public static synchronized String getAPPVersionName(String pck, Context context) {
PackageManager pm = context.getPackageManager();
String versionName;
try {
PackageInfo packageInfo = pm.getPackageInfo("com.jiaoguanyi.store", 0);
PackageInfo packageInfo = pm.getPackageInfo(pck, 0);
versionName = packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
versionName = "0";
versionName = "";
}
return versionName;
}
@@ -704,7 +710,7 @@ public class Utils {
}
} catch (Exception e) {
e.printStackTrace();
Logutils.e("e", "读取设备序列号异常:" + e.toString());
Log.e("e", "读取设备序列号异常:" + e.toString());
}
if (BuildConfig.DEBUG) {
// return "QNG2DKB00463";
@@ -759,7 +765,7 @@ public class Utils {
return String.format("%.2fGB", gbValue);
} else {
double mbValue = (double) space / A_MB;
// Logutils.e("GB", "gbvalue=" + mbValue);
// Log.e("GB", "gbvalue=" + mbValue);
if (mbValue >= 1) {
return String.format("%.2fMB", mbValue);
} else {
@@ -877,7 +883,7 @@ public class Utils {
//
// float roundPx = 15; //圆角半径
// mPaint.setAntiAlias(true);
// //Logutils.d("wy"+TAG,"mBitmap.getWidth()="+mBitmap.getWidth()+", mBitmap.getHeight()="+mBitmap.getHeight());
// //Log.d("wy"+TAG,"mBitmap.getWidth()="+mBitmap.getWidth()+", mBitmap.getHeight()="+mBitmap.getHeight());
// mCanvas.drawRoundRect(mRectF, roundPx, roundPx, mPaint);
// mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
// mCanvas.drawBitmap(mBitmap, mRect, mRect, mPaint);
@@ -996,9 +1002,9 @@ public class Utils {
list += str + ",";
}
list = list.substring(0, list.length() - 1);
Logutils.e("fht", list);
Log.e("fht", list);
writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_app_forbid", list);
Logutils.e("fht", "qch_app_forbid:" + list);
Log.e("fht", "qch_app_forbid:" + list);
} else {
writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_app_forbid", "Invalid");
}
@@ -1042,22 +1048,23 @@ public class Utils {
public static void ariaDownload(Context context, String url, JSONObject jsonObject) {
String fileName = getFileNamefromURL(url);
String urlMD5 = jsonObject.getString("MD5");
Logutils.e("ariaDownload", "urlMD5=" + urlMD5);
String p = PathUtils.getExternalDownloadsPath();
File file = new File(PathUtils.getExternalDownloadsPath() + "/jgy/" + fileName);
Log.e("ariaDownload", "urlMD5=" + urlMD5);
String p = JGYUtils.getInstance().getDownLoadPath();
File file = new File(JGYUtils.getInstance().getDownLoadPath() + fileName);
if (file.exists() && !file.isDirectory()) {
String filenameMD5 = getMD5fromFileName(url);
String fileMD5 = FileUtils.getFileMD5ToString(file);
Logutils.e("ariaDownload", "filenameMD5=" + filenameMD5);
Logutils.e("ariaDownload", "fileMD5=" + fileMD5);
Log.e("ariaDownload", "filenameMD5=" + filenameMD5);
Log.e("ariaDownload", "fileMD5=" + fileMD5);
//后端还没有完成json字段的MD5,暂时用文件名获取
if (fileMD5.equalsIgnoreCase(urlMD5)) {
ApkUtils.installApp(context, file.getAbsolutePath());
} else {
Aria.download(context)
.load(url) //读取下载地址
.setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + fileName, true)
.setFilePath(JGYUtils.getInstance().getDownLoadPath() + fileName)
.ignoreFilePathOccupy()
.setExtendField(jsonObject.toJSONString())
.create(); //启动下载}
// SaveListUtils.addDownLoadList(app_package);
@@ -1066,11 +1073,11 @@ public class Utils {
} else {
Aria.download(context)
.load(url) //读取下载地址
.setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + fileName, true)
.setFilePath(JGYUtils.getInstance().getDownLoadPath() + fileName)
.ignoreFilePathOccupy()
.setExtendField(jsonObject.toJSONString())
.create(); //启动下载}
}
}
/**
@@ -1098,15 +1105,15 @@ public class Utils {
@Override
public void onNext(Integer integer) {
if (integer == 0) {
Logutils.e("doss", "成功");
Log.e("doss", "成功");
} else {
Logutils.e("doss", "失败");
Log.e("doss", "失败");
}
}
@Override
public void onError(Throwable e) {
Logutils.e("doss", "Throwable=" + e.getMessage());
Log.e("doss", "Throwable=" + e.getMessage());
}
@Override
@@ -1117,12 +1124,12 @@ public class Utils {
// new Thread(new Runnable() {
// @Override
// public void run() {
// Logutils.e("whh0914", "开始屏幕截图...");
// Log.e("whh0914", "开始屏幕截图...");
// String filepath = context.getFileStreamPath("screenshot").getAbsolutePath();
// try {
// CmdUtil.execute("screencap -p " + filepath);
// } catch (Exception e) {
// Logutils.e("whh0914", "屏幕截图出现异常:" + e.toString());
// Log.e("whh0914", "屏幕截图出现异常:" + e.toString());
// }
// }
// }).start();
@@ -1172,12 +1179,12 @@ public class Utils {
int screenWidth = (int) (width / density); // 屏幕宽度(dp)
int screenHeight = (int) (height / density);// 屏幕高度(dp)
// Logutils.e("h_bl", "屏幕宽度(像素):" + width);
// Logutils.e("h_bl", "屏幕高度(像素):" + height);
// Logutils.e("h_bl", "屏幕密度(0.75 / 1.0 / 1.5):" + density);
// Logutils.e("h_bl", "屏幕密度dpi(120 / 160 / 240):" + densityDpi);
// Logutils.e("h_bl", "屏幕宽度(dp):" + screenWidth);
// Logutils.e("h_bl", "屏幕高度(dp):" + screenHeight);
// Log.e("h_bl", "屏幕宽度(像素):" + width);
// Log.e("h_bl", "屏幕高度(像素):" + height);
// Log.e("h_bl", "屏幕密度(0.75 / 1.0 / 1.5):" + density);
// Log.e("h_bl", "屏幕密度dpi(120 / 160 / 240):" + densityDpi);
// Log.e("h_bl", "屏幕宽度(dp):" + screenWidth);
// Log.e("h_bl", "屏幕高度(dp):" + screenHeight);
return width + "×" + height;
}
@@ -1223,14 +1230,14 @@ public class Utils {
// IMEI = (String) method.invoke(TelephonyMgr);
// } catch (Exception e) {
// e.printStackTrace();
// Logutils.e("getIMEI", e.getMessage());
// Log.e("getIMEI", e.getMessage());
// }
// IMEI = TelephonyMgr.getDeviceId();
// } else {//9.0到10.0获取
IMEI = Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
Logutils.e("IMEI:", "IMEI: " + IMEI);
Log.e("IMEI:", "IMEI: " + IMEI);
if (null == IMEI) {
return "-";
} else {
@@ -1253,8 +1260,12 @@ public class Utils {
jsonObject.put("firmware_version", firmware_version);
jsonObject.put("rom", rom);
jsonObject.put("screen_rate", screen_rate);
jsonObject.put("working_time", SystemClock.elapsedRealtime() / 1000);
jsonObject.put("restart_count", SPUtils.get(context, "restart_count", 0));
jsonObject.put("storage_usable", getRemnantSize(context));
jsonObject.put("storage_total", getDataTotalSize(context));
String jsonString = jsonObject.toJSONString();
Logutils.e(TAG, "getMachine: " + jsonString);
Log.e(TAG, "getMachine: " + jsonString);
return jsonString;
}
@@ -1263,7 +1274,7 @@ public class Utils {
int electric = getBattery(context);
int charging = getIsCharging(context);
String memory = Formatter.formatFileSize(context, getFreeMemory(context)) + "\t 已用" + "/" + "共" + Formatter.formatFileSize(context, getTotalMemory(context));
Logutils.e("getHardware", "Memory: " + memory);
Log.e("getHardware", "Memory: " + memory);
String storage = getRemnantSize(context) + "/" + getDataTotalSize(context);
int CPU = getNumCores();
JSONObject jsonObject = new JSONObject();
@@ -1273,7 +1284,7 @@ public class Utils {
jsonObject.put("storage", storage);
jsonObject.put("CPU", CPU + "核");
String jsonString = jsonObject.toJSONString();
Logutils.e(TAG, "getHardware: " + jsonString);
Log.e(TAG, "getHardware: " + jsonString);
return jsonString;
}
@@ -1309,7 +1320,7 @@ public class Utils {
BatteryManager batteryManager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
} catch (Exception e) {
Logutils.e("getBattery", "getBattery" + e.getMessage());
Log.e("getBattery", "getBattery" + e.getMessage());
}
return 0;
}
@@ -1370,7 +1381,7 @@ public class Utils {
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
long freeMem = memoryInfo.totalMem - memoryInfo.availMem;
// Logutils.e("getHardware", "getFreeMemory: " + freeMem);
// Log.e("getHardware", "getFreeMemory: " + freeMem);
return freeMem;
}
@@ -1383,7 +1394,7 @@ public class Utils {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
// Logutils.e("getHardware", "getFreeMemory: " + memoryInfo.totalMem);
// Log.e("getHardware", "getFreeMemory: " + memoryInfo.totalMem);
return memoryInfo.totalMem;
}
@@ -1456,13 +1467,13 @@ public class Utils {
long totalSize = statFs.getTotalBytes();
long availableSize = statFs.getAvailableBytes();
Logutils.e("statfs", "total = " + getUnit(totalSize));
Logutils.e("statfs", "availableSize = " + getUnit(availableSize));
Log.e("statfs", "total = " + getUnit(totalSize));
Log.e("statfs", "availableSize = " + getUnit(availableSize));
//这里可以看出 available 是小于 free ,free 包括保留块。
Logutils.e("statfs", "total = " + getUnit(blockSize * blockCount));
Logutils.e("statfs", "available = " + getUnit(blockSize * availableCount));
Logutils.e("statfs", "free = " + getUnit(blockSize * freeBlocks));
Log.e("statfs", "total = " + getUnit(blockSize * blockCount));
Log.e("statfs", "available = " + getUnit(blockSize * availableCount));
Log.e("statfs", "free = " + getUnit(blockSize * freeBlocks));
}
@@ -1541,5 +1552,86 @@ public class Utils {
}
return "获取失败";
}
/**
* 获取公网IP并保存
*
* @param context
*/
public static void getPublicIP(Context context) {
HTTPInterface.getPublicIP(context, new HTTPInterface.PublicIP() {
@Override
public void set(String ip) {
SPUtils.put(context, "PublicIP", ip);
Log.e("getPublicIP", "set: " + ip);
}
});
}
/**
* 获取WiFi信号强度
*
* @param context
* @return
*/
public static int obtainWifiInfo(Context context) {
// Wifi的连接速度及信号强度:
WifiManager wifiManager = (WifiManager) context.getSystemService(WIFI_SERVICE);
// WifiInfo wifiInfo = wifiManager.getConnectionInfo();
WifiInfo info = wifiManager.getConnectionInfo();
if (info.getBSSID() != null) {
// 链接信号强度
int strength = WifiManager.calculateSignalLevel(info.getRssi(), 5);
// 链接速度
int speed = info.getLinkSpeed();
// 链接速度单位
String units = WifiInfo.LINK_SPEED_UNITS;
// Wifi源名称
String ssid = info.getSSID();
int RSSI = info.getRssi();
return RSSI;
} else {
return 0;
}
}
public static String getWifiAlias(Context context) {
WifiManager wifiManager = (WifiManager) context.getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo.getSSID() == null) {
return "WiFi未连接";
} else {
Log.e(TAG, "getWifiAlias: " + wifiInfo.getSSID());
return wifiInfo.getSSID();
}
}
public static String getBluetoothList() {
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
return "没有蓝牙设备";
} else {
if (!bluetoothAdapter.isEnabled())//判断蓝牙设备是否已开起
{
return "蓝牙未开启";
// //开起蓝牙设备
// Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
// context.startActivity(intent);
} else {
Set<BluetoothDevice> devices = bluetoothAdapter.getBondedDevices();
StringBuilder stringBuilder = new StringBuilder();
for (Iterator<BluetoothDevice> iterator = devices.iterator(); iterator.hasNext(); ) {
BluetoothDevice device = iterator.next();
stringBuilder.append(device.getAlias()).append(";");
}
Log.e(TAG, "getBluetoothList: " + stringBuilder.toString());
return stringBuilder.toString();
}
}
}
}