Merge "Remove injecting multi-user settings into settings itself" into main
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 75c6fbb..26386c5 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3389,16 +3389,6 @@
                 <action android:name="android.settings.USER_SETTINGS" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
-            <intent-filter>
-                <action android:name="com.android.settings.action.SETTINGS" />
-            </intent-filter>
-            <meta-data android:name="com.android.settings.order" android:value="-45"/>
-            <meta-data android:name="com.android.settings.category"
-                       android:value="com.android.settings.category.ia.system" />
-            <meta-data android:name="com.android.settings.summary_uri"
-                       android:value="content://com.android.settings.dashboard.SummaryProvider/user" />
-            <meta-data android:name="com.android.settings.icon"
-                       android:resource="@drawable/ic_settings_multiuser" />
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                        android:value="com.android.settings.users.UserSettings" />
             <meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
diff --git a/res/xml/system_dashboard_fragment.xml b/res/xml/system_dashboard_fragment.xml
index 1f5559f..54dc195 100644
--- a/res/xml/system_dashboard_fragment.xml
+++ b/res/xml/system_dashboard_fragment.xml
@@ -93,6 +93,14 @@
     </Preference>
 
     <Preference
+        android:key="system_multiuser"
+        android:title="@string/user_settings_title"
+        android:icon="@drawable/ic_settings_multiuser"
+        android:order="-45"
+        android:fragment="com.android.settings.users.UserSettings"
+        settings:controller="com.android.settings.users.MultiUserPreferenceController"/>
+
+    <Preference
         android:key="reset_dashboard"
         android:title="@string/reset_dashboard_title"
         android:icon="@drawable/ic_restore"
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 4c20231..3b0dd40 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -781,12 +781,6 @@
                 Utils.isBandwidthControlEnabled(), isAdmin)
                 || somethingChanged;
 
-        somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
-                        Settings.UserSettingsActivity.class.getName()),
-                UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
-                        && !Utils.isMonkeyRunning(), isAdmin)
-                || somethingChanged;
-
         final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)
                 && !Utils.isMonkeyRunning();
         somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
diff --git a/src/com/android/settings/dashboard/SummaryProvider.java b/src/com/android/settings/dashboard/SummaryProvider.java
index 6acc663..cd388b9 100644
--- a/src/com/android/settings/dashboard/SummaryProvider.java
+++ b/src/com/android/settings/dashboard/SummaryProvider.java
@@ -20,15 +20,10 @@
 
 import android.content.ContentProvider;
 import android.content.ContentValues;
-import android.content.Context;
-import android.content.pm.UserInfo;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.Bundle;
-import android.os.UserHandle;
-import android.os.UserManager;
 
-import com.android.settings.R;
 import com.android.settings.backup.BackupSettingsHelper;
 
 /** Provide preference summary for injected items. */
@@ -44,14 +39,6 @@
                 bundle.putString(META_DATA_PREFERENCE_SUMMARY,
                         new BackupSettingsHelper(getContext()).getSummary());
                 break;
-            case USER:
-                final Context context = getContext();
-                final UserInfo info = context.getSystemService(UserManager.class).getUserInfo(
-                        UserHandle.myUserId());
-                bundle.putString(META_DATA_PREFERENCE_SUMMARY,
-                        context.getString(R.string.users_summary,
-                                info.name));
-                break;
             default:
                 throw new IllegalArgumentException("Unknown Uri format: " + uri);
         }
diff --git a/src/com/android/settings/users/MultiUserPreferenceController.java b/src/com/android/settings/users/MultiUserPreferenceController.java
new file mode 100644
index 0000000..2eb57ec
--- /dev/null
+++ b/src/com/android/settings/users/MultiUserPreferenceController.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2023 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.users;
+
+import android.content.Context;
+import android.content.pm.UserInfo;
+import android.os.UserHandle;
+import android.os.UserManager;
+
+import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.core.BasePreferenceController;
+
+public class MultiUserPreferenceController extends BasePreferenceController {
+
+    public MultiUserPreferenceController(Context context, String preferenceKey) {
+        super(context, preferenceKey);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return (UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
+                && !Utils.isMonkeyRunning()) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+    }
+
+    @Override
+    public CharSequence getSummary() {
+        UserManager um = mContext.getSystemService(UserManager.class);
+        UserInfo info = um.getUserInfo(UserHandle.myUserId());
+        return mContext.getString(R.string.users_summary, info.name);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/users/MultiUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/users/MultiUserPreferenceControllerTest.java
new file mode 100644
index 0000000..fd73eab
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/users/MultiUserPreferenceControllerTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2023 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.users;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.testutils.shadow.ShadowUserManager;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {ShadowUserManager.class})
+public class MultiUserPreferenceControllerTest {
+
+    private Context mContext;
+    private ShadowUserManager mUserManager;
+    private MultiUserPreferenceController mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        mUserManager = ShadowUserManager.getShadow();
+        mController = new MultiUserPreferenceController(mContext, "test_key");
+    }
+
+    @After
+    public void tearDown() {
+        ShadowUserManager.reset();
+    }
+
+    @Test
+    public void getAvailabilityStatus_multiuserEnabled_shouldReturnAvailable() {
+        mUserManager.setSupportsMultipleUsers(true);
+
+        assertThat(mController.getAvailabilityStatus())
+                .isEqualTo(BasePreferenceController.AVAILABLE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_multiuserDisabled_shouldReturnNotAvailable() {
+        mUserManager.setSupportsMultipleUsers(false);
+
+        assertThat(mController.getAvailabilityStatus())
+                .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
+    }
+}