From 3ee7557fb5007fedfd291a55b85afa8417a48ff9 Mon Sep 17 00:00:00 2001 From: Richard Gaywood Date: Tue, 18 Feb 2020 15:59:06 +0000 Subject: [PATCH] Add method to return merged stats to AIDL For procstats aggregated stats collection, we need to expose the aggregated ProcessStats object back to the caller. Change-Id: Ifb52f813d679e3e0a1e061f983d8b4f539d6d72a Test: nothing yet --- .../internal/app/procstats/IProcessStats.aidl | 11 +++++++++++ .../internal/app/procstats/ProcessStats.java | 9 +++++++++ .../android/server/am/ProcessStatsService.java | 18 ++++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/core/java/com/android/internal/app/procstats/IProcessStats.aidl b/core/java/com/android/internal/app/procstats/IProcessStats.aidl index 0c203ab763464..7a6301f6f180c 100644 --- a/core/java/com/android/internal/app/procstats/IProcessStats.aidl +++ b/core/java/com/android/internal/app/procstats/IProcessStats.aidl @@ -34,4 +34,15 @@ interface IProcessStats { */ long getCommittedStats(long highWaterMarkMs, int section, boolean doAggregate, out List committedStats); + + /** + * Get stats committed after highWaterMarkMs + * @param highWaterMarkMs Report stats committed after this time. + * @param section Integer mask to indicate which sections to include in the stats. + * @param doAggregate Whether to aggregate the stats or keep them separated. + * @param List of Files of individual commits in protobuf binary or one that is merged from them. + * @param ProcessStats object that will be used to return the full set of merged stats. + */ + long getCommittedStatsMerged(long highWaterMarkMs, int section, boolean doAggregate, + out List committedStats, out ProcessStats mergedStats); } diff --git a/core/java/com/android/internal/app/procstats/ProcessStats.java b/core/java/com/android/internal/app/procstats/ProcessStats.java index 3045410a2ca21..009b1e0fa829d 100644 --- a/core/java/com/android/internal/app/procstats/ProcessStats.java +++ b/core/java/com/android/internal/app/procstats/ProcessStats.java @@ -266,6 +266,15 @@ public final class ProcessStats implements Parcelable { readFromParcel(in); } + /** + * No-arg constructor is for use in AIDL-derived stubs. + * + *

This defaults to the non-running state, so is equivalent to ProcessStats(false). + */ + public ProcessStats() { + this(false); + } + public void add(ProcessStats other) { ArrayMap>> pkgMap = other.mPackages.getMap(); diff --git a/services/core/java/com/android/server/am/ProcessStatsService.java b/services/core/java/com/android/server/am/ProcessStatsService.java index 3ada0c366758f..5bf0ed6d24387 100644 --- a/services/core/java/com/android/server/am/ProcessStatsService.java +++ b/services/core/java/com/android/server/am/ProcessStatsService.java @@ -539,15 +539,29 @@ public final class ProcessStatsService extends IProcessStats.Stub { * @param highWaterMarkMs Report stats committed after this time. * @param section Integer mask to indicage which sections to include in the stats. * @param doAggregate Whether to aggregate the stats or keep them separated. - * @return List of proto binary of individual commit files or one that is merged from them. + * @return List of proto binary of individual commit files or one that is merged from them */ @Override public long getCommittedStats(long highWaterMarkMs, int section, boolean doAggregate, List committedStats) { + return getCommittedStatsMerged(highWaterMarkMs, section, doAggregate, committedStats, + new ProcessStats(false)); + } + + /** + * Get stats committed after highWaterMarkMs + * @param highWaterMarkMs Report stats committed after this time. + * @param section Integer mask to indicage which sections to include in the stats. + * @param doAggregate Whether to aggregate the stats or keep them separated. + * @return List of proto binary of individual commit files or one that is merged from them; + * the merged, final ProcessStats object. + */ + @Override + public long getCommittedStatsMerged(long highWaterMarkMs, int section, boolean doAggregate, + List committedStats, ProcessStats mergedStats) { mAm.mContext.enforceCallingOrSelfPermission( android.Manifest.permission.PACKAGE_USAGE_STATS, null); - ProcessStats mergedStats = new ProcessStats(false); long newHighWaterMark = highWaterMarkMs; mWriteLock.lock(); try {