Commit dd7ee1eb authored by Sarah Hu's avatar Sarah Hu Committed by Commit Bot

cros: Add debug UI for public account user in views login screen.

Bug: 853869
Change-Id: Ifa67aef8421b4169d8c34711df72293135ce7f8b
Reviewed-on: https://chromium-review.googlesource.com/1123764
Commit-Queue: Xiaoyin Hu <xiaoyinh@chromium.org>
Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575364}
parent 45c3d39c
...@@ -1267,7 +1267,10 @@ keyboard::KeyboardController* LockContentsView::GetKeyboardController() const { ...@@ -1267,7 +1267,10 @@ keyboard::KeyboardController* LockContentsView::GetKeyboardController() const {
return GetWidget() ? GetKeyboardControllerForWidget(GetWidget()) : nullptr; return GetWidget() ? GetKeyboardControllerForWidget(GetWidget()) : nullptr;
} }
void LockContentsView::OnPublicAccountTapped() { void LockContentsView::OnPublicAccountTapped(bool is_primary) {
// Set the public account user to be the active user.
SwapActiveAuthBetweenPrimaryAndSecondary(is_primary);
// Update expanded_view_ in case CurrentBigUserView has changed. // Update expanded_view_ in case CurrentBigUserView has changed.
// 1. It happens when the active big user is changed. For example both // 1. It happens when the active big user is changed. For example both
// primary and secondary big user are public account and user switches from // primary and secondary big user are public account and user switches from
...@@ -1299,8 +1302,9 @@ LoginBigUserView* LockContentsView::AllocateLoginBigUserView( ...@@ -1299,8 +1302,9 @@ LoginBigUserView* LockContentsView::AllocateLoginBigUserView(
LoginPublicAccountUserView::Callbacks public_account_callbacks; LoginPublicAccountUserView::Callbacks public_account_callbacks;
public_account_callbacks.on_tap = auth_user_callbacks.on_tap; public_account_callbacks.on_tap = auth_user_callbacks.on_tap;
public_account_callbacks.on_public_account_tapped = base::BindRepeating( public_account_callbacks.on_public_account_tapped =
&LockContentsView::OnPublicAccountTapped, base::Unretained(this)); base::BindRepeating(&LockContentsView::OnPublicAccountTapped,
base::Unretained(this), is_primary);
return new LoginBigUserView(user, auth_user_callbacks, return new LoginBigUserView(user, auth_user_callbacks,
public_account_callbacks); public_account_callbacks);
} }
...@@ -1358,6 +1362,8 @@ void LockContentsView::UpdateAuthForPublicAccount( ...@@ -1358,6 +1362,8 @@ void LockContentsView::UpdateAuthForPublicAccount(
opt_to_update->SetAuthEnabled(true /*enabled*/, animate); opt_to_update->SetAuthEnabled(true /*enabled*/, animate);
if (opt_to_hide) if (opt_to_hide)
opt_to_hide->SetAuthEnabled(false /*enabled*/, animate); opt_to_hide->SetAuthEnabled(false /*enabled*/, animate);
Layout();
} }
void LockContentsView::UpdateAuthForAuthUser(LoginAuthUserView* opt_to_update, void LockContentsView::UpdateAuthForAuthUser(LoginAuthUserView* opt_to_update,
......
...@@ -302,7 +302,7 @@ class ASH_EXPORT LockContentsView ...@@ -302,7 +302,7 @@ class ASH_EXPORT LockContentsView
keyboard::KeyboardController* GetKeyboardController() const; keyboard::KeyboardController* GetKeyboardController() const;
// Called when the public account is tapped. // Called when the public account is tapped.
void OnPublicAccountTapped(); void OnPublicAccountTapped(bool is_primary);
// Helper method to allocate a LoginBigUserView instance. // Helper method to allocate a LoginBigUserView instance.
LoginBigUserView* AllocateLoginBigUserView( LoginBigUserView* AllocateLoginBigUserView(
......
...@@ -54,6 +54,7 @@ enum { ...@@ -54,6 +54,7 @@ enum {
kPerUserForceOnlineSignIn, kPerUserForceOnlineSignIn,
kPerUserToggleAuthEnabled, kPerUserToggleAuthEnabled,
kPerUserUseDetachableBase, kPerUserUseDetachableBase,
kPerUserTogglePublicAccount,
}; };
} // namespace ButtonId } // namespace ButtonId
...@@ -62,6 +63,11 @@ constexpr const char* kDebugUserNames[] = { ...@@ -62,6 +63,11 @@ constexpr const char* kDebugUserNames[] = {
"Debbie Craig", "Stella Wong", "Stephanie Wade", "Debbie Craig", "Stella Wong", "Stephanie Wade",
}; };
constexpr const char* kDebugPublicAccountNames[] = {
"Seattle Public Library", "San Jose Public Library",
"Sunnyvale Public Library", "Mountain View Public Library",
};
constexpr const char* kDebugDetachableBases[] = {"Base A", "Base B", "Base C"}; constexpr const char* kDebugDetachableBases[] = {"Base A", "Base B", "Base C"};
constexpr const char kDebugOsVersion[] = constexpr const char kDebugOsVersion[] =
...@@ -72,17 +78,23 @@ constexpr const char kDebugBluetoothName[] = "Bluetooth adapter"; ...@@ -72,17 +78,23 @@ constexpr const char kDebugBluetoothName[] = "Bluetooth adapter";
constexpr const char kDebugKioskAppId[] = "asdf1234"; constexpr const char kDebugKioskAppId[] = "asdf1234";
constexpr const char kDebugKioskAppName[] = "Test App Name"; constexpr const char kDebugKioskAppName[] = "Test App Name";
constexpr const char kDebugDefaultLocaleCode[] = "en-GB";
constexpr const char kDebugDefaultLocaleTitle[] = "English";
constexpr const char kDebugEnterpriseDomain[] = "library.com";
// Additional state for a user that the debug UI needs to reference. // Additional state for a user that the debug UI needs to reference.
struct UserMetadata { struct UserMetadata {
explicit UserMetadata(const mojom::UserInfoPtr& user_info) explicit UserMetadata(const mojom::UserInfoPtr& user_info)
: account_id(user_info->account_id), : account_id(user_info->account_id),
display_name(user_info->display_name) {} display_name(user_info->display_name),
type(user_info->type) {}
AccountId account_id; AccountId account_id;
std::string display_name; std::string display_name;
bool enable_pin = false; bool enable_pin = false;
bool enable_click_to_unlock = false; bool enable_click_to_unlock = false;
bool enable_auth = true; bool enable_auth = true;
user_manager::UserType type = user_manager::USER_TYPE_REGULAR;
mojom::EasyUnlockIconId easy_unlock_id = mojom::EasyUnlockIconId::NONE; mojom::EasyUnlockIconId easy_unlock_id = mojom::EasyUnlockIconId::NONE;
}; };
...@@ -101,6 +113,48 @@ std::string DetachableBasePairingStatusToString( ...@@ -101,6 +113,48 @@ std::string DetachableBasePairingStatusToString(
return "Unknown"; return "Unknown";
} }
// Update the user data based on |type| and |user_index|.
mojom::LoginUserInfoPtr PopulateUserData(const mojom::LoginUserInfoPtr& user,
user_manager::UserType type,
int user_index) {
mojom::LoginUserInfoPtr result = user->Clone();
result->basic_user_info->type = type;
bool is_regular_user = type == user_manager::USER_TYPE_REGULAR;
// Set debug user names and email. Useful for the stub user, which does not
// have a name and email set.
result->basic_user_info->display_name =
is_regular_user
? kDebugUserNames[user_index % base::size(kDebugUserNames)]
: kDebugPublicAccountNames[user_index %
base::size(kDebugPublicAccountNames)];
result->basic_user_info->display_email =
result->basic_user_info->account_id.GetUserEmail();
if (is_regular_user) {
result->public_account_info.reset();
} else {
result->public_account_info = ash::mojom::PublicAccountInfo::New();
result->public_account_info->enterprise_domain = kDebugEnterpriseDomain;
result->public_account_info->default_locale = kDebugDefaultLocaleCode;
std::vector<ash::mojom::LocaleItemPtr> locales;
mojom::LocaleItemPtr locale_item = ash::mojom::LocaleItem::New();
locale_item->language_code = kDebugDefaultLocaleCode;
locale_item->title = kDebugDefaultLocaleTitle;
locales.push_back(std::move(locale_item));
result->public_account_info->available_locales = std::move(locales);
// Request keyboard layouts for the default locale.
Shell::Get()
->login_screen_controller()
->RequestPublicSessionKeyboardLayouts(
result->basic_user_info->account_id, kDebugDefaultLocaleCode);
}
return result;
}
} // namespace } // namespace
// Applies a series of user-defined transformations to a |LoginDataDispatcher| // Applies a series of user-defined transformations to a |LoginDataDispatcher|
...@@ -125,7 +179,10 @@ class LockDebugView::DebugDataDispatcherTransformer ...@@ -125,7 +179,10 @@ class LockDebugView::DebugDataDispatcherTransformer
LoginDataDispatcher* debug_dispatcher() { return &debug_dispatcher_; } LoginDataDispatcher* debug_dispatcher() { return &debug_dispatcher_; }
// Changes the number of displayed users to |count|. // Changes the number of displayed users to |count|.
void SetUserCount(int count) { void SetUserCount(int count) { NotifyUsers(BuildUserList(count)); }
// Create user list.
std::vector<mojom::LoginUserInfoPtr> BuildUserList(int count) {
DCHECK(!root_users_.empty()); DCHECK(!root_users_.empty());
count = std::max(count, 0); count = std::max(count, 0);
...@@ -146,15 +203,20 @@ class LockDebugView::DebugDataDispatcherTransformer ...@@ -146,15 +203,20 @@ class LockDebugView::DebugDataDispatcherTransformer
std::to_string(i)); std::to_string(i));
} }
// Set debug user names. Useful for the stub user, which does not have a // Setup user data based on the user type in debug_users_.
// name set. user_manager::UserType type = (i < debug_users_.size())
users[i]->basic_user_info->display_name = ? debug_users_[i].type
kDebugUserNames[i % base::size(kDebugUserNames)]; : users[i]->basic_user_info->type;
users[i] = PopulateUserData(users[i], type, i);
if (i >= debug_users_.size()) if (i >= debug_users_.size())
debug_users_.push_back(UserMetadata(users[i]->basic_user_info)); debug_users_.push_back(UserMetadata(users[i]->basic_user_info));
} }
return users;
}
void NotifyUsers(std::vector<mojom::LoginUserInfoPtr> users) {
// User notification resets PIN state. // User notification resets PIN state.
for (UserMetadata& user : debug_users_) for (UserMetadata& user : debug_users_)
user.enable_pin = false; user.enable_pin = false;
...@@ -256,6 +318,24 @@ class LockDebugView::DebugDataDispatcherTransformer ...@@ -256,6 +318,24 @@ class LockDebugView::DebugDataDispatcherTransformer
base::TimeDelta::FromHours(8)); base::TimeDelta::FromHours(8));
} }
// Convert user type to regular user or public account for the user at
// |user_index|.
void TogglePublicAccountForUserIndex(size_t user_index) {
DCHECK(user_index >= 0 && user_index < debug_users_.size());
UserMetadata& user = debug_users_[user_index];
user_manager::UserType new_type =
user.type == user_manager::USER_TYPE_REGULAR
? user_manager::USER_TYPE_PUBLIC_ACCOUNT
: user_manager::USER_TYPE_REGULAR;
user.type = new_type;
std::vector<mojom::LoginUserInfoPtr> users =
BuildUserList(debug_users_.size());
// Update display name and email in debug users.
debug_users_[user_index] = UserMetadata(users[user_index]->basic_user_info);
NotifyUsers(std::move(users));
}
void ToggleLockScreenNoteButton() { void ToggleLockScreenNoteButton() {
if (lock_screen_note_state_ == mojom::TrayActionState::kAvailable) { if (lock_screen_note_state_ == mojom::TrayActionState::kAvailable) {
lock_screen_note_state_ = mojom::TrayActionState::kNotAvailable; lock_screen_note_state_ = mojom::TrayActionState::kNotAvailable;
...@@ -758,6 +838,13 @@ void LockDebugView::ButtonPressed(views::Button* sender, ...@@ -758,6 +838,13 @@ void LockDebugView::ButtonPressed(views::Button* sender,
debug_detachable_base_model_->SetBaseLastUsedForUser( debug_detachable_base_model_->SetBaseLastUsedForUser(
debug_data_dispatcher_->GetAccountIdForUserIndex(sender->tag())); debug_data_dispatcher_->GetAccountIdForUserIndex(sender->tag()));
} }
// Convert this user to regular user or public account.
if (sender->id() == ButtonId::kPerUserTogglePublicAccount) {
debug_data_dispatcher_->TogglePublicAccountForUserIndex(sender->tag());
UpdatePerUserActionContainer();
Layout();
}
} }
void LockDebugView::UpdatePerUserActionContainer() { void LockDebugView::UpdatePerUserActionContainer() {
...@@ -793,6 +880,10 @@ void LockDebugView::UpdatePerUserActionContainer() { ...@@ -793,6 +880,10 @@ void LockDebugView::UpdatePerUserActionContainer() {
->set_tag(i); ->set_tag(i);
} }
AddButton("Toggle Public Account", ButtonId::kPerUserTogglePublicAccount,
row)
->set_tag(i);
per_user_action_view_container_->AddChildView(row); per_user_action_view_container_->AddChildView(row);
} }
} }
......
...@@ -332,7 +332,7 @@ class RightPaneView : public NonAccessibleView, ...@@ -332,7 +332,7 @@ class RightPaneView : public NonAccessibleView,
current_user_->basic_user_info->account_id, current_user_->basic_user_info->account_id,
selected_language_item_.value, selected_keyboard_item_.value); selected_language_item_.value, selected_keyboard_item_.value);
} else if (sender == language_selection_) { } else if (sender == language_selection_) {
if (!language_menu_->IsVisible()) { if (!language_menu_->IsVisible() && !language_items_.empty()) {
LoginMenuView* view = new LoginMenuView( LoginMenuView* view = new LoginMenuView(
language_items_, language_selection_ /*anchor_view*/, language_items_, language_selection_ /*anchor_view*/,
base::BindRepeating(&RightPaneView::OnLanguageSelected, base::BindRepeating(&RightPaneView::OnLanguageSelected,
...@@ -343,7 +343,7 @@ class RightPaneView : public NonAccessibleView, ...@@ -343,7 +343,7 @@ class RightPaneView : public NonAccessibleView,
language_menu_->Close(); language_menu_->Close();
} }
} else if (sender == keyboard_selection_) { } else if (sender == keyboard_selection_) {
if (!keyboard_menu_->IsVisible()) { if (!keyboard_menu_->IsVisible() && !keyboard_items_.empty()) {
LoginMenuView* view = new LoginMenuView( LoginMenuView* view = new LoginMenuView(
keyboard_items_, keyboard_selection_ /*anchor_view*/, keyboard_items_, keyboard_selection_ /*anchor_view*/,
base::BindRepeating(&RightPaneView::OnKeyboardSelected, base::BindRepeating(&RightPaneView::OnKeyboardSelected,
......
...@@ -113,6 +113,8 @@ void LoginPublicAccountUserView::SetAuthEnabled(bool enabled, bool animate) { ...@@ -113,6 +113,8 @@ void LoginPublicAccountUserView::SetAuthEnabled(bool enabled, bool animate) {
user_view_->SetTapEnabled(!enabled); user_view_->SetTapEnabled(!enabled);
if (enabled) if (enabled)
arrow_button_->RequestFocus(); arrow_button_->RequestFocus();
PreferredSizeChanged();
} }
void LoginPublicAccountUserView::UpdateForUser( void LoginPublicAccountUserView::UpdateForUser(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment