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