OSDN Git Service

Emulator: wait for qemu-props to finish
authorbohu <bohu@google.com>
Wed, 10 Aug 2016 15:34:13 +0000 (08:34 -0700)
committerBjoern Johansson <bjoernj@google.com>
Wed, 11 Jan 2017 21:03:23 +0000 (13:03 -0800)
Emulator camera module checks the qemu.sf.fake_camera property
to decide how to setup emulated cameras. If qemu-props has not
set it up yet, there will be no emulated cameras and any later
usage of emulated camera will fail.

Bug: 30768229
Test: ran camera CTS tests
Change-Id: Idb2bebd5ca3737aa416fc3094ecf15c1132ed989
(cherry picked from commit 144ee8937774ba95e9b80882b37f9f5310d498cd)

camera/EmulatedCameraFactory.cpp
camera/EmulatedCameraFactory.h

index 137d8ab..cf8440a 100755 (executable)
@@ -55,6 +55,8 @@ EmulatedCameraFactory::EmulatedCameraFactory()
         createQemuCameras();
     }
 
+    waitForQemuSfFakeCameraPropertyAvailable();
+
     if (isBackFakeCameraEmulationOn()) {
         /* Camera ID. */
         const int camera_id = mEmulatedCameraNum;
@@ -169,7 +171,7 @@ EmulatedCameraFactory::EmulatedCameraFactory()
         }
     }
 
-    ALOGV("%d cameras are being emulated. %d of them are fake cameras.",
+    ALOGE("%d cameras are being emulated. %d of them are fake cameras.",
           mEmulatedCameraNum, mFakeCameraNum);
 
     /* Create hotplug thread */
@@ -437,6 +439,26 @@ void EmulatedCameraFactory::createQemuCameras()
     mEmulatedCameraNum = index;
 }
 
+void EmulatedCameraFactory::waitForQemuSfFakeCameraPropertyAvailable() {
+    // Camera service may start running before qemu-props sets qemu.sf.fake_camera to
+    // any of the follwing four values: "none,front,back,both"; so we need to wait.
+    // android/camera/camera-service.c
+    // bug: 30768229
+    int numAttempts = 100;
+    char prop[PROPERTY_VALUE_MAX];
+    bool timeout = true;
+    for (int i = 0; i < numAttempts; ++i) {
+        if (property_get("qemu.sf.fake_camera", prop, NULL) != 0 ) {
+            timeout = false;
+            break;
+        }
+        usleep(5000);
+    }
+    if (timeout) {
+        ALOGE("timeout (%dms) waiting for property qemu.sf.fake_camera to be set\n", 5 * numAttempts);
+    }
+}
+
 bool EmulatedCameraFactory::isBackFakeCameraEmulationOn()
 {
     /* Defined by 'qemu.sf.fake_camera' boot property: if property exist, and
index 3f19be1..da261c3 100755 (executable)
@@ -156,6 +156,9 @@ private:
      */
     void createQemuCameras();
 
+    /* Waits till qemu-props has done setup, timeout after 500ms */
+    void waitForQemuSfFakeCameraPropertyAvailable();
+
     /* Checks if fake camera emulation is on for the camera facing back. */
     bool isBackFakeCameraEmulationOn();