From 47f876b74be0a2d6d417f5ff385f85d835a97fe9 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Tue, 17 Apr 2018 13:56:46 +0900 Subject: Hide some headers from libbinder to vendors The headers that are related to system services are now hidden to vendors. Note that this does not break anything because vendors have already been disallowed to talk to system services via sepolicy. Their use of binder is strictly limited within themselves (via /dev/vndbinder). The hidden headers are now guarded with __ANDROID_VNDK__ and including them from vendors (or vendor variants of other VNDK libraries) will trigger a build-time error. Bug: 78113963 Test: m -j Test: devices boots to the UI Change-Id: I19be5ca024fc4081b7861d908d75758c1d956a83 --- libs/binder/Static.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libs/binder/Static.cpp') diff --git a/libs/binder/Static.cpp b/libs/binder/Static.cpp index f0613d1631..9899b65288 100644 --- a/libs/binder/Static.cpp +++ b/libs/binder/Static.cpp @@ -94,6 +94,8 @@ static LibBinderIPCtStatics gIPCStatics; Mutex gDefaultServiceManagerLock; sp gDefaultServiceManager; +#ifndef __ANDROID_VNDK__ sp gPermissionController; +#endif } // namespace android -- cgit v1.2.3-59-g8ed1b From 788e1c413914731b2e2e52a9b1e007422fc367cf Mon Sep 17 00:00:00 2001 From: Yunfan Chen Date: Thu, 29 Mar 2018 16:52:09 +0900 Subject: Reduce the polling interval in getService() to 100ms The 1 second polling interval is too long and 100ms interval can reduce the boot time, especially for ARC++. The test results can be found in b/30892329. This CL also adds some ALOGs to show the service start failure as well as to avoid spam. Bug: 38432898 Test: Services can still start. Test cheets_PerfBootServer for ARC++. Change-Id: I9c0da9ef8a18a0e1432c39d98a34377bb66c5d85 --- libs/binder/IServiceManager.cpp | 36 +++++++++++++++++++++-------- libs/binder/Static.cpp | 1 + libs/binder/include/private/binder/Static.h | 1 + 3 files changed, 28 insertions(+), 10 deletions(-) (limited to 'libs/binder/Static.cpp') diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp index 711143c34a..be3bbf7494 100644 --- a/libs/binder/IServiceManager.cpp +++ b/libs/binder/IServiceManager.cpp @@ -24,6 +24,7 @@ #include #endif #include +#include #include #include #include @@ -142,20 +143,35 @@ public: virtual sp getService(const String16& name) const { - unsigned n; - for (n = 0; n < 5; n++){ - if (n > 0) { - if (!strcmp(ProcessState::self()->getDriverName().c_str(), "/dev/vndbinder")) { - ALOGI("Waiting for vendor service %s...", String8(name).string()); - CallStack stack(LOG_TAG); - } else { - ALOGI("Waiting for service %s...", String8(name).string()); - } - sleep(1); + sp svc = checkService(name); + if (svc != NULL) return svc; + + const bool isVendorService = + strcmp(ProcessState::self()->getDriverName().c_str(), "/dev/vndbinder") == 0; + const long timeout = uptimeMillis() + 5000; + if (!gSystemBootCompleted) { + char bootCompleted[PROPERTY_VALUE_MAX]; + property_get("sys.boot_completed", bootCompleted, "0"); + gSystemBootCompleted = strcmp(bootCompleted, "1") == 0 ? true : false; + } + // retry interval in millisecond. + const long sleepTime = gSystemBootCompleted ? 1000 : 100; + + int n = 0; + while (uptimeMillis() < timeout) { + n++; + if (isVendorService) { + ALOGI("Waiting for vendor service %s...", String8(name).string()); + CallStack stack(LOG_TAG); + } else if (n%10 == 0) { + ALOGI("Waiting for service %s...", String8(name).string()); } + usleep(1000*sleepTime); + sp svc = checkService(name); if (svc != NULL) return svc; } + ALOGW("Service %s didn't start. Returning NULL", String8(name).string()); return NULL; } diff --git a/libs/binder/Static.cpp b/libs/binder/Static.cpp index 9899b65288..c5c3fd58c3 100644 --- a/libs/binder/Static.cpp +++ b/libs/binder/Static.cpp @@ -97,5 +97,6 @@ sp gDefaultServiceManager; #ifndef __ANDROID_VNDK__ sp gPermissionController; #endif +bool gSystemBootCompleted = false; } // namespace android diff --git a/libs/binder/include/private/binder/Static.h b/libs/binder/include/private/binder/Static.h index f04bcae5a7..6ca75926a4 100644 --- a/libs/binder/include/private/binder/Static.h +++ b/libs/binder/include/private/binder/Static.h @@ -41,5 +41,6 @@ extern sp gDefaultServiceManager; #ifndef __ANDROID_VNDK__ extern sp gPermissionController; #endif +extern bool gSystemBootCompleted; } // namespace android -- cgit v1.2.3-59-g8ed1b From c39caf36da9999c4b61ec8898f8735dcce7fd199 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Tue, 5 Jun 2018 14:34:36 -0700 Subject: libbinder: fix using destroyed mutex warning. Bug: 77473515 Test: run `pm list instrumentation` for several hours, Test: and no warning appears. Change-Id: I66a39ddd66731779fdc6e534f827ad524685b3ba --- libs/binder/Static.cpp | 2 +- libs/binder/include/private/binder/Static.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'libs/binder/Static.cpp') diff --git a/libs/binder/Static.cpp b/libs/binder/Static.cpp index c5c3fd58c3..d6d0340a36 100644 --- a/libs/binder/Static.cpp +++ b/libs/binder/Static.cpp @@ -72,7 +72,7 @@ TextOutput& aerr(gStderrTextOutput); // ------------ ProcessState.cpp -Mutex gProcessMutex; +Mutex& gProcessMutex = *new Mutex; sp gProcess; class LibBinderIPCtStatics diff --git a/libs/binder/include/private/binder/Static.h b/libs/binder/include/private/binder/Static.h index 6ca75926a4..171be7791e 100644 --- a/libs/binder/include/private/binder/Static.h +++ b/libs/binder/include/private/binder/Static.h @@ -32,7 +32,7 @@ namespace android { extern Vector gTextBuffers; // For ProcessState.cpp -extern Mutex gProcessMutex; +extern Mutex& gProcessMutex; extern sp gProcess; // For IServiceManager.cpp -- cgit v1.2.3-59-g8ed1b