OSDN Git Service

Fix camera facing by querying characteristics oreo-x86 android-x86-8.1-r4 android-x86-8.1-r5 android-x86-8.1-r6
authorhenryhsu <henryhsu@google.com>
Tue, 8 Mar 2016 02:50:25 +0000 (10:50 +0800)
committerLiu Xiaoxu <liuxiaoxu@openthos.org>
Wed, 19 Feb 2020 04:01:08 +0000 (12:01 +0800)
Query facing from characteristics instead of hard coded.
Some code like camera_id_icons still assume the back camera id is
0. But these codes are only used when switching cameras. If there
is only one camera (either front or back), camera app works fine.
If there are two cameras, back camera id should be 0.

Also changing CHECK_BACK_CAMERA_ONLY to false because some devices
only have a front camera.

BUG=27516910
TEST=manually run camera app on device

Change-Id: I9f6914e2eb7609a6cb7eb840e3e27e440a7c81df
(cherry picked from commit daa06b80d28adfccfb785b8fa9b73898af50579b)

src/com/android/camera/CaptureModule.java
src/com/android/camera/DisableCameraReceiver.java
src/com/android/camera/captureintent/resource/ResourceConstructedImpl.java
src/com/android/camera/settings/CameraFacingSetting.java

index 640da4f..00a58cd 100644 (file)
@@ -1537,12 +1537,10 @@ public class CaptureModule extends CameraModule implements
 
     /**
      * Returns which way around the camera is facing, based on it's ID.
-     * <p>
-     * TODO: This needs to change so that we store the direction directly in the
-     * settings, rather than a Camera ID.
      */
-    private static Facing getFacingFromCameraId(int cameraId) {
-        return cameraId == 1 ? Facing.FRONT : Facing.BACK;
+    private Facing getFacingFromCameraId(int cameraId) {
+        return mAppController.getCameraProvider().getCharacteristics(cameraId)
+                .isFacingFront() ? Facing.FRONT : Facing.BACK;
     }
 
     private void resetTextureBufferSize() {
index aea6ec5..5237c1d 100644 (file)
@@ -30,7 +30,7 @@ import com.android.camera.debug.Log;
 // this receiver will be disabled, so it will not run again.
 public class DisableCameraReceiver extends BroadcastReceiver {
     private static final Log.Tag TAG = new Log.Tag("DisableCamRcver");
-    private static final boolean CHECK_BACK_CAMERA_ONLY = true;
+    private static final boolean CHECK_BACK_CAMERA_ONLY = false;
     private static final String ACTIVITIES[] = {
         "com.android.camera.CameraLauncher",
     };
index 588b7d4..5e90f40 100644 (file)
@@ -76,7 +76,7 @@ public final class ResourceConstructedImpl implements ResourceConstructed {
             AppController appController,
             FatalErrorHandler fatalErrorHandler) {
         final CameraFacingSetting cameraFacingSetting = new CameraFacingSetting(
-                context.getResources(), settingsManager, settingScopeNamespace);
+                context.getResources(), settingsManager, settingScopeNamespace, appController);
         final ResolutionSetting resolutionSetting = new ResolutionSetting(
                 settingsManager, oneCameraManager, context.getContentResolver());
         return new RefCountBase<ResourceConstructed>(new ResourceConstructedImpl(
index 1881d7e..8227ad6 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.android.camera.settings;
 
+import com.android.camera.app.AppController;
 import com.android.camera.CameraActivity;
 import com.android.camera.one.OneCamera;
 import com.android.camera2.R;
@@ -40,18 +41,24 @@ public class CameraFacingSetting {
     public CameraFacingSetting(
             Resources resources,
             SettingsManager settingsManager,
-            String moduleSettingScope) {
+            String moduleSettingScope,
+            AppController appController) {
         mSettingsManager = settingsManager;
 
         mSettingScope = SettingsManager.getModuleSettingScope(moduleSettingScope);
 
         mCameraFacingSettingKey = Keys.KEY_CAMERA_ID;
-        mCameraFacingBackValue =
-                Integer.parseInt(resources.getString(R.string.pref_camera_id_entry_back_value));
-        mCameraFacingFrontValue =
-                Integer.parseInt(resources.getString(R.string.pref_camera_id_entry_front_value));
         mCameraFacingDefaultValue =
                 Integer.parseInt(resources.getString(R.string.pref_camera_id_default));
+
+        if (appController.getCameraProvider().getCharacteristics(mCameraFacingDefaultValue).
+                isFacingFront()) {
+            mCameraFacingFrontValue = 0;
+            mCameraFacingBackValue = 1;
+        } else {
+            mCameraFacingBackValue = 0;
+            mCameraFacingFrontValue = 1;
+        }
     }
 
     @Override