From 031a84bc72c2f8d5483fefc24539bb5ee08d5fdc Mon Sep 17 00:00:00 2001 From: Joshua Trask Date: Thu, 9 Feb 2023 18:26:37 +0000 Subject: Remove plain `startActivity` plumbing APIs These were unused, and the pruned-down API surface better indicates that we *always* launch activities to an explicit *user* (and *maybe* with additional specification about the caller identity -- something to do with the "safe forwarding mode" feature I'm still trying to get my mind aroud). While I was in here, I changed the signature of the one 'activity starter' method that arbitrarily took a `ResolverActivity` instead of the more generic `Activity` used in the others. We've been commenting about the opportunity to make this fix for a while now, and there's no time like the present. Test: `atest IntentResolverUnitTests` Bug: 202167050 Change-Id: I33be96b68e6feba8b7fdb0295431373aadd2c2bf --- .../chooser/ImmutableTargetInfoTest.kt | 54 +--------------------- 1 file changed, 2 insertions(+), 52 deletions(-) (limited to 'java/tests') diff --git a/java/tests/src/com/android/intentresolver/chooser/ImmutableTargetInfoTest.kt b/java/tests/src/com/android/intentresolver/chooser/ImmutableTargetInfoTest.kt index 4d825f6b..4989a3f1 100644 --- a/java/tests/src/com/android/intentresolver/chooser/ImmutableTargetInfoTest.kt +++ b/java/tests/src/com/android/intentresolver/chooser/ImmutableTargetInfoTest.kt @@ -348,43 +348,9 @@ class ImmutableTargetInfoTest { assertThat(info.isDisplayResolveInfo).isTrue() } - @Test - fun testActivityStarter_correctNumberOfInvocations_start() { - val activityStarter = object : TestActivityStarter() { - override fun startAsCaller( - target: TargetInfo, activity: Activity, options: Bundle, userId: Int): Boolean { - throw RuntimeException("Wrong API used: startAsCaller") - } - - override fun startAsUser( - target: TargetInfo, activity: Activity, options: Bundle, user: UserHandle - ): Boolean { - throw RuntimeException("Wrong API used: startAsUser") - } - } - - val info = ImmutableTargetInfo.newBuilder().setActivityStarter(activityStarter).build() - val activity: Activity = mock() - val options = Bundle() - options.putInt("TEST_KEY", 1) - - info.start(activity, options) - - assertThat(activityStarter.totalInvocations).isEqualTo(1) - assertThat(activityStarter.lastInvocationTargetInfo).isEqualTo(info) - assertThat(activityStarter.lastInvocationActivity).isEqualTo(activity) - assertThat(activityStarter.lastInvocationOptions).isEqualTo(options) - assertThat(activityStarter.lastInvocationUserId).isNull() - assertThat(activityStarter.lastInvocationAsCaller).isFalse() - } - @Test fun testActivityStarter_correctNumberOfInvocations_startAsCaller() { val activityStarter = object : TestActivityStarter() { - override fun start(target: TargetInfo, activity: Activity, options: Bundle): Boolean { - throw RuntimeException("Wrong API used: start") - } - override fun startAsUser( target: TargetInfo, activity: Activity, options: Bundle, user: UserHandle ): Boolean { @@ -410,10 +376,6 @@ class ImmutableTargetInfoTest { @Test fun testActivityStarter_correctNumberOfInvocations_startAsUser() { val activityStarter = object : TestActivityStarter() { - override fun start(target: TargetInfo, activity: Activity, options: Bundle): Boolean { - throw RuntimeException("Wrong API used: start") - } - override fun startAsCaller( target: TargetInfo, activity: Activity, options: Bundle, userId: Int): Boolean { throw RuntimeException("Wrong API used: startAsCaller") @@ -441,16 +403,14 @@ class ImmutableTargetInfoTest { val info1 = ImmutableTargetInfo.newBuilder().setActivityStarter(activityStarter).build() val info2 = info1.toBuilder().build() - info1.start(mock(), Bundle()) + info1.startAsCaller(mock(), Bundle(), 42) assertThat(activityStarter.lastInvocationTargetInfo).isEqualTo(info1) - info2.start(mock(), Bundle()) - assertThat(activityStarter.lastInvocationTargetInfo).isEqualTo(info2) info2.startAsCaller(mock(), Bundle(), 42) assertThat(activityStarter.lastInvocationTargetInfo).isEqualTo(info2) info2.startAsUser(mock(), Bundle(), UserHandle.of(42)) assertThat(activityStarter.lastInvocationTargetInfo).isEqualTo(info2) - assertThat(activityStarter.totalInvocations).isEqualTo(4) // Instance is still shared. + assertThat(activityStarter.totalInvocations).isEqualTo(3) // Instance is still shared. } } @@ -462,16 +422,6 @@ private open class TestActivityStarter : ImmutableTargetInfo.TargetActivityStart var lastInvocationUserId: Integer? = null var lastInvocationAsCaller = false - override fun start(target: TargetInfo, activity: Activity, options: Bundle): Boolean { - ++totalInvocations - lastInvocationTargetInfo = target - lastInvocationActivity = activity - lastInvocationOptions = options - lastInvocationUserId = null - lastInvocationAsCaller = false - return true - } - override fun startAsCaller( target: TargetInfo, activity: Activity, options: Bundle, userId: Int): Boolean { ++totalInvocations -- cgit v1.2.3-59-g8ed1b