Android camera: CameraServiceProxy

本文深入解析了CameraServiceProxy服务的工作原理及其在Android系统中的实现细节。CameraServiceProxy作为system_server与media_server之间的桥梁,负责处理摄像头状态更新等关键任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CameraServiceProxy service的实现

frameworks/base/services/core/java/com/android/server/camera/CameraServiceProxy.java

/**
 * CameraServiceProxy is the system_server analog to the camera service running in mediaserver.
 *
 * @hide
 */
public class CameraServiceProxy extends SystemService

{

   public static final String CAMERA_SERVICE_PROXY_BINDER_NAME = "media.camera.proxy";

    private final ICameraServiceProxy.Stub mCameraServiceProxy = new ICameraServiceProxy.Stub() {
        @Override
        public void pingForUserUpdate() {
            notifySwitchWithRetries(30);
        }

        @Override
        public void notifyCameraState(String cameraId, int newCameraState) {
            String state = cameraStateToString(newCameraState);
            if (DEBUG) Slog.v(TAG, "Camera " + cameraId + " state now " + state);

            updateActivityCount(cameraId, newCameraState);
        }
    };

    @Override
    public void onStart() {
        mUserManager = UserManager.get(mContext);

        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_USER_ADDED);
        filter.addAction(Intent.ACTION_USER_REMOVED);
        filter.addAction(Intent.ACTION_USER_INFO_CHANGED);
        filter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED);
        filter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
        mContext.registerReceiver(mIntentReceiver, filter);

        publishBinderService(CAMERA_SERVICE_PROXY_BINDER_NAME, mCameraServiceProxy);
    }

}

怎样使用该service

frameworks/av/services/camera/libcameraservice/CameraService.cpp
void CameraService::updateProxyDeviceState(ICameraServiceProxy::CameraState newState,
        const String8& cameraId) {
    sp<ICameraServiceProxy> proxyBinder = getCameraServiceProxy();
    if (proxyBinder == nullptr) return;
    String16 id(cameraId);
    proxyBinder->notifyCameraState(id, newState);
}
sp<ICameraServiceProxy> CameraService::getCameraServiceProxy() {
    sp<ICameraServiceProxy> proxyBinder = nullptr;
    sp<IServiceManager> sm = defaultServiceManager();
    // Use checkService because cameraserver normally starts before the
    // system server and the proxy service. So the long timeout that getService
    // has before giving up is inappropriate.
    sp<IBinder> binder = sm->checkService(String16("media.camera.proxy"));
    if (binder != nullptr) {
        proxyBinder = interface_cast<ICameraServiceProxy>(binder);
    }
    return proxyBinder;
}

template <typename TClientBase>
void Camera2ClientBase<TClientBase>::notifyShutter(const CaptureResultExtras& resultExtras,
                                                   nsecs_t timestamp) {
    (void)resultExtras;
    (void)timestamp;

    if (!mDeviceActive) {
        getCameraService()->updateProxyDeviceState(
            hardware::ICameraServiceProxy::CAMERA_STATE_ACTIVE, TClientBase::mCameraIdStr,
            TClientBase::mCameraFacing, TClientBase::mClientPackageName);
    }
    mDeviceActive = true;

    ALOGV("%s: Shutter notification for request id %" PRId32 " at time %" PRId64,
            __FUNCTION__, resultExtras.requestId, timestamp);
}
16:05:30.999151 2502 23822 I cameraserver: OmojiManager.cpp: 125 isSupportOmoji: property version: 08-05 16:05:30.999158 2502 23822 I cameraserver: OmojiManager.cpp: 126 isSupportOmoji: property switch: 08-05 16:05:30.999196 2502 23822 I cameraserver: OmojiManager.cpp: 194 omoji support: packageName = com.oplus.camera, activityName = NULL, ret=0 08-05 16:05:30.999209 2502 23822 I cameraserver: OmojiManager.cpp: 125 isSupportOmoji: property version: 08-05 16:05:30.999212 2502 23822 I cameraserver: OmojiManager.cpp: 126 isSupportOmoji: property switch: 08-05 16:05:30.999230 2502 23822 I cameraserver: OmojiManager.cpp: 194 omoji support: packageName = com.oplus.camera, activityName = NULL, ret=0 08-05 16:05:30.999237 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 4193 addRemovePackageName() APS2Omoji after set omoji whitelist,mSupportAps2Omoji = 0 08-05 16:05:30.999262 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 5082 getTrdPartyFBJsonValue() getTrdPartyFBJsonValue apkPropName: oplus.video.beauty.com.oplus.camera, prop value: -1 08-05 16:05:30.999268 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 5082 getTrdPartyFBJsonValue() getTrdPartyFBJsonValue apkPropName: oplus.video.beauty.com.oplus.camera, prop value: -1 08-05 16:05:30.999272 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 4198 addRemovePackageName() trdPartyFBSupportability: 0, getTrdPartyFBSupportability(): 0, mSupportFwkOmoji: 0, mSupportAps2Omoji: 0 08-05 16:05:30.999284 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 4119 operator()() operator(): Unknown tag com.oplus.trdParty.isSupport.video.faceBeauty, ignoring 08-05 16:05:30.999309 2502 23822 I cameraserver: APSInterface.cpp: 105 updateAPSSwitch , fbEnable 1 08-05 16:05:30.999316 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 5082 getTrdPartyFBJsonValue() getTrdPartyFBJsonValue apkPropName: oplus.video.beauty.com.oplus.camera, prop value: -1 08-05 16:05:30.999324 2502 23822 I cameraserver: OmojiManager.cpp: 100 getOmojiEnable,Line:100, mOmojiEnable:0 08-05 16:05:30.999328 2502 23822 I cameraserver: APSInterface.cpp: 143 updateAPSSwitch mNeedAPSProcess 0, mApkPropName: oplus.video.beauty.com.oplus.camera, prop value: -1, platform: pineapple, activityName: NULL, activitysupport: 0 mStreamNeedAPSProcess: 0 08-05 16:05:30.999789 2502 23822 D Camera3-Device: Set real time priority for request queue thread (tid 29608) 08-05 16:05:31.000201 2502 23822 D Camera3-Utils: Set regular priority for thread (tid 23822) 08-05 16:05:31.000260 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 556 afterEndConfigure() afterEndConfigure: 556, clear mFromExtension: 0 08-05 16:05:31.000265 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 562 afterEndConfigure() afterEndConfigure: 562, mFromExtension: 0 08-05 16:05:31.000274 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 575 afterEndConfigure() afterEndConfigure: com.oplus.camera not using cameraunit. 08-05 16:05:31.000518 26917 27181 I BpBinder: onLastStrongRef automatically unlinking death recipients: 08-05 16:05:31.000602 26917 27310 I BpBinder: onLastStrongRef automatically unlinking death recipients: 08-05 16:05:31.001008 26917 27881 I BpBinder: onLastStrongRef automatically unlinking death recipients: 08-05 16:05:31.001220 26917 27438 I BpBinder: onLastStrongRef automatically unlinking death recipients: 08-05 16:05:31.001299 26917 27347 I BpBinder: onLastStrongRef automatically unlinking death recipients: 08-05 16:05:31.001906 26917 27347 I BpBinder: onLastStrongRef automatically unlinking death recipients: 08-05 16:05:31.002378 3384 6132 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1281 com.android.server.camera.OplusCameraStateBroadcast.notifyCameraState:52 com.android.server.camera.CameraServiceProxyExtImpl.extendNotifyCameraState:370 com.android.server.camera.CameraServiceProxy.updateActivityCount:1580 com.android.server.camera.CameraServiceProxy.-$$Nest$mupdateActivityCount:0 08-05 16:05:31.002519 26917 27005 W CameraUnit, StateCallback: onConfigured,android.hardware.camera2.impl.CameraCaptureSessionImpl@2a7688f 08-05 16:05:31.002547 26917 27005 E CameraUnit, CameraUnit_TRACE: traceBeginSection, msg: CameraUnit.CameraStartupPerformance.onCameraCaptureSessionConfigured 08-05 16:05:31.002566 26917 26995 E CameraUnit, CameraUnit_TRACE: traceEndSection, msg: CameraUnit.CameraStartupPerformance.createCaptureSession 08-05 16:05:31.002629 26917 27005 E CameraUnit, CameraUnit_TRACE: traceEndSection, msg: CameraUnit.CameraStartupPerformance.onCameraCaptureSessionConfigured 08-05 16:05:31.002636 26917 26995 E CameraUnit, CameraUnit_TRACE: traceEndSection, msg: CameraUnitCamera2ImplCreateSession 08-05 16:05:31.002705 26917 27005 I CameraUnit, Camera2Impl: PreviewRequestCallback, onCaptureFailed, fail reason: 1, sequenceId:2 08-05 16:05:31.002853 26917 26995 I CameraUnit, Camera2StateMachineImpl: setDeviceState, cameraName: rear_sat, mDeviceState: SESSION_CREATING -> SESSION_CONFIGURED 08-05 16:05:31.002900 26917 27005 I CameraUnit, Camera2Impl: PreviewRequestCallback, onCaptureFailed, fail reason: 1, sequenceId:2 08-05 16:05:31.002983 26917 27005 I CameraUnit, Camera2Impl: PreviewRequestCallback, onCaptureFailed, fail reason: 1, sequenceId:2 08-05 16:05:31.003003 26917 27005 I CameraUnit, Camera2Impl: PreviewRequestCallback, onCaptureFailed, fail reason: 1, sequenceId:2 08-05 16:05:31.003013 26917 26995 D CameraUnit, ConsumerImpl: onSessionConfigured, previewCaptureRequest: android.hardware.camera2.CaptureRequest@c68851b6 08-05 16:05:31.003026 26917 27005 I CameraUnit, Camera2Impl: PreviewRequestCallback, onCaptureFailed, fail reason: 1, sequenceId:2 08-05 16:05:31.003055 26917 27005 I CameraUnit, Camera2Impl: PreviewRequestCallback, onCaptureFailed, fail reason: 1, sequenceId:2 08-05 16:05:31.003206 26917 26995 V CameraUnit, ConsumerImpl: onSessionConfigured, mbEnableUX: true, mbDebug3ASyncSession: false, aeReq: null 08-05 16:05:31.003310 26917 27002 E CameraUnit, CameraUnit_TRACE: traceBeginSection, msg: ConsumerImpl.onSessionConfigured 08-05 16:05:31.003324 26917 26995 D CameraUnit, ProducerImpl: onSessionConfigured 08-05 16:05:31.003576 26917 26985 I OCAM_OneCameraImpl: onSessionConfigured, mSessionCallback:ei.i$f@a62c618 上面高通日志解释
最新发布
08-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值