diff options
| author | 2023-02-09 18:26:37 +0000 | |
|---|---|---|
| committer | 2023-02-09 21:18:24 +0000 | |
| commit | 031a84bc72c2f8d5483fefc24539bb5ee08d5fdc (patch) | |
| tree | 3f2f0ae3a379712d4864325e69d4ad345e9cc54b /java | |
| parent | 691cfdb494fd6d4e194b1e9dc07470ab64564bfe (diff) | |
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
Diffstat (limited to 'java')
7 files changed, 15 insertions, 111 deletions
diff --git a/java/src/com/android/intentresolver/chooser/DisplayResolveInfo.java b/java/src/com/android/intentresolver/chooser/DisplayResolveInfo.java index 4bbf59d8..0bbd6901 100644 --- a/java/src/com/android/intentresolver/chooser/DisplayResolveInfo.java +++ b/java/src/com/android/intentresolver/chooser/DisplayResolveInfo.java @@ -27,7 +27,6 @@ import android.content.pm.ResolveInfo; import android.os.Bundle; import android.os.UserHandle; -import com.android.intentresolver.ResolverActivity; import com.android.intentresolver.TargetPresentationGetter; import java.util.ArrayList; @@ -205,13 +204,7 @@ public class DisplayResolveInfo implements TargetInfo { } @Override - public boolean start(Activity activity, Bundle options) { - activity.startActivity(mResolvedIntent, options); - return true; - } - - @Override - public boolean startAsCaller(ResolverActivity activity, Bundle options, int userId) { + public boolean startAsCaller(Activity activity, Bundle options, int userId) { TargetInfo.prepareIntentForCrossProfileLaunch(mResolvedIntent, userId); activity.startActivityAsCaller(mResolvedIntent, options, false, userId); return true; @@ -220,6 +213,12 @@ public class DisplayResolveInfo implements TargetInfo { @Override public boolean startAsUser(Activity activity, Bundle options, UserHandle user) { TargetInfo.prepareIntentForCrossProfileLaunch(mResolvedIntent, user.getIdentifier()); + // TODO: is this equivalent to `startActivityAsCaller` with `ignoreTargetSecurity=true`? If + // so, we can consolidate on the one API method to show that this flag is the only + // distinction between `startAsCaller` and `startAsUser`. We can even bake that flag into + // the `TargetActivityStarter` upfront since it just reflects our "safe forwarding mode" -- + // which is constant for the duration of our lifecycle, leaving clients no other + // responsibilities in this logic. activity.startActivityAsUser(mResolvedIntent, options, user); return false; } diff --git a/java/src/com/android/intentresolver/chooser/ImmutableTargetInfo.java b/java/src/com/android/intentresolver/chooser/ImmutableTargetInfo.java index 315cea4d..38991c78 100644 --- a/java/src/com/android/intentresolver/chooser/ImmutableTargetInfo.java +++ b/java/src/com/android/intentresolver/chooser/ImmutableTargetInfo.java @@ -31,8 +31,6 @@ import android.util.Log; import androidx.annotation.VisibleForTesting; -import com.android.intentresolver.ResolverActivity; - import com.google.common.collect.ImmutableList; import java.util.ArrayList; @@ -55,15 +53,6 @@ public final class ImmutableTargetInfo implements TargetInfo { /** Delegate interface to request that the target be launched by a particular API. */ public interface TargetActivityStarter { /** - * Request that the delegate use the {@link Activity#startActivity()} API to launch the - * specified {@code target}. - * - * @return true if the target was launched successfully. - */ - boolean start(TargetInfo target, Activity activity, Bundle options); - - - /** * Request that the delegate use the {@link Activity#startAsCaller()} API to launch the * specified {@code target}. * @@ -418,12 +407,7 @@ public final class ImmutableTargetInfo implements TargetInfo { } @Override - public boolean start(Activity activity, Bundle options) { - return mActivityStarter.start(this, activity, options); - } - - @Override - public boolean startAsCaller(ResolverActivity activity, Bundle options, int userId) { + public boolean startAsCaller(Activity activity, Bundle options, int userId) { return mActivityStarter.startAsCaller(this, activity, options, userId); } diff --git a/java/src/com/android/intentresolver/chooser/MultiDisplayResolveInfo.java b/java/src/com/android/intentresolver/chooser/MultiDisplayResolveInfo.java index 0d79e5d5..0938c55e 100644 --- a/java/src/com/android/intentresolver/chooser/MultiDisplayResolveInfo.java +++ b/java/src/com/android/intentresolver/chooser/MultiDisplayResolveInfo.java @@ -21,8 +21,6 @@ import android.content.Intent; import android.os.Bundle; import android.os.UserHandle; -import com.android.intentresolver.ResolverActivity; - import java.util.ArrayList; import java.util.List; @@ -106,12 +104,7 @@ public class MultiDisplayResolveInfo extends DisplayResolveInfo { } @Override - public boolean start(Activity activity, Bundle options) { - return mTargetInfos.get(mSelected).start(activity, options); - } - - @Override - public boolean startAsCaller(ResolverActivity activity, Bundle options, int userId) { + public boolean startAsCaller(Activity activity, Bundle options, int userId) { return mTargetInfos.get(mSelected).startAsCaller(activity, options, userId); } diff --git a/java/src/com/android/intentresolver/chooser/NotSelectableTargetInfo.java b/java/src/com/android/intentresolver/chooser/NotSelectableTargetInfo.java index c63ebc8c..6444e13b 100644 --- a/java/src/com/android/intentresolver/chooser/NotSelectableTargetInfo.java +++ b/java/src/com/android/intentresolver/chooser/NotSelectableTargetInfo.java @@ -79,11 +79,6 @@ public final class NotSelectableTargetInfo { private static ImmutableTargetInfo.TargetActivityStarter makeNoOpActivityStarter() { return new ImmutableTargetInfo.TargetActivityStarter() { @Override - public boolean start(TargetInfo target, Activity activity, Bundle options) { - return false; - } - - @Override public boolean startAsCaller( TargetInfo target, Activity activity, Bundle options, int userId) { return false; diff --git a/java/src/com/android/intentresolver/chooser/SelectableTargetInfo.java b/java/src/com/android/intentresolver/chooser/SelectableTargetInfo.java index ca778233..df27c2b0 100644 --- a/java/src/com/android/intentresolver/chooser/SelectableTargetInfo.java +++ b/java/src/com/android/intentresolver/chooser/SelectableTargetInfo.java @@ -33,7 +33,6 @@ import android.text.SpannableStringBuilder; import android.util.HashedStringCache; import android.util.Log; -import com.android.intentresolver.ResolverActivity; import com.android.internal.config.sysui.SystemUiDeviceConfigFlags; import java.util.ArrayList; @@ -332,12 +331,7 @@ public final class SelectableTargetInfo extends ChooserTargetInfo { } @Override - public boolean start(Activity activity, Bundle options) { - return mActivityStarter.start(activity, options); - } - - @Override - public boolean startAsCaller(ResolverActivity activity, Bundle options, int userId) { + public boolean startAsCaller(Activity activity, Bundle options, int userId) { return mActivityStarter.startAsCaller(activity, options, userId); } diff --git a/java/src/com/android/intentresolver/chooser/TargetInfo.java b/java/src/com/android/intentresolver/chooser/TargetInfo.java index 7dcf66b2..69f58a7b 100644 --- a/java/src/com/android/intentresolver/chooser/TargetInfo.java +++ b/java/src/com/android/intentresolver/chooser/TargetInfo.java @@ -32,8 +32,6 @@ import android.service.chooser.ChooserTarget; import android.text.TextUtils; import android.util.HashedStringCache; -import com.android.intentresolver.ResolverActivity; - import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -124,24 +122,15 @@ public interface TargetInfo { } /** - * Start the activity referenced by this target. - * - * @param activity calling Activity performing the launch - * @param options ActivityOptions bundle - * @return true if the start completed successfully - */ - boolean start(Activity activity, Bundle options); - - /** - * Start the activity referenced by this target as if the ResolverActivity's caller - * was performing the start operation. + * Start the activity referenced by this target as if the Activity's caller was performing the + * start operation. * * @param activity calling Activity (actually) performing the launch * @param options ActivityOptions bundle * @param userId userId to start as or {@link UserHandle#USER_NULL} for activity's caller * @return true if the start completed successfully */ - boolean startAsCaller(ResolverActivity activity, Bundle options, int userId); + boolean startAsCaller(Activity activity, Bundle options, int userId); /** * Start the activity referenced by this target as a given user. 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 @@ -349,42 +349,8 @@ class ImmutableTargetInfoTest { } @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 |