Merge "Enhance Settings deep link transition" into tm-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a13c0f4..d927073 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -154,8 +154,7 @@
         <!-- Activity for launching deep link page in 2-pane. -->
         <activity android:name=".homepage.DeepLinkHomepageActivity"
                   android:label="@string/settings_label_launcher"
-                  android:theme="@style/Theme.Settings.Home.DeepLink"
-                  android:taskAffinity=""
+                  android:theme="@style/Theme.Settings.Home"
                   android:launchMode="singleTask"
                   android:exported="true"
                   android:enabled="false"
@@ -169,9 +168,9 @@
                        android:value="true" />
         </activity>
 
-        <activity android:name=".homepage.SliceDeepLinkHomepageActivity"
+        <activity android:name=".homepage.DeepLinkHomepageActivityInternal"
                   android:label="@string/settings_label_launcher"
-                  android:theme="@style/Theme.Settings.Home.DeepLink"
+                  android:theme="@style/Theme.Settings.Home.NoAnimation"
                   android:taskAffinity=""
                   android:launchMode="singleTask"
                   android:exported="false"
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 3328b6c..ff56e7e 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -218,7 +218,7 @@
         <item name="android:statusBarColor">?attr/colorPrimaryDark</item>
     </style>
 
-    <style name="Theme.Settings.Home.DeepLink">
+    <style name="Theme.Settings.Home.NoAnimation">
         <item name="android:windowAnimationStyle">@null</item>
     </style>
 
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index d258cc2..4e2088e 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -65,8 +65,8 @@
 import com.android.settings.core.SubSettingLauncher;
 import com.android.settings.core.gateway.SettingsGateway;
 import com.android.settings.dashboard.DashboardFeatureProvider;
+import com.android.settings.homepage.DeepLinkHomepageActivityInternal;
 import com.android.settings.homepage.SettingsHomepageActivity;
-import com.android.settings.homepage.SliceDeepLinkHomepageActivity;
 import com.android.settings.homepage.TopLevelSettings;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.wfd.WifiDisplaySettings;
@@ -254,7 +254,7 @@
         final Intent intent = getIntent();
 
         if (shouldShowTwoPaneDeepLink(intent) && tryStartTwoPaneDeepLink(intent)) {
-            finishAndRemoveTask();
+            finish();
             super.onCreate(savedState);
             return;
         }
@@ -421,7 +421,7 @@
                 mHighlightMenuKey = highlightMenuKey;
             }
             trampolineIntent = getTrampolineIntent(intent, mHighlightMenuKey);
-            trampolineIntent.setClass(this, SliceDeepLinkHomepageActivity.class);
+            trampolineIntent.setClass(this, DeepLinkHomepageActivityInternal.class);
         } else {
             trampolineIntent = getTrampolineIntent(intent, mHighlightMenuKey);
         }
@@ -440,8 +440,11 @@
             return false;
         }
 
-        // If the activity is not the task root, it should not start trampoline for deep links.
-        if (!isTaskRoot()) {
+        // If the activity is task root, starting trampoline is needed in order to show two-pane UI.
+        // If FLAG_ACTIVITY_NEW_TASK is set, the activity will become the start of a new task on
+        // this history stack, so starting trampoline is needed in order to notify the homepage that
+        // the highlight key is changed.
+        if (!isTaskRoot() && (intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
             return false;
         }
 
diff --git a/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java b/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java
index 3ca8168..ad0d4ea 100644
--- a/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java
+++ b/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java
@@ -41,8 +41,8 @@
 import com.android.settings.biometrics.fingerprint.FingerprintEnrollIntroductionInternal;
 import com.android.settings.core.FeatureFlags;
 import com.android.settings.homepage.DeepLinkHomepageActivity;
+import com.android.settings.homepage.DeepLinkHomepageActivityInternal;
 import com.android.settings.homepage.SettingsHomepageActivity;
-import com.android.settings.homepage.SliceDeepLinkHomepageActivity;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.users.AvatarPickerActivity;
 
@@ -106,9 +106,7 @@
     }
 
     /**
-     * Register a new SplitPairRule for Settings home. Because homepage is able to be opened by
-     * {@link Settings} or {@link SettingsHomepageActivity} or
-     * {@link SliceDeepLinkHomepageActivity}, we register split rule for above cases.
+     * Registers a {@link SplitPairRule} for all classes that Settings homepage can be invoked from.
      */
     public static void registerTwoPanePairRuleForSettingsHome(Context context,
             ComponentName secondaryComponent,
@@ -151,7 +149,7 @@
 
         registerTwoPanePairRule(
                 context,
-                new ComponentName(context, SliceDeepLinkHomepageActivity.class),
+                new ComponentName(context, DeepLinkHomepageActivityInternal.class),
                 secondaryComponent,
                 secondaryIntentAction,
                 finishPrimaryWithSecondary ? SplitRule.FINISH_ALWAYS : SplitRule.FINISH_NEVER,
@@ -202,8 +200,6 @@
     private void registerHomepagePlaceholderRule() {
         final Set<ActivityFilter> activityFilters = new HashSet<>();
         addActivityFilter(activityFilters, SettingsHomepageActivity.class);
-        addActivityFilter(activityFilters, DeepLinkHomepageActivity.class);
-        addActivityFilter(activityFilters, SliceDeepLinkHomepageActivity.class);
         addActivityFilter(activityFilters, Settings.class);
 
         final Intent intent = new Intent(mContext, Settings.NetworkDashboardActivity.class);
diff --git a/src/com/android/settings/homepage/DeepLinkHomepageActivity.java b/src/com/android/settings/homepage/DeepLinkHomepageActivity.java
index 59cfc3c..fce7b66 100644
--- a/src/com/android/settings/homepage/DeepLinkHomepageActivity.java
+++ b/src/com/android/settings/homepage/DeepLinkHomepageActivity.java
@@ -16,6 +16,6 @@
 
 package com.android.settings.homepage;
 
-/** Activity for other apps to launch Settings deep link page */
+/** Activity for other apps to launch a Settings deep link page */
 public class DeepLinkHomepageActivity extends SettingsHomepageActivity {
 }
diff --git a/src/com/android/settings/homepage/SliceDeepLinkHomepageActivity.java b/src/com/android/settings/homepage/DeepLinkHomepageActivityInternal.java
similarity index 75%
rename from src/com/android/settings/homepage/SliceDeepLinkHomepageActivity.java
rename to src/com/android/settings/homepage/DeepLinkHomepageActivityInternal.java
index 2ea8a83..7a206a1 100644
--- a/src/com/android/settings/homepage/SliceDeepLinkHomepageActivity.java
+++ b/src/com/android/settings/homepage/DeepLinkHomepageActivityInternal.java
@@ -16,6 +16,9 @@
 
 package com.android.settings.homepage;
 
-/** Activity for Slices to launch Settings deep link page */
-public class SliceDeepLinkHomepageActivity extends SettingsHomepageActivity {
+/**
+ * Activity used for search results and slices to launch a deep link page without the cross-app
+ * transition animation
+ */
+public class DeepLinkHomepageActivityInternal extends SettingsHomepageActivity {
 }
diff --git a/src/com/android/settings/homepage/SettingsHomepageActivity.java b/src/com/android/settings/homepage/SettingsHomepageActivity.java
index 3ed305e..7aeea11 100644
--- a/src/com/android/settings/homepage/SettingsHomepageActivity.java
+++ b/src/com/android/settings/homepage/SettingsHomepageActivity.java
@@ -344,7 +344,7 @@
         }
 
         if (!(this instanceof DeepLinkHomepageActivity
-                || this instanceof SliceDeepLinkHomepageActivity)) {
+                || this instanceof DeepLinkHomepageActivityInternal)) {
             Log.e(TAG, "Not a deep link component");
             finish();
             return;
diff --git a/src/com/android/settings/search/SearchResultTrampoline.java b/src/com/android/settings/search/SearchResultTrampoline.java
index ab2d27c..5e71029 100644
--- a/src/com/android/settings/search/SearchResultTrampoline.java
+++ b/src/com/android/settings/search/SearchResultTrampoline.java
@@ -34,6 +34,7 @@
 import com.android.settings.activityembedding.ActivityEmbeddingRulesController;
 import com.android.settings.activityembedding.ActivityEmbeddingUtils;
 import com.android.settings.core.FeatureFlags;
+import com.android.settings.homepage.DeepLinkHomepageActivityInternal;
 import com.android.settings.homepage.SettingsHomepageActivity;
 import com.android.settings.overlay.FeatureFactory;
 
@@ -101,6 +102,7 @@
         } else if (isSettingsIntelligence(callingActivity)) {
             if (FeatureFlagUtils.isEnabled(this, FeatureFlags.SETTINGS_SEARCH_ALWAYS_EXPAND)) {
                 startActivity(SettingsActivity.getTrampolineIntent(intent, highlightMenuKey)
+                        .setClass(this, DeepLinkHomepageActivityInternal.class)
                         .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS));
             } else {