diff options
author | codeworkx <codeworkx@cyanogenmod.org> | 2016-12-22 20:05:52 +0100 |
---|---|---|
committer | Chippa-a <vusal1372@gmail.com> | 2019-10-25 15:55:25 +0300 |
commit | d8447450778d33262aebd7f7ed4346a8832f192e (patch) | |
tree | 63f5141db5c3fbb8023430b96b4a3d9c6be2272e | |
parent | aeefca79db8916396109271160321aa4fc3346b8 (diff) | |
download | android_packages_apps_Snap-d8447450778d33262aebd7f7ed4346a8832f192e.tar.gz android_packages_apps_Snap-d8447450778d33262aebd7f7ed4346a8832f192e.tar.bz2 android_packages_apps_Snap-d8447450778d33262aebd7f7ed4346a8832f192e.zip |
Snap: Make openLegacy an option
Using openLegacy on QCamera3 forces it to use QCamera2
and fall back to api v1 which is not what we want on v2 devices.
Author: codeworkx <codeworkx@cyanogenmod.org>
Date: Tue Jan 5 23:02:12 2016 +0100
make openLegacy an option
Change-Id: Ia4142288ef0fafa62fa0ab855dc342b363b640cd
Author: Zhao Wei Liew <zhaoweiliew@gmail.com>
Date: Sun Jul 10 15:11:43 2016 +0800
Snap: Tighten openLegacy() try-catch block
We only have to enclose the openLegacy() call in a try-catch block.
This prevents us from re-calling open() when open() fails and
throws a RuntimeException.
Change-Id: I81396e453f57215338a0c4da41c4116f2b4d42ca
Change-Id: Ic392a4ae9403ebae36940ddf0727237d9cb9e8f0
-rw-r--r-- | res/values/config.xml | 6 | ||||
-rw-r--r-- | src/com/android/camera/AndroidCameraManagerImpl.java | 45 |
2 files changed, 40 insertions, 11 deletions
diff --git a/res/values/config.xml b/res/values/config.xml index 6ac6ecea1..0b84c97d6 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -28,6 +28,12 @@ of the fullscreen pano preview. --> <bool name="enable_warped_pano_preview">true</bool> + <!-- Opens back camera using openLegacy() and forces api v1 --> + <bool name="back_camera_open_legacy">true</bool> + + <!-- Opens front camera using openLegacy() and forces api v1 --> + <bool name="front_camera_open_legacy">true</bool> + <!-- Restart preview for back camera onPictureTaken --> <bool name="back_camera_restart_preview_onPictureTaken">false</bool> diff --git a/src/com/android/camera/AndroidCameraManagerImpl.java b/src/com/android/camera/AndroidCameraManagerImpl.java index cad136cde..f2cb69f67 100644 --- a/src/com/android/camera/AndroidCameraManagerImpl.java +++ b/src/com/android/camera/AndroidCameraManagerImpl.java @@ -21,10 +21,12 @@ import static com.android.camera.util.CameraUtil.Assert; import java.io.IOException; import android.annotation.TargetApi; +import android.content.Context; import android.graphics.SurfaceTexture; import android.hardware.Camera; import android.hardware.Camera.AutoFocusCallback; import android.hardware.Camera.AutoFocusMoveCallback; +import android.hardware.Camera.CameraInfo; import android.hardware.Camera.ErrorCallback; import android.hardware.Camera.FaceDetectionListener; import android.hardware.Camera.OnZoomChangeListener; @@ -41,11 +43,13 @@ import android.util.Log; import android.view.SurfaceHolder; import android.hardware.Camera.CameraDataCallback; import android.hardware.Camera.CameraMetaDataCallback; +import com.android.camera.app.CameraApp; import com.android.camera.util.ApiHelper; import android.os.ConditionVariable; import java.lang.reflect.Method; import org.codeaurora.snapcam.wrapper.CameraWrapper; +import org.codeaurora.snapcam.R; /** * A class to implement {@link CameraManager} of the Android camera framework. @@ -235,16 +239,35 @@ class AndroidCameraManagerImpl implements CameraManager { try { switch (msg.what) { case OPEN_CAMERA: - try { - Method openMethod = Class.forName("android.hardware.Camera").getMethod( - "openLegacy", int.class, int.class); - mCamera = (android.hardware.Camera) openMethod.invoke( - null, msg.arg1, CAMERA_HAL_API_VERSION_1_0); - } catch (Exception e) { - /* Retry with open if openLegacy doesn't exist/fails */ - Log.v(TAG, "openLegacy failed due to " + e.getMessage() - + ", using open instead"); - mCamera = android.hardware.Camera.open(msg.arg1); + final int cameraId = msg.arg1; + Context context = CameraApp.getContext(); + + CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId]; + + final boolean isBackCamera = + info.facing == CameraInfo.CAMERA_FACING_BACK; + final boolean isFrontCamera = + info.facing == CameraInfo.CAMERA_FACING_FRONT; + final boolean useOpenLegacyForBackCamera = context.getResources() + .getBoolean(R.bool.back_camera_open_legacy); + final boolean useOpenLegacyForFrontCamera = context.getResources() + .getBoolean(R.bool.front_camera_open_legacy); + + if (isBackCamera && useOpenLegacyForBackCamera || + isFrontCamera && useOpenLegacyForFrontCamera) { + try { + Method openMethod = Class.forName("android.hardware.Camera") + .getMethod("openLegacy", int.class, int.class); + mCamera = (android.hardware.Camera) openMethod.invoke(null, + cameraId, CAMERA_HAL_API_VERSION_1_0); + } catch (Exception e) { + /* Retry with open if openLegacy doesn't exist/fails */ + Log.v(TAG, "openLegacy failed due to " + e.getMessage() + + ", using open instead"); + mCamera = android.hardware.Camera.open(cameraId); + } + } else { + mCamera = android.hardware.Camera.open(cameraId); } if (mCamera != null) { @@ -256,7 +279,7 @@ class AndroidCameraManagerImpl implements CameraManager { } } else { if (msg.obj != null) { - ((CameraOpenErrorCallback) msg.obj).onDeviceOpenFailure(msg.arg1); + ((CameraOpenErrorCallback) msg.obj).onDeviceOpenFailure(cameraId); } } return; |