Remove injecting multi-user settings into settings itself
- It can improve performance because we use less injected item Bug: 242152448 Test: robotest Change-Id: I892e1ac9c3f8297c489fc1fec934e9f5f2e2f5e9
This commit is contained in:
@@ -3389,16 +3389,6 @@
|
|||||||
<action android:name="android.settings.USER_SETTINGS" />
|
<action android:name="android.settings.USER_SETTINGS" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</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"
|
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||||
android:value="com.android.settings.users.UserSettings" />
|
android:value="com.android.settings.users.UserSettings" />
|
||||||
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
|
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
|
||||||
|
@@ -92,6 +92,14 @@
|
|||||||
<intent android:action="android.settings.SYSTEM_UPDATE_SETTINGS"/>
|
<intent android:action="android.settings.SYSTEM_UPDATE_SETTINGS"/>
|
||||||
</Preference>
|
</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
|
<Preference
|
||||||
android:key="reset_dashboard"
|
android:key="reset_dashboard"
|
||||||
android:title="@string/reset_dashboard_title"
|
android:title="@string/reset_dashboard_title"
|
||||||
|
@@ -781,12 +781,6 @@ public class SettingsActivity extends SettingsBaseActivity
|
|||||||
Utils.isBandwidthControlEnabled(), isAdmin)
|
Utils.isBandwidthControlEnabled(), isAdmin)
|
||||||
|| somethingChanged;
|
|| 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)
|
final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)
|
||||||
&& !Utils.isMonkeyRunning();
|
&& !Utils.isMonkeyRunning();
|
||||||
somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
|
somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
|
||||||
|
@@ -20,15 +20,10 @@ import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SUMM
|
|||||||
|
|
||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.UserInfo;
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.os.UserManager;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.backup.BackupSettingsHelper;
|
import com.android.settings.backup.BackupSettingsHelper;
|
||||||
|
|
||||||
/** Provide preference summary for injected items. */
|
/** Provide preference summary for injected items. */
|
||||||
@@ -44,14 +39,6 @@ public class SummaryProvider extends ContentProvider {
|
|||||||
bundle.putString(META_DATA_PREFERENCE_SUMMARY,
|
bundle.putString(META_DATA_PREFERENCE_SUMMARY,
|
||||||
new BackupSettingsHelper(getContext()).getSummary());
|
new BackupSettingsHelper(getContext()).getSummary());
|
||||||
break;
|
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:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown Uri format: " + uri);
|
throw new IllegalArgumentException("Unknown Uri format: " + uri);
|
||||||
}
|
}
|
||||||
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user