Skip to content

Commit

Permalink
Disable shutdown controls during supervision transition screen.
Browse files Browse the repository at this point in the history
When supervision transition screen is being displayed, we ask users not
to power off their devices, so we're disabling the shutdown button and
system tray.

Bug: 903851
Change-Id: I719c6a2ea53062a8fc220b3dbd9cb114a380ddcb
Reviewed-on: https://chromium-review.googlesource.com/c/1375670
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Bruno Santos <brunoad@google.com>
Cr-Commit-Position: refs/heads/master@{#616649}
  • Loading branch information
Bruno Santos authored and Commit Bot committed Dec 14, 2018
1 parent dd855e2 commit cf9d9cc
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ash/login/login_screen_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,13 @@ void LoginScreenController::SetAddUserButtonEnabled(bool enable) {
->SetAddUserButtonEnabled(enable);
}

void LoginScreenController::SetShutdownButtonEnabled(bool enable) {
Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
->shelf_widget()
->login_shelf_view()
->SetShutdownButtonEnabled(enable);
}

void LoginScreenController::LaunchKioskApp(const std::string& app_id) {
login_screen_client_->LaunchKioskApp(app_id);
}
Expand Down
1 change: 1 addition & 0 deletions ash/login/login_screen_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class ASH_EXPORT LoginScreenController : public mojom::LoginScreen,
void ShowKioskAppError(const std::string& message) override;
void NotifyOobeDialogState(mojom::OobeDialogState state) override;
void SetAddUserButtonEnabled(bool enable) override;
void SetShutdownButtonEnabled(bool enable) override;
void SetAllowLoginAsGuest(bool allow_guest) override;
void SetShowGuestButtonInOobe(bool show) override;
void FocusLoginShelf(bool reverse) override;
Expand Down
3 changes: 3 additions & 0 deletions ash/public/interfaces/login_screen.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ interface LoginScreen {
// Sets whether users can be added from the login screen.
SetAddUserButtonEnabled(bool enable);

// Sets whether shutdown button is enabled in the login screen.
SetShutdownButtonEnabled(bool enable);

// Sets if the guest button on the login shelf can be shown. Even if set to
// true the button may still not be visible.
SetAllowLoginAsGuest(bool allow_guest);
Expand Down
4 changes: 4 additions & 0 deletions ash/shelf/login_shelf_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ void LoginShelfView::SetAddUserButtonEnabled(bool enable_add_user) {
GetViewByID(kAddUser)->SetEnabled(enable_add_user);
}

void LoginShelfView::SetShutdownButtonEnabled(bool enable_shutdown_button) {
GetViewByID(kShutdown)->SetEnabled(enable_shutdown_button);
}

void LoginShelfView::OnLockScreenNoteStateChanged(
mojom::TrayActionState state) {
UpdateUi();
Expand Down
3 changes: 3 additions & 0 deletions ash/shelf/login_shelf_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class ASH_EXPORT LoginShelfView : public views::View,
// Sets whether users can be added from the login screen.
void SetAddUserButtonEnabled(bool enable_add_user);

// Sets whether shutdown button is enabled in the login screen.
void SetShutdownButtonEnabled(bool enable_shutdown_button);

// views::View:
const char* GetClassName() const override;
void OnFocus() override;
Expand Down
21 changes: 21 additions & 0 deletions ash/shelf/login_shelf_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -498,5 +498,26 @@ TEST_F(LoginShelfViewTest, ShouldUpdateUiAfterAddButtonStatusChange) {
EXPECT_TRUE(IsButtonEnabled(LoginShelfView::kAddUser));
}

TEST_F(LoginShelfViewTest, ShouldUpdateUiAfterShutdownButtonStatusChange) {
login_shelf_view_->SetAllowLoginAsGuest(true /*allow_guest*/);
NotifySessionStateChanged(SessionState::LOGIN_PRIMARY);
EXPECT_TRUE(ShowsShelfButtons({LoginShelfView::kShutdown,
LoginShelfView::kBrowseAsGuest,
LoginShelfView::kAddUser}));
EXPECT_TRUE(IsButtonEnabled(LoginShelfView::kShutdown));

login_shelf_view_->SetShutdownButtonEnabled(false /*enable_shutdown_button*/);
EXPECT_TRUE(ShowsShelfButtons({LoginShelfView::kShutdown,
LoginShelfView::kBrowseAsGuest,
LoginShelfView::kAddUser}));
EXPECT_FALSE(IsButtonEnabled(LoginShelfView::kShutdown));

login_shelf_view_->SetShutdownButtonEnabled(true /*enable_shutdown_button*/);
EXPECT_TRUE(ShowsShelfButtons({LoginShelfView::kShutdown,
LoginShelfView::kBrowseAsGuest,
LoginShelfView::kAddUser}));
EXPECT_TRUE(IsButtonEnabled(LoginShelfView::kShutdown));
}

} // namespace
} // namespace ash
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "chrome/browser/chromeos/login/screens/supervision_transition_screen.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/login_screen_client.h"
#include "chrome/browser/ui/ash/system_tray_client.h"
#include "chrome/grit/generated_resources.h"
#include "components/arc/arc_prefs.h"
#include "components/login/localized_values_builder.h"
Expand Down Expand Up @@ -90,6 +91,10 @@ void SupervisionTransitionScreenHandler::Show() {
&SupervisionTransitionScreenHandler::OnSupervisionTransitionFinished,
weak_factory_.GetWeakPtr()));

// Disable system tray, shutdown button and prevent login as guest when
// supervision transition screen is shown.
SystemTrayClient::Get()->SetPrimaryTrayEnabled(false);
LoginScreenClient::Get()->login_screen()->SetShutdownButtonEnabled(false);
LoginScreenClient::Get()->login_screen()->SetAllowLoginAsGuest(false);
LoginScreenClient::Get()->login_screen()->SetShowGuestButtonInOobe(false);

Expand All @@ -114,6 +119,9 @@ void SupervisionTransitionScreenHandler::Initialize() {

void SupervisionTransitionScreenHandler::OnSupervisionTransitionFailed() {
LOG(ERROR) << "Supervision transition failed; resetting ARC++ data.";
// Prevent ARC++ data removal below from triggering the success flow (since it
// will reset the supervision transition pref).
registrar_.RemoveAll();
arc::ArcSessionManager::Get()->RequestArcDataRemoval();
arc::ArcSessionManager::Get()->StopAndEnableArc();
if (screen_) {
Expand All @@ -123,6 +131,12 @@ void SupervisionTransitionScreenHandler::OnSupervisionTransitionFailed() {
}

void SupervisionTransitionScreenHandler::OnSupervisionTransitionFinished() {
// This method is called both when supervision transition succeeds (observing
// pref changes) and when it fails ("OK" button from error screen, see
// RegisterMessages()). Once this screen exits, user session will be started,
// so there's no need to re-enable shutdown button from login screen, only the
// system tray.
SystemTrayClient::Get()->SetPrimaryTrayEnabled(true);
if (screen_)
screen_->OnSupervisionTransitionFinished();
}
Expand Down

0 comments on commit cf9d9cc

Please sign in to comment.