Fix test failures on API 22
A SecurityException is thrown when using
AccountManager.addAccountExplicitly because the app doesn't have
AUTHENTICATE_ACCOUNTS permission. This bumps the Sdk required for the
failing tests instead of taking the additional permission since
AUTHENTICATE_ACCOUNTS isn't needed on API 23 and higher.
Test
ran GoogleContactsTests
Bug 32938088
Change-Id: I57ecd4e4fd7269b378268abebba5fae1ded59469
diff --git a/tests/src/com/android/contacts/common/database/SimContactDaoTests.java b/tests/src/com/android/contacts/common/database/SimContactDaoTests.java
index 7250593..265600c 100644
--- a/tests/src/com/android/contacts/common/database/SimContactDaoTests.java
+++ b/tests/src/com/android/contacts/common/database/SimContactDaoTests.java
@@ -53,9 +53,13 @@
@RunWith(Enclosed.class)
public class SimContactDaoTests {
- // Lollipop MR1 required for AccountManager.removeAccountExplicitly
+ // On pre-M addAccountExplicitly (which we call via AccountsTestHelper) causes a
+ // SecurityException to be thrown unless we add AUTHENTICATE_ACCOUNTS permission to the app
+ // manifest. Instead of adding the extra permission just for tests we'll just only run them
+ // on M or newer
+ @SdkSuppress(minSdkVersion = VERSION_CODES.M)
+ // Lollipop MR1 is required for removeAccountExplicitly
@RequiresApi(api = VERSION_CODES.LOLLIPOP_MR1)
- @SdkSuppress(minSdkVersion = VERSION_CODES.LOLLIPOP_MR1)
@LargeTest
@RunWith(AndroidJUnit4.class)
public static class ImportIntegrationTest {
diff --git a/tests/src/com/android/contacts/tests/AccountsTestHelper.java b/tests/src/com/android/contacts/tests/AccountsTestHelper.java
index 22e288d..123d538 100644
--- a/tests/src/com/android/contacts/tests/AccountsTestHelper.java
+++ b/tests/src/com/android/contacts/tests/AccountsTestHelper.java
@@ -20,15 +20,12 @@
import android.content.ContentResolver;
import android.content.Context;
import android.os.Build;
-import android.os.Bundle;
import android.provider.ContactsContract.RawContacts;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.test.InstrumentationRegistry;
-import android.util.Log;
import com.android.contacts.common.model.account.AccountWithDataSet;
-import com.android.contacts.common.preference.ContactsPreferences;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;