Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 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 | |
| 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 Borger | 4a870a3 | 2022-02-25 01:48:41 +0000 | [diff] [blame] | 51 | void onActive(float maxPreviewFps); |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 52 | void onIdle(int64_t requestCount, int64_t resultErrorCount, bool deviceError, |
Shuzhen Wang | 9372b0b | 2022-05-11 18:55:19 -0700 | [diff] [blame] | 53 | const std::string& userTag, int32_t videoStabilizationMode, |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 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 |
Austin Borger | 4a870a3 | 2022-02-25 01:48:41 +0000 | [diff] [blame] | 85 | static void logActive(const String8& id, float maxPreviewFps); |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 86 | |
| 87 | // Session state becomes idle |
| 88 | static void logIdle(const String8& id, |
| 89 | int64_t requestCount, int64_t resultErrorCount, bool deviceError, |
Shuzhen Wang | 9372b0b | 2022-05-11 18:55:19 -0700 | [diff] [blame] | 90 | const std::string& userTag, int32_t videoStabilizationMode, |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 91 | const std::vector<hardware::CameraStreamStats>& streamStats); |
| 92 | |
| 93 | // Ping camera service proxy for user update |
| 94 | static void pingCameraServiceProxy(); |
Emilian Peev | b91f180 | 2021-03-23 14:50:28 -0700 | [diff] [blame] | 95 | |
Emilian Peev | 5368ebf | 2021-10-08 17:52:18 -0700 | [diff] [blame] | 96 | // Return the current top activity rotate and crop override. |
Emilian Peev | 065b2c1 | 2021-11-23 13:12:57 -0800 | [diff] [blame] | 97 | static int getRotateAndCropOverride(String16 packageName, int lensFacing, int userId); |
Austin Borger | 5f7abe2 | 2022-04-26 15:55:10 -0700 | [diff] [blame] | 98 | |
| 99 | // Detect if the camera is disabled by device policy. |
Austin Borger | 80173a9 | 2022-08-03 17:50:40 -0700 | [diff] [blame] | 100 | static bool isCameraDisabled(int userId); |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | } // android |
| 104 | |
| 105 | #endif // ANDROID_SERVERS_CAMERA_SERVICE_PROXY_WRAPPER_H_ |