Loading apex/statsd/aidl/android/os/IStatsd.aidl +14 −4 Original line number Diff line number Diff line Loading @@ -30,6 +30,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. Loading Loading @@ -182,6 +187,11 @@ interface IStatsd { */ void sendAppBreadcrumbAtom(int label, int state); /** * Tell the stats daemon that all the pullers registered during boot have been sent. */ oneway void allPullersFromBootRegistered(); /** * Registers a puller callback function that, when invoked, pulls the data * for the specified atom tag. Loading apex/statsd/service/java/com/android/server/stats/StatsCompanion.java +3 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,9 @@ public class StatsCompanion { if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) { mStatsCompanionService.systemReady(); } if (phase == PHASE_BOOT_COMPLETED) { mStatsCompanionService.bootCompleted(); } } } Loading apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java +48 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -688,6 +700,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. Loading Loading @@ -749,6 +774,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { mContext.unregisterReceiver(receiver); } statsdNotReadyLocked(); mSentBootComplete = false; } } } Loading @@ -758,6 +784,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) Loading apex/statsd/service/java/com/android/server/stats/StatsManagerService.java +1 −0 Original line number Diff line number Diff line Loading @@ -600,6 +600,7 @@ public class StatsManagerService extends IStatsManagerService.Stub { statsd.registerPullAtomCallback(key.getUid(), key.getAtom(), value.getCoolDownMillis(), value.getTimeoutMillis(), value.getAdditiveFields(), value.getCallback()); } statsd.allPullersFromBootRegistered(); } // Pre-condition: the Binder calling identity has already been cleared Loading cmds/statsd/src/StatsService.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -1205,6 +1213,14 @@ Status StatsService::sendAppBreadcrumbAtom(int32_t label, int32_t state) { return Status::ok(); } Status StatsService::allPullersFromBootRegistered() { ENFORCE_UID(AID_SYSTEM); VLOG("StatsService::allPullersFromBootRegistered was called"); return Status::ok(); } Status StatsService::registerPullAtomCallback(int32_t uid, int32_t atomTag, int64_t coolDownMillis, int64_t timeoutMillis, const std::vector<int32_t>& additiveFields, Loading Loading
apex/statsd/aidl/android/os/IStatsd.aidl +14 −4 Original line number Diff line number Diff line Loading @@ -30,6 +30,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. Loading Loading @@ -182,6 +187,11 @@ interface IStatsd { */ void sendAppBreadcrumbAtom(int label, int state); /** * Tell the stats daemon that all the pullers registered during boot have been sent. */ oneway void allPullersFromBootRegistered(); /** * Registers a puller callback function that, when invoked, pulls the data * for the specified atom tag. Loading
apex/statsd/service/java/com/android/server/stats/StatsCompanion.java +3 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,9 @@ public class StatsCompanion { if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) { mStatsCompanionService.systemReady(); } if (phase == PHASE_BOOT_COMPLETED) { mStatsCompanionService.bootCompleted(); } } } Loading
apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java +48 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -688,6 +700,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. Loading Loading @@ -749,6 +774,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { mContext.unregisterReceiver(receiver); } statsdNotReadyLocked(); mSentBootComplete = false; } } } Loading @@ -758,6 +784,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) Loading
apex/statsd/service/java/com/android/server/stats/StatsManagerService.java +1 −0 Original line number Diff line number Diff line Loading @@ -600,6 +600,7 @@ public class StatsManagerService extends IStatsManagerService.Stub { statsd.registerPullAtomCallback(key.getUid(), key.getAtom(), value.getCoolDownMillis(), value.getTimeoutMillis(), value.getAdditiveFields(), value.getCallback()); } statsd.allPullersFromBootRegistered(); } // Pre-condition: the Binder calling identity has already been cleared Loading
cmds/statsd/src/StatsService.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -1205,6 +1213,14 @@ Status StatsService::sendAppBreadcrumbAtom(int32_t label, int32_t state) { return Status::ok(); } Status StatsService::allPullersFromBootRegistered() { ENFORCE_UID(AID_SYSTEM); VLOG("StatsService::allPullersFromBootRegistered was called"); return Status::ok(); } Status StatsService::registerPullAtomCallback(int32_t uid, int32_t atomTag, int64_t coolDownMillis, int64_t timeoutMillis, const std::vector<int32_t>& additiveFields, Loading