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

Commit f2326ac9 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala Committed by Android (Google) Code Review
Browse files

Merge "CameraService: Add support for module init, some logging updates"

parents ffb9710d 1527f07e
Loading
Loading
Loading
Loading
+97 −69
Original line number Diff line number Diff line
@@ -140,14 +140,29 @@ void CameraService::onFirstRef()
    BnCameraService::onFirstRef();

    camera_module_t *rawModule;
    if (hw_get_module(CAMERA_HARDWARE_MODULE_ID,
                (const hw_module_t **)&rawModule) < 0) {
        ALOGE("Could not load camera HAL module");
    int err = hw_get_module(CAMERA_HARDWARE_MODULE_ID,
            (const hw_module_t **)&rawModule);
    if (err < 0) {
        ALOGE("Could not load camera HAL module: %d (%s)", err, strerror(-err));
        logServiceError("Could not load camera HAL module", err);
        mNumberOfCameras = 0;
        return;
    }
    else {

    mModule = new CameraModule(rawModule);
    ALOGI("Loaded \"%s\" camera module", mModule->getModuleName());
    err = mModule->init();
    if (err != OK) {
        ALOGE("Could not initialize camera HAL module: %d (%s)", err,
            strerror(-err));
        logServiceError("Could not initialize camera HAL module", err);

        mNumberOfCameras = 0;
        delete mModule;
        mModule = nullptr;
        return;
    }

    mNumberOfCameras = mModule->getNumberOfCameras();

    mFlashlight = new CameraFlashlight(*mModule, *this);
@@ -210,7 +225,6 @@ void CameraService::onFirstRef()

    CameraDeviceFactory::registerService(this);
}
}

CameraService::~CameraService() {
    if (mModule) {
@@ -1553,6 +1567,11 @@ void CameraService::logClientDied(int clientPid, const char* reason) {
    logEvent(String8::format("DIED client(s) with PID %d, reason: (%s)", clientPid, reason));
}

void CameraService::logServiceError(const char* msg, int errorCode) {
    String8 curTime = getFormattedCurrentTime();
    logEvent(String8::format("SERVICE ERROR: %s : %d (%s)", msg, errorCode, strerror(errorCode)));
}

status_t CameraService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
        uint32_t flags) {

@@ -1995,6 +2014,10 @@ status_t CameraService::dump(int fd, const Vector<String16>& args) {
        if (!mModule) {
            result = String8::format("No camera module available!\n");
            write(fd, result.string(), result.size());

            // Dump event log for error information
            dumpEventLog(fd);

            if (locked) mServiceLock.unlock();
            return NO_ERROR;
        }
@@ -2020,20 +2043,7 @@ status_t CameraService::dump(int fd, const Vector<String16>& args) {
            desc->dump(fd, /*verbosity*/2, /*indentation*/4);
        }

        result = String8("Prior client events (most recent at top):\n");

        {
            Mutex::Autolock l(mLogLock);
            for (const auto& msg : mEventLog) {
                result.appendFormat("%s\n", msg.string());
            }

            if (mEventLog.size() == DEFAULT_EVENT_LOG_LENGTH) {
                result.append("...\n");
            }
        }

        write(fd, result.string(), result.size());
        dumpEventLog(fd);

        bool stateLocked = tryLock(mCameraStatesLock);
        if (!stateLocked) {
@@ -2141,6 +2151,24 @@ status_t CameraService::dump(int fd, const Vector<String16>& args) {
    return NO_ERROR;
}

void CameraService::dumpEventLog(int fd) {
    String8 result = String8("\nPrior client events (most recent at top):\n");

    Mutex::Autolock l(mLogLock);
    for (const auto& msg : mEventLog) {
        result.appendFormat("  %s\n", msg.string());
    }

    if (mEventLog.size() == DEFAULT_EVENT_LOG_LENGTH) {
        result.append("  ...\n");
    } else if (mEventLog.size() == 0) {
        result.append("  [no events yet]\n");
    }
    result.append("\n");

    write(fd, result.string(), result.size());
}

void CameraService::handleTorchClientBinderDied(const wp<IBinder> &who) {
    Mutex::Autolock al(mTorchClientMapMutex);
    for (size_t i = 0; i < mTorchClientMap.size(); i++) {
+10 −0
Original line number Diff line number Diff line
@@ -590,6 +590,16 @@ private:
     */
    void logClientDied(int clientPid, const char* reason);

    /**
     * Add a event log message that a serious service-level error has occured
     */
    void logServiceError(const char* msg, int errorCode);

    /**
     * Dump the event log to an FD
     */
    void dumpEventLog(int fd);

    int                 mNumberOfCameras;

    // sounds
+9 −2
Original line number Diff line number Diff line
@@ -57,6 +57,14 @@ CameraModule::CameraModule(camera_module_t *module) {
    mCameraInfoMap.setCapacity(getNumberOfCameras());
}

int CameraModule::init() {
    if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4 &&
            mModule->init != NULL) {
        return mModule->init();
    }
    return OK;
}

int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) {
    Mutex::Autolock lock(mCameraInfoLock);
    if (cameraId < 0) {
@@ -98,7 +106,7 @@ int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) {
    assert(index != NAME_NOT_FOUND);
    // return the cached camera info
    *info = mCameraInfoMap[index];
    return 0;
    return OK;
}

int CameraModule::open(const char* id, struct hw_device_t** device) {
@@ -166,4 +174,3 @@ void* CameraModule::getDso() {
}

}; // namespace android
+4 −1
Original line number Diff line number Diff line
@@ -34,6 +34,10 @@ class CameraModule {
public:
    CameraModule(camera_module_t *module);

    // Must be called after construction
    // Returns OK on success, NO_INIT on failure
    int init();

    int getCameraInfo(int cameraId, struct camera_info *info);
    int getNumberOfCameras(void);
    int open(const char* id, struct hw_device_t** device);
@@ -63,4 +67,3 @@ private:
} // namespace android

#endif