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

Commit 412fe56c authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

CameraService: Notify camera service proxy of device status

Send the camera proxy service in system server updates to
camera device state: opened/closed/active/idle.

Bug: 23393557
Change-Id: Id7c70f134821efa34af8f6e7b4caa4c2ab128ebc
parent 37ea1d0d
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -29,11 +29,21 @@ public:
    BpCameraServiceProxy(const sp<IBinder>& impl) : BpInterface<ICameraServiceProxy>(impl) {}

    virtual void pingForUserUpdate() {
        Parcel data, reply;
        Parcel data;
        data.writeInterfaceToken(ICameraServiceProxy::getInterfaceDescriptor());
        remote()->transact(BnCameraServiceProxy::PING_FOR_USER_UPDATE, data, &reply,
        remote()->transact(BnCameraServiceProxy::PING_FOR_USER_UPDATE, data, nullptr,
                IBinder::FLAG_ONEWAY);
    }

    virtual void notifyCameraState(String16 cameraId, CameraState newCameraState) {
        Parcel data;
        data.writeInterfaceToken(ICameraServiceProxy::getInterfaceDescriptor());
        data.writeString16(cameraId);
        data.writeInt32(newCameraState);
        remote()->transact(BnCameraServiceProxy::NOTIFY_CAMERA_STATE, data, nullptr,
                IBinder::FLAG_ONEWAY);
    }

};


@@ -47,9 +57,16 @@ status_t BnCameraServiceProxy::onTransact(uint32_t code, const Parcel& data, Par
            pingForUserUpdate();
            return NO_ERROR;
        } break;
        case NOTIFY_CAMERA_STATE: {
            CHECK_INTERFACE(ICameraServiceProxy, data, reply);
            String16 cameraId = data.readString16();
            CameraState newCameraState =
                static_cast<CameraState>(data.readInt32());
            notifyCameraState(cameraId, newCameraState);
            return NO_ERROR;
        } break;
        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
}
}; // namespace android
+15 −2
Original line number Diff line number Diff line
@@ -23,15 +23,30 @@

namespace android {

/**
 * Interface from native camera service to managed-side camera service proxy.
 *
 * Keep in sync with frameworks/base/core/java/android/hardware/ICameraServiceProxy.aidl
 *
 */
class ICameraServiceProxy : public IInterface {
public:
    enum {
        PING_FOR_USER_UPDATE = IBinder::FIRST_CALL_TRANSACTION,
        NOTIFY_CAMERA_STATE
    };

    enum CameraState {
        CAMERA_STATE_OPEN,
        CAMERA_STATE_ACTIVE,
        CAMERA_STATE_IDLE,
        CAMERA_STATE_CLOSED
    };

    DECLARE_META_INTERFACE(CameraServiceProxy);

    virtual void pingForUserUpdate() = 0;
    virtual void notifyCameraState(String16 cameraId, CameraState newCameraState) = 0;
};

class BnCameraServiceProxy: public BnInterface<ICameraServiceProxy>
@@ -48,5 +63,3 @@ public:
}; // namespace android

#endif // ANDROID_HARDWARE_ICAMERASERVICEPROXY_H

+24 −3
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@
#include <binder/MemoryBase.h>
#include <binder/MemoryHeapBase.h>
#include <binder/ProcessInfoService.h>
#include <camera/ICameraServiceProxy.h>
#include <cutils/atomic.h>
#include <cutils/properties.h>
#include <gui/Surface.h>
@@ -250,13 +249,19 @@ void CameraService::onFirstRef()
    CameraService::pingCameraServiceProxy();
}

void CameraService::pingCameraServiceProxy() {
sp<ICameraServiceProxy> CameraService::getCameraServiceProxy() {
    sp<IServiceManager> sm = defaultServiceManager();
    sp<IBinder> binder = sm->getService(String16("media.camera.proxy"));
    if (binder == nullptr) {
        return;
        return nullptr;
    }
    sp<ICameraServiceProxy> proxyBinder = interface_cast<ICameraServiceProxy>(binder);
    return proxyBinder;
}

void CameraService::pingCameraServiceProxy() {
    sp<ICameraServiceProxy> proxyBinder = getCameraServiceProxy();
    if (proxyBinder == nullptr) return;
    proxyBinder->pingForUserUpdate();
}

@@ -1948,6 +1953,10 @@ status_t CameraService::BasicClient::startCameraOps() {
    mCameraService->updateStatus(ICameraServiceListener::STATUS_NOT_AVAILABLE,
            String8::format("%d", mCameraId));

    // Transition device state to OPEN
    mCameraService->updateProxyDeviceState(ICameraServiceProxy::CAMERA_STATE_OPEN,
            String8::format("%d", mCameraId));

    return OK;
}

@@ -1966,6 +1975,10 @@ status_t CameraService::BasicClient::finishCameraOps() {
        mCameraService->updateStatus(ICameraServiceListener::STATUS_PRESENT,
                String8::format("%d", mCameraId), rejected);

        // Transition device state to CLOSED
        mCameraService->updateProxyDeviceState(ICameraServiceProxy::CAMERA_STATE_CLOSED,
                String8::format("%d", mCameraId));

        // Notify flashlight that a camera device is closed.
        mCameraService->mFlashlight->deviceClosed(
                String8::format("%d", mCameraId));
@@ -2466,6 +2479,14 @@ void CameraService::updateStatus(ICameraServiceListener::Status status, const St
        });
}

void CameraService::updateProxyDeviceState(ICameraServiceProxy::CameraState newState,
        const String8& cameraId) {
    sp<ICameraServiceProxy> proxyBinder = getCameraServiceProxy();
    if (proxyBinder == nullptr) return;
    String16 id(cameraId);
    proxyBinder->notifyCameraState(id, newState);
}

status_t CameraService::getTorchStatusLocked(
        const String8& cameraId,
        ICameraServiceListener::TorchStatus *status) const {
+10 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <binder/BinderService.h>
#include <binder/IAppOpsCallback.h>
#include <camera/ICameraService.h>
#include <camera/ICameraServiceProxy.h>
#include <hardware/camera.h>

#include <camera/ICamera.h>
@@ -164,6 +165,14 @@ public:
    void                playSound(sound_kind kind);
    void                releaseSound();

    /**
     * Update the state of a given camera device (open/close/active/idle) with
     * the camera proxy service in the system service
     */
    static void         updateProxyDeviceState(
            ICameraServiceProxy::CameraState newState,
            const String8& cameraId);

    /////////////////////////////////////////////////////////////////////
    // CameraDeviceFactory functionality
    int                 getDeviceVersion(int cameraId, int* facing = NULL);
@@ -728,6 +737,7 @@ private:

    static String8 toString(std::set<userid_t> intSet);

    static sp<ICameraServiceProxy> getCameraServiceProxy();
    static void pingCameraServiceProxy();

};
+2 −0
Original line number Diff line number Diff line
@@ -1912,6 +1912,8 @@ void Camera2Client::notifyShutter(const CaptureResultExtras& resultExtras,
    ALOGV("%s: Shutter notification for request id %" PRId32 " at time %" PRId64,
            __FUNCTION__, resultExtras.requestId, timestamp);
    mCaptureSequencer->notifyShutter(resultExtras, timestamp);

    Camera2ClientBase::notifyShutter(resultExtras, timestamp);
}

camera2::SharedParameters& Camera2Client::getParameters() {
Loading