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

Commit ee844a80 authored by Ivan Podogov's avatar Ivan Podogov
Browse files

Don't try to connect camera service if it is disabled.

On Android Wear devices we don't have cameras, so we don't need the
proxy service as well. If it is disabled by the system property, don't
wait for it to start, but rather return null pointer in
getCameraService(), which causes getNumberOfCameras() to report zero
cameras available.
The same logic applies to ACameraManager, where we return an empty list.

Bug: 28560707
Change-Id: I4c0bc29f061f1b66710c8188a7916bfaf089d23f
parent 47c996ba
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <utils/Log.h>
#include <utils/threads.h>
#include <utils/Mutex.h>
#include <cutils/properties.h>

#include <android/hardware/ICameraService.h>

@@ -90,6 +91,12 @@ const sp<::android::hardware::ICameraService>& CameraBase<TCam, TCamTraits>::get
{
    Mutex::Autolock _l(gLock);
    if (gCameraService.get() == 0) {
        char value[PROPERTY_VALUE_MAX];
        property_get("config.disable_cameraservice", value, "0");
        if (strncmp(value, "0", 2) != 0 && strncasecmp(value, "false", 6) != 0) {
            return gCameraService;
        }

        sp<IServiceManager> sm = defaultServiceManager();
        sp<IBinder> binder;
        do {
+18 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include "ACameraMetadata.h"
#include "ACameraDevice.h"
#include <utils/Vector.h>
#include <cutils/properties.h>
#include <stdlib.h>
#include <camera/VendorTagDescriptor.h>

@@ -71,9 +72,19 @@ CameraManagerGlobal::~CameraManagerGlobal() {
    mCameraService.clear();
}

static bool isCameraServiceDisabled() {
    char value[PROPERTY_VALUE_MAX];
    property_get("config.disable_cameraservice", value, "0");
    return (strncmp(value, "0", 2) != 0 && strncasecmp(value, "false", 6) != 0);
}

sp<hardware::ICameraService> CameraManagerGlobal::getCameraService() {
    Mutex::Autolock _l(mLock);
    if (mCameraService.get() == nullptr) {
        if (isCameraServiceDisabled()) {
            return mCameraService;
        }

        sp<IServiceManager> sm = defaultServiceManager();
        sp<IBinder> binder;
        do {
@@ -302,6 +313,13 @@ void CameraManagerGlobal::onStatusChangedLocked(
camera_status_t
ACameraManager::getOrCreateCameraIdListLocked(ACameraIdList** cameraIdList) {
    if (mCachedCameraIdList.numCameras == kCameraIdListNotInit) {
        if (isCameraServiceDisabled()) {
            mCachedCameraIdList.numCameras = 0;
            mCachedCameraIdList.cameraIds = new const char*[0];
            *cameraIdList = &mCachedCameraIdList;
            return ACAMERA_OK;
        }

        int numCameras = 0;
        Vector<char *> cameraIds;
        sp<hardware::ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();