blob: eb818d1a8b86a938d230b431cb68ecaca04b9eb5 [file] [log] [blame]
Shuzhen Wang316781a2020-08-18 18:11:01 -07001/*
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
30namespace android {
31
32class CameraServiceProxyWrapper {
33private:
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
43 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);
Austin Borger4a870a32022-02-25 01:48:41 +000051 void onActive(float maxPreviewFps);
Shuzhen Wang316781a2020-08-18 18:11:01 -070052 void onIdle(int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Shuzhen Wang9372b0b2022-05-11 18:55:19 -070053 const std::string& userTag, int32_t videoStabilizationMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -070054 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
71public:
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
Austin Borger4a870a32022-02-25 01:48:41 +000085 static void logActive(const String8& id, float maxPreviewFps);
Shuzhen Wang316781a2020-08-18 18:11:01 -070086
87 // Session state becomes idle
88 static void logIdle(const String8& id,
89 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Shuzhen Wang9372b0b2022-05-11 18:55:19 -070090 const std::string& userTag, int32_t videoStabilizationMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -070091 const std::vector<hardware::CameraStreamStats>& streamStats);
92
93 // Ping camera service proxy for user update
94 static void pingCameraServiceProxy();
Emilian Peevb91f1802021-03-23 14:50:28 -070095
Emilian Peev5368ebf2021-10-08 17:52:18 -070096 // Return the current top activity rotate and crop override.
Emilian Peev065b2c12021-11-23 13:12:57 -080097 static int getRotateAndCropOverride(String16 packageName, int lensFacing, int userId);
Austin Borger5f7abe22022-04-26 15:55:10 -070098
99 // Detect if the camera is disabled by device policy.
Austin Borger80173a92022-08-03 17:50:40 -0700100 static bool isCameraDisabled(int userId);
Shuzhen Wang316781a2020-08-18 18:11:01 -0700101};
102
103} // android
104
105#endif // ANDROID_SERVERS_CAMERA_SERVICE_PROXY_WRAPPER_H_