COnvert sync error to int
Bug: 8152259
Change-Id: I99fc99f70796c70ec0566c40ba350e10c36b90b7
diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java
index 94d27ec..fefd343 100644
--- a/core/java/android/content/ContentResolver.java
+++ b/core/java/android/content/ContentResolver.java
@@ -193,6 +193,23 @@
return SYNC_ERROR_NAMES[error - 1];
}
+ /** @hide */
+ public static int syncErrorStringToInt(String error) {
+ for (int i = 0, n = SYNC_ERROR_NAMES.length; i < n; i++) {
+ if (SYNC_ERROR_NAMES[i].equals(error)) {
+ return i + 1;
+ }
+ }
+ if (error != null) {
+ try {
+ return Integer.parseInt(error);
+ } catch (NumberFormatException e) {
+ Log.d(TAG, "error parsing sync error: " + error);
+ }
+ }
+ return 0;
+ }
+
public static final int SYNC_OBSERVER_TYPE_SETTINGS = 1<<0;
public static final int SYNC_OBSERVER_TYPE_PENDING = 1<<1;
public static final int SYNC_OBSERVER_TYPE_ACTIVE = 1<<2;
diff --git a/core/java/android/content/SyncStatusInfo.java b/core/java/android/content/SyncStatusInfo.java
index 49e3e35..ff628d9 100644
--- a/core/java/android/content/SyncStatusInfo.java
+++ b/core/java/android/content/SyncStatusInfo.java
@@ -51,14 +51,13 @@
}
public int getLastFailureMesgAsInt(int def) {
- try {
- if (lastFailureMesg != null) {
- return Integer.parseInt(lastFailureMesg);
- }
- } catch (NumberFormatException e) {
- Log.d(TAG, "error parsing lastFailureMesg of " + lastFailureMesg, e);
+ final int i = ContentResolver.syncErrorStringToInt(lastFailureMesg);
+ if (i > 0) {
+ return i;
+ } else {
+ Log.d(TAG, "Unknown lastFailureMesg:" + lastFailureMesg);
+ return def;
}
- return def;
}
public int describeContents() {