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 --- .../intentresolver/chooser/DisplayResolveInfo.java | 15 +++++++-------- .../intentresolver/chooser/ImmutableTargetInfo.java | 18 +----------------- .../chooser/MultiDisplayResolveInfo.java | 9 +-------- .../chooser/NotSelectableTargetInfo.java | 5 ----- .../intentresolver/chooser/SelectableTargetInfo.java | 8 +------- .../com/android/intentresolver/chooser/TargetInfo.java | 17 +++-------------- 6 files changed, 13 insertions(+), 59 deletions(-) (limited to 'java/src') 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; @@ -54,15 +52,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 @@ -78,11 +78,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) { 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. -- cgit v1.2.3-59-g8ed1b