Bug fix in SensorManager.

If SensorService hasn't started when SensorManager instance is requested, keep retrying for a
longer duration.

Bug: 22529981
Change-Id: I4ba6b760608e34d79273aeb39568f0fa72fbaf9d
diff --git a/include/gui/SensorManager.h b/include/gui/SensorManager.h
index 3796067..9794d4e 100644
--- a/include/gui/SensorManager.h
+++ b/include/gui/SensorManager.h
@@ -101,7 +101,6 @@
         return *sensorManager;
     }
 
-    SensorManager(const String16& opPackageName);
     ~SensorManager();
 
     ssize_t getSensorList(Sensor const* const** list) const;
@@ -113,6 +112,7 @@
     // DeathRecipient interface
     void sensorManagerDied();
 
+    SensorManager(const String16& opPackageName);
     status_t assertStateLocked() const;
 
 private:
@@ -127,6 +127,8 @@
     const String16 mOpPackageName;
 };
 
+android::Mutex android::SensorManager::sLock;
+std::map<String16, SensorManager*> android::SensorManager::sPackageInstances;
 // ----------------------------------------------------------------------------
 }; // namespace android
 
diff --git a/libs/gui/SensorManager.cpp b/libs/gui/SensorManager.cpp
index dd37781..ead535e 100644
--- a/libs/gui/SensorManager.cpp
+++ b/libs/gui/SensorManager.cpp
@@ -59,12 +59,13 @@
 
 status_t SensorManager::assertStateLocked() const {
     if (mSensorServer == NULL) {
-        // try for one second
         const String16 name("sensorservice");
-        for (int i=0 ; i<4 ; i++) {
+        // try 10 times before giving up ...
+        for (int i = 0; i < 10; ++i) {
             status_t err = getService(name, &mSensorServer);
             if (err == NAME_NOT_FOUND) {
-                usleep(250000);
+                // Sleep for 1 second before retrying.
+                sleep(1);
                 continue;
             }
             if (err != NO_ERROR) {
@@ -73,6 +74,10 @@
             break;
         }
 
+        if (mSensorServer == NULL) {
+            ALOGE("FATAL getsensorservice returned` NULL");
+        }
+
         class DeathObserver : public IBinder::DeathRecipient {
             SensorManager& mSensorManger;
             virtual void binderDied(const wp<IBinder>& who) {