|
|
|
@ -62,6 +62,7 @@ import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Timer; |
|
|
|
import java.util.TimerTask; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.Executors; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
@ -92,6 +93,7 @@ import qianmu.container.util.BitmapUtil; |
|
|
|
import qianmu.container.util.DeviceUtil; |
|
|
|
import qianmu.container.util.FileUtil; |
|
|
|
import qianmu.container.util.LoggerUtil; |
|
|
|
import qianmu.container.util.RootCmdUtil; |
|
|
|
import qianmu.container.util.SignWayUtil; |
|
|
|
import qianmu.container.util.StringUtil; |
|
|
|
import retrofit2.Call; |
|
|
|
@ -634,66 +636,87 @@ public class MQTTService extends Service { |
|
|
|
/** |
|
|
|
* 截屏 |
|
|
|
* */ |
|
|
|
public static void screenShot(long time) { |
|
|
|
private static final ExecutorService SCREEN_SHOT_EXECUTOR = Executors.newSingleThreadExecutor(); |
|
|
|
|
|
|
|
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(SignWayUtil.getgetAndroidModle().equals("t982")){ |
|
|
|
//亿晟主板t982特殊处理上传
|
|
|
|
boolean b = SignWayUtil.ysTakeScreenshot(path); |
|
|
|
if(!b){ |
|
|
|
return; |
|
|
|
} |
|
|
|
Executors.newSingleThreadExecutor().execute(() -> { |
|
|
|
try { |
|
|
|
|
|
|
|
uploadScreenShot(path,DeviceData.getDeviceInfo(DeviceData.HINT_DEVICE_CODE),String.valueOf(time)); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
String cmd = "screencap -p " + path; |
|
|
|
Executors.newSingleThreadExecutor().execute(() -> { |
|
|
|
public static void screenShot(long time) { |
|
|
|
SCREEN_SHOT_EXECUTOR.submit(() -> { |
|
|
|
try { |
|
|
|
Process process = Runtime.getRuntime().exec("su");//不同的设备权限不一样
|
|
|
|
PrintWriter pw = new PrintWriter(process.getOutputStream()); |
|
|
|
pw.println(cmd); |
|
|
|
pw.flush(); |
|
|
|
pw.println("exit"); |
|
|
|
pw.flush(); |
|
|
|
try { |
|
|
|
process.waitFor(2500, TimeUnit.MILLISECONDS);; |
|
|
|
} catch (InterruptedException e) { |
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
pw.close(); |
|
|
|
process.destroy(); |
|
|
|
|
|
|
|
if(!new File(path).exists()){ |
|
|
|
LoggerUtil.e("screenShot","截屏失败"); |
|
|
|
if (Constant.androidBoardType.equals("nova")) { |
|
|
|
MessageEvent messageEvent = new MessageEvent(Constant.NOVA_SCREEN_SHOT); |
|
|
|
messageEvent.setData("" + time); |
|
|
|
EventBus.getDefault().post(messageEvent); |
|
|
|
return; |
|
|
|
} |
|
|
|
uploadScreenShot(path,DeviceData.getDeviceInfo(DeviceData.HINT_DEVICE_CODE),String.valueOf(time)); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
String path = StringUtil.strSplice(BitmapUtil.SAVE_SCREEN_SHOT_PATH, "/screenShot.png"); |
|
|
|
// ====================== 修复点3:子线程内安全创建file ======================
|
|
|
|
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; |
|
|
|
final int MAX_RETRY = 15; |
|
|
|
final long SLEEP_MS = 300; |
|
|
|
long lastSize = 0; |
|
|
|
|
|
|
|
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(SLEEP_MS); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
break; |
|
|
|
} |
|
|
|
retryCount++; |
|
|
|
} |
|
|
|
|
|
|
|
} 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(); |
|
|
|
} |
|
|
|
shotSuccess = new File(path).exists(); |
|
|
|
} |
|
|
|
// 上传
|
|
|
|
if (shotSuccess) { |
|
|
|
LoggerUtil.e("screenShot", "开始上传"); |
|
|
|
uploadScreenShot(path, DeviceData.getDeviceInfo(DeviceData.HINT_DEVICE_CODE), String.valueOf(time)); |
|
|
|
} else { |
|
|
|
LoggerUtil.e("screenShot", "截屏失败"); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
// ====================== 修复点6:全局捕获所有异常,绝不崩溃 ======================
|
|
|
|
LoggerUtil.e("screenShot", "截屏异常:" + e.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//上传截屏
|
|
|
|
|