blob: ad2ab3f6810773b075cf3ec58d90a00ce50499e2 [file] [log] [blame]
Jon Westd3f9c782019-04-17 20:45:29 -04001From b08e3e719c2401cd4ed9c0c9e639f3f539425918 Mon Sep 17 00:00:00 2001
2From: Artem Borisov <dedsa2002@gmail.com>
3Date: Tue, 25 Sep 2018 12:39:22 +0300
4Subject: [PATCH 6/6] CameraService: Support calling addStates in
5 enumerateProviders
6
7Some pre-P camera HALs trigger onDeviceStatusChange callback during HAL init.
8This is horribly wrong and causes a race condition between enumerateProviders
9and onDeviceStatusChange. While it wasn't really harmful in O, in P call sequence
10was changed and now this race condition leads to two problems: null pointer dereference
11in addStates because mFlashlight is not initialized at a proper timing; mServiceLock
12deadlock because updateCameraNumAndIds and enumerateProviders are called at the same time.
13Moving addStates back to enumerateProviders makes the sequence more similar to O, and doesn't
14let these two issues to happen.
15Enable TARGET_CAMERA_NEEDS_ADD_STATES_IN_ENUMERATE when it is necessary.
16
17@Dil3mm4 edit: Instead of TARGET_CAMERA_NEEDS_ADD_STATES_IN_ENUMERATE let's use a system property to make it more generic and suitable for GSI use.
18
19Change-Id: Ife25b9753fdb679ab0c77f385e1b8527551a4711
20---
21 .../camera/libcameraservice/CameraService.cpp | 17 +++++++++++++++++
22 1 file changed, 17 insertions(+)
23
24diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
25index 157f769a3..208b27051 100644
26--- a/services/camera/libcameraservice/CameraService.cpp
27+++ b/services/camera/libcameraservice/CameraService.cpp
28@@ -181,6 +181,21 @@ status_t CameraService::enumerateProviders() {
29
30 for (auto& cameraId : deviceIds) {
31 String8 id8 = String8(cameraId.c_str());
32+
33+ if (property_get_bool("persist.sys.camera.huawei", false)) {
34+ bool cameraFound = false;
35+ {
36+ Mutex::Autolock lock(mCameraStatesLock);
37+ auto iter = mCameraStates.find(id8);
38+ if (iter != mCameraStates.end()) {
39+ cameraFound = true;
40+ }
41+ }
42+ if (!cameraFound) {
43+ addStates(id8);
44+ }
45+ }
46+
47 onDeviceStatusChanged(id8, CameraDeviceStatus::PRESENT);
48 }
49
50@@ -279,8 +294,10 @@ void CameraService::onDeviceStatusChanged(const String8& id,
51 ALOGI("%s: Unknown camera ID %s, a new camera is added",
52 __FUNCTION__, id.string());
53
54+ if (!property_get_bool("persist.sys.camera.huawei", false)) {
55 // First add as absent to make sure clients are notified below
56 addStates(id);
57+ }
58
59 updateStatus(newStatus, id);
60 } else {
61--
622.17.1
63