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

Commit 49435ed8 authored by Andy Hung's avatar Andy Hung Committed by android-build-merger
Browse files

MediaRecorderClient: Use checkService instead of getService for camera

am: 58aef303

Change-Id: I3d1c047ea67dc805531b512e982c820b41ec817c
parents 7a1c0543 58aef303
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -368,14 +368,21 @@ status_t MediaRecorderClient::setListener(const sp<IMediaRecorderClient>& listen
    mRecorder->setListener(listener);

    sp<IServiceManager> sm = defaultServiceManager();
    sp<IBinder> binder = sm->getService(String16("media.camera"));

    // WORKAROUND: We don't know if camera exists here and getService might block for 5 seconds.
    // Use checkService for camera if we don't know it exists.
    static std::atomic<bool> sCameraChecked(false);  // once true never becomes false.
    static std::atomic<bool> sCameraVerified(false); // once true never becomes false.
    sp<IBinder> binder = (sCameraVerified || !sCameraChecked)
        ? sm->getService(String16("media.camera")) : sm->checkService(String16("media.camera"));
    // If the device does not have a camera, do not create a death listener for it.
    if (binder != NULL) {
        sCameraVerified = true;
        mCameraDeathListener = new ServiceDeathNotifier(binder, listener,
                MediaPlayerService::CAMERA_PROCESS_DEATH);
        binder->linkToDeath(mCameraDeathListener);
    }
    sCameraChecked = true;

    binder = sm->getService(String16("media.codec"));
    mCodecDeathListener = new ServiceDeathNotifier(binder, listener,