|
|
|
@ -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<String> mTargetPaths = new ArrayList<>();
|
|
|
|
|
private Runnable mRunnable;
|
|
|
|
|
|
|
|
|
|
public String getTargetPath() {
|
|
|
|
|
return mTargetPath;
|
|
|
|
|
public List<String> 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<File> opFile = Arrays.stream(cameraPath.listFiles(File::isFile))
|
|
|
|
|
boolean res = false;
|
|
|
|
|
for (int idx = 0; idx < 10; idx++) {
|
|
|
|
|
|
|
|
|
|
Optional<File> 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;
|
|
|
|
|