From 9dc4c8ebfbd742f5fecd9a47cc3b86fd27bd34f2 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 14 Oct 2024 23:16:11 +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 --- app/src/main/cpp/MicroPhoto.cpp | 21 ++++++++-- app/src/main/cpp/PhoneDevice.cpp | 40 +++++++++++++++++- app/src/main/cpp/PhoneDevice.h | 2 + .../com/xypower/mpapp/MicroPhotoService.java | 42 +++++++++---------- .../java/com/xypower/mpapp/adb/CameraAdb.java | 25 +++-------- 5 files changed, 84 insertions(+), 46 deletions(-) diff --git a/app/src/main/cpp/MicroPhoto.cpp b/app/src/main/cpp/MicroPhoto.cpp index 51439600..e147d28d 100644 --- a/app/src/main/cpp/MicroPhoto.cpp +++ b/app/src/main/cpp/MicroPhoto.cpp @@ -950,7 +950,7 @@ Java_com_xypower_mpapp_MicroPhotoService_reloadConfigs( extern "C" JNIEXPORT jboolean JNICALL Java_com_xypower_mpapp_MicroPhotoService_sendExternalPhoto( - JNIEnv* env, jclass cls, jlong handler, jstring path) { + JNIEnv* env, jclass cls, jlong handler, jstring path, jlong photoInfo) { CTerminal* pTerminal = reinterpret_cast(handler); if (pTerminal == NULL) @@ -963,10 +963,25 @@ Java_com_xypower_mpapp_MicroPhotoService_sendExternalPhoto( return JNI_FALSE; } - const char *pathStr = env->GetStringUTFChars(path, 0); + IDevice::PHOTO_INFO* pPhotoInfo = photoInfo == 0 ? NULL : reinterpret_cast(photoInfo); + + const char *pathStr = NULL; + + if (path != NULL) + { + pathStr = env->GetStringUTFChars(path, 0); + } + bool res = pTerminal->SendExternalPhoto(pathStr); - env->ReleaseStringUTFChars(path, pathStr); + if (pathStr != NULL) + { + env->ReleaseStringUTFChars(path, pathStr); + } + if (pPhotoInfo != NULL) + { + delete pPhotoInfo; + } return res ? JNI_TRUE : JNI_FALSE; } diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 145fa43e..dae8b5ba 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -433,6 +433,8 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa mExecHdrplusMid = env->GetMethodID(classService, "execHdrplus", "(IILjava/lang/String;Ljava/lang/String;)I"); + mCallSysCameraMid = env->GetMethodID(classService, "callSystemCamera", "(IJ)V"); + env->DeleteLocalRef(classService); } @@ -1441,7 +1443,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< TurnOnCameraPower(NULL); res = true; - if (mPhotoInfo.mediaType == 0/* && mPhotoInfo.usingRawFormat == 0*/) + if (mPhotoInfo.mediaType == 0 && mPhotoInfo.usingSysCamera == 0) { mCamera = new CPhoneCamera(this, photoInfo.width, photoInfo.height, params); // mCamera = new CJpegCamera(this, photoInfo.width, photoInfo.height, mPath, params); @@ -1463,6 +1465,28 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< } } } + else if (mPhotoInfo.usingSysCamera == 1) + { + JNIEnv* env = NULL; + bool didAttachThread = false; + res = GetJniEnv(m_vm, &env, didAttachThread); + if (!res) + { + ALOGE("Failed to get JNI Env"); + return false; + } + + IDevice::PHOTO_INFO *pPhotoInfo = new IDevice::PHOTO_INFO(mPhotoInfo); + + jboolean photoOrVideo = mPhotoInfo.mediaType == 0 ? JNI_TRUE : JNI_FALSE; + env->CallVoidMethod(m_javaService, mCallSysCameraMid, mPhotoInfo.cameraId, + reinterpret_cast(pPhotoInfo)); + + if (didAttachThread) + { + m_vm->DetachCurrentThread(); + } + } else { JNIEnv* env = NULL; @@ -2870,6 +2894,20 @@ bool CPhoneDevice::OnVideoReady(bool photoOrVideo, bool result, const char* path { if (photoOrVideo) { + mPhotoInfo.photoTime = time(NULL); + CPhoneCamera* pCamera = NULL; + + std::vector objs; + std::string fullPath = mPath + CTerminal::BuildPhotoFileName(mPhotoInfo); + if (result) + { + std::rename(path, fullPath.c_str()); + } + TakePhotoCb(result ? 3 : 0, mPhotoInfo, fullPath, time(NULL), objs); + + bool turnOffOtg = (mPhotoInfo.usbCamera != 0); + std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, turnOffOtg); + m_threadClose.swap(closeThread); } else { diff --git a/app/src/main/cpp/PhoneDevice.h b/app/src/main/cpp/PhoneDevice.h index ee40d011..c0ad2ee1 100644 --- a/app/src/main/cpp/PhoneDevice.h +++ b/app/src/main/cpp/PhoneDevice.h @@ -324,6 +324,8 @@ protected: jmethodID mRequestPositionMid; jmethodID mExecHdrplusMid; + jmethodID mCallSysCameraMid; + std::string mPath; IDevice::PHOTO_INFO mPhotoInfo; vector mOsds; diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index cb597c76..b805fbb6 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -432,27 +432,6 @@ public class MicroPhotoService extends Service { Log.i(TAG, "PhotoTimer Fired: CH=" + channel + " PR=" + preset); mService.notifyToTakePhoto(mService.mNativeHandle, channel, preset, ts, photoOrVideo); } - - File cameraAdbCfg = new File(MicroPhotoContext.buildMpAppDir(mService.getApplication()), "data/cameraAdb.cfg"); - if (cameraAdbCfg.exists()) { - final String appPath = MicroPhotoContext.buildMpAppDir(context); - mService.mHander.postDelayed(new Runnable() { - @Override - public void run() { - final CameraAdb cameraAdb = new CameraAdb(context, appPath); - cameraAdb.setCallback(new Runnable() { - @Override - public void run() { - List targetPaths = cameraAdb.getTargetPaths(); - for (String targetPath : targetPaths) { - mService.sendExternalPhoto(mService.mNativeHandle, targetPath); - } - } - }); - cameraAdb.takePhoto(); - } - }, 10000 * cnt); - } } // Register Next Photo Timer @@ -1480,7 +1459,7 @@ cellSignalStrengthGsm.getDbm(); protected native void burstCaptureFinished(long handler, boolean result, int numberOfCaptures, String pathsJoinedByTab, boolean frontCamera, int rotation, long photoId); public static native long takePhoto(int channel, int preset, boolean photoOrVideo, String configFilePath, String path); public static native void releaseDeviceHandle(long deviceHandle); - public static native boolean sendExternalPhoto(long deviceHandle, String path); + public static native boolean sendExternalPhoto(long deviceHandle, String path, long photoInfo); public static native void infoLog(String log); public static native void setOtgState(boolean enabled); @@ -1570,6 +1549,25 @@ cellSignalStrengthGsm.getDbm(); } }; + + public void callSystemCamera(final int cameraId, final long photoId) { + Context context = getApplicationContext(); + final CameraAdb cameraAdb = new CameraAdb(context, MicroPhotoContext.buildMpAppDir(context)); + cameraAdb.setCallback(new Runnable() { + @Override + public void run() { + List targetPaths = cameraAdb.getTargetPaths(); + if (targetPaths.isEmpty()) { + recordingFinished(mNativeHandle, true, false, null, photoId); + } else { + for (String targetPath : targetPaths) { + recordingFinished(mNativeHandle, true, true, targetPath, photoId); + } + } + } + }); + cameraAdb.takePhoto(cameraId); + } ////////////////////////GPS//////////////////// private void setDefaultDataSubId(int subId) { 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 ee2a589c..01d36fbc 100644 --- a/app/src/main/java/com/xypower/mpapp/adb/CameraAdb.java +++ b/app/src/main/java/com/xypower/mpapp/adb/CameraAdb.java @@ -78,19 +78,19 @@ public class CameraAdb { mAdbKeyPair = AdbKeyPair.read(priKeyFile, pubKeyFile); } - public void takePhoto() { + public void takePhoto(final int cameraId) { new Thread(new Runnable() { @Override public void run() { - takePhotoImpl(); + takePhotoImpl(cameraId); } }).start(); } - private void takePhotoImpl() { + private void takePhotoImpl(final int cameraId) { long requestTime = System.currentTimeMillis() / 1000; - takePhoto(false); + takePhoto(cameraId == 1); long takingTime = System.currentTimeMillis() / 1000; sleep(1500); String path = movePhoto(false, requestTime, takingTime); @@ -100,21 +100,6 @@ public class CameraAdb { sleep(100); SysApi.forceStopApp(mContext, "com.mediatek.camera"); - sleep(1000); - - requestTime = System.currentTimeMillis() / 1000; - takePhoto(true); - takingTime = System.currentTimeMillis() / 1000; - - 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(); } @@ -168,7 +153,7 @@ public class CameraAdb { } } - public void takePhoto(final boolean frontCamera) { + protected void takePhoto(final boolean frontCamera) { Dadb adb = Dadb.create(mDeviceIp, 5555, mAdbKeyPair); if (adb == null) {