diff --git a/app/src/main/java/net/sourceforge/opencamera/PropertyUtility.java b/app/src/main/java/net/sourceforge/opencamera/PropertyUtility.java deleted file mode 100644 index 6037989d4dd8ff779fb2c657dfe287d81109c702..0000000000000000000000000000000000000000 --- a/app/src/main/java/net/sourceforge/opencamera/PropertyUtility.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2022 E FOUNDATION - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.sourceforge.opencamera; - -import android.annotation.SuppressLint; -import android.util.Log; - -import androidx.annotation.Nullable; - -import java.lang.reflect.Method; - -public class PropertyUtility { - - private static final String TAG = PropertyUtility.class.getName(); - - /** - * Retrieve the property value from systemProperties - * @param key the property key - * @return value of the property, null if the value is not present - */ - @Nullable - public static String getProperty(String key) { - String value = null; - try { - @SuppressLint("PrivateApi") Class c = Class.forName("android.os.SystemProperties"); - Method get = c.getMethod("get", String.class); - - value = (String) get.invoke(c, key); - - } catch (Exception e) { - Log.e(TAG, e.getMessage()); - } - - return value; - } - - private PropertyUtility() { - } -} diff --git a/app/src/main/java/net/sourceforge/opencamera/cameracontroller/CameraController1.java b/app/src/main/java/net/sourceforge/opencamera/cameracontroller/CameraController1.java index c5f0ca4a43d61188aba235b2bcf9b29dbf378a96..ccb28d48e299a13ce5bc8801c92fb31b53a6b804 100644 --- a/app/src/main/java/net/sourceforge/opencamera/cameracontroller/CameraController1.java +++ b/app/src/main/java/net/sourceforge/opencamera/cameracontroller/CameraController1.java @@ -13,6 +13,7 @@ import android.view.TextureView; import net.sourceforge.opencamera.MyDebug; import java.io.IOException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -58,15 +59,28 @@ public class CameraController1 extends CameraController { if( MyDebug.LOG ) Log.d(TAG, "create new CameraController1: " + cameraId); this.camera_error_cb = camera_error_cb; + try { - camera = Camera.open(cameraId); + Method openMethod = Class.forName("android.hardware.Camera") + .getMethod("openLegacy", int.class, int.class); + camera = (Camera) openMethod.invoke(null, + cameraId, 0x100); + } catch (Exception e) { + /* Retry with open if openLegacy doesn't exist/fails */ + camera = null; } - catch(RuntimeException e) { - if( MyDebug.LOG ) - Log.e(TAG, "failed to open camera"); - e.printStackTrace(); - throw new CameraControllerException(); + + if (camera == null) { + try { + camera = Camera.open(cameraId); + } catch (RuntimeException e) { + if (MyDebug.LOG) + Log.e(TAG, "failed to open camera"); + e.printStackTrace(); + throw new CameraControllerException(); + } } + if( camera == null ) { // Although the documentation says Camera.open() should throw a RuntimeException, it seems that it some cases it can return null // I've seen this in some crashes reported in Google Play; also see: diff --git a/app/src/main/java/net/sourceforge/opencamera/preview/Preview.java b/app/src/main/java/net/sourceforge/opencamera/preview/Preview.java index eb4e623b32030d2400f440687c12aee21d6e8cb7..053f7c6dc85ea50a81c40e5643d8b10b3ec7b2f8 100644 --- a/app/src/main/java/net/sourceforge/opencamera/preview/Preview.java +++ b/app/src/main/java/net/sourceforge/opencamera/preview/Preview.java @@ -40,7 +40,6 @@ import android.util.Log; import android.util.Pair; import android.view.Display; import android.view.GestureDetector; -//import android.view.Gravity; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.OrientationEventListener; @@ -63,7 +62,6 @@ import androidx.core.content.ContextCompat; import net.sourceforge.opencamera.MainActivity; import net.sourceforge.opencamera.MyDebug; -import net.sourceforge.opencamera.PropertyUtility; import net.sourceforge.opencamera.ScriptC_histogram_compute; import net.sourceforge.opencamera.TakePhoto; import net.sourceforge.opencamera.ToastBoxer; @@ -1700,10 +1698,7 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu //final boolean use_background_thread = false; //final boolean use_background_thread = true; - boolean use_background_thread = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; - if ("true".equalsIgnoreCase(PropertyUtility.getProperty("camera.load.sync"))) { - use_background_thread = true; - } + final boolean use_background_thread = true; /* Opening camera on background thread is important so that we don't block the UI thread: * - For old Camera API, this is recommended behaviour by Google for Camera.open(). - For Camera2, the manager.openCamera() call is asynchronous, but CameraController2