• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package android.content;
2 
3 import android.os.Parcel;
4 import android.os.Parcelable;
5 
6 /**
7  * This class is used to store information about the result of a sync
8  */
9 public final class SyncResult implements Parcelable {
10     public final boolean syncAlreadyInProgress;
11     public boolean tooManyDeletions;
12     public boolean tooManyRetries;
13     public boolean databaseError;
14     public boolean fullSyncRequested;
15     public boolean partialSyncUnavailable;
16     public boolean moreRecordsToGet;
17     public final SyncStats stats;
18     public static final SyncResult ALREADY_IN_PROGRESS;
19 
20     static {
21         ALREADY_IN_PROGRESS = new SyncResult(true);
22     }
23 
SyncResult()24     public SyncResult() {
25         this(false);
26     }
27 
SyncResult(boolean syncAlreadyInProgress)28     private SyncResult(boolean syncAlreadyInProgress) {
29         this.syncAlreadyInProgress = syncAlreadyInProgress;
30         this.tooManyDeletions = false;
31         this.tooManyRetries = false;
32         this.fullSyncRequested = false;
33         this.partialSyncUnavailable = false;
34         this.moreRecordsToGet = false;
35         this.stats = new SyncStats();
36     }
37 
SyncResult(Parcel parcel)38     private SyncResult(Parcel parcel) {
39         syncAlreadyInProgress = parcel.readInt() != 0;
40         tooManyDeletions = parcel.readInt() != 0;
41         tooManyRetries = parcel.readInt() != 0;
42         databaseError = parcel.readInt() != 0;
43         fullSyncRequested = parcel.readInt() != 0;
44         partialSyncUnavailable = parcel.readInt() != 0;
45         moreRecordsToGet = parcel.readInt() != 0;
46         stats = new SyncStats(parcel);
47     }
48 
hasHardError()49     public boolean hasHardError() {
50         return stats.numParseExceptions > 0
51                 || stats.numConflictDetectedExceptions > 0
52                 || stats.numAuthExceptions > 0
53                 || tooManyDeletions
54                 || tooManyRetries
55                 || databaseError;
56     }
57 
hasSoftError()58     public boolean hasSoftError() {
59         return syncAlreadyInProgress || stats.numIoExceptions > 0;
60     }
61 
hasError()62     public boolean hasError() {
63         return hasSoftError() || hasHardError();
64     }
65 
madeSomeProgress()66     public boolean madeSomeProgress() {
67         return ((stats.numDeletes > 0) && !tooManyDeletions)
68                 || stats.numInserts > 0
69                 || stats.numUpdates > 0;
70     }
71 
clear()72     public void clear() {
73         if (syncAlreadyInProgress) {
74             throw new UnsupportedOperationException(
75                     "you are not allowed to clear the ALREADY_IN_PROGRESS SyncStats");
76         }
77         tooManyDeletions = false;
78         tooManyRetries = false;
79         databaseError = false;
80         fullSyncRequested = false;
81         partialSyncUnavailable = false;
82         moreRecordsToGet = false;
83         stats.clear();
84     }
85 
86     public static final Creator<SyncResult> CREATOR = new Creator<SyncResult>() {
87         public SyncResult createFromParcel(Parcel in) {
88             return new SyncResult(in);
89         }
90 
91         public SyncResult[] newArray(int size) {
92             return new SyncResult[size];
93         }
94     };
95 
describeContents()96     public int describeContents() {
97         return 0;
98     }
99 
writeToParcel(Parcel parcel, int flags)100     public void writeToParcel(Parcel parcel, int flags) {
101         parcel.writeInt(syncAlreadyInProgress ? 1 : 0);
102         parcel.writeInt(tooManyDeletions ? 1 : 0);
103         parcel.writeInt(tooManyRetries ? 1 : 0);
104         parcel.writeInt(databaseError ? 1 : 0);
105         parcel.writeInt(fullSyncRequested ? 1 : 0);
106         parcel.writeInt(partialSyncUnavailable ? 1 : 0);
107         parcel.writeInt(moreRecordsToGet ? 1 : 0);
108         stats.writeToParcel(parcel, flags);
109     }
110 
111     @Override
toString()112     public String toString() {
113         StringBuilder sb = new StringBuilder();
114         sb.append("SyncResult:");
115         if (syncAlreadyInProgress) {
116             sb.append(" syncAlreadyInProgress: ").append(syncAlreadyInProgress);
117         }
118         if (tooManyDeletions) sb.append(" tooManyDeletions: ").append(tooManyDeletions);
119         if (tooManyRetries) sb.append(" tooManyRetries: ").append(tooManyRetries);
120         if (databaseError) sb.append(" databaseError: ").append(databaseError);
121         if (fullSyncRequested) sb.append(" fullSyncRequested: ").append(fullSyncRequested);
122         if (partialSyncUnavailable) {
123             sb.append(" partialSyncUnavailable: ").append(partialSyncUnavailable);
124         }
125         if (moreRecordsToGet) sb.append(" moreRecordsToGet: ").append(moreRecordsToGet);
126         sb.append(stats);
127         return sb.toString();
128     }
129 
130     /**
131      * Generates a debugging string indicating the status.
132      * The string consist of a sequence of code letter followed by the count.
133      * Code letters are f - fullSyncRequested, r - partialSyncUnavailable,
134      * X - hardError, e - numParseExceptions, c - numConflictDetectedExceptions,
135      * a - numAuthExceptions, D - tooManyDeletions, R - tooManyRetries,
136      * b - databaseError, x - softError, l - syncAlreadyInProgress,
137      * I - numIoExceptions
138      * @return debugging string.
139      */
toDebugString()140     public String toDebugString() {
141         StringBuffer sb = new StringBuffer();
142 
143         if (fullSyncRequested) {
144             sb.append("f1");
145         }
146         if (partialSyncUnavailable) {
147             sb.append("r1");
148         }
149         if (hasHardError()) {
150             sb.append("X1");
151         }
152         if (stats.numParseExceptions > 0) {
153             sb.append("e").append(stats.numParseExceptions);
154         }
155         if (stats.numConflictDetectedExceptions > 0) {
156             sb.append("c").append(stats.numConflictDetectedExceptions);
157         }
158         if (stats.numAuthExceptions > 0) {
159             sb.append("a").append(stats.numAuthExceptions);
160         }
161         if (tooManyDeletions) {
162             sb.append("D1");
163         }
164         if (tooManyRetries) {
165             sb.append("R1");
166         }
167         if (databaseError) {
168             sb.append("b1");
169         }
170         if (hasSoftError()) {
171             sb.append("x1");
172         }
173         if (syncAlreadyInProgress) {
174             sb.append("l1");
175         }
176         if (stats.numIoExceptions > 0) {
177             sb.append("I").append(stats.numIoExceptions);
178         }
179         return sb.toString();
180     }
181 }
182