blob: f90a841b092ab98617183603e022ae4f5769fd3a [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
Austin Borger74fca042022-05-23 12:41:21 -070035 Mutex mProxyMutex;
Shuzhen Wang316781a2020-08-18 18:11:01 -070036 // Cached interface to the camera service proxy in system service
Austin Borger74fca042022-05-23 12:41:21 -070037 sp<hardware::ICameraServiceProxy> mCameraServiceProxy;
Shuzhen Wang316781a2020-08-18 18:11:01 -070038
Austin Borger74fca042022-05-23 12:41:21 -070039 class CameraSessionStatsWrapper {
40 private:
Shuzhen Wang316781a2020-08-18 18:11:01 -070041 hardware::CameraSessionStats mSessionStats;
42 Mutex mLock; // lock for per camera session stats
43
Austin Borger74fca042022-05-23 12:41:21 -070044 /**
45 * Update the session stats of a given camera device (open/close/active/idle) with
46 * the camera proxy service in the system service
47 */
48 void updateProxyDeviceState(sp<hardware::ICameraServiceProxy>& proxyBinder);
49
50 public:
Shuzhen Wang316781a2020-08-18 18:11:01 -070051 CameraSessionStatsWrapper(const String16& cameraId, int facing, int newCameraState,
52 const String16& clientName, int apiLevel, bool isNdk, int32_t latencyMs) :
53 mSessionStats(cameraId, facing, newCameraState, clientName, apiLevel, isNdk, latencyMs)
Austin Borger74fca042022-05-23 12:41:21 -070054 { }
Shuzhen Wang316781a2020-08-18 18:11:01 -070055
Austin Borger74fca042022-05-23 12:41:21 -070056 void onOpen(sp<hardware::ICameraServiceProxy>& proxyBinder);
Shuzhen Wang03fe6232023-02-05 12:41:15 -080057 void onClose(sp<hardware::ICameraServiceProxy>& proxyBinder, int32_t latencyMs,
58 bool deviceError);
Shuzhen Wang316781a2020-08-18 18:11:01 -070059 void onStreamConfigured(int operatingMode, bool internalReconfig, int32_t latencyMs);
Austin Borger74fca042022-05-23 12:41:21 -070060 void onActive(sp<hardware::ICameraServiceProxy>& proxyBinder, float maxPreviewFps);
61 void onIdle(sp<hardware::ICameraServiceProxy>& proxyBinder,
62 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Shuzhen Wang9372b0b2022-05-11 18:55:19 -070063 const std::string& userTag, int32_t videoStabilizationMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -070064 const std::vector<hardware::CameraStreamStats>& streamStats);
65 };
66
67 // Lock for camera session stats map
Austin Borger74fca042022-05-23 12:41:21 -070068 Mutex mLock;
Shuzhen Wang316781a2020-08-18 18:11:01 -070069 // Map from camera id to the camera's session statistics
Austin Borger74fca042022-05-23 12:41:21 -070070 std::map<String8, std::shared_ptr<CameraSessionStatsWrapper>> mSessionStatsMap;
Shuzhen Wang316781a2020-08-18 18:11:01 -070071
Austin Borger74fca042022-05-23 12:41:21 -070072 sp<hardware::ICameraServiceProxy> getCameraServiceProxy();
Shuzhen Wang316781a2020-08-18 18:11:01 -070073
74public:
Austin Borger74fca042022-05-23 12:41:21 -070075 CameraServiceProxyWrapper(sp<hardware::ICameraServiceProxy> serviceProxy = nullptr) :
76 mCameraServiceProxy(serviceProxy)
77 { }
78
79 static sp<hardware::ICameraServiceProxy> getDefaultCameraServiceProxy();
80
Shuzhen Wang316781a2020-08-18 18:11:01 -070081 // Open
Austin Borger74fca042022-05-23 12:41:21 -070082 void logOpen(const String8& id, int facing,
Shuzhen Wang316781a2020-08-18 18:11:01 -070083 const String16& clientPackageName, int apiLevel, bool isNdk,
84 int32_t latencyMs);
85
86 // Close
Shuzhen Wang03fe6232023-02-05 12:41:15 -080087 void logClose(const String8& id, int32_t latencyMs, bool deviceError);
Shuzhen Wang316781a2020-08-18 18:11:01 -070088
89 // Stream configuration
Austin Borger74fca042022-05-23 12:41:21 -070090 void logStreamConfigured(const String8& id, int operatingMode, bool internalReconfig,
Shuzhen Wang316781a2020-08-18 18:11:01 -070091 int32_t latencyMs);
92
93 // Session state becomes active
Austin Borger74fca042022-05-23 12:41:21 -070094 void logActive(const String8& id, float maxPreviewFps);
Shuzhen Wang316781a2020-08-18 18:11:01 -070095
96 // Session state becomes idle
Austin Borger74fca042022-05-23 12:41:21 -070097 void logIdle(const String8& id,
Shuzhen Wang316781a2020-08-18 18:11:01 -070098 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Shuzhen Wang9372b0b2022-05-11 18:55:19 -070099 const std::string& userTag, int32_t videoStabilizationMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700100 const std::vector<hardware::CameraStreamStats>& streamStats);
101
102 // Ping camera service proxy for user update
Austin Borger74fca042022-05-23 12:41:21 -0700103 void pingCameraServiceProxy();
Emilian Peevb91f1802021-03-23 14:50:28 -0700104
Emilian Peev5368ebf2021-10-08 17:52:18 -0700105 // Return the current top activity rotate and crop override.
Austin Borger74fca042022-05-23 12:41:21 -0700106 int getRotateAndCropOverride(String16 packageName, int lensFacing, int userId);
Austin Borger5f7abe22022-04-26 15:55:10 -0700107
Bharatt Kukreja7146ced2022-10-25 15:45:29 +0000108 // Return the current top activity autoframing.
109 int getAutoframingOverride(const String16& packageName);
110
Austin Borger5f7abe22022-04-26 15:55:10 -0700111 // Detect if the camera is disabled by device policy.
Austin Borger9bfa0a72022-08-03 17:50:40 -0700112 bool isCameraDisabled(int userId);
Shuzhen Wang316781a2020-08-18 18:11:01 -0700113};
114
115} // android
116
117#endif // ANDROID_SERVERS_CAMERA_SERVICE_PROXY_WRAPPER_H_