diff options
author | 2023-08-18 23:13:47 -0400 | |
---|---|---|
committer | 2023-09-01 18:04:26 -0400 | |
commit | 19bc659baa6bba03f27f76cd91372870f5bb57d5 (patch) | |
tree | 2efb490658fa4f033bcf400abf9167a93519a32a | |
parent | bd2bbb2264c2d6dc3a22c7fc7c04b2f88a5308ff (diff) |
Set IntentResolverUnitTests' targetSdk to "current"
It was previously fixed at "30" which was hiding a lot of API
lint. While fixing and reviewing that code I also found and
corrected anumber of timeout checks with no assertions
or no timeout duration (causing false positives or hangs).
Bug: 297527444
Bug: 297549732
Test: atest IntentResolverUnitTests
Change-Id: I65eda95ea3dc84b7b4b5c497b195474f094e048d
5 files changed, 19 insertions, 10 deletions
diff --git a/java/tests/Android.bp b/java/tests/Android.bp index 90c7fb7a..29ecd95d 100644 --- a/java/tests/Android.bp +++ b/java/tests/Android.bp @@ -35,6 +35,8 @@ android_test { "testables", "truth-prebuilt", ], + min_sdk_version: "current", + target_sdk_version: "current", plugins: ["dagger2-compiler"], test_suites: ["general-tests"], sdk_version: "core_platform", diff --git a/java/tests/AndroidManifest.xml b/java/tests/AndroidManifest.xml index 05830c4c..4517a60c 100644 --- a/java/tests/AndroidManifest.xml +++ b/java/tests/AndroidManifest.xml @@ -17,8 +17,6 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.intentresolver.tests"> - <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30" /> - <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/> <uses-permission android:name="android.permission.QUERY_USERS"/> <uses-permission android:name="android.permission.READ_CLIPBOARD_IN_BACKGROUND"/> diff --git a/java/tests/src/com/android/intentresolver/ChooserActionFactoryTest.kt b/java/tests/src/com/android/intentresolver/ChooserActionFactoryTest.kt index 7f06e683..2d1ac4e4 100644 --- a/java/tests/src/com/android/intentresolver/ChooserActionFactoryTest.kt +++ b/java/tests/src/com/android/intentresolver/ChooserActionFactoryTest.kt @@ -20,6 +20,7 @@ import android.app.Activity import android.app.PendingIntent import android.content.BroadcastReceiver import android.content.Context +import android.content.Context.RECEIVER_EXPORTED import android.content.Intent import android.content.IntentFilter import android.content.res.Resources @@ -69,7 +70,7 @@ class ChooserActionFactoryTest { @Before fun setup() { - context.registerReceiver(testReceiver, IntentFilter(testAction)) + context.registerReceiver(testReceiver, IntentFilter(testAction), RECEIVER_EXPORTED) } @After @@ -190,7 +191,8 @@ class ChooserActionFactoryTest { } private fun createFactory(includeModifyShare: Boolean = false): ChooserActionFactory { - val testPendingIntent = PendingIntent.getActivity(context, 0, Intent(testAction), 0) + val testPendingIntent = + PendingIntent.getActivity(context, 0, Intent(testAction), PendingIntent.FLAG_IMMUTABLE) val targetIntent = Intent() val action = ChooserAction.Builder( diff --git a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java index b8b57403..7e82601b 100644 --- a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java +++ b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java @@ -47,6 +47,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; @@ -435,7 +436,7 @@ public class UnbundledChooserActivityTest { String previewTitle = "My Content Preview Title"; Uri uri = Uri.parse( "android.resource://com.android.frameworks.coretests/" - + R.drawable.test320x240); + + com.android.intentresolver.tests.R.drawable.test320x240); Intent sendIntent = createSendTextIntentWithPreview(previewTitle, uri); ChooserActivityOverrideData.getInstance().imageLoader = createImageLoader(uri, createBitmap()); @@ -1835,11 +1836,13 @@ public class UnbundledChooserActivityTest { broadcastInvoked.countDown(); } }; - testContext.registerReceiver(testReceiver, new IntentFilter(testAction)); + testContext.registerReceiver(testReceiver, new IntentFilter(testAction), + Context.RECEIVER_EXPORTED); try { onView(withText(customActionLabel)).perform(click()); - broadcastInvoked.await(); + assertTrue("Timeout waiting for broadcast", + broadcastInvoked.await(5000, TimeUnit.MILLISECONDS)); } finally { testContext.unregisterReceiver(testReceiver); } @@ -1875,11 +1878,14 @@ public class UnbundledChooserActivityTest { broadcastInvoked.countDown(); } }; - testContext.registerReceiver(testReceiver, new IntentFilter(modifyShareAction)); + testContext.registerReceiver(testReceiver, new IntentFilter(modifyShareAction), + Context.RECEIVER_EXPORTED); try { onView(withText(label)).perform(click()); - broadcastInvoked.await(); + assertTrue("Timeout waiting for broadcast", + broadcastInvoked.await(5000, TimeUnit.MILLISECONDS)); + } finally { testContext.unregisterReceiver(testReceiver); } diff --git a/java/tests/src/com/android/intentresolver/contentpreview/ImagePreviewImageLoaderTest.kt b/java/tests/src/com/android/intentresolver/contentpreview/ImagePreviewImageLoaderTest.kt index b5fd1fa6..89978707 100644 --- a/java/tests/src/com/android/intentresolver/contentpreview/ImagePreviewImageLoaderTest.kt +++ b/java/tests/src/com/android/intentresolver/contentpreview/ImagePreviewImageLoaderTest.kt @@ -55,6 +55,7 @@ import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.setMain import kotlinx.coroutines.yield import org.junit.After +import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test import org.mockito.Mockito.never @@ -301,7 +302,7 @@ class ImagePreviewImageLoaderTest { val latch = CountDownLatch(1) synchronized(pendingThumbnailCalls) { pendingThumbnailCalls.offer(latch) } thumbnailCallsCdl.countDown() - latch.await() + assertTrue("Timeout waiting thumbnail calls", latch.await(1, SECONDS)) bitmap } } |