The name "Allow multiple users" is too ambiguous. It sounds like by toggling it off, the feature is completely disabled. In fact, it only hides user switcher. In conjunction with hiding other users from the list, it makes it appear as all the users get deleted when the toggle is off. On the contrary, users might be running in background when the toggle is off. After this change, the new name better represents the intention behind this toggle, as well as makes the UI more intuitive. The users are not being hidden anymore. But switching preference gets disabled. Since the toggle can only be enabled or disabled by owner (after this refactoring), it means that Owner has full control over multiuser settings and is able to perform actions on users without having to enable the toggle. Bug: 336762423 Test: atest UserSettingsTest && atest UserDetailsSettingsTest Flag: android.multiuser.new_multiuser_settings_ux Change-Id: Id9d507039b58d3df66fe78710409716fd4816890
84 lines
2.9 KiB
Java
84 lines
2.9 KiB
Java
/*
|
|
* Copyright (C) 2022 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.PackageManager;
|
|
import android.os.Bundle;
|
|
import android.os.UserManager;
|
|
|
|
import androidx.preference.Preference;
|
|
|
|
import com.android.settings.R;
|
|
import com.android.settings.core.TogglePreferenceController;
|
|
|
|
/**
|
|
* Controls the preference on the user settings screen which determines whether the guest user
|
|
* should have access to telephony or not.
|
|
*/
|
|
public class GuestTelephonyPreferenceController extends TogglePreferenceController {
|
|
|
|
private final UserManager mUserManager;
|
|
private final UserCapabilities mUserCaps;
|
|
|
|
public GuestTelephonyPreferenceController(Context context, String preferenceKey) {
|
|
super(context, preferenceKey);
|
|
mUserManager = context.getSystemService(UserManager.class);
|
|
mUserCaps = UserCapabilities.create(context);
|
|
}
|
|
|
|
@Override
|
|
public int getAvailabilityStatus() {
|
|
if (!mUserCaps.isAdmin() || !mUserCaps.mCanAddGuest) {
|
|
return DISABLED_FOR_USER;
|
|
} else if (android.multiuser.Flags.newMultiuserSettingsUx()) {
|
|
return AVAILABLE;
|
|
} else {
|
|
return mUserCaps.mUserSwitcherEnabled ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean isChecked() {
|
|
return !mUserManager.getDefaultGuestRestrictions()
|
|
.getBoolean(UserManager.DISALLOW_OUTGOING_CALLS, false);
|
|
}
|
|
|
|
@Override
|
|
public boolean setChecked(boolean isChecked) {
|
|
Bundle guestRestrictions = mUserManager.getDefaultGuestRestrictions();
|
|
guestRestrictions.putBoolean(UserManager.DISALLOW_SMS, true);
|
|
guestRestrictions.putBoolean(UserManager.DISALLOW_OUTGOING_CALLS, !isChecked);
|
|
mUserManager.setDefaultGuestRestrictions(guestRestrictions);
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int getSliceHighlightMenuRes() {
|
|
return R.string.menu_key_system;
|
|
}
|
|
|
|
@Override
|
|
public void updateState(Preference preference) {
|
|
super.updateState(preference);
|
|
mUserCaps.updateAddUserCapabilities(mContext);
|
|
preference.setVisible(isAvailable()
|
|
&& mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)
|
|
&& !UserManager.isHeadlessSystemUserMode());
|
|
}
|
|
}
|