Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19d96a19 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

CameraManager: Handle camera service being disabled explicitly

Previously, CameraManager handled a disabled camera service
implicitly, the same as it handles a temporarily-crashed camera
service.

However, the error reporting for the those cases isn't really the
same, so switch to being explicit - check for the disabled camera
service system property, and if it's set, short-circuit calls.

Test: Camera CTS continues to pass, Watch device with no camera
      service also now passes camera CTS.
Bug: 62269118

Change-Id: I65a97f8c1b0f101999b2c04d4f1096b7f3aee858
parent bcc35f5a
Loading
Loading
Loading
Loading
+21 −9
Original line number Diff line number Diff line
@@ -16,28 +16,29 @@

package android.hardware.camera2;

import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.content.Context;
import android.hardware.ICameraService;
import android.hardware.ICameraServiceListener;
import android.hardware.CameraInfo;
import android.hardware.CameraStatus;
import android.hardware.ICameraService;
import android.hardware.ICameraServiceListener;
import android.hardware.camera2.impl.CameraMetadataNative;
import android.hardware.camera2.legacy.CameraDeviceUserShim;
import android.hardware.camera2.legacy.LegacyMetadataMapper;
import android.os.IBinder;
import android.os.Binder;
import android.os.DeadObjectException;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceSpecificException;
import android.util.Log;
import android.os.SystemProperties;
import android.util.ArrayMap;
import android.util.Log;

import java.util.ArrayList;

@@ -210,7 +211,9 @@ public final class CameraManager {
    public CameraCharacteristics getCameraCharacteristics(@NonNull String cameraId)
            throws CameraAccessException {
        CameraCharacteristics characteristics = null;

        if (CameraManagerGlobal.sCameraServiceDisabled) {
            throw new IllegalArgumentException("No cameras available on device");
        }
        synchronized (mLock) {
            /*
             * Get the camera characteristics from the camera service directly if it supports it,
@@ -462,6 +465,9 @@ public final class CameraManager {
                        "Handler argument is null, but no looper exists in the calling thread");
            }
        }
        if (CameraManagerGlobal.sCameraServiceDisabled) {
            throw new IllegalArgumentException("No cameras available on device");
        }

        openCameraDeviceUserAsync(cameraId, callback, handler, clientUid);
    }
@@ -507,6 +513,9 @@ public final class CameraManager {
     */
    public void setTorchMode(@NonNull String cameraId, boolean enabled)
            throws CameraAccessException {
        if (CameraManagerGlobal.sCameraServiceDisabled) {
            throw new IllegalArgumentException("No cameras available on device");
        }
        CameraManagerGlobal.get().setTorchMode(cameraId, enabled);
    }

@@ -745,6 +754,9 @@ public final class CameraManager {
        private CameraManagerGlobal() {
        }

        public static final boolean sCameraServiceDisabled =
                SystemProperties.getBoolean("config.disable_cameraservice", false);

        public static CameraManagerGlobal get() {
            return gCameraManager;
        }
@@ -764,7 +776,7 @@ public final class CameraManager {
        public ICameraService getCameraService() {
            synchronized(mLock) {
                connectCameraServiceLocked();
                if (mCameraService == null) {
                if (mCameraService == null && !sCameraServiceDisabled) {
                    Log.e(TAG, "Camera service is unavailable");
                }
                return mCameraService;
@@ -779,7 +791,7 @@ public final class CameraManager {
         */
        private void connectCameraServiceLocked() {
            // Only reconnect if necessary
            if (mCameraService != null) return;
            if (mCameraService != null || sCameraServiceDisabled) return;

            Log.i(TAG, "Connecting to camera service");