|
|
@ -4,10 +4,15 @@ import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.dev.devapi.api.SysApi;
|
|
|
|
import com.xypower.common.FilesUtils;
|
|
|
|
import com.xypower.common.FilesUtils;
|
|
|
|
|
|
|
|
import com.xypower.common.MicroPhotoContext;
|
|
|
|
|
|
|
|
import com.xypower.mpapp.MicroPhotoService;
|
|
|
|
import com.xypower.mpapp.v2.Camera2VideoActivity;
|
|
|
|
import com.xypower.mpapp.v2.Camera2VideoActivity;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
|
|
import dadb.AdbKeyPair;
|
|
|
|
import dadb.AdbKeyPair;
|
|
|
|
import dadb.AdbShellResponse;
|
|
|
|
import dadb.AdbShellResponse;
|
|
|
@ -41,18 +46,66 @@ public class CameraAdb {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void takePhoto() {
|
|
|
|
public void takePhoto() {
|
|
|
|
(new Thread(new Runnable() {
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
takePhotoImpl();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}).start();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void takePhotoImpl() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long requestTime = System.currentTimeMillis() / 1000;
|
|
|
|
|
|
|
|
takePhoto(false);
|
|
|
|
|
|
|
|
long takingTime = System.currentTimeMillis() / 1000;
|
|
|
|
|
|
|
|
movePhoto(false, requestTime, takingTime);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SysApi.forceStopApp(mContext, "com.mediatek.camera");
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
runImpl();
|
|
|
|
Thread.sleep(2000);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
requestTime = System.currentTimeMillis() / 1000;
|
|
|
|
|
|
|
|
takePhoto(true);
|
|
|
|
|
|
|
|
takingTime = System.currentTimeMillis() / 1000;
|
|
|
|
|
|
|
|
movePhoto(true, requestTime, takingTime);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SysApi.forceStopApp(mContext, "com.mediatek.camera");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MicroPhotoService.restartApp(mContext, MicroPhotoContext.PACKAGE_NAME_MPAPP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void runImpl() {
|
|
|
|
private void movePhoto(boolean frontCamera, long requestTime, long takingTime) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String photoPath = mAppPath + "photos/";
|
|
|
|
|
|
|
|
String photoFile = "IMG_" + Long.toHexString(requestTime).toUpperCase() + "_"
|
|
|
|
|
|
|
|
+ (frontCamera ? "2" : "1") + "_FF_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))
|
|
|
|
|
|
|
|
.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();
|
|
|
|
|
|
|
|
res = srcFile.renameTo(targetFile);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
|
|
|
|
Log.e(TAG, "Failed to copy photo from Camera");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void takePhoto(final boolean frontCamera) {
|
|
|
|
Dadb adb = Dadb.discover(mDeviceIp, mAdbKeyPair);
|
|
|
|
Dadb adb = Dadb.discover(mDeviceIp, mAdbKeyPair);
|
|
|
|
|
|
|
|
|
|
|
|
if (adb == null) {
|
|
|
|
if (adb == null) {
|
|
|
@ -63,11 +116,14 @@ public class CameraAdb {
|
|
|
|
boolean res = false;
|
|
|
|
boolean res = false;
|
|
|
|
|
|
|
|
|
|
|
|
String[] cmds = {
|
|
|
|
String[] cmds = {
|
|
|
|
|
|
|
|
"content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0",
|
|
|
|
|
|
|
|
"content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1",
|
|
|
|
"am force-stop com.mediatek.camera",
|
|
|
|
"am force-stop com.mediatek.camera",
|
|
|
|
"setprop mtk.camera.app.keycode.enable 1",
|
|
|
|
"setprop mtk.camera.app.keycode.enable 1",
|
|
|
|
"setprop mtk.camera.switch.camera.debug 1",
|
|
|
|
"setprop mtk.camera.switch.camera.debug 1",
|
|
|
|
"setprop mtk.camera.switch.id.debug back-1",
|
|
|
|
"setprop mtk.camera.switch.id.debug back-1",
|
|
|
|
"am start -a android.media.action.STILL_IMAGE_CAMERA --ez com.google.assistant.extra.USE_FRONT_CAMERA true -f " + Integer.toString(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP),
|
|
|
|
"am start -a android.media.action.STILL_IMAGE_CAMERA " +
|
|
|
|
|
|
|
|
(frontCamera ? "--ez com.google.assistant.extra.USE_FRONT_CAMERA true" : "") + " -f " + Integer.toString(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP),
|
|
|
|
"wait",
|
|
|
|
"wait",
|
|
|
|
"input keyevent 27"};
|
|
|
|
"input keyevent 27"};
|
|
|
|
|
|
|
|
|
|
|
@ -94,10 +150,6 @@ public class CameraAdb {
|
|
|
|
Log.i(TAG, line);
|
|
|
|
Log.i(TAG, line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})).start();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|