From d3286b198124fa21b86fdd99b68fb0fc44e0ec37 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Wed, 22 Jun 2022 10:24:29 +0800 Subject: [PATCH] Add FLAG_ACTIVITY_SINGLE_TOP to shortcuts intent This is to simplify the shortcut launch flow on large screen devices when launching the same shortcut, which also improves the performance. FLAG_ACTIVITY_CLEAR_TOP flag is used for the launch a shortcut. When launching a shortcut whose activity is in the background on a large screen device, the background activity is cleared by the system and a new activity is started. Thus, the activity goes though the complete deep link flow that invokes the trampoline homepage activity to start the target page. After the change, the system will bring the background activity to the foreground rather than kill it and start a new one. Test: create a shortcut and observe the adb log Fix: 234681140 Change-Id: Id922af1f59a6a64ea6f6150cf6fea92808a6de65 --- .../CreateShortcutPreferenceController.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java b/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java index c871e9fc219..89ee19bc8a7 100644 --- a/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java +++ b/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java @@ -46,6 +46,7 @@ import androidx.preference.PreferenceGroup; import com.android.settings.R; import com.android.settings.Settings; import com.android.settings.Settings.TetherSettingsActivity; +import com.android.settings.activityembedding.ActivityEmbeddingUtils; import com.android.settings.core.BasePreferenceController; import com.android.settings.gestures.OneHandedSettingsUtils; import com.android.settings.overlay.FeatureFactory; @@ -127,7 +128,7 @@ public class CreateShortcutPreferenceController extends BasePreferenceController return false; } final Intent shortcutIntent = createResultIntent( - buildShortcutIntent(info), + buildShortcutIntent(uiContext, info), info, clickTarget.getTitle()); mHost.setResult(Activity.RESULT_OK, shortcutIntent); logCreateShortcut(info); @@ -210,10 +211,14 @@ public class CreateShortcutPreferenceController extends BasePreferenceController info.activityInfo.name); } - private static Intent buildShortcutIntent(ResolveInfo info) { - return new Intent(SHORTCUT_PROBE) + private static Intent buildShortcutIntent(Context context, ResolveInfo info) { + Intent intent = new Intent(SHORTCUT_PROBE) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP) .setClassName(info.activityInfo.packageName, info.activityInfo.name); + if (ActivityEmbeddingUtils.isEmbeddingActivityEnabled(context)) { + intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + } + return intent; } private static ShortcutInfo createShortcutInfo(Context context, Intent shortcutIntent, @@ -277,8 +282,8 @@ public class CreateShortcutPreferenceController extends BasePreferenceController ResolveInfo ri = context.getPackageManager().resolveActivity(si.getIntent(), 0); if (ri != null) { - updatedShortcuts.add(createShortcutInfo(context, buildShortcutIntent(ri), ri, - si.getShortLabel())); + updatedShortcuts.add(createShortcutInfo(context, + buildShortcutIntent(context, ri), ri, si.getShortLabel())); } } }