Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 00e38301 authored by Wenyi Wang's avatar Wenyi Wang Committed by Android (Google) Code Review
Browse files

Merge "Silence some caught exceptions if from test app" into ub-contactsdialer-h-dev

parents 47c03a32 daa6fb87
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -418,7 +418,7 @@ public class ExternalAccountType extends BaseAccountType {
            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 @@ public class ExternalAccountType extends BaseAccountType {
        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");
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -79,6 +79,11 @@ public class ExternalAccountTypeTest extends InstrumentationTestCase {
                "@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.
     */