Add ability to switch between support versions

Creates a trampoline activity and adds functionality
to the SupportFeatureProvider interface so that we can
conditionally launch support V1 or V2.

Test: Test in ag/2144016
Bug: 37306241
Change-Id: I6d24e65cad91692e457ea216713e90239845b4f5
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 1db185e..5aee7bf 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -168,6 +168,7 @@
         }
     }
     public static class WebViewAppPickerActivity extends SettingsActivity { /* empty */ }
+    public static class LegacySupportActivity extends SettingsActivity{ /* empty */ }
 
     // Top level categories for new IA
     public static class NetworkDashboardActivity extends SettingsActivity {}
@@ -176,6 +177,5 @@
     public static class StorageDashboardActivity extends SettingsActivity {}
     public static class UserAndAccountDashboardActivity extends SettingsActivity {}
     public static class SystemDashboardActivity extends SettingsActivity {}
-    public static class SupportDashboardActivity extends SettingsActivity {}
 
 }
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index caac95f..068e2a2 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -260,7 +260,6 @@
             Settings.SecuritySettingsActivity.class.getName(),
             Settings.AccessibilitySettingsActivity.class.getName(),
             Settings.SystemDashboardActivity.class.getName(),
-            Settings.SupportDashboardActivity.class.getName(),
             // Home page > Network & Internet
             Settings.WifiSettingsActivity.class.getName(),
             Settings.DataUsageSummaryActivity.class.getName(),
diff --git a/src/com/android/settings/dashboard/SupportDashboardActivity.java b/src/com/android/settings/dashboard/SupportDashboardActivity.java
new file mode 100644
index 0000000..6cd6612
--- /dev/null
+++ b/src/com/android/settings/dashboard/SupportDashboardActivity.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.dashboard;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import com.android.settings.Settings.LegacySupportActivity;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.overlay.SupportFeatureProvider;
+
+/**
+ * Trampoline activity that decides which version of support should be shown to the user.
+ */
+public class SupportDashboardActivity extends Activity {
+
+    public SupportDashboardActivity() {}
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        SupportFeatureProvider supportFeatureProvider = FeatureFactory.getFactory(this)
+                .getSupportFeatureProvider(this);
+
+        // try to launch support v2 if we have the feature provider
+        if (supportFeatureProvider != null && supportFeatureProvider.isSupportV2Enabled()) {
+            supportFeatureProvider.startSupportV2(this);
+        } else {
+            startActivity(new Intent(this, LegacySupportActivity.class));
+        }
+        finish();
+    }
+}
diff --git a/src/com/android/settings/overlay/SupportFeatureProvider.java b/src/com/android/settings/overlay/SupportFeatureProvider.java
index 0f8d424..1831486 100644
--- a/src/com/android/settings/overlay/SupportFeatureProvider.java
+++ b/src/com/android/settings/overlay/SupportFeatureProvider.java
@@ -129,6 +129,19 @@
     void startSupport(Activity activity, Account account, @SupportType int type);
 
     /**
+     * Starts support v2, invokes the support home page. Will no-op if support v2 is not enabled.
+     *
+     * @param activity Calling activity.
+     */
+    void startSupportV2(Activity activity);
+
+    /**
+     * Checks if support v2 is enabled for this device.
+     * @return a boolean indicating if support v2 is enabled.
+     */
+    boolean isSupportV2Enabled();
+
+    /**
      * Returns an {@link Intent} that opens help and allow user get help on sign in.
      */
     Intent getSignInHelpIntent(Context context);