Silence some caught exceptions if from test app am: daa6fb877f
am: d8a2c4fdac
Change-Id: I9d5ac776a82e244480bb566ba5f2c5ce36e3fc98
diff --git a/src/com/android/contacts/common/model/account/ExternalAccountType.java b/src/com/android/contacts/common/model/account/ExternalAccountType.java
index 6803a6b..5c5a26a 100644
--- a/src/com/android/contacts/common/model/account/ExternalAccountType.java
+++ b/src/com/android/contacts/common/model/account/ExternalAccountType.java
@@ -418,7 +418,7 @@
return -1; // Empty text is okay.
}
if (resourceName.charAt(0) != '@') {
- if (Log.isLoggable(TAG, Log.WARN)) {
+ if (Log.isLoggable(TAG, Log.WARN) && !isFromTestApp(packageName)) {
Log.w(TAG, xmlAttributeName + " must be a resource name beginnig with '@'");
}
return -1;
@@ -428,18 +428,23 @@
try {
res = context.getPackageManager().getResourcesForApplication(packageName);
} catch (NameNotFoundException e) {
- if (Log.isLoggable(TAG, Log.WARN)) {
+ if (Log.isLoggable(TAG, Log.WARN) && !isFromTestApp(packageName)) {
Log.w(TAG, "Unable to load package " + packageName);
}
return -1;
}
final int resId = res.getIdentifier(name, null, packageName);
if (resId == 0) {
- if (Log.isLoggable(TAG, Log.WARN)) {
+ if (Log.isLoggable(TAG, Log.WARN) && !isFromTestApp(packageName)) {
Log.w(TAG, "Unable to load " + resourceName + " from package " + packageName);
}
return -1;
}
return resId;
}
+
+ @VisibleForTesting
+ static boolean isFromTestApp(String packageName) {
+ return TextUtils.equals(packageName, "com.google.android.contacts.tests");
+ }
}
diff --git a/tests/src/com/android/contacts/common/model/account/ExternalAccountTypeTest.java b/tests/src/com/android/contacts/common/model/account/ExternalAccountTypeTest.java
index 96e776f..0ddeb67 100644
--- a/tests/src/com/android/contacts/common/model/account/ExternalAccountTypeTest.java
+++ b/tests/src/com/android/contacts/common/model/account/ExternalAccountTypeTest.java
@@ -79,6 +79,11 @@
"@string/test_string", packageName, ""));
}
+ public void testIsFromTestApp() {
+ assertTrue(ExternalAccountType.isFromTestApp("com.google.android.contacts.tests"));
+ assertFalse(ExternalAccountType.isFromTestApp("com.google.android.contacts"));
+ }
+
/**
* Initialize with an invalid package name and see if type will be initialized, but empty.
*/