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
This commit is contained in:
Jason Chiu
2022-06-22 10:24:29 +08:00
parent ea9b715e78
commit d3286b1981

View File

@@ -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()));
}
}
}