summaryrefslogtreecommitdiff
path: root/core/java/android/content/SyncStatusInfo.java
diff options
context:
space:
mode:
authorVarun Shah <varunshah@google.com>2019-10-30 17:40:15 -0700
committerVarun Shah <varunshah@google.com>2019-11-11 10:56:08 -0800
commit816cf63bc554d821a6f91cb77869e9847f0cb8ba (patch)
tree76d2aa507436ac24833d9954638a5541a1f3278e /core/java/android/content/SyncStatusInfo.java
parent89cc836c2eaa5c851dd40c846b5984581fb31d28 (diff)
Update SyncStorageEngine to use protos.
Status and Statistics info within SyncStorageEngine was being stored using Parcels, which is not recommended. Updating both of them to use protos now. Additionally, because of protos, storage space on disk consumed by these files are reduced by more than 50%. Also added unit tests for SyncStorageEngine. Bug: 38177679 Test: atest com.android.server.content.SyncStorageEngineTest Test: build and flash - no errors in logs Change-Id: I187cb6c271333f366f5c7f651f75b4161fee90d4
Diffstat (limited to 'core/java/android/content/SyncStatusInfo.java')
-rw-r--r--core/java/android/content/SyncStatusInfo.java56
1 files changed, 52 insertions, 4 deletions
diff --git a/core/java/android/content/SyncStatusInfo.java b/core/java/android/content/SyncStatusInfo.java
index 3f6451577258..0eea47a248af 100644
--- a/core/java/android/content/SyncStatusInfo.java
+++ b/core/java/android/content/SyncStatusInfo.java
@@ -20,6 +20,9 @@ import android.annotation.UnsupportedAppUsage;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
+import android.util.Pair;
+
+import com.android.internal.util.ArrayUtils;
import java.util.ArrayList;
import java.util.Calendar;
@@ -139,10 +142,10 @@ public class SyncStatusInfo implements Parcelable {
public final long[] perSourceLastSuccessTimes = new long[SOURCE_COUNT];
public final long[] perSourceLastFailureTimes = new long[SOURCE_COUNT];
- // Warning: It is up to the external caller to ensure there are
- // no race conditions when accessing this list
- @UnsupportedAppUsage
- private ArrayList<Long> periodicSyncTimes;
+ // Warning: It is up to the external caller to ensure there are
+ // no race conditions when accessing this list
+ @UnsupportedAppUsage
+ private ArrayList<Long> periodicSyncTimes;
private final ArrayList<Long> mLastEventTimes = new ArrayList<>();
private final ArrayList<String> mLastEvents = new ArrayList<>();
@@ -292,9 +295,28 @@ public class SyncStatusInfo implements Parcelable {
}
}
+ /**
+ * Copies all data from the given SyncStatusInfo object.
+ *
+ * @param other the SyncStatusInfo object to copy data from
+ */
public SyncStatusInfo(SyncStatusInfo other) {
authorityId = other.authorityId;
+ copyFrom(other);
+ }
+
+ /**
+ * Copies all data from the given SyncStatusInfo object except for its authority id.
+ *
+ * @param authorityId the new authority id
+ * @param other the SyncStatusInfo object to copy data from
+ */
+ public SyncStatusInfo(int authorityId, SyncStatusInfo other) {
+ this.authorityId = authorityId;
+ copyFrom(other);
+ }
+ private void copyFrom(SyncStatusInfo other) {
other.totalStats.copyTo(totalStats);
other.todayStats.copyTo(todayStats);
other.yesterdayStats.copyTo(yesterdayStats);
@@ -323,6 +345,14 @@ public class SyncStatusInfo implements Parcelable {
System.arraycopy(from, 0, to, 0, to.length);
}
+ public int getPeriodicSyncTimesSize() {
+ return periodicSyncTimes == null ? 0 : periodicSyncTimes.size();
+ }
+
+ public void addPeriodicSyncTime(long time) {
+ periodicSyncTimes = ArrayUtils.add(periodicSyncTimes, time);
+ }
+
@UnsupportedAppUsage
public void setPeriodicSyncTime(int index, long when) {
// The list is initialized lazily when scheduling occurs so we need to make sure
@@ -347,6 +377,24 @@ public class SyncStatusInfo implements Parcelable {
}
}
+ /**
+ * Populates {@code mLastEventTimes} and {@code mLastEvents} with the given list. <br>
+ * <i>Note: This method is mainly used to repopulate the event info from disk and it will clear
+ * both {@code mLastEventTimes} and {@code mLastEvents} before populating.</i>
+ *
+ * @param lastEventInformation the list to populate with
+ */
+ public void populateLastEventsInformation(ArrayList<Pair<Long, String>> lastEventInformation) {
+ mLastEventTimes.clear();
+ mLastEvents.clear();
+ final int size = lastEventInformation.size();
+ for (int i = 0; i < size; i++) {
+ final Pair<Long, String> lastEventInfo = lastEventInformation.get(i);
+ mLastEventTimes.add(lastEventInfo.first);
+ mLastEvents.add(lastEventInfo.second);
+ }
+ }
+
/** */
public void addEvent(String message) {
if (mLastEventTimes.size() >= MAX_EVENT_COUNT) {