From dd56729179a3566822cd06c8772bdfa5209188f7 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 9 Sep 2024 16:39:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=B3=BB=E7=BB=9F=E7=9B=B8?= =?UTF-8?q?=E6=9C=BA=E6=8B=8D=E7=85=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xypower/mpapp/MicroPhotoService.java | 4 +- .../java/com/xypower/mpapp/adb/CameraAdb.java | 55 +++++++++++-------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index 7e7e534e..bc3fc9f8 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -346,8 +346,8 @@ public class MicroPhotoService extends Service { cameraAdb.setCallback(new Runnable() { @Override public void run() { - String targetPath = cameraAdb.getTargetPath(); - if (!TextUtils.isEmpty(targetPath)) { + List targetPaths = cameraAdb.getTargetPaths(); + for (String targetPath : targetPaths) { mService.sendExternalPhoto(mService.mNativeHandle, targetPath); } } diff --git a/app/src/main/java/com/xypower/mpapp/adb/CameraAdb.java b/app/src/main/java/com/xypower/mpapp/adb/CameraAdb.java index 094a53f4..ee2a589c 100644 --- a/app/src/main/java/com/xypower/mpapp/adb/CameraAdb.java +++ b/app/src/main/java/com/xypower/mpapp/adb/CameraAdb.java @@ -13,7 +13,9 @@ import com.xypower.mpapp.v2.Camera2VideoActivity; import java.io.File; import java.io.FilenameFilter; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.Optional; import dadb.AdbKeyPair; @@ -27,11 +29,11 @@ public class CameraAdb { private String mAppPath; private AdbKeyPair mAdbKeyPair; private String mDeviceIp = "127.0.0.1"; - private String mTargetPath; + private List mTargetPaths = new ArrayList<>(); private Runnable mRunnable; - public String getTargetPath() { - return mTargetPath; + public List getTargetPaths() { + return mTargetPaths; } public void setCallback(Runnable runnable) { @@ -91,22 +93,28 @@ public class CameraAdb { takePhoto(false); long takingTime = System.currentTimeMillis() / 1000; sleep(1500); - movePhoto(false, requestTime, takingTime); + String path = movePhoto(false, requestTime, takingTime); + if (!TextUtils.isEmpty(path)) { + mTargetPaths.add(path); + } sleep(100); SysApi.forceStopApp(mContext, "com.mediatek.camera"); - sleep(200); + sleep(1000); requestTime = System.currentTimeMillis() / 1000; takePhoto(true); takingTime = System.currentTimeMillis() / 1000; - sleep(250); - String path = movePhoto(true, requestTime, takingTime); sleep(200); SysApi.forceStopApp(mContext, "com.mediatek.camera"); + sleep(250); + path = movePhoto(true, requestTime, takingTime); + if (!TextUtils.isEmpty(path)) { + mTargetPaths.add(path); + } if (mRunnable != null) { mRunnable.run(); } @@ -117,33 +125,36 @@ public class CameraAdb { String targetPath = null; String photoPath = mAppPath + "photos/"; String photoFile = "IMG_" + Long.toHexString(requestTime).toUpperCase() + "_" - + (frontCamera ? "2" : "1") + "_FF_0_" + Long.toHexString(requestTime).toUpperCase() + + (frontCamera ? "2" : "1") + "_FE_0_" + Long.toHexString(requestTime).toUpperCase() + "_" + Long.toHexString(takingTime).toUpperCase() + ".jpg"; File cameraPath = new File("/sdcard/DCIM/Camera/"); - Optional opFile = Arrays.stream(cameraPath.listFiles(File::isFile)) + boolean res = false; + for (int idx = 0; idx < 10; idx++) { + + Optional opFile = Arrays.stream(cameraPath.listFiles(File::isFile)) .max((f1, f2) -> Long.compare(f1.lastModified(), f2.lastModified())); - boolean res = false; - if (opFile.isPresent()) { - File targetFile = new File(new File(photoPath), photoFile); - try { - File srcFile = opFile.get(); - for (int idx = 0; idx < 10; idx++) { + if (opFile.isPresent()) { + File targetFile = new File(new File(photoPath), photoFile); + try { + File srcFile = opFile.get(); + res = srcFile.renameTo(targetFile); if (res) { targetPath = targetFile.getAbsolutePath(); break; } - sleep(200); + } catch (Exception e) { + e.printStackTrace(); } - } catch (Exception e) { - e.printStackTrace(); - } - if (!res) { - Log.e(TAG, "Failed to copy photo from Camera"); } + sleep(200); + } + + if (!res) { + Log.e(TAG, "Failed to copy photo from Camera"); } return targetPath; @@ -158,7 +169,7 @@ public class CameraAdb { } public void takePhoto(final boolean frontCamera) { - Dadb adb = Dadb.discover(mDeviceIp, mAdbKeyPair); + Dadb adb = Dadb.create(mDeviceIp, 5555, mAdbKeyPair); if (adb == null) { return;