[Large screen] Make slice deep linking to Settings show in 2-pane

- add a standalone home activity for slice deep link.
- add EXTRA_IS_FROM_SLICE to control the slice deep link flow.
- Intent#parseUri fails if the intent data schema is set.
  Add EXTRA_SETTINGS_LARGE_SCREEN_DEEP_LINK_INTENT_DATA to relay the
  data schema.

Bug: 201397123
Test: manual, robotest
      1.  Say 'Enable NFC'/'Enable Bluetooth'to Google assistant.
      2.  Click the the NFC/BT Slice.
Change-Id: Ia3216956328c32b2109cb2d70ad1105327661f26
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 91ad937..df30d8b 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -16,6 +16,10 @@
 
 package com.android.settings;
 
+import static android.provider.Settings.ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY;
+import static android.provider.Settings.EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_HIGHLIGHT_MENU_KEY;
+import static android.provider.Settings.EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_INTENT_URI;
+
 import static com.android.settings.applications.appinfo.AppButtonsPreferenceController.KEY_REMOVE_TASK_WHEN_FINISHING;
 
 import android.app.ActionBar;
@@ -61,6 +65,7 @@
 import com.android.settings.core.gateway.SettingsGateway;
 import com.android.settings.dashboard.DashboardFeatureProvider;
 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;
@@ -140,6 +145,12 @@
             ":settings:show_fragment_as_subsetting";
 
     /**
+     * Additional extra of Settings#ACTION_SETTINGS_LARGE_SCREEN_DEEP_LINK.
+     * Set true when the deep link intent is from a slice
+     */
+    public static final String EXTRA_IS_FROM_SLICE = "is_from_slice";
+
+    /**
      * Personal or Work profile tab of {@link ProfileSelectFragment}
      * <p>0: Personal tab.
      * <p>1: Work profile tab.
@@ -363,15 +374,34 @@
             return false;
         }
 
+        final Intent detailIntent = new Intent(intent);
         // It's a deep link intent, SettingsHomepageActivity will set SplitPairRule and start it.
-        final Intent trampolineIntent =
-                new Intent(android.provider.Settings.ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY);
-        trampolineIntent.replaceExtras(intent);
+        final Intent trampolineIntent = new Intent(ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY);
+
+        trampolineIntent.replaceExtras(detailIntent);
+
+        // Relay detail intent data to prevent failure of Intent#ParseUri.
+        // If Intent#getData() is not null, Intent#toUri will return an Uri which has the scheme of
+        // Intent#getData() and it may not be the scheme of an Intent.
         trampolineIntent.putExtra(
-                android.provider.Settings.EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_INTENT_URI,
-                intent.toUri(Intent.URI_INTENT_SCHEME));
-        trampolineIntent.putExtra(
-                android.provider.Settings.EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_HIGHLIGHT_MENU_KEY,
+                SettingsHomepageActivity.EXTRA_SETTINGS_LARGE_SCREEN_DEEP_LINK_INTENT_DATA,
+                detailIntent.getData());
+        detailIntent.setData(null);
+
+        trampolineIntent.putExtra(EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_INTENT_URI,
+                detailIntent.toUri(Intent.URI_INTENT_SCHEME));
+
+        if (detailIntent.getBooleanExtra(EXTRA_IS_FROM_SLICE, false)) {
+            trampolineIntent.setClass(this, SliceDeepLinkHomepageActivity.class);
+            // Get menu key for slice deep link case.
+            final String highlightMenuKey = detailIntent.getStringExtra(
+                    EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_HIGHLIGHT_MENU_KEY);
+            if (!TextUtils.isEmpty(highlightMenuKey)) {
+                mHighlightMenuKey = highlightMenuKey;
+            }
+        }
+
+        trampolineIntent.putExtra(EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_HIGHLIGHT_MENU_KEY,
                 mHighlightMenuKey);
         trampolineIntent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
         startActivity(trampolineIntent);
@@ -391,6 +421,12 @@
             return false;
         }
 
+        if (intent.getBooleanExtra(EXTRA_IS_FROM_SLICE, false)) {
+            // Slice deep link starts the Intent using SubSettingLauncher. Returns true to show
+            // 2-pane deep link.
+            return true;
+        }
+
         if (isSubSettings(intent)) {
             return false;
         }