Browse Source

fix: ci

master
高志龙 7 months ago
parent
commit
cdfb147646
  1. 2
      app/src/main/java/qianmu/container/activity/device/DeviceInfoActivity.java
  2. 2
      app/src/main/java/qianmu/container/app/MyApplication.java
  3. 89
      app/src/main/java/qianmu/container/mqtt/MQTTService.java
  4. 133
      app/src/main/java/qianmu/container/util/DeviceUtil.java
  5. 5
      app/src/main/java/qianmu/container/util/SignWayUtil.java

2
app/src/main/java/qianmu/container/activity/device/DeviceInfoActivity.java

@ -104,7 +104,7 @@ public class DeviceInfoActivity extends BaseActivity {
ActivityCompat.requestPermissions(this,new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO,
Manifest.permission.RECEIVE_BOOT_COMPLETED,

2
app/src/main/java/qianmu/container/app/MyApplication.java

@ -240,7 +240,7 @@ public class MyApplication extends Application {
stopService(new Intent(this, MusicService.class));// 背景音乐
}
try {
Thread.sleep(1000);
Thread.sleep(6000);
SignWayUtil.reboot();
} catch (InterruptedException e) {
e.printStackTrace();

89
app/src/main/java/qianmu/container/mqtt/MQTTService.java

@ -68,6 +68,8 @@ import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLContext;
@ -649,45 +651,66 @@ public class MQTTService extends Service {
File parent = file.getParentFile();
if (!parent.exists()) parent.mkdirs();
if(SignWayUtil.getgetAndroidModle().equals("t982")){
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
try {
Future<Boolean> screenshotFuture = null;
//亿晟主板t982特殊处理上传
boolean b = SignWayUtil.ysTakeScreenshot(path);
if(!b){
if(SignWayUtil.getgetAndroidModle().equals("t982")){
screenshotFuture = singleThreadExecutor.submit(() ->
SignWayUtil.ysTakeScreenshot(path)
);
}else{
screenshotFuture = singleThreadExecutor.submit(() -> {
View decorView = MyApplication.getInstance().getCurrentActivity().getWindow().getDecorView();
decorView.setDrawingCacheEnabled(true);
decorView.buildDrawingCache();
Bitmap bmp = decorView.getDrawingCache();
Rect frame = new Rect();
decorView.getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
Bitmap screenBitmap = Bitmap.createBitmap(bmp, 0, statusBarHeight, decorView.getWidth(), decorView.getHeight() - statusBarHeight);
decorView.setDrawingCacheEnabled(false);
//保存
try (FileOutputStream fos = new FileOutputStream(file)) {
screenBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
} catch (IOException e) {
e.printStackTrace();
}
if(new File(path).exists()){
LoggerUtil.e("screenShot","截屏完成");
return true;
}
return false;
});
}
if (!screenshotFuture.get(10, TimeUnit.SECONDS)) { // 添加超时时间
LoggerUtil.e("screenShot","截屏失败");
return;
}
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
singleThreadExecutor.execute(() -> {
try {
uploadScreenShot(path,DeviceData.getDeviceInfo(DeviceData.HINT_DEVICE_CODE),String.valueOf(time));
} catch (Exception e) {
e.printStackTrace();
}
});
Future<?> uploadFuture = singleThreadExecutor.submit(() ->
uploadScreenShot(path,
DeviceData.getDeviceInfo(DeviceData.HINT_DEVICE_CODE),
String.valueOf(time))
);
uploadFuture.get(30, TimeUnit.SECONDS); // 添加上传超时时间
} catch (Exception e) {
LoggerUtil.e("screenShot","截屏失败");
} finally {
singleThreadExecutor.shutdown();
return;
try {
if (!singleThreadExecutor.awaitTermination(5, TimeUnit.SECONDS)) {
singleThreadExecutor.shutdownNow();
}
} catch (InterruptedException e) {
singleThreadExecutor.shutdownNow();
Thread.currentThread().interrupt();
}
}
View decorView = MyApplication.getInstance().getCurrentActivity().getWindow().getDecorView();
decorView.setDrawingCacheEnabled(true);
decorView.buildDrawingCache();
Bitmap bmp = decorView.getDrawingCache();
Rect frame = new Rect();
decorView.getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
Bitmap screenBitmap = Bitmap.createBitmap(bmp, 0, statusBarHeight, decorView.getWidth(), decorView.getHeight() - statusBarHeight);
decorView.setDrawingCacheEnabled(false);
//保存
try (FileOutputStream fos = new FileOutputStream(file)) {
screenBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
} catch (IOException e) {
e.printStackTrace();
}
if(!new File(path).exists()){
LoggerUtil.e("screenShot","截屏失败");
return;
}
uploadScreenShot(path,DeviceData.getDeviceInfo(DeviceData.HINT_DEVICE_CODE),String.valueOf(time));
//
}
//上传截屏

133
app/src/main/java/qianmu/container/util/DeviceUtil.java

@ -1,5 +1,6 @@
package qianmu.container.util;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.Service;
@ -13,10 +14,14 @@ import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.Log;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
@ -157,15 +162,16 @@ public class DeviceUtil {
public static String getMacFromHardware() {
String mac= "";
try {
String Localmac = getLocalMacAddressFromIp();
String Localmac = getLocalMacAddress();
if(Localmac!= null && !Localmac.equals("")){
mac = Localmac.toLowerCase();
}else{
mac = getWifiMacAddress();
}
LoggerUtil.e("mac获取","mac:"+mac);
} catch (Exception e) {
mac="";
LoggerUtil.e("mac获取","mac获取失败"+e.getMessage());
}
return mac;
}
@ -174,7 +180,7 @@ public class DeviceUtil {
* 根据IP地址获取MAC地址
* @return
*/
public static String getLocalMacAddressFromIp() {
public static String getLocalMacAddress() {
String macAddress="";
macAddress = getMacFromNetworkInterface("wlan0");
if (!StringUtil.isEmpty(macAddress)) {
@ -183,34 +189,123 @@ public class DeviceUtil {
macAddress = getMacFromNetworkInterface("eth0");
if (!StringUtil.isEmpty(macAddress)) {
return macAddress;
}else{
macAddress = getLocalMacAddressFromIp();
}
return macAddress;
}
public static String getMacFromNetworkInterface(String interfaceName) {
try {
for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
if (interfaceName.equalsIgnoreCase(networkInterface.getName())) {
byte[] macBytes = networkInterface.getHardwareAddress();
if (macBytes != null) {
StringBuilder sb = new StringBuilder();
for (byte b : macBytes) {
sb.append(String.format("%02X:", b));
}
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1);
}
return sb.toString();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
/**
* 通过网络接口获取MAC地址备选方案
* 获取系统属性
*/
private static String getMacFromNetworkInterface(String interfaceName) {
private static String getSystemProperty(String key) {
try {
NetworkInterface networkInterface = NetworkInterface.getByName(interfaceName);
if (networkInterface == null) {
return "";
}
byte[] macBytes = networkInterface.getHardwareAddress();
if (macBytes == null) {
return "";
Class<?> systemProperties = Class.forName("android.os.SystemProperties");
Method getMethod = systemProperties.getMethod("get", String.class);
return (String) getMethod.invoke(null, key);
} catch (Exception e) {
return "";
}
}
/**
* 验证MAC地址格式
*/
private static boolean isValidMacAddress(String mac) {
if (StringUtil.isEmpty(mac)) {
return false;
}
// MAC地址正则表达式
String macPattern = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$";
return mac.matches(macPattern);
}
/**
* 格式化MAC地址
*/
private static String formatMacAddress(String mac) {
if (StringUtil.isEmpty(mac)) {
return "";
}
// 移除所有分隔符
String cleanMac = mac.replace(":", "").replace("-", "").replace(" ", "");
// 重新格式化为冒号分隔
if (cleanMac.length() == 12) {
StringBuilder formatted = new StringBuilder();
for (int i = 0; i < 12; i += 2) {
formatted.append(cleanMac.substring(i, i + 2));
if (i < 10) {
formatted.append(":");
}
}
StringBuilder sb = new StringBuilder();
for (byte b : macBytes) {
sb.append(String.format("%02X:", b));
return formatted.toString().toUpperCase();
}
return mac.toUpperCase();
}
/**
* 根据IP地址获取MAC地址
* @return
*/
public static String getLocalMacAddressFromIp() {
String strMacAddr = null;
try {
//获得IpD地址
InetAddress ip = getLocalInetAddress();
LoggerUtil.e("IP: ", ip.getHostAddress());
byte[] b = NetworkInterface.getByInetAddress(ip).getHardwareAddress();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < b.length; i++) {
if (i != 0) {
buffer.append(':');
}
String str = Integer.toHexString(b[i] & 0xFF);
buffer.append(str.length() == 1 ? 0 + str : str);
}
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1);
strMacAddr = buffer.toString().toUpperCase();
} catch (Exception e) {
}
return strMacAddr;
}
@SuppressLint("HardwareIds")
public static String getWifiMacAddress() {
try {
WifiManager wifiManager = (WifiManager) MyApplication.getInstance().getSystemService(Context.WIFI_SERVICE);
if (wifiManager != null) {
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
return wifiInfo.getMacAddress();
}
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
return "";
}
return null;
}
/**
* 获取移动设备本地IP

5
app/src/main/java/qianmu/container/util/SignWayUtil.java

@ -146,7 +146,7 @@ public class SignWayUtil {
EventBus.getDefault().post(messageEvent);
}else if(Constant.androidBoardType.equals("huidu")){
HuiduTech helper = new HuiduTech(MyApplication.getInstance());
helper.install(path);
helper.installAndStart(path,"qianmu.container","qianmu.container.activity.H5.UpdateFileActivity");
}
} catch (Throwable t) {
LoggerUtil.e("silentInstallApk", StringUtil.getThrowableStr(t));
@ -298,10 +298,9 @@ public class SignWayUtil {
File file = new File(path);
File parent = file.getParentFile();
if (!parent.exists()) parent.mkdirs();
Log.e("TAG","开始截屏");
MyManager manager = MyManager.getInstance(MyApplication.getInstance());
boolean b =manager.takeScreenshot(path);
Log.e("TAG","截屏结果:"+b);
LoggerUtil.e("takeScreenshot","截屏结果:"+b);
return b;
} catch (Throwable t) {
LoggerUtil.e("takeScreenshot", StringUtil.getThrowableStr(t));

Loading…
Cancel
Save