• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(float maxPreviewFps);
52         void onIdle(int64_t requestCount, int64_t resultErrorCount, bool deviceError,
53                 const std::string& userTag, int32_t videoStabilizationMode,
54                 const std::vector<hardware::CameraStreamStats>& streamStats);
55     };
56 
57     // Lock for camera session stats map
58     static Mutex mLock;
59     // Map from camera id to the camera's session statistics
60     static std::map<String8, std::shared_ptr<CameraSessionStatsWrapper>> mSessionStatsMap;
61 
62     /**
63      * Update the session stats of a given camera device (open/close/active/idle) with
64      * the camera proxy service in the system service
65      */
66     static void updateProxyDeviceState(
67             const hardware::CameraSessionStats& sessionStats);
68 
69     static sp<hardware::ICameraServiceProxy> getCameraServiceProxy();
70 
71 public:
72     // Open
73     static void logOpen(const String8& id, int facing,
74             const String16& clientPackageName, int apiLevel, bool isNdk,
75             int32_t latencyMs);
76 
77     // Close
78     static void logClose(const String8& id, int32_t latencyMs);
79 
80     // Stream configuration
81     static void logStreamConfigured(const String8& id, int operatingMode, bool internalReconfig,
82             int32_t latencyMs);
83 
84     // Session state becomes active
85     static void logActive(const String8& id, float maxPreviewFps);
86 
87     // Session state becomes idle
88     static void logIdle(const String8& id,
89             int64_t requestCount, int64_t resultErrorCount, bool deviceError,
90             const std::string& userTag, int32_t videoStabilizationMode,
91             const std::vector<hardware::CameraStreamStats>& streamStats);
92 
93     // Ping camera service proxy for user update
94     static void pingCameraServiceProxy();
95 
96     // Return the current top activity rotate and crop override.
97     static int getRotateAndCropOverride(String16 packageName, int lensFacing, int userId);
98 
99     // Detect if the camera is disabled by device policy.
100     static bool isCameraDisabled(int userId);
101 };
102 
103 } // android
104 
105 #endif // ANDROID_SERVERS_CAMERA_SERVICE_PROXY_WRAPPER_H_
106