1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_SERVERS_CAMERA_SERVICE_PROXY_WRAPPER_H_ 18 #define ANDROID_SERVERS_CAMERA_SERVICE_PROXY_WRAPPER_H_ 19 20 #include <android/hardware/ICameraServiceProxy.h> 21 22 #include <utils/Mutex.h> 23 #include <utils/String8.h> 24 #include <utils/String16.h> 25 #include <utils/StrongPointer.h> 26 #include <utils/Timers.h> 27 28 #include <camera/CameraSessionStats.h> 29 30 namespace android { 31 32 class CameraServiceProxyWrapper { 33 private: 34 // Guard mCameraServiceProxy 35 static Mutex sProxyMutex; 36 // Cached interface to the camera service proxy in system service 37 static sp<hardware::ICameraServiceProxy> sCameraServiceProxy; 38 39 struct CameraSessionStatsWrapper { 40 hardware::CameraSessionStats mSessionStats; 41 Mutex mLock; // lock for per camera session stats 42 CameraSessionStatsWrapperCameraSessionStatsWrapper43 CameraSessionStatsWrapper(const String16& cameraId, int facing, int newCameraState, 44 const String16& clientName, int apiLevel, bool isNdk, int32_t latencyMs) : 45 mSessionStats(cameraId, facing, newCameraState, clientName, apiLevel, isNdk, latencyMs) 46 {} 47 48 void onOpen(); 49 void onClose(int32_t latencyMs); 50 void onStreamConfigured(int operatingMode, bool internalReconfig, int32_t latencyMs); 51 void onActive(); 52 void onIdle(int64_t requestCount, int64_t resultErrorCount, bool deviceError, 53 const std::vector<hardware::CameraStreamStats>& streamStats); 54 }; 55 56 // Lock for camera session stats map 57 static Mutex mLock; 58 // Map from camera id to the camera's session statistics 59 static std::map<String8, std::shared_ptr<CameraSessionStatsWrapper>> mSessionStatsMap; 60 61 /** 62 * Update the session stats of a given camera device (open/close/active/idle) with 63 * the camera proxy service in the system service 64 */ 65 static void updateProxyDeviceState( 66 const hardware::CameraSessionStats& sessionStats); 67 68 static sp<hardware::ICameraServiceProxy> getCameraServiceProxy(); 69 70 public: 71 // Open 72 static void logOpen(const String8& id, int facing, 73 const String16& clientPackageName, int apiLevel, bool isNdk, 74 int32_t latencyMs); 75 76 // Close 77 static void logClose(const String8& id, int32_t latencyMs); 78 79 // Stream configuration 80 static void logStreamConfigured(const String8& id, int operatingMode, bool internalReconfig, 81 int32_t latencyMs); 82 83 // Session state becomes active 84 static void logActive(const String8& id); 85 86 // Session state becomes idle 87 static void logIdle(const String8& id, 88 int64_t requestCount, int64_t resultErrorCount, bool deviceError, 89 const std::vector<hardware::CameraStreamStats>& streamStats); 90 91 // Ping camera service proxy for user update 92 static void pingCameraServiceProxy(); 93 94 // Check whether the current top activity needs a rotate and crop override. 95 static bool isRotateAndCropOverrideNeeded(String16 packageName, int sensorOrientation, 96 int lensFacing); 97 }; 98 99 } // android 100 101 #endif // ANDROID_SERVERS_CAMERA_SERVICE_PROXY_WRAPPER_H_ 102