diff options
| author | 2020-04-06 18:09:55 -0700 | |
|---|---|---|
| committer | 2020-04-09 17:29:19 -0700 | |
| commit | d8f533060d882b09f953d280f5045a13342204f6 (patch) | |
| tree | d439ddff1c0ca73baf3b1722ae05fac10f0c6102 | |
| parent | d7fda53855502d32ab0160b609a10ed4e9faab78 (diff) | |
Send boot completed to statsd
Bug: 153384066
Test: m -j
Change-Id: I3f91241851a93d0869dad210bc278b3a1ba6b762
5 files changed, 65 insertions, 0 deletions
diff --git a/apex/statsd/aidl/android/os/IStatsd.aidl b/apex/statsd/aidl/android/os/IStatsd.aidl index db80650b8c1c..80308d26a430 100644 --- a/apex/statsd/aidl/android/os/IStatsd.aidl +++ b/apex/statsd/aidl/android/os/IStatsd.aidl @@ -31,6 +31,11 @@ interface IStatsd { oneway void systemRunning(); /** + * Tell the stats daemon that the android system has finished booting. + */ + oneway void bootCompleted(); + + /** * Tell the stats daemon that the StatsCompanionService is up and running. * Two-way binder call so that caller knows message received. */ diff --git a/apex/statsd/service/java/com/android/server/stats/StatsCompanion.java b/apex/statsd/service/java/com/android/server/stats/StatsCompanion.java index c1ba73f03c06..dc477a5590ea 100644 --- a/apex/statsd/service/java/com/android/server/stats/StatsCompanion.java +++ b/apex/statsd/service/java/com/android/server/stats/StatsCompanion.java @@ -87,6 +87,9 @@ public class StatsCompanion { if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) { mStatsCompanionService.systemReady(); } + if (phase == PHASE_BOOT_COMPLETED) { + mStatsCompanionService.bootCompleted(); + } } } diff --git a/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java b/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java index aad51124c8d2..7162229ad0e3 100644 --- a/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java +++ b/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java @@ -112,6 +112,18 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { private final HashMap<Long, String> mDeletedFiles = new HashMap<>(); private final CompanionHandler mHandler; + // Flag that is set when PHASE_BOOT_COMPLETED is triggered in the StatsCompanion lifecycle. This + // and the flag mSentBootComplete below is used for synchronization to ensure that the boot + // complete signal is only ever sent once to statsd. Two signals are needed because + // #sayHiToStatsd can be called from both statsd and #onBootPhase + // PHASE_THIRD_PARTY_APPS_CAN_START. + @GuardedBy("sStatsdLock") + private boolean mBootCompleted = false; + // Flag that is set when IStatsd#bootCompleted is called. This flag ensures that boot complete + // signal is only ever sent once. + @GuardedBy("sStatsdLock") + private boolean mSentBootComplete = false; + public StatsCompanionService(Context context) { super(); mContext = context; @@ -704,6 +716,19 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { List.of(appUpdateReceiver, userUpdateReceiver, shutdownEventReceiver)); final long token = Binder.clearCallingIdentity(); + + // Used so we can call statsd.bootComplete() outside of the lock. + boolean shouldSendBootComplete = false; + synchronized (sStatsdLock) { + if (mBootCompleted && !mSentBootComplete) { + mSentBootComplete = true; + shouldSendBootComplete = true; + } + } + if (shouldSendBootComplete) { + statsd.bootCompleted(); + } + try { // Pull the latest state of UID->app name, version mapping when // statsd starts. @@ -765,6 +790,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { mContext.unregisterReceiver(receiver); } statsdNotReadyLocked(); + mSentBootComplete = false; } } } @@ -774,6 +800,28 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { mStatsManagerService.statsdNotReady(); } + void bootCompleted() { + IStatsd statsd = getStatsdNonblocking(); + synchronized (sStatsdLock) { + mBootCompleted = true; + if (mSentBootComplete) { + // do not send a boot complete a second time. + return; + } + if (statsd == null) { + // Statsd is not yet ready. + // Delay the boot completed ping to {@link #sayHiToStatsd()} + return; + } + mSentBootComplete = true; + } + try { + statsd.bootCompleted(); + } catch (RemoteException e) { + Log.e(TAG, "Failed to notify statsd that boot completed"); + } + } + @Override protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp index d51bf77e3c21..dd1d40083a6b 100644 --- a/cmds/statsd/src/StatsService.cpp +++ b/cmds/statsd/src/StatsService.cpp @@ -1054,6 +1054,14 @@ Status StatsService::statsCompanionReady() { return Status::ok(); } +Status StatsService::bootCompleted() { + ENFORCE_UID(AID_SYSTEM); + + VLOG("StatsService::bootCompleted was called"); + + return Status::ok(); +} + void StatsService::Startup() { mConfigManager->Startup(); mProcessor->LoadActiveConfigsFromDisk(); diff --git a/cmds/statsd/src/StatsService.h b/cmds/statsd/src/StatsService.h index ca01eeba8096..23d4c1bd199d 100644 --- a/cmds/statsd/src/StatsService.h +++ b/cmds/statsd/src/StatsService.h @@ -64,6 +64,7 @@ public: virtual Status systemRunning(); virtual Status statsCompanionReady(); + virtual Status bootCompleted(); virtual Status informAnomalyAlarmFired(); virtual Status informPollAlarmFired(); virtual Status informAlarmForSubscriberTriggeringFired(); |