|
|
|
@ -657,138 +657,81 @@ public class MQTTService extends Service { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 截屏 |
|
|
|
* */ |
|
|
|
public static void screenShot(long time) { |
|
|
|
|
|
|
|
if(Constant.androidBoardType.equals("nova")){ |
|
|
|
MessageEvent messageEvent = new MessageEvent(Constant.NOVA_SCREEN_SHOT); |
|
|
|
messageEvent.setData(""+time); |
|
|
|
EventBus.getDefault().post(messageEvent); |
|
|
|
return; |
|
|
|
} |
|
|
|
String path = StringUtil.strSplice(BitmapUtil.SAVE_SCREEN_SHOT_PATH, "/screenShot.png"); |
|
|
|
File file = new File(path); |
|
|
|
File parent = file.getParentFile(); |
|
|
|
if (!parent.exists()) parent.mkdirs(); |
|
|
|
if (file.exists()) file.delete(); |
|
|
|
|
|
|
|
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); |
|
|
|
try { |
|
|
|
Future<Boolean> screenshotFuture = null; |
|
|
|
//亿晟主板t982特殊处理上传
|
|
|
|
if(SignWayUtil.getgetAndroidModle().equals("t982")){ |
|
|
|
screenshotFuture = singleThreadExecutor.submit(() -> |
|
|
|
SignWayUtil.ysTakeScreenshot(path) |
|
|
|
); |
|
|
|
}else if(!"".equals(Constant.androidBoardType)){ |
|
|
|
screenshotFuture = singleThreadExecutor.submit(() -> { |
|
|
|
private static final ExecutorService SCREEN_SHOT_EXECUTOR = Executors.newSingleThreadExecutor(); |
|
|
|
public static void screenShot(long time) { |
|
|
|
SCREEN_SHOT_EXECUTOR.submit(() -> { |
|
|
|
try { |
|
|
|
if (Constant.androidBoardType.equals("nova")) { |
|
|
|
MessageEvent messageEvent = new MessageEvent(Constant.NOVA_SCREEN_SHOT); |
|
|
|
messageEvent.setData("" + time); |
|
|
|
EventBus.getDefault().post(messageEvent); |
|
|
|
return; |
|
|
|
} |
|
|
|
String path = StringUtil.strSplice(BitmapUtil.SAVE_SCREEN_SHOT_PATH, "/screenShot.png"); |
|
|
|
File file = new File(path); |
|
|
|
File parent = file.getParentFile(); |
|
|
|
if (!parent.exists()) parent.mkdirs(); |
|
|
|
if (file.exists()) file.delete(); |
|
|
|
boolean shotSuccess = false; |
|
|
|
// 亿晟主板
|
|
|
|
if (SignWayUtil.getgetAndroidModle().equals("t982")) { |
|
|
|
shotSuccess = SignWayUtil.ysTakeScreenshot(path); |
|
|
|
} else if (!"".equals(Constant.androidBoardType)) { |
|
|
|
SignWayUtil.takeScreenshot(path); |
|
|
|
int retryCount = 0; |
|
|
|
boolean isSuccess = false; |
|
|
|
final int MAX_RETRY = 15; |
|
|
|
final long SLEEP_MS = 300; |
|
|
|
long lastSize = 0; |
|
|
|
while (retryCount < 20) { // 最多5秒超时
|
|
|
|
if (file.exists()) { |
|
|
|
long currentSize = file.length(); |
|
|
|
// 关键:文件大小 2 次都不变 → 真正写完
|
|
|
|
if (currentSize > 0 && currentSize == lastSize) { |
|
|
|
LoggerUtil.e("screenShot","截屏完成"); |
|
|
|
isSuccess = true; |
|
|
|
break; |
|
|
|
while (retryCount < MAX_RETRY) { |
|
|
|
File f = new File(path); |
|
|
|
if (f.exists()) { |
|
|
|
long currentSize = f.length(); |
|
|
|
if (currentSize > 1024) { |
|
|
|
if (currentSize == lastSize) { |
|
|
|
LoggerUtil.e("screenShot", "截屏完成"); |
|
|
|
shotSuccess = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
lastSize = currentSize; |
|
|
|
} |
|
|
|
try { |
|
|
|
Thread.sleep(300); |
|
|
|
Thread.sleep(SLEEP_MS); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
break; |
|
|
|
} |
|
|
|
retryCount++; |
|
|
|
} |
|
|
|
return isSuccess; |
|
|
|
}); |
|
|
|
}else if(RootCmdUtil.checkSuCommand()){ //root
|
|
|
|
LoggerUtil.e("screenShot","root截屏"); |
|
|
|
screenshotFuture = singleThreadExecutor.submit(() -> { |
|
|
|
String[] cmd = new String[]{"su", "-c", "screencap -p " + path}; |
|
|
|
} else { |
|
|
|
LoggerUtil.e("screenShot", "root截屏"); |
|
|
|
String[] cmd = {"su", "-c", "screencap -p " + path}; |
|
|
|
Process process = Runtime.getRuntime().exec(cmd); |
|
|
|
BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); |
|
|
|
String line; |
|
|
|
while ((line = errorReader.readLine()) != null) { |
|
|
|
LoggerUtil.e("screenShot", "error: " + line); |
|
|
|
} |
|
|
|
boolean finished = process.waitFor(3, TimeUnit.SECONDS); |
|
|
|
if (!finished) { |
|
|
|
process.destroyForcibly(); |
|
|
|
return false; |
|
|
|
} |
|
|
|
if(new File(path).exists()){ |
|
|
|
LoggerUtil.e("screenShot","截屏完成"); |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
}); |
|
|
|
}else{ |
|
|
|
screenshotFuture = singleThreadExecutor.submit(() -> { |
|
|
|
Bitmap screenBitmap = null; |
|
|
|
View decorView = MyApplication.getInstance().getCurrentActivity().getWindow().getDecorView(); |
|
|
|
if(decorView != null){ |
|
|
|
//调用截屏
|
|
|
|
try { |
|
|
|
decorView.setDrawingCacheEnabled(true); |
|
|
|
decorView.buildDrawingCache(); |
|
|
|
screenBitmap = Bitmap.createBitmap(decorView.getWidth(), decorView.getHeight(), Bitmap.Config.ARGB_8888); |
|
|
|
Canvas canvas = new Canvas(screenBitmap); |
|
|
|
decorView.draw(canvas); |
|
|
|
decorView.setDrawingCacheEnabled(false); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
//保存
|
|
|
|
if(screenBitmap != null){ |
|
|
|
try (FileOutputStream fos = new FileOutputStream(file)) { |
|
|
|
screenBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); |
|
|
|
fos.flush(); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
screenBitmap.recycle(); |
|
|
|
if(new File(path).exists()){ |
|
|
|
LoggerUtil.e("screenShot","截屏完成"); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if (!screenshotFuture.get(10, TimeUnit.SECONDS)) { // 添加超时时间
|
|
|
|
LoggerUtil.e("screenShot","截屏失败"); |
|
|
|
return; |
|
|
|
} |
|
|
|
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 { |
|
|
|
LoggerUtil.e("screenShot","截屏失败"); |
|
|
|
singleThreadExecutor.shutdown(); |
|
|
|
try { |
|
|
|
if (!singleThreadExecutor.awaitTermination(5, TimeUnit.SECONDS)) { |
|
|
|
singleThreadExecutor.shutdownNow(); |
|
|
|
shotSuccess = new File(path).exists(); |
|
|
|
} |
|
|
|
} catch (InterruptedException e) { |
|
|
|
singleThreadExecutor.shutdownNow(); |
|
|
|
Thread.currentThread().interrupt(); |
|
|
|
// 上传
|
|
|
|
if (shotSuccess) { |
|
|
|
LoggerUtil.e("screenShot", "开始上传"); |
|
|
|
uploadScreenShot(path, DeviceData.getDeviceInfo(DeviceData.HINT_DEVICE_CODE), String.valueOf(time)); |
|
|
|
} else { |
|
|
|
LoggerUtil.e("screenShot", "截屏失败"); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
LoggerUtil.e("screenShot", "截屏异常:" + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
//上传截屏
|
|
|
|
public static void uploadScreenShot(String filePath,String code,String timestamp) { |
|
|
|
|
|
|
|
File file = new File(filePath); |
|
|
|
if (!file.exists()||code.isEmpty()) return; |
|
|
|
if(SignWayUtil.getgetAndroidModle().equals("t982")){ |
|
|
|
@ -807,13 +750,11 @@ public class MQTTService extends Service { |
|
|
|
public void onResponse(Call<Resp> call, Response<Resp> response) { |
|
|
|
LoggerUtil.e("uploadScreenShot", new Gson().toJson(response.body())); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<Resp> call, Throwable t) { |
|
|
|
LoggerUtil.e("uploadScreenShot", StringUtil.getThrowableStr(t)); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|