From 7ce78c23df6ffc3e01e146aab6eb59480d12e244 Mon Sep 17 00:00:00 2001 From: Varun Shah Date: Wed, 6 May 2020 20:48:06 -0700 Subject: [PATCH] Persist Locus Id Event to UsageStatsProto. Currently, we are only using UsageStatsProto for backup and restore purposes but to ensure it is in sync with UsageStatsProtoV2, adding the recently added LOCUS_ID event. This enables us to easily fall back to the earlier proto version if there are issues with V2. This also allows us to backup all events data if we decide to do that in the future before updating the B&R restore logic to use V2. Bug: 155935953 Test: atest UsageStatsDatabaseTest Change-Id: I792f20a0b44d13f1ed17c4dbebe5555044afa165 --- core/proto/android/server/usagestatsservice.proto | 2 ++ .../java/com/android/server/usage/IntervalStats.java | 9 +++++++++ .../java/com/android/server/usage/UsageStatsProto.java | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/core/proto/android/server/usagestatsservice.proto b/core/proto/android/server/usagestatsservice.proto index f26eefad24e18..e32c07f50ff27 100644 --- a/core/proto/android/server/usagestatsservice.proto +++ b/core/proto/android/server/usagestatsservice.proto @@ -93,6 +93,8 @@ message IntervalStatsProto { optional int32 task_root_package_index = 15; // task_root_class_index contains the index + 1 of the task root class name in the string pool optional int32 task_root_class_index = 16; + // locus_id_index contains the index + 1 of the locus id in the string pool + optional int32 locus_id_index = 17; } // The following fields contain supplemental data used to build IntervalStats, such as a string diff --git a/services/usage/java/com/android/server/usage/IntervalStats.java b/services/usage/java/com/android/server/usage/IntervalStats.java index 5ee3b4859d548..fd462c2e6dc27 100644 --- a/services/usage/java/com/android/server/usage/IntervalStats.java +++ b/services/usage/java/com/android/server/usage/IntervalStats.java @@ -234,6 +234,10 @@ public class IntervalStats { event.mTaskRootClass = getCachedStringRef(stringPool.get( parser.readInt(IntervalStatsProto.Event.TASK_ROOT_CLASS_INDEX) - 1)); break; + case (int) IntervalStatsProto.Event.LOCUS_ID_INDEX: + event.mLocusId = getCachedStringRef(stringPool.get( + parser.readInt(IntervalStatsProto.Event.LOCUS_ID_INDEX) - 1)); + break; case ProtoInputStream.NO_MORE_FIELDS: // Handle default values for certain events types switch (event.mEventType) { @@ -252,6 +256,11 @@ public class IntervalStats { event.mNotificationChannelId = ""; } break; + case LOCUS_ID_SET: + if (event.mLocusId == null) { + event.mLocusId = ""; + } + break; } return event; } diff --git a/services/usage/java/com/android/server/usage/UsageStatsProto.java b/services/usage/java/com/android/server/usage/UsageStatsProto.java index 463fc378c27d7..78b14779d6b39 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsProto.java +++ b/services/usage/java/com/android/server/usage/UsageStatsProto.java @@ -481,6 +481,13 @@ final class UsageStatsProto { } } break; + case UsageEvents.Event.LOCUS_ID_SET: + if (event.mLocusId != null) { + final int locusIdIndex = stats.mStringCache.indexOf(event.mLocusId); + if (locusIdIndex >= 0) { + proto.write(IntervalStatsProto.Event.LOCUS_ID_INDEX, locusIdIndex + 1); + } + } } proto.end(token); }