• 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 #define LOG_TAG "CameraServiceProxyWrapper"
18 #define ATRACE_TAG ATRACE_TAG_CAMERA
19 //#define LOG_NDEBUG 0
20 
21 #include <gui/Surface.h>
22 #include <inttypes.h>
23 #include <utils/Log.h>
24 #include <utils/String16.h>
25 #include <camera/StringUtils.h>
26 #include <binder/IServiceManager.h>
27 #include <system/window.h>
28 
29 #include "aidl/android/hardware/graphics/common/Dataspace.h"
30 
31 #include "CameraServiceProxyWrapper.h"
32 
33 namespace android {
34 
35 using hardware::CameraExtensionSessionStats;
36 using hardware::CameraFeatureCombinationStats;
37 using hardware::CameraSessionStats;
38 using hardware::ICameraServiceProxy;
39 using hardware::camera2::params::SessionConfiguration;
40 
41 namespace {
42 // Sentinel value to be returned when extension session with a stale or invalid key is reported.
43 const std::string POISON_EXT_STATS_KEY("poisoned_stats");
44 } // anonymous namespace
45 
46 /**
47  * CameraSessionStatsWrapper functions
48  */
49 
updateProxyDeviceState(sp<hardware::ICameraServiceProxy> & proxyBinder)50 void CameraServiceProxyWrapper::CameraSessionStatsWrapper::updateProxyDeviceState(
51         sp<hardware::ICameraServiceProxy>& proxyBinder) {
52     if (proxyBinder == nullptr) return;
53     proxyBinder->notifyCameraState(mSessionStats);
54 }
55 
onOpen(sp<hardware::ICameraServiceProxy> & proxyBinder)56 void CameraServiceProxyWrapper::CameraSessionStatsWrapper::onOpen(
57         sp<hardware::ICameraServiceProxy>& proxyBinder) {
58     Mutex::Autolock l(mLock);
59     updateProxyDeviceState(proxyBinder);
60 }
61 
onClose(sp<hardware::ICameraServiceProxy> & proxyBinder,int32_t latencyMs,bool deviceError)62 void CameraServiceProxyWrapper::CameraSessionStatsWrapper::onClose(
63     sp<hardware::ICameraServiceProxy>& proxyBinder, int32_t latencyMs,
64     bool deviceError) {
65     Mutex::Autolock l(mLock);
66 
67     mSessionStats.mNewCameraState = CameraSessionStats::CAMERA_STATE_CLOSED;
68     mSessionStats.mLatencyMs = latencyMs;
69     mSessionStats.mDeviceError = deviceError;
70     mSessionStats.mSessionIndex = 0;
71     updateProxyDeviceState(proxyBinder);
72 }
73 
onStreamConfigured(int operatingMode,bool internalReconfig,int32_t latencyMs)74 void CameraServiceProxyWrapper::CameraSessionStatsWrapper::onStreamConfigured(
75         int operatingMode, bool internalReconfig, int32_t latencyMs) {
76     Mutex::Autolock l(mLock);
77 
78     if (internalReconfig) {
79         mSessionStats.mInternalReconfigure++;
80     } else {
81         mSessionStats.mLatencyMs = latencyMs;
82         mSessionStats.mSessionType = operatingMode;
83     }
84 }
85 
onActive(sp<hardware::ICameraServiceProxy> & proxyBinder,float maxPreviewFps)86 void CameraServiceProxyWrapper::CameraSessionStatsWrapper::onActive(
87     sp<hardware::ICameraServiceProxy>& proxyBinder, float maxPreviewFps) {
88     Mutex::Autolock l(mLock);
89 
90     mSessionStats.mNewCameraState = CameraSessionStats::CAMERA_STATE_ACTIVE;
91     mSessionStats.mMaxPreviewFps = maxPreviewFps;
92     mSessionStats.mSessionIndex++;
93     updateProxyDeviceState(proxyBinder);
94 
95     // Reset mCreationDuration to -1 to distinguish between 1st session
96     // after configuration, and all other sessions after configuration.
97     mSessionStats.mLatencyMs = -1;
98 }
99 
onIdle(sp<hardware::ICameraServiceProxy> & proxyBinder,int64_t requestCount,int64_t resultErrorCount,bool deviceError,const std::string & userTag,int32_t videoStabilizationMode,bool usedUltraWide,bool usedZoomOverride,std::pair<int32_t,int32_t> mostRequestedFpsRange,const std::vector<hardware::CameraStreamStats> & streamStats)100 void CameraServiceProxyWrapper::CameraSessionStatsWrapper::onIdle(
101         sp<hardware::ICameraServiceProxy>& proxyBinder,
102         int64_t requestCount, int64_t resultErrorCount, bool deviceError,
103         const std::string& userTag, int32_t videoStabilizationMode, bool usedUltraWide,
104         bool usedZoomOverride, std::pair<int32_t, int32_t> mostRequestedFpsRange,
105         const std::vector<hardware::CameraStreamStats>& streamStats) {
106     Mutex::Autolock l(mLock);
107 
108     mSessionStats.mNewCameraState = CameraSessionStats::CAMERA_STATE_IDLE;
109     mSessionStats.mRequestCount = requestCount;
110     mSessionStats.mResultErrorCount = resultErrorCount;
111     mSessionStats.mDeviceError = deviceError;
112     mSessionStats.mUserTag = userTag;
113     mSessionStats.mVideoStabilizationMode = videoStabilizationMode;
114     mSessionStats.mUsedUltraWide = usedUltraWide;
115     mSessionStats.mUsedZoomOverride = usedZoomOverride;
116     mSessionStats.mMostRequestedFpsRange = mostRequestedFpsRange;
117     mSessionStats.mStreamStats = streamStats;
118 
119     updateProxyDeviceState(proxyBinder);
120 
121     mSessionStats.mInternalReconfigure = 0;
122     mSessionStats.mStreamStats.clear();
123     mSessionStats.mCameraExtensionSessionStats = {};
124 }
125 
getLogId()126 int64_t CameraServiceProxyWrapper::CameraSessionStatsWrapper::getLogId() {
127     Mutex::Autolock l(mLock);
128     return mSessionStats.mLogId;
129 }
130 
updateExtensionSessionStats(const hardware::CameraExtensionSessionStats & extStats)131 std::string CameraServiceProxyWrapper::CameraSessionStatsWrapper::updateExtensionSessionStats(
132         const hardware::CameraExtensionSessionStats& extStats) {
133     Mutex::Autolock l(mLock);
134     CameraExtensionSessionStats& currStats = mSessionStats.mCameraExtensionSessionStats;
135     if (currStats.key != extStats.key) {
136         // Mismatched keys. Extensions stats likely reported for a closed session
137         ALOGW("%s: mismatched extensions stats key: current='%s' reported='%s'. Dropping stats.",
138               __FUNCTION__, toStdString(currStats.key).c_str(), toStdString(extStats.key).c_str());
139         return POISON_EXT_STATS_KEY; // return poisoned key to so future calls are
140                                      // definitely dropped.
141     }
142 
143     // Matching keys...
144     if (currStats.key.size()) {
145         // non-empty matching keys. overwrite.
146         ALOGV("%s: Overwriting extension session stats: %s", __FUNCTION__,
147               extStats.toString().c_str());
148         currStats = extStats;
149         return toStdString(currStats.key);
150     }
151 
152     // Matching empty keys...
153     if (mSessionStats.mClientName != toStdString(extStats.clientName)) {
154         ALOGW("%s: extension stats reported for unexpected package: current='%s' reported='%s'. "
155               "Dropping stats.", __FUNCTION__,
156               mSessionStats.mClientName.c_str(),
157               toStdString(extStats.clientName).c_str());
158         return POISON_EXT_STATS_KEY;
159     }
160 
161     // Matching empty keys for the current client...
162     if (mSessionStats.mNewCameraState == CameraSessionStats::CAMERA_STATE_OPEN ||
163         mSessionStats.mNewCameraState == CameraSessionStats::CAMERA_STATE_IDLE) {
164         // Camera is open, but not active. It is possible that the active callback hasn't
165         // occurred yet. Keep the stats, but don't associate it with any session.
166         ALOGV("%s: extension stat reported for an open, but not active camera. "
167               "Saving stats, but not generating key.", __FUNCTION__);
168         currStats = extStats;
169         return {}; // Subsequent calls will handle setting the correct key.
170     }
171 
172     if (mSessionStats.mNewCameraState == CameraSessionStats::CAMERA_STATE_ACTIVE) {
173         // camera is active. First call for the session!
174         currStats = extStats;
175 
176         // Generate a new key from logId and sessionIndex.
177         std::ostringstream key;
178         key << mSessionStats.mSessionIndex << '/' << mSessionStats.mLogId;
179         currStats.key = String16(key.str().c_str());
180         ALOGV("%s: New extension session stats: %s", __FUNCTION__, currStats.toString().c_str());
181         return toStdString(currStats.key);
182     }
183 
184     // Camera is closed. Probably a stale call.
185     ALOGW("%s: extension stats reported for closed camera id '%s'. Dropping stats.",
186           __FUNCTION__, mSessionStats.mCameraId.c_str());
187     return {};
188 }
189 
190 /**
191  * CameraServiceProxyWrapper functions
192  */
193 
getCameraServiceProxy()194 sp<ICameraServiceProxy> CameraServiceProxyWrapper::getCameraServiceProxy() {
195 #ifndef __BRILLO__
196     Mutex::Autolock al(mProxyMutex);
197     if (mCameraServiceProxy == nullptr) {
198         mCameraServiceProxy = getDefaultCameraServiceProxy();
199     }
200 #endif
201     return mCameraServiceProxy;
202 }
203 
getDefaultCameraServiceProxy()204 sp<hardware::ICameraServiceProxy> CameraServiceProxyWrapper::getDefaultCameraServiceProxy() {
205 #ifndef __BRILLO__
206     sp<IServiceManager> sm = defaultServiceManager();
207     // Use checkService because cameraserver normally starts before the
208     // system server and the proxy service. So the long timeout that getService
209     // has before giving up is inappropriate.
210     sp<IBinder> binder = sm->checkService(String16("media.camera.proxy"));
211     if (binder != nullptr) {
212         return interface_cast<ICameraServiceProxy>(binder);
213     }
214 #endif
215     return nullptr;
216 }
217 
pingCameraServiceProxy()218 void CameraServiceProxyWrapper::pingCameraServiceProxy() {
219     sp<ICameraServiceProxy> proxyBinder = getCameraServiceProxy();
220     if (proxyBinder == nullptr) return;
221     proxyBinder->pingForUserUpdate();
222 }
223 
encodeSessionConfiguration(const SessionConfiguration & sessionConfig)224 int64_t CameraServiceProxyWrapper::encodeSessionConfiguration(
225         const SessionConfiguration& sessionConfig) {
226     int64_t features = CameraFeatureCombinationStats::CAMERA_FEATURE_UNKNOWN;
227     const static int32_t WIDTH_4K = 3840;
228     const static int32_t HEIGHT_4K = 2160;
229 
230     // Check session parameters
231     if (sessionConfig.hasSessionParameters()) {
232         const auto& parameters = sessionConfig.getSessionParameters();
233 
234         camera_metadata_ro_entry fpsEntry = parameters.find(ANDROID_CONTROL_AE_TARGET_FPS_RANGE);
235         if (fpsEntry.count == 2 && fpsEntry.data.i32[1] == 60) {
236             features |= CameraFeatureCombinationStats::CAMERA_FEATURE_60_FPS;
237         }
238 
239         camera_metadata_ro_entry stabEntry =
240                 parameters.find(ANDROID_CONTROL_VIDEO_STABILIZATION_MODE);
241         if (stabEntry.count == 1 && stabEntry.data.u8[0] ==
242                 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_PREVIEW_STABILIZATION) {
243             features |= CameraFeatureCombinationStats::CAMERA_FEATURE_STABILIZATION;
244         }
245     }
246 
247     // Check output configurations
248     const auto& outputConfigs = sessionConfig.getOutputConfigurations();
249     for (const auto& config : outputConfigs) {
250         int format = config.getFormat();
251         int dataSpace = config.getDataspace();
252         int64_t dynamicRangeProfile = config.getDynamicRangeProfile();
253 
254         // Check JPEG and JPEG_R features
255         if (format == HAL_PIXEL_FORMAT_BLOB) {
256             if (dataSpace == HAL_DATASPACE_V0_JFIF) {
257                 features |= CameraFeatureCombinationStats::CAMERA_FEATURE_JPEG;
258             } else if (dataSpace == static_cast<android_dataspace_t>(
259                     aidl::android::hardware::graphics::common::Dataspace::JPEG_R)) {
260                 features |= CameraFeatureCombinationStats::CAMERA_FEATURE_JPEG_R;
261             }
262         } else {
263             if (dynamicRangeProfile == HAL_DATASPACE_BT2020_HLG) {
264                 features |= CameraFeatureCombinationStats::CAMERA_FEATURE_HLG10;
265             }
266 
267             // Check 4K
268             const auto& gbps = config.getGraphicBufferProducers();
269             int32_t width = 0, height = 0;
270             if (gbps.size() > 0) {
271                 if (gbps[0] == nullptr) {
272                     ALOGE("%s: Failed to query size due to abandoned surface.",
273                             __FUNCTION__);
274                     return CameraFeatureCombinationStats::CAMERA_FEATURE_UNKNOWN;
275                 }
276 
277                 sp<Surface> surface = new Surface(gbps[0], /*useAsync*/false);
278                 ANativeWindow *anw = surface.get();
279 
280                 width = ANativeWindow_getWidth(anw);
281                 if (width < 0) {
282                     ALOGE("%s: Failed to query Surface width: %s (%d)",
283                             __FUNCTION__, strerror(-width), width);
284                     return CameraFeatureCombinationStats::CAMERA_FEATURE_UNKNOWN;
285                 }
286                 height = ANativeWindow_getHeight(anw);
287                 if (height < 0) {
288                     ALOGE("%s: Failed to query Surface height: %s (%d)",
289                             __FUNCTION__, strerror(-height), height);
290                     return CameraFeatureCombinationStats::CAMERA_FEATURE_UNKNOWN;
291                 }
292             } else {
293                 width = config.getWidth();
294                 height = config.getHeight();
295             }
296             if (width == WIDTH_4K && height == HEIGHT_4K) {
297                 features |= CameraFeatureCombinationStats::CAMERA_FEATURE_4K;
298             }
299         }
300     }
301     return features;
302 }
303 
304 // Note: The `ret` parameter is the return value of the
305 // `isSessionConfigurationWithParametersSupporteed` binder call from the app.
logFeatureCombinationInternal(const std::string & cameraId,int clientUid,const SessionConfiguration & sessionConfiguration,binder::Status ret,int type)306 void CameraServiceProxyWrapper::logFeatureCombinationInternal(
307         const std::string &cameraId, int clientUid,
308         const SessionConfiguration& sessionConfiguration, binder::Status ret,
309         int type) {
310     sp<hardware::ICameraServiceProxy> proxyBinder = getCameraServiceProxy();
311     if (proxyBinder == nullptr) return;
312 
313     int64_t featureCombination = encodeSessionConfiguration(sessionConfiguration);
314     int queryStatus = ret.isOk() ? OK : ret.serviceSpecificErrorCode();
315     CameraFeatureCombinationStats stats;
316     stats.mCameraId = cameraId;
317     stats.mUid = clientUid;
318     stats.mFeatureCombination = featureCombination;
319     stats.mQueryType = type;
320     stats.mStatus = queryStatus;
321 
322     auto status = proxyBinder->notifyFeatureCombinationStats(stats);
323     if (!status.isOk()) {
324         ALOGE("%s: Failed to notify feature combination stats: %s", __FUNCTION__,
325                 status.exceptionMessage().c_str());
326     }
327 }
328 
getRotateAndCropOverride(const std::string & packageName,int lensFacing,int userId)329 int CameraServiceProxyWrapper::getRotateAndCropOverride(const std::string &packageName,
330         int lensFacing, int userId) {
331     sp<ICameraServiceProxy> proxyBinder = getCameraServiceProxy();
332     if (proxyBinder == nullptr) return true;
333     int ret = 0;
334     auto status = proxyBinder->getRotateAndCropOverride(packageName, lensFacing,
335             userId, &ret);
336     if (!status.isOk()) {
337         ALOGE("%s: Failed during top activity orientation query: %s", __FUNCTION__,
338                 status.exceptionMessage().c_str());
339     }
340 
341     return ret;
342 }
343 
getAutoframingOverride(const std::string & packageName)344 int CameraServiceProxyWrapper::getAutoframingOverride(const std::string& packageName) {
345     sp<ICameraServiceProxy> proxyBinder = getCameraServiceProxy();
346     if (proxyBinder == nullptr) {
347         return ANDROID_CONTROL_AUTOFRAMING_OFF;
348     }
349     int ret = 0;
350     auto status = proxyBinder->getAutoframingOverride(packageName, &ret);
351     if (!status.isOk()) {
352         ALOGE("%s: Failed during autoframing override query: %s", __FUNCTION__,
353                 status.exceptionMessage().c_str());
354     }
355 
356     return ret;
357 }
358 
logStreamConfigured(const std::string & id,int operatingMode,bool internalConfig,int32_t latencyMs)359 void CameraServiceProxyWrapper::logStreamConfigured(const std::string& id,
360         int operatingMode, bool internalConfig, int32_t latencyMs) {
361     std::shared_ptr<CameraSessionStatsWrapper> sessionStats;
362     {
363         Mutex::Autolock l(mLock);
364         if (mSessionStatsMap.count(id) == 0) {
365             ALOGE("%s: SessionStatsMap should contain camera %s",
366                     __FUNCTION__, id.c_str());
367             return;
368         }
369         sessionStats = mSessionStatsMap[id];
370     }
371 
372     ALOGV("%s: id %s, operatingMode %d, internalConfig %d, latencyMs %d",
373             __FUNCTION__, id.c_str(), operatingMode, internalConfig, latencyMs);
374     sessionStats->onStreamConfigured(operatingMode, internalConfig, latencyMs);
375 }
376 
logActive(const std::string & id,float maxPreviewFps)377 void CameraServiceProxyWrapper::logActive(const std::string& id, float maxPreviewFps) {
378     std::shared_ptr<CameraSessionStatsWrapper> sessionStats;
379     {
380         Mutex::Autolock l(mLock);
381         if (mSessionStatsMap.count(id) == 0) {
382             ALOGE("%s: SessionStatsMap should contain camera %s when logActive is called",
383                     __FUNCTION__, id.c_str());
384             return;
385         }
386         sessionStats = mSessionStatsMap[id];
387     }
388 
389     ALOGV("%s: id %s", __FUNCTION__, id.c_str());
390     sp<hardware::ICameraServiceProxy> proxyBinder = getCameraServiceProxy();
391     sessionStats->onActive(proxyBinder, maxPreviewFps);
392 }
393 
logIdle(const std::string & id,int64_t requestCount,int64_t resultErrorCount,bool deviceError,const std::string & userTag,int32_t videoStabilizationMode,bool usedUltraWide,bool usedZoomOverride,std::pair<int32_t,int32_t> mostRequestedFpsRange,const std::vector<hardware::CameraStreamStats> & streamStats)394 void CameraServiceProxyWrapper::logIdle(const std::string& id,
395         int64_t requestCount, int64_t resultErrorCount, bool deviceError,
396         const std::string& userTag, int32_t videoStabilizationMode, bool usedUltraWide,
397         bool usedZoomOverride, std::pair<int32_t, int32_t> mostRequestedFpsRange,
398         const std::vector<hardware::CameraStreamStats>& streamStats) {
399     std::shared_ptr<CameraSessionStatsWrapper> sessionStats;
400     {
401         Mutex::Autolock l(mLock);
402         if (mSessionStatsMap.count(id) == 0) {
403             ALOGE("%s: SessionStatsMap should contain camera %s when logIdle is called",
404                 __FUNCTION__, id.c_str());
405             return;
406         }
407         sessionStats = mSessionStatsMap[id];
408     }
409 
410     ALOGV("%s: id %s, requestCount %" PRId64 ", resultErrorCount %" PRId64 ", deviceError %d"
411             ", userTag %s, videoStabilizationMode %d, most common FPS [%d,%d]",
412             __FUNCTION__, id.c_str(), requestCount, resultErrorCount, deviceError, userTag.c_str(),
413             videoStabilizationMode, mostRequestedFpsRange.first, mostRequestedFpsRange.second);
414     for (size_t i = 0; i < streamStats.size(); i++) {
415         ALOGV("%s: streamStats[%zu]: w %d h %d, requestedCount %" PRId64 ", dropCount %"
416                 PRId64 ", startTimeMs %d" ,
417                 __FUNCTION__, i, streamStats[i].mWidth, streamStats[i].mHeight,
418                 streamStats[i].mRequestCount, streamStats[i].mErrorCount,
419                 streamStats[i].mStartLatencyMs);
420     }
421 
422     sp<hardware::ICameraServiceProxy> proxyBinder = getCameraServiceProxy();
423     sessionStats->onIdle(proxyBinder, requestCount, resultErrorCount, deviceError, userTag,
424             videoStabilizationMode, usedUltraWide, usedZoomOverride,
425             mostRequestedFpsRange, streamStats);
426 }
427 
logOpen(const std::string & id,int facing,const std::string & clientPackageName,int effectiveApiLevel,bool isNdk,int32_t latencyMs)428 void CameraServiceProxyWrapper::logOpen(const std::string& id, int facing,
429             const std::string& clientPackageName, int effectiveApiLevel, bool isNdk,
430             int32_t latencyMs) {
431     std::shared_ptr<CameraSessionStatsWrapper> sessionStats;
432     {
433         Mutex::Autolock l(mLock);
434         if (mSessionStatsMap.count(id) > 0) {
435             ALOGE("%s: SessionStatsMap shouldn't contain camera %s",
436                     __FUNCTION__, id.c_str());
437             return;
438         }
439 
440         int apiLevel = CameraSessionStats::CAMERA_API_LEVEL_1;
441         if (effectiveApiLevel == 2) {
442             apiLevel = CameraSessionStats::CAMERA_API_LEVEL_2;
443         }
444 
445         // Generate a new log ID for open events
446         int64_t logId = generateLogId(mRandomDevice);
447 
448         sessionStats = std::make_shared<CameraSessionStatsWrapper>(
449                 id, facing, CameraSessionStats::CAMERA_STATE_OPEN, clientPackageName,
450                 apiLevel, isNdk, latencyMs, logId);
451         mSessionStatsMap.emplace(id, sessionStats);
452         ALOGV("%s: Adding id %s", __FUNCTION__, id.c_str());
453     }
454 
455     ALOGV("%s: id %s, facing %d, effectiveApiLevel %d, isNdk %d, latencyMs %d",
456             __FUNCTION__, id.c_str(), facing, effectiveApiLevel, isNdk, latencyMs);
457     sp<hardware::ICameraServiceProxy> proxyBinder = getCameraServiceProxy();
458     sessionStats->onOpen(proxyBinder);
459 }
460 
logClose(const std::string & id,int32_t latencyMs,bool deviceError)461 void CameraServiceProxyWrapper::logClose(const std::string& id, int32_t latencyMs,
462         bool deviceError) {
463     std::shared_ptr<CameraSessionStatsWrapper> sessionStats;
464     {
465         Mutex::Autolock l(mLock);
466         if (mSessionStatsMap.count(id) == 0) {
467             ALOGE("%s: SessionStatsMap should contain camera %s before it's closed",
468                     __FUNCTION__, id.c_str());
469             return;
470         }
471 
472         sessionStats = mSessionStatsMap[id];
473         if (sessionStats == nullptr) {
474             ALOGE("%s: SessionStatsMap should contain camera %s",
475                     __FUNCTION__, id.c_str());
476             return;
477         }
478 
479         mSessionStatsMap.erase(id);
480         ALOGV("%s: Erasing id %s, deviceError %d", __FUNCTION__, id.c_str(), deviceError);
481     }
482 
483     ALOGV("%s: id %s, latencyMs %d, deviceError %d", __FUNCTION__,
484             id.c_str(), latencyMs, deviceError);
485     sp<hardware::ICameraServiceProxy> proxyBinder = getCameraServiceProxy();
486     sessionStats->onClose(proxyBinder, latencyMs, deviceError);
487 }
488 
isCameraDisabled(int userId)489 bool CameraServiceProxyWrapper::isCameraDisabled(int userId) {
490     sp<ICameraServiceProxy> proxyBinder = getCameraServiceProxy();
491     if (proxyBinder == nullptr) return true;
492     bool ret = false;
493     auto status = proxyBinder->isCameraDisabled(userId, &ret);
494     if (!status.isOk()) {
495         ALOGE("%s: Failed during camera disabled query: %s", __FUNCTION__,
496                 status.exceptionMessage().c_str());
497     }
498     return ret;
499 }
500 
getCurrentLogIdForCamera(const std::string & cameraId)501 int64_t CameraServiceProxyWrapper::getCurrentLogIdForCamera(const std::string& cameraId) {
502     std::shared_ptr<CameraSessionStatsWrapper> stats;
503     {
504         Mutex::Autolock _l(mLock);
505         if (mSessionStatsMap.count(cameraId) == 0) {
506             ALOGE("%s: SessionStatsMap should contain camera %s before asking for its logging ID.",
507                   __FUNCTION__, cameraId.c_str());
508             return 0;
509         }
510 
511         stats = mSessionStatsMap[cameraId];
512     }
513     return stats->getLogId();
514 }
515 
generateLogId(std::random_device & randomDevice)516 int64_t CameraServiceProxyWrapper::generateLogId(std::random_device& randomDevice) {
517     int64_t ret = 0;
518     do {
519         // std::random_device generates 32 bits per call, so we call it twice
520         ret = randomDevice();
521         ret = ret << 32;
522         ret = ret | randomDevice();
523     } while (ret == 0); // 0 is not a valid identifier
524 
525     return ret;
526 }
527 
updateExtensionStats(const hardware::CameraExtensionSessionStats & extStats)528 std::string CameraServiceProxyWrapper::updateExtensionStats(
529         const hardware::CameraExtensionSessionStats& extStats) {
530     std::shared_ptr<CameraSessionStatsWrapper> stats;
531     std::string cameraId = toStdString(extStats.cameraId);
532     {
533         Mutex::Autolock _l(mLock);
534         if (mSessionStatsMap.count(cameraId) == 0) {
535             ALOGE("%s CameraExtensionSessionStats reported for camera id that isn't open: %s",
536                   __FUNCTION__, cameraId.c_str());
537             return {};
538         }
539 
540         stats = mSessionStatsMap[cameraId];
541         return stats->updateExtensionSessionStats(extStats);
542     }
543 }
544 
545 }  // namespace android
546