2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.content;
19 import android.os.Parcelable;
20 import android.os.Parcel;
23 * Used to record various statistics about the result of a sync operation. The SyncManager
24 * gets access to these via a {@link SyncResult} and uses some of them to determine the
25 * disposition of the sync. See {@link SyncResult} for further dicussion on how the
26 * SyncManager uses these values.
28 public class SyncStats implements Parcelable {
30 * The SyncAdapter was unable to authenticate the {@link android.accounts.Account}
31 * that was specified in the request. The user needs to take some action to resolve
32 * before a future request can expect to succeed. This is considered a hard error.
34 public long numAuthExceptions;
37 * The SyncAdapter had a problem, most likely with the network connectivity or a timeout
38 * while waiting for a network response. The request may succeed if it is tried again
39 * later. This is considered a soft error.
41 public long numIoExceptions;
44 * The SyncAdapter had a problem with the data it received from the server or the storage
45 * later. This problem will likely repeat if the request is tried again. The problem
46 * will need to be cleared up by either the server or the storage layer (likely with help
47 * from the user). If the SyncAdapter cleans up the data itself then it typically won't
48 * increment this value although it may still do so in order to record that it had to
49 * perform some cleanup. E.g., if the SyncAdapter received a bad entry from the server
50 * when processing a feed of entries, it may choose to drop the entry and thus make
51 * progress and still increment this value just so the SyncAdapter can record that an
52 * error occurred. This is considered a hard error.
54 public long numParseExceptions;
57 * The SyncAdapter detected that there was an unrecoverable version conflict when it
58 * attempted to update or delete a version of a resource on the server. This is expected
59 * to clear itself automatically once the new state is retrieved from the server,
60 * though it may remain until the user intervenes manually, perhaps by clearing the
61 * local storage and starting over frmo scratch. This is considered a hard error.
63 public long numConflictDetectedExceptions;
66 * Counter for tracking how many inserts were performed by the sync operation, as defined
69 public long numInserts;
72 * Counter for tracking how many updates were performed by the sync operation, as defined
75 public long numUpdates;
78 * Counter for tracking how many deletes were performed by the sync operation, as defined
81 public long numDeletes;
84 * Counter for tracking how many entries were affected by the sync operation, as defined
87 public long numEntries;
90 * Counter for tracking how many entries, either from the server or the local store, were
91 * ignored during the sync operation. This could happen if the SyncAdapter detected some
92 * unparsable data but decided to skip it and move on rather than failing immediately.
94 public long numSkippedEntries;
97 numAuthExceptions = 0;
99 numParseExceptions = 0;
100 numConflictDetectedExceptions = 0;
105 numSkippedEntries = 0;
108 public SyncStats(Parcel in) {
109 numAuthExceptions = in.readLong();
110 numIoExceptions = in.readLong();
111 numParseExceptions = in.readLong();
112 numConflictDetectedExceptions = in.readLong();
113 numInserts = in.readLong();
114 numUpdates = in.readLong();
115 numDeletes = in.readLong();
116 numEntries = in.readLong();
117 numSkippedEntries = in.readLong();
121 public String toString() {
122 StringBuilder sb = new StringBuilder();
123 sb.append(" stats [");
124 if (numAuthExceptions > 0) sb.append(" numAuthExceptions: ").append(numAuthExceptions);
125 if (numIoExceptions > 0) sb.append(" numIoExceptions: ").append(numIoExceptions);
126 if (numParseExceptions > 0) sb.append(" numParseExceptions: ").append(numParseExceptions);
127 if (numConflictDetectedExceptions > 0)
128 sb.append(" numConflictDetectedExceptions: ").append(numConflictDetectedExceptions);
129 if (numInserts > 0) sb.append(" numInserts: ").append(numInserts);
130 if (numUpdates > 0) sb.append(" numUpdates: ").append(numUpdates);
131 if (numDeletes > 0) sb.append(" numDeletes: ").append(numDeletes);
132 if (numEntries > 0) sb.append(" numEntries: ").append(numEntries);
133 if (numSkippedEntries > 0) sb.append(" numSkippedEntries: ").append(numSkippedEntries);
135 return sb.toString();
139 * Reset all the counters to 0.
141 public void clear() {
142 numAuthExceptions = 0;
144 numParseExceptions = 0;
145 numConflictDetectedExceptions = 0;
150 numSkippedEntries = 0;
153 public int describeContents() {
157 public void writeToParcel(Parcel dest, int flags) {
158 dest.writeLong(numAuthExceptions);
159 dest.writeLong(numIoExceptions);
160 dest.writeLong(numParseExceptions);
161 dest.writeLong(numConflictDetectedExceptions);
162 dest.writeLong(numInserts);
163 dest.writeLong(numUpdates);
164 dest.writeLong(numDeletes);
165 dest.writeLong(numEntries);
166 dest.writeLong(numSkippedEntries);
169 public static final Creator<SyncStats> CREATOR = new Creator<SyncStats>() {
170 public SyncStats createFromParcel(Parcel in) {
171 return new SyncStats(in);
174 public SyncStats[] newArray(int size) {
175 return new SyncStats[size];