Add user and account dashboard category for new IA.

Add the initial version for the User & accounts category and set the
tile's intent if it contains metadata but fragment is null.

Test: RunSettingsRoboTests
Bug: 31801423
Change-Id: Ic63bf8aeaf47f68a184af73c9a8a72b89b597a17
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c987ec0..755c6e3 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3364,6 +3364,29 @@
                        android:value="true" />
         </activity-alias>
 
+        <activity android:name=".Settings$UserAndAccountDashboardActivity"
+                  android:label="@string/account_dashboard_title"
+                  android:icon="@drawable/ic_settings_accounts">
+            <intent-filter android:priority="2">
+                <action android:name="com.android.settings.action.SETTINGS"/>
+            </intent-filter>
+            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+                       android:value="com.android.settings.accounts.UserAndAccountDashboardFragment"/>
+            <meta-data android:name="com.android.settings.category"
+                       android:value="com.android.settings.category.ia.homepage"/>
+        </activity>
+
+        <activity-alias android:name="UserDashboardAlias"
+                        android:targetActivity="Settings$UserSettingsActivity">
+            <intent-filter android:priority="8">
+                <action android:name="com.android.settings.action.SETTINGS"/>
+            </intent-filter>
+            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+                       android:value="com.android.settings.users.UserSettings" />
+            <meta-data android:name="com.android.settings.category"
+                       android:value="com.android.settings.category.ia.accounts" />
+        </activity-alias>
+
         <!-- End of information architecture host activities -->
 
         <service
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8d6e5ff..b0e7b6b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5931,6 +5931,8 @@
     <string name="connected_devices_dashboard_title">Connected devices</string>
     <!-- Title for setting tile leading to Apps & Notification settings [CHAR LIMIT=40]-->
     <string name="app_and_notification_dashboard_title">Apps &amp; notifications</string>
+    <!-- Title for setting tile leading to User and accounts settings [CHAR LIMIT=40]-->
+    <string name="account_dashboard_title">User &amp; accounts</string>
     <!-- Summary text for system preference tile, showing current display language of device [CHAR LIMIT=NONE]-->
     <string name="system_dashboard_summary">Language: <xliff:g id="language">%1$s</xliff:g></string>
 
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index bfecbbf..451c7e3 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -168,6 +168,7 @@
     public static class ConnectedDeviceDashboardActivity extends SettingsActivity {}
     public static class AppAndNotificationDashboardActivity extends SettingsActivity {}
     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/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 11f8105..34dd095 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -61,6 +61,7 @@
 import com.android.settings.accounts.AccountSyncSettings;
 import com.android.settings.accounts.ChooseAccountActivity;
 import com.android.settings.accounts.ManagedProfileSettings;
+import com.android.settings.accounts.UserAndAccountDashboardFragment;
 import com.android.settings.applications.AppAndNotificationDashboardFragment;
 import com.android.settings.applications.AdvancedAppSettings;
 import com.android.settings.applications.DrawOverlayDetails;
@@ -279,6 +280,7 @@
             "com.android.settings.Settings.DisplayDashboardAlias",
             "com.android.settings.Settings.SoundDashboardAlias",
             "com.android.settings.Settings.SecurityDashboardAlias",
+            Settings.UserAndAccountDashboardActivity.class.getName(),
             Settings.SystemDashboardActivity.class.getName(),
             Settings.SupportDashboardActivity.class.getName(),
             // Home page > Apps & Notifications
@@ -396,6 +398,7 @@
             NetworkDashboardFragment.class.getName(),
             ConnectedDeviceDashboardFragment.class.getName(),
             AppAndNotificationDashboardFragment.class.getName(),
+            UserAndAccountDashboardFragment.class.getName(),
     };
 
 
diff --git a/src/com/android/settings/accounts/UserAndAccountDashboardFragment.java b/src/com/android/settings/accounts/UserAndAccountDashboardFragment.java
new file mode 100644
index 0000000..34d6dc4
--- /dev/null
+++ b/src/com/android/settings/accounts/UserAndAccountDashboardFragment.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2016 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.accounts;
+
+import android.content.Context;
+
+import com.android.internal.logging.MetricsProto.MetricsEvent;
+import com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settingslib.drawer.CategoryKey;
+
+import java.util.List;
+
+public class UserAndAccountDashboardFragment extends DashboardFragment {
+
+    private static final String TAG = "UserAndAccountDashboard";
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsEvent.ACCOUNT;
+    }
+
+    @Override
+    protected String getCategoryKey() {
+        return CategoryKey.CATEGORY_ACCOUNT;
+    }
+
+    @Override
+    protected String getLogTag() {
+        return TAG;
+    }
+
+    @Override
+    protected int getPreferenceScreenResId() {
+        return R.xml.account_settings;
+    }
+
+    @Override
+    protected List<PreferenceController> getPreferenceControllers(Context context) {
+        return null;
+    }
+
+}
\ No newline at end of file
diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java
index 37bc447..fd125af 100644
--- a/src/com/android/settings/dashboard/DashboardFragment.java
+++ b/src/com/android/settings/dashboard/DashboardFragment.java
@@ -344,11 +344,12 @@
             pref.setIcon(tile.icon.loadDrawable(context));
         }
         final Bundle metadata = tile.metaData;
+        String clsName = null;
         if (metadata != null) {
-            String clsName = metadata.getString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS);
-            if (!TextUtils.isEmpty(clsName)) {
-                pref.setFragment(clsName);
-            }
+            clsName = metadata.getString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS);
+        }
+        if (!TextUtils.isEmpty(clsName)) {
+            pref.setFragment(clsName);
         } else if (tile.intent != null) {
             final Intent intent = new Intent(tile.intent);
             pref.setOnPreferenceClickListener(preference -> {
diff --git a/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java
new file mode 100644
index 0000000..2d266b6
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2016 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.accounts;
+
+import android.content.Context;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settingslib.drawer.CategoryKey;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class UserAndAccountDashboardFragmentTest {
+
+  @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+  private Context mContext;
+
+  private UserAndAccountDashboardFragment mFragment;
+
+  @Before
+  public void setUp() {
+    MockitoAnnotations.initMocks(this);
+    FakeFeatureFactory.setupForTest(mContext);
+    mFragment = new UserAndAccountDashboardFragment();
+  }
+
+  @Test
+  public void testCategory_isConnectedDevice() {
+    assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_ACCOUNT);
+  }
+
+}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
index e4222ce..8fc290e 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
@@ -16,6 +16,7 @@
 package com.android.settings.dashboard;
 
 import android.content.Context;
+import android.content.Intent;
 import android.graphics.Bitmap;
 import android.graphics.drawable.Icon;
 import android.os.Bundle;
@@ -142,6 +143,21 @@
         assertThat(preference.getOrder()).isEqualTo(-tile.priority);
     }
 
+    @Test
+    public void bindPreference_noFragmentMetadata_shouldBindIntent() {
+        final Preference preference = new Preference(
+                ShadowApplication.getInstance().getApplicationContext());
+        final Tile tile = new Tile();
+        tile.metaData = new Bundle();
+        tile.priority = 10;
+        tile.intent = new Intent();
+        mTestFragment.bindPreferenceToTile(mContext, preference, tile, "123");
+
+        assertThat(preference.getFragment()).isNull();
+        assertThat(preference.getIntent()).isNotNull();
+        assertThat(preference.getOrder()).isEqualTo(-tile.priority);
+    }
+
     public static class TestPreferenceController extends PreferenceController {
 
         public TestPreferenceController(Context context) {