Merge "Remove user switcher when multiple users is disabled"
This commit is contained in:
committed by
Android (Google) Code Review
commit
18cfa9abac
@@ -22,7 +22,6 @@ import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEX
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.ContentObserver;
|
||||
import android.graphics.PorterDuff.Mode;
|
||||
@@ -320,29 +319,13 @@ public class QSFooterImpl extends FrameLayout implements QSFooter,
|
||||
mSettingsContainer.findViewById(R.id.tuner_icon).setVisibility(
|
||||
TunerService.isTunerEnabled(mContext) ? View.VISIBLE : View.INVISIBLE);
|
||||
final boolean isDemo = UserManager.isDeviceInDemoMode(mContext);
|
||||
mMultiUserSwitch.setVisibility(showUserSwitcher(isDemo) ? View.VISIBLE : View.INVISIBLE);
|
||||
mMultiUserSwitch.setVisibility(showUserSwitcher() ? View.VISIBLE : View.INVISIBLE);
|
||||
mEditContainer.setVisibility(isDemo || !mExpanded ? View.INVISIBLE : View.VISIBLE);
|
||||
mSettingsButton.setVisibility(isDemo || !mExpanded ? View.INVISIBLE : View.VISIBLE);
|
||||
}
|
||||
|
||||
private boolean showUserSwitcher(boolean isDemo) {
|
||||
if (!mExpanded || isDemo || !UserManager.supportsMultipleUsers()) {
|
||||
return false;
|
||||
}
|
||||
UserManager userManager = UserManager.get(mContext);
|
||||
if (userManager.hasUserRestriction(UserManager.DISALLOW_USER_SWITCH)) {
|
||||
return false;
|
||||
}
|
||||
int switchableUserCount = 0;
|
||||
for (UserInfo user : userManager.getUsers(true)) {
|
||||
if (user.supportsSwitchToByUser()) {
|
||||
++switchableUserCount;
|
||||
if (switchableUserCount > 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return getResources().getBoolean(R.bool.qs_show_user_switcher_for_single_user);
|
||||
private boolean showUserSwitcher() {
|
||||
return mExpanded && mMultiUserSwitch.isMultiUserEnabled();
|
||||
}
|
||||
|
||||
private void updateListeners() {
|
||||
|
||||
@@ -187,9 +187,9 @@ public class KeyguardStatusBarView extends RelativeLayout
|
||||
}
|
||||
if (mKeyguardUserSwitcher == null) {
|
||||
// If we have no keyguard switcher, the screen width is under 600dp. In this case,
|
||||
// we don't show the multi-user avatar unless there is more than 1 user on the device.
|
||||
if (mUserSwitcherController != null
|
||||
&& mUserSwitcherController.getSwitchableUserCount() > 1) {
|
||||
// we only show the multi-user switch if it's enabled through UserManager as well as
|
||||
// by the user.
|
||||
if (mMultiUserSwitch.isMultiUserEnabled()) {
|
||||
mMultiUserSwitch.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mMultiUserSwitch.setVisibility(View.GONE);
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package com.android.systemui.statusbar.phone;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserManager;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
@@ -33,7 +33,6 @@ import com.android.systemui.Dependency;
|
||||
import com.android.systemui.Prefs;
|
||||
import com.android.systemui.Prefs.Key;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.plugins.ActivityStarter;
|
||||
import com.android.systemui.plugins.qs.DetailAdapter;
|
||||
import com.android.systemui.qs.QSPanel;
|
||||
import com.android.systemui.statusbar.policy.KeyguardUserSwitcher;
|
||||
@@ -95,6 +94,26 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
|
||||
registerListener();
|
||||
}
|
||||
|
||||
public boolean isMultiUserEnabled() {
|
||||
// Short-circuiting from UserManager. Needs to be extracted because of SystemUI boolean flag
|
||||
// qs_show_user_switcher_for_single_user
|
||||
|
||||
final boolean userSwitcherEnabled = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.USER_SWITCHER_ENABLED, 1) != 0;
|
||||
|
||||
if (!UserManager.supportsMultipleUsers()
|
||||
|| mUserManager.hasUserRestriction(UserManager.DISALLOW_USER_SWITCH)
|
||||
|| UserManager.isDeviceInDemoMode(mContext)
|
||||
|| !userSwitcherEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
|
||||
.getGuestUserDisabled(null);
|
||||
return mUserSwitcherController.getSwitchableUserCount() > 1 || guestEnabled
|
||||
|| mContext.getResources().getBoolean(R.bool.qs_show_user_switcher_for_single_user);
|
||||
}
|
||||
|
||||
private void registerListener() {
|
||||
if (mUserManager.isUserSwitcherEnabled() && mUserListener == null) {
|
||||
|
||||
@@ -118,29 +137,20 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mUserManager.isUserSwitcherEnabled()) {
|
||||
if (mKeyguardMode) {
|
||||
if (mKeyguardUserSwitcher != null) {
|
||||
mKeyguardUserSwitcher.show(true /* animate */);
|
||||
}
|
||||
} else if (mQsPanel != null && mUserSwitcherController != null) {
|
||||
View center = getChildCount() > 0 ? getChildAt(0) : this;
|
||||
|
||||
center.getLocationInWindow(mTmpInt2);
|
||||
mTmpInt2[0] += center.getWidth() / 2;
|
||||
mTmpInt2[1] += center.getHeight() / 2;
|
||||
|
||||
mQsPanel.showDetailAdapter(true,
|
||||
getUserDetailAdapter(),
|
||||
mTmpInt2);
|
||||
}
|
||||
} else {
|
||||
if (mQsPanel != null) {
|
||||
Intent intent = ContactsContract.QuickContact.composeQuickContactsIntent(
|
||||
getContext(), v, ContactsContract.Profile.CONTENT_URI,
|
||||
ContactsContract.QuickContact.MODE_LARGE, null);
|
||||
Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(intent, 0);
|
||||
if (mKeyguardMode) {
|
||||
if (mKeyguardUserSwitcher != null) {
|
||||
mKeyguardUserSwitcher.show(true /* animate */);
|
||||
}
|
||||
} else if (mQsPanel != null && mUserSwitcherController != null) {
|
||||
View center = getChildCount() > 0 ? getChildAt(0) : this;
|
||||
|
||||
center.getLocationInWindow(mTmpInt2);
|
||||
mTmpInt2[0] += center.getWidth() / 2;
|
||||
mTmpInt2[1] += center.getHeight() / 2;
|
||||
|
||||
mQsPanel.showDetailAdapter(true,
|
||||
getUserDetailAdapter(),
|
||||
mTmpInt2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -403,7 +403,7 @@ public class UserSwitcherController implements Dumpable {
|
||||
final int N = mUsers.size();
|
||||
for (int i = 0; i < N; ++i) {
|
||||
UserRecord record = mUsers.get(i);
|
||||
if (record.info != null && record.info.supportsSwitchTo()) {
|
||||
if (record.info != null && record.info.supportsSwitchToByUser()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user