From e785c01e0a53fdc6244f5bc6e59bd638b10b0f38 Mon Sep 17 00:00:00 2001 From: Vova Sharaienko Date: Mon, 29 Mar 2021 23:10:39 +0000 Subject: [PATCH] Stats: updated the order of service registration Stats need to be registered prior sensors service start Bug: 183916090 Test: build, flash & boot Change-Id: I4d6eb1adbb0d57e42489ec85829b777e8a27069c --- .../core/jni/com_android_server_SystemServer.cpp | 13 ++++++++----- services/java/com/android/server/SystemServer.java | 12 ++++++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/services/core/jni/com_android_server_SystemServer.cpp b/services/core/jni/com_android_server_SystemServer.cpp index fe728ab14dff8..fb664abb2d54b 100644 --- a/services/core/jni/com_android_server_SystemServer.cpp +++ b/services/core/jni/com_android_server_SystemServer.cpp @@ -60,7 +60,7 @@ static void startStatsAidlService() { const std::string instance = std::string() + IStats::descriptor + "/default"; const binder_exception_t err = AServiceManager_addService(statsService->asBinder().get(), instance.c_str()); - LOG_ALWAYS_FATAL_IF(err != EX_NONE, "Cannot register %s: %d", instance.c_str(), err); + LOG_ALWAYS_FATAL_IF(err != EX_NONE, "Cannot register AIDL %s: %d", instance.c_str(), err); } static void startStatsHidlService() { @@ -69,13 +69,18 @@ static void startStatsHidlService() { android::sp statsHal = new StatsHal(); const android::status_t err = statsHal->registerAsService(); - LOG_ALWAYS_FATAL_IF(err != android::OK, "Cannot register %s: %d", IStats::descriptor, err); + LOG_ALWAYS_FATAL_IF(err != android::OK, "Cannot register HIDL %s: %d", IStats::descriptor, err); } } // namespace namespace android { +static void android_server_SystemServer_startIStatsService(JNIEnv* /* env */, jobject /* clazz */) { + startStatsHidlService(); + startStatsAidlService(); +} + static void android_server_SystemServer_startSensorService(JNIEnv* /* env */, jobject /* clazz */) { char propBuf[PROPERTY_VALUE_MAX]; property_get("system_init.startsensorservice", propBuf, "1"); @@ -129,9 +134,6 @@ static void android_server_SystemServer_startHidlServices(JNIEnv* env, jobject / } else { ALOGW("%s is deprecated. Skipping registration.", ISchedulingPolicyService::descriptor); } - - startStatsAidlService(); - startStatsHidlService(); } static void android_server_SystemServer_initZygoteChildHeapProfiling(JNIEnv* /* env */, @@ -160,6 +162,7 @@ static void android_server_SystemServer_setIncrementalServiceSystemReady(JNIEnv* */ static const JNINativeMethod gMethods[] = { /* name, signature, funcPtr */ + {"startIStatsService", "()V", (void*)android_server_SystemServer_startIStatsService}, {"startSensorService", "()V", (void*)android_server_SystemServer_startSensorService}, {"startMemtrackProxyService", "()V", (void*)android_server_SystemServer_startMemtrackProxyService}, diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 9b2a1e7a4e07d..bcda022e6208d 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -442,15 +442,15 @@ public final class SystemServer implements Dumpable { private final SystemServerDumper mDumper = new SystemServerDumper(); - /** * The pending WTF to be logged into dropbox. */ private static LinkedList> sPendingWtfs; - /** - * Start the sensor service. This is a blocking call and can take time. - */ + /** Start the IStats services. This is a blocking call and can take time. */ + private static native void startIStatsService(); + + /** Start the sensor service. This is a blocking call and can take time. */ private static native void startSensorService(); /** @@ -1029,6 +1029,10 @@ public final class SystemServer implements Dumpable { mSystemServiceManager.startService(PowerStatsService.class); t.traceEnd(); + t.traceBegin("StartIStatsService"); + startIStatsService(); + t.traceEnd(); + // Start MemtrackProxyService before ActivityManager, so that early calls // to Memtrack::getMemory() don't fail. t.traceBegin("MemtrackProxyService");