OSDN Git Service

IServiceManager: Improve getService responsiveness in absence of service
authorAndy Hung <hunga@google.com>
Tue, 6 Dec 2016 17:40:01 +0000 (09:40 -0800)
committerAndy Hung <hunga@google.com>
Wed, 7 Dec 2016 01:19:54 +0000 (01:19 +0000)
Now blocks for 4 seconds worst case instead of 5 seconds.
Some android devices may not have all the normal android phone services.

Test: Wear device on feldspar-dev
Bug: 33086228
Change-Id: Id83fc8cd6b657b53ef78823a460d5fba4a522ab4
(cherry picked from commit 6456e4488d59c0568a1f29dc93b7beb472236086)

libs/binder/IServiceManager.cpp

index 61f24d6..44d235f 100644 (file)
@@ -140,10 +140,12 @@ public:
     {
         unsigned n;
         for (n = 0; n < 5; n++){
+            if (n > 0) {
+                ALOGI("Waiting for service %s...", String8(name).string());
+                sleep(1);
+            }
             sp<IBinder> svc = checkService(name);
             if (svc != NULL) return svc;
-            ALOGI("Waiting for service %s...\n", String8(name).string());
-            sleep(1);
         }
         return NULL;
     }