From f56042d6a496fca2e5cfc1f598251f77a9bc7986 Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Tue, 19 Sep 2017 15:25:10 -0700 Subject: Pass dumpsys priority to IServiceManager Modify IServiceManger to accept supported dumpsys priority as a bitmask with NORMAL being the default priority. Change listServices to return a list of services filtered by the priority or all services when the priority is set to ALL. BUG:27429130 Test: mmm -j32 frameworks/native/cmds/dumpsys && \ adb sync data && adb shell /data/nativetest/dumpsys_test/dumpsys_test && \ adb shell /data/nativetest64/dumpsys_test/dumpsys_test && \ printf "\n\n#### ALL TESTS PASSED ####\n" Change-Id: Ibccba63035ace9970c2967a621ee2ad8d15cbeea --- libs/binder/IServiceManager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libs/binder/IServiceManager.cpp') diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp index c7a0f43a9d..70f5108722 100644 --- a/libs/binder/IServiceManager.cpp +++ b/libs/binder/IServiceManager.cpp @@ -161,19 +161,18 @@ public: } virtual status_t addService(const String16& name, const sp& service, - bool allowIsolated) - { + bool allowIsolated, int dumpsysPriority) { Parcel data, reply; data.writeInterfaceToken(IServiceManager::getInterfaceDescriptor()); data.writeString16(name); data.writeStrongBinder(service); data.writeInt32(allowIsolated ? 1 : 0); + data.writeInt32(dumpsysPriority); status_t err = remote()->transact(ADD_SERVICE_TRANSACTION, data, &reply); return err == NO_ERROR ? reply.readExceptionCode() : err; } - virtual Vector listServices() - { + virtual Vector listServices(int dumpsysPriority) { Vector res; int n = 0; @@ -181,6 +180,7 @@ public: Parcel data, reply; data.writeInterfaceToken(IServiceManager::getInterfaceDescriptor()); data.writeInt32(n++); + data.writeInt32(dumpsysPriority); status_t err = remote()->transact(LIST_SERVICES_TRANSACTION, data, &reply); if (err != NO_ERROR) break; -- cgit v1.2.3-59-g8ed1b 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/Android.bp | 22 ++++++++++++++++++++++ libs/binder/IServiceManager.cpp | 8 ++++++++ libs/binder/Static.cpp | 2 ++ libs/binder/include/binder/ActivityManager.h | 6 ++++++ libs/binder/include/binder/AppOpsManager.h | 6 ++++++ libs/binder/include/binder/IActivityManager.h | 6 ++++++ libs/binder/include/binder/IAppOpsCallback.h | 6 ++++++ libs/binder/include/binder/IAppOpsService.h | 6 ++++++ libs/binder/include/binder/IBatteryStats.h | 6 ++++++ libs/binder/include/binder/IMediaResourceMonitor.h | 6 ++++++ libs/binder/include/binder/IPermissionController.h | 6 ++++++ libs/binder/include/binder/IProcessInfoService.h | 6 ++++++ libs/binder/include/binder/IServiceManager.h | 1 - libs/binder/include/binder/IUidObserver.h | 6 ++++++ libs/binder/include/binder/IpPrefix.h | 6 ++++++ libs/binder/include/binder/PermissionCache.h | 6 ++++++ libs/binder/include/binder/PermissionController.h | 6 ++++++ libs/binder/include/binder/ProcessInfoService.h | 6 ++++++ libs/binder/include/private/binder/Static.h | 4 ++++ libs/gui/BufferQueueConsumer.cpp | 10 +++++++++- libs/sensor/SensorManager.cpp | 1 + 21 files changed, 130 insertions(+), 2 deletions(-) (limited to 'libs/binder/IServiceManager.cpp') diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp index 6103188801..7c1eaaf923 100644 --- a/libs/binder/Android.bp +++ b/libs/binder/Android.bp @@ -75,6 +75,28 @@ cc_library { ":libbinder_aidl", ], + target: { + vendor: { + exclude_srcs: [ + "ActivityManager.cpp", + "AppOpsManager.cpp", + "IActivityManager.cpp", + "IAppOpsCallback.cpp", + "IAppOpsService.cpp", + "IBatteryStats.cpp", + "IMediaResourceMonitor.cpp", + "IPermissionController.cpp", + "IProcessInfoService.cpp", + "IUidObserver.cpp", + "PermissionCache.cpp", + "PermissionController.cpp", + "ProcessInfoService.cpp", + "IpPrefix.cpp", + ":libbinder_aidl", + ], + }, + }, + aidl: { export_aidl_headers: true, }, diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp index 70f5108722..711143c34a 100644 --- a/libs/binder/IServiceManager.cpp +++ b/libs/binder/IServiceManager.cpp @@ -20,6 +20,9 @@ #include #include +#ifndef __ANDROID_VNDK__ +#include +#endif #include #include #include @@ -48,6 +51,9 @@ sp defaultServiceManager() return gDefaultServiceManager; } +#ifndef __ANDROID_VNDK__ +// IPermissionController is not accessible to vendors + bool checkCallingPermission(const String16& permission) { return checkCallingPermission(permission, NULL, NULL); @@ -122,6 +128,8 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid) } } +#endif //__ANDROID_VNDK__ + // ---------------------------------------------------------------------- class BpServiceManager : public BpInterface 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 diff --git a/libs/binder/include/binder/ActivityManager.h b/libs/binder/include/binder/ActivityManager.h index 3090cae12a..b8db09145f 100644 --- a/libs/binder/include/binder/ActivityManager.h +++ b/libs/binder/include/binder/ActivityManager.h @@ -17,6 +17,8 @@ #ifndef ANDROID_ACTIVITY_MANAGER_H #define ANDROID_ACTIVITY_MANAGER_H +#ifndef __ANDROID_VNDK__ + #include #include @@ -64,4 +66,8 @@ private: }; // namespace android // --------------------------------------------------------------------------- +#else // __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif // __ANDROID_VNDK__ + #endif // ANDROID_ACTIVITY_MANAGER_H diff --git a/libs/binder/include/binder/AppOpsManager.h b/libs/binder/include/binder/AppOpsManager.h index a44d270411..c5b57c7edf 100644 --- a/libs/binder/include/binder/AppOpsManager.h +++ b/libs/binder/include/binder/AppOpsManager.h @@ -17,6 +17,8 @@ #ifndef ANDROID_APP_OPS_MANAGER_H #define ANDROID_APP_OPS_MANAGER_H +#ifndef __ANDROID_VNDK__ + #include #include @@ -117,4 +119,8 @@ private: }; // namespace android // --------------------------------------------------------------------------- +#else // __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif // __ANDROID_VNDK__ + #endif // ANDROID_APP_OPS_MANAGER_H diff --git a/libs/binder/include/binder/IActivityManager.h b/libs/binder/include/binder/IActivityManager.h index 6607c0e8e6..f34969be51 100644 --- a/libs/binder/include/binder/IActivityManager.h +++ b/libs/binder/include/binder/IActivityManager.h @@ -17,6 +17,8 @@ #ifndef ANDROID_IACTIVITY_MANAGER_H #define ANDROID_IACTIVITY_MANAGER_H +#ifndef __ANDROID_VNDK__ + #include #include @@ -49,4 +51,8 @@ public: }; // namespace android +#else // __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif // __ANDROID_VNDK__ + #endif // ANDROID_IACTIVITY_MANAGER_H diff --git a/libs/binder/include/binder/IAppOpsCallback.h b/libs/binder/include/binder/IAppOpsCallback.h index b62e9e264d..e5b12a9720 100644 --- a/libs/binder/include/binder/IAppOpsCallback.h +++ b/libs/binder/include/binder/IAppOpsCallback.h @@ -18,6 +18,8 @@ #ifndef ANDROID_IAPP_OPS_CALLBACK_H #define ANDROID_IAPP_OPS_CALLBACK_H +#ifndef __ANDROID_VNDK__ + #include namespace android { @@ -51,5 +53,9 @@ public: }; // namespace android +#else // __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif // __ANDROID_VNDK__ + #endif // ANDROID_IAPP_OPS_CALLBACK_H diff --git a/libs/binder/include/binder/IAppOpsService.h b/libs/binder/include/binder/IAppOpsService.h index ecba5d66b3..f0c5e1743d 100644 --- a/libs/binder/include/binder/IAppOpsService.h +++ b/libs/binder/include/binder/IAppOpsService.h @@ -18,6 +18,8 @@ #ifndef ANDROID_IAPP_OPS_SERVICE_H #define ANDROID_IAPP_OPS_SERVICE_H +#ifndef __ANDROID_VNDK__ + #include #include @@ -75,4 +77,8 @@ public: }; // namespace android +#else // __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif // __ANDROID_VNDK__ + #endif // ANDROID_IAPP_OPS_SERVICE_H diff --git a/libs/binder/include/binder/IBatteryStats.h b/libs/binder/include/binder/IBatteryStats.h index e15d6f07e9..59e806c177 100644 --- a/libs/binder/include/binder/IBatteryStats.h +++ b/libs/binder/include/binder/IBatteryStats.h @@ -17,6 +17,8 @@ #ifndef ANDROID_IBATTERYSTATS_H #define ANDROID_IBATTERYSTATS_H +#ifndef __ANDROID_VNDK__ + #include namespace android { @@ -76,4 +78,8 @@ public: }; // namespace android +#else // __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif // __ANDROID_VNDK__ + #endif // ANDROID_IBATTERYSTATS_H diff --git a/libs/binder/include/binder/IMediaResourceMonitor.h b/libs/binder/include/binder/IMediaResourceMonitor.h index b21047fc49..213ee63ea8 100644 --- a/libs/binder/include/binder/IMediaResourceMonitor.h +++ b/libs/binder/include/binder/IMediaResourceMonitor.h @@ -17,6 +17,8 @@ #ifndef ANDROID_I_MEDIA_RESOURCE_MONITOR_H #define ANDROID_I_MEDIA_RESOURCE_MONITOR_H +#ifndef __ANDROID_VNDK__ + #include namespace android { @@ -52,4 +54,8 @@ public: }; // namespace android +#else // __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif // __ANDROID_VNDK__ + #endif // ANDROID_I_MEDIA_RESOURCE_MONITOR_H diff --git a/libs/binder/include/binder/IPermissionController.h b/libs/binder/include/binder/IPermissionController.h index b83d226189..3ec459fc32 100644 --- a/libs/binder/include/binder/IPermissionController.h +++ b/libs/binder/include/binder/IPermissionController.h @@ -18,6 +18,8 @@ #ifndef ANDROID_IPERMISSION_CONTROLLER_H #define ANDROID_IPERMISSION_CONTROLLER_H +#ifndef __ANDROID_VNDK__ + #include #include @@ -64,5 +66,9 @@ public: }; // namespace android +#else // __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif // __ANDROID_VNDK__ + #endif // ANDROID_IPERMISSION_CONTROLLER_H diff --git a/libs/binder/include/binder/IProcessInfoService.h b/libs/binder/include/binder/IProcessInfoService.h index 2669f9193d..033c145363 100644 --- a/libs/binder/include/binder/IProcessInfoService.h +++ b/libs/binder/include/binder/IProcessInfoService.h @@ -17,6 +17,8 @@ #ifndef ANDROID_I_PROCESS_INFO_SERVICE_H #define ANDROID_I_PROCESS_INFO_SERVICE_H +#ifndef __ANDROID_VNDK__ + #include namespace android { @@ -46,4 +48,8 @@ public: }; // namespace android +#else // __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif // __ANDROID_VNDK__ + #endif // ANDROID_I_PROCESS_INFO_SERVICE_H diff --git a/libs/binder/include/binder/IServiceManager.h b/libs/binder/include/binder/IServiceManager.h index cf4c08a46a..197026d5d6 100644 --- a/libs/binder/include/binder/IServiceManager.h +++ b/libs/binder/include/binder/IServiceManager.h @@ -19,7 +19,6 @@ #define ANDROID_ISERVICE_MANAGER_H #include -#include #include #include diff --git a/libs/binder/include/binder/IUidObserver.h b/libs/binder/include/binder/IUidObserver.h index fd4d8a6de1..d81789e399 100644 --- a/libs/binder/include/binder/IUidObserver.h +++ b/libs/binder/include/binder/IUidObserver.h @@ -18,6 +18,8 @@ #ifndef ANDROID_IUID_OBSERVER_H #define ANDROID_IUID_OBSERVER_H +#ifndef __ANDROID_VNDK__ + #include namespace android { @@ -55,4 +57,8 @@ public: }; // namespace android +#else // __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif // __ANDROID_VNDK__ + #endif // ANDROID_IUID_OBSERVER_H diff --git a/libs/binder/include/binder/IpPrefix.h b/libs/binder/include/binder/IpPrefix.h index 96ebaac437..dd5bc3aafd 100644 --- a/libs/binder/include/binder/IpPrefix.h +++ b/libs/binder/include/binder/IpPrefix.h @@ -17,6 +17,8 @@ #ifndef ANDROID_IP_PREFIX_H #define ANDROID_IP_PREFIX_H +#ifndef __ANDROID_VNDK__ + #include #include @@ -85,4 +87,8 @@ private: } // namespace android +#else // __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif // __ANDROID_VNDK__ + #endif // ANDROID_IP_PREFIX_H diff --git a/libs/binder/include/binder/PermissionCache.h b/libs/binder/include/binder/PermissionCache.h index bcdf0c2914..95eabff7ac 100644 --- a/libs/binder/include/binder/PermissionCache.h +++ b/libs/binder/include/binder/PermissionCache.h @@ -17,6 +17,8 @@ #ifndef BINDER_PERMISSION_H #define BINDER_PERMISSION_H +#ifndef __ANDROID_VNDK__ + #include #include @@ -77,4 +79,8 @@ public: // --------------------------------------------------------------------------- }; // namespace android +#else // __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif // __ANDROID_VNDK__ + #endif /* BINDER_PERMISSION_H */ diff --git a/libs/binder/include/binder/PermissionController.h b/libs/binder/include/binder/PermissionController.h index cc5b6fe02b..d81f5142bc 100644 --- a/libs/binder/include/binder/PermissionController.h +++ b/libs/binder/include/binder/PermissionController.h @@ -17,6 +17,8 @@ #ifndef ANDROID_PERMISSION_CONTROLLER_H #define ANDROID_PERMISSION_CONTROLLER_H +#ifndef __ANDROID_VNDK__ + #include #include @@ -60,4 +62,8 @@ private: }; // namespace android // --------------------------------------------------------------------------- +#else // __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif // __ANDROID_VNDK__ + #endif // ANDROID_PERMISSION_CONTROLLER_H diff --git a/libs/binder/include/binder/ProcessInfoService.h b/libs/binder/include/binder/ProcessInfoService.h index 0da61ee3cb..a03aae98ee 100644 --- a/libs/binder/include/binder/ProcessInfoService.h +++ b/libs/binder/include/binder/ProcessInfoService.h @@ -17,6 +17,8 @@ #ifndef ANDROID_PROCESS_INFO_SERVICE_H #define ANDROID_PROCESS_INFO_SERVICE_H +#ifndef __ANDROID_VNDK__ + #include #include #include @@ -78,5 +80,9 @@ public: }; // namespace android +#else // __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif // __ANDROID_VNDK__ + #endif // ANDROID_PROCESS_INFO_SERVICE_H diff --git a/libs/binder/include/private/binder/Static.h b/libs/binder/include/private/binder/Static.h index 3d10456a8d..f04bcae5a7 100644 --- a/libs/binder/include/private/binder/Static.h +++ b/libs/binder/include/private/binder/Static.h @@ -21,7 +21,9 @@ #include #include +#ifndef __ANDROID_VNDK__ #include +#endif #include namespace android { @@ -36,6 +38,8 @@ extern sp gProcess; // For IServiceManager.cpp extern Mutex gDefaultServiceManagerLock; extern sp gDefaultServiceManager; +#ifndef __ANDROID_VNDK__ extern sp gPermissionController; +#endif } // namespace android diff --git a/libs/gui/BufferQueueConsumer.cpp b/libs/gui/BufferQueueConsumer.cpp index 17cf677e09..d70e1422b0 100644 --- a/libs/gui/BufferQueueConsumer.cpp +++ b/libs/gui/BufferQueueConsumer.cpp @@ -35,7 +35,9 @@ #include #include +#ifndef __ANDROID_VNDK__ #include +#endif #include @@ -757,12 +759,18 @@ status_t BufferQueueConsumer::dumpState(const String8& prefix, String8* outResul } const IPCThreadState* ipc = IPCThreadState::self(); - const pid_t pid = ipc->getCallingPid(); const uid_t uid = ipc->getCallingUid(); +#ifndef __ANDROID_VNDK__ + // permission check can't be done for vendors as vendors have no access to + // the PermissionController + const pid_t pid = ipc->getCallingPid(); if ((uid != shellUid) && !PermissionCache::checkPermission(String16("android.permission.DUMP"), pid, uid)) { outResult->appendFormat("Permission Denial: can't dump BufferQueueConsumer " "from pid=%d, uid=%d\n", pid, uid); +#else + if (uid != shellUid) { +#endif android_errorWriteWithInfoLog(0x534e4554, "27046057", static_cast(uid), NULL, 0); return PERMISSION_DENIED; diff --git a/libs/sensor/SensorManager.cpp b/libs/sensor/SensorManager.cpp index 6fe72a13ba..b9ae524ee8 100644 --- a/libs/sensor/SensorManager.cpp +++ b/libs/sensor/SensorManager.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include -- 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/IServiceManager.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