From 7d5569f51ff64ca8896d90128e085ca33596433d Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Mon, 8 Apr 2019 13:57:54 -0700 Subject: [PATCH] Cameraservice: Cache camera service proxy interface To improve camera launch performance, cache the proxy service interface. System tracing indicates fetching the interface can take up to 8-10 ms during real camera opens, which is a percent or two of total camera startup time. Test: atest CameraCtsTestCases Bug: 130173970 Change-Id: Icdf5218b04f608b897dcbf2085f971b04a913f3b --- .../camera/libcameraservice/CameraService.cpp | 23 +++++++++++-------- .../camera/libcameraservice/CameraService.h | 5 ++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp index 8113c3f19b..cb9ece7a46 100644 --- a/services/camera/libcameraservice/CameraService.cpp +++ b/services/camera/libcameraservice/CameraService.cpp @@ -117,6 +117,9 @@ static void setLogLevel(int level) { static const String16 sManageCameraPermission("android.permission.MANAGE_CAMERA"); +Mutex CameraService::sProxyMutex; +sp CameraService::sCameraServiceProxy; + CameraService::CameraService() : mEventLog(DEFAULT_EVENT_LOG_LENGTH), mNumberOfCameras(0), @@ -203,18 +206,20 @@ status_t CameraService::enumerateProviders() { } sp CameraService::getCameraServiceProxy() { - sp proxyBinder = nullptr; #ifndef __BRILLO__ - sp 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 binder = sm->checkService(String16("media.camera.proxy")); - if (binder != nullptr) { - proxyBinder = interface_cast(binder); + Mutex::Autolock al(sProxyMutex); + if (sCameraServiceProxy == nullptr) { + sp 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 binder = sm->checkService(String16("media.camera.proxy")); + if (binder != nullptr) { + sCameraServiceProxy = interface_cast(binder); + } } #endif - return proxyBinder; + return sCameraServiceProxy; } void CameraService::pingCameraServiceProxy() { diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h index 344dd92cfc..4bcdeb2442 100644 --- a/services/camera/libcameraservice/CameraService.h +++ b/services/camera/libcameraservice/CameraService.h @@ -930,6 +930,11 @@ private: static StatusInternal mapToInternal(hardware::camera::common::V1_0::CameraDeviceStatus status); static int32_t mapToInterface(StatusInternal status); + // Guard mCameraServiceProxy + static Mutex sProxyMutex; + // Cached interface to the camera service proxy in system service + static sp sCameraServiceProxy; + static sp getCameraServiceProxy(); static void pingCameraServiceProxy();