0

focus-mode: Hide focus mode pod in the lock screen

This CL will make it so that the focus mode quick settings pod is hidden
when the user is in the lock screen.

Also includes some minor refactoring to remove all settings button code
since we will only show this in the new quick settings UI.

BUG=b/297919886
TEST=added FocusModeFeaturePodControllerTest*

Change-Id: Idf016938ad7a20043934e25b2445bf85b3c7fc3f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4817698
Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
Commit-Queue: Richard Chui <richui@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1193880}
This commit is contained in:
Richard Chui
2023-09-08 01:33:01 +00:00
committed by Chromium LUCI CQ
parent 1c72951e6a
commit 4f10f09b1e
6 changed files with 129 additions and 35 deletions

@ -3418,6 +3418,7 @@ test("ash_unittests") {
"system/firmware_update/firmware_update_notification_controller_unittest.cc",
"system/focus_mode/focus_mode_controller_unittest.cc",
"system/focus_mode/focus_mode_detailed_view_unittest.cc",
"system/focus_mode/focus_mode_feature_pod_controller_unittest.cc",
"system/focus_mode/focus_mode_tray_unittest.cc",
"system/geolocation/geolocation_controller_test_util.cc",
"system/geolocation/geolocation_controller_test_util.h",

@ -36,7 +36,7 @@ class ASH_EXPORT FocusModeDetailedViewController
// This is the view being controlled, which contains all the Focus Mode
// settings and controls.
raw_ptr<FocusModeDetailedView> detailed_view_ = nullptr;
raw_ptr<FocusModeDetailedView, DanglingUntriaged> detailed_view_ = nullptr;
};
} // namespace ash

@ -24,6 +24,8 @@ namespace ash {
FocusModeFeaturePodController::FocusModeFeaturePodController(
UnifiedSystemTrayController* tray_controller)
: tray_controller_(tray_controller) {
CHECK(features::IsQsRevampEnabled());
CHECK(features::IsFocusModeEnabled());
FocusModeController::Get()->AddObserver(this);
}
@ -32,27 +34,24 @@ FocusModeFeaturePodController::~FocusModeFeaturePodController() {
}
FeaturePodButton* FocusModeFeaturePodController::CreateButton() {
CHECK(!button_);
CHECK(!features::IsQsRevampEnabled());
std::unique_ptr<FeaturePodButton> button =
std::make_unique<FeaturePodButton>(/*controller=*/this);
button_ = button.get();
button_->ShowDetailedViewArrow();
button_->SetVectorIcon(kCaptureModeIcon);
button_->SetLabel(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_FOCUS_MODE));
button_->icon_button()->SetTooltipText(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_FOCUS_MODE));
OnFocusModeChanged(FocusModeController::Get()->in_focus_session());
return button.release();
NOTREACHED();
return nullptr;
}
std::unique_ptr<FeatureTile> FocusModeFeaturePodController::CreateTile(
bool compact) {
CHECK(features::IsQsRevampEnabled());
auto tile = std::make_unique<FeatureTile>(
base::BindRepeating(&FocusModeFeaturePodController::OnLabelPressed,
weak_factory_.GetWeakPtr()));
tile_ = tile.get();
const bool target_visibility =
!Shell::Get()->session_controller()->IsUserSessionBlocked();
tile_->SetVisible(target_visibility);
if (target_visibility) {
TrackVisibilityUMA();
}
tile_->SetIconClickable(true);
tile_->SetIconClickCallback(
base::BindRepeating(&FocusModeFeaturePodController::OnIconPressed,
@ -82,14 +81,8 @@ void FocusModeFeaturePodController::OnLabelPressed() {
}
void FocusModeFeaturePodController::OnFocusModeChanged(bool in_focus_session) {
if (features::IsQsRevampEnabled()) {
CHECK(tile_);
tile_->SetToggled(in_focus_session);
} else {
CHECK(button_);
button_->SetToggled(in_focus_session);
}
CHECK(tile_);
tile_->SetToggled(in_focus_session);
UpdateUI();
}
@ -100,6 +93,7 @@ void FocusModeFeaturePodController::OnTimerTick() {
void FocusModeFeaturePodController::UpdateUI() {
auto* controller = FocusModeController::Get();
CHECK(controller);
CHECK(tile_);
std::u16string sub_text;
if (controller->in_focus_session()) {
@ -117,10 +111,6 @@ void FocusModeFeaturePodController::UpdateUI() {
base::FormatNumber(controller->session_duration().InMinutes()));
}
if (features::IsQsRevampEnabled()) {
tile_->SetSubLabel(sub_text);
} else {
button_->SetSubLabel(sub_text);
}
tile_->SetSubLabel(sub_text);
}
} // namespace ash

@ -44,11 +44,11 @@ class ASH_EXPORT FocusModeFeaturePodController
private:
void UpdateUI();
const raw_ptr<UnifiedSystemTrayController, ExperimentalAsh> tray_controller_;
raw_ptr<FeaturePodButton, ExperimentalAsh> button_ =
nullptr; // Owned by views hierarchy.
raw_ptr<FeatureTile, ExperimentalAsh> tile_ =
nullptr; // Owned by views hierarchy.
// Owned by views hierarchy.
raw_ptr<FeatureTile, DanglingUntriaged> tile_ = nullptr;
const raw_ptr<UnifiedSystemTrayController, DanglingUntriaged>
tray_controller_;
base::WeakPtrFactory<FocusModeFeaturePodController> weak_factory_{this};
};

@ -0,0 +1,106 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/focus_mode/focus_mode_feature_pod_controller.h"
#include <memory>
#include "ash/constants/ash_features.h"
#include "ash/system/focus_mode/focus_mode_controller.h"
#include "ash/system/focus_mode/focus_mode_detailed_view.h"
#include "ash/system/unified/feature_tile.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "ash/test/ash_test_base.h"
#include "base/test/scoped_feature_list.h"
#include "ui/views/view_utils.h"
namespace ash {
class FocusModeFeaturePodControllerTest : public AshTestBase {
public:
FocusModeFeaturePodControllerTest() {
feature_list_.InitWithFeatures(
/*enabled_features=*/{features::kFocusMode, features::kQsRevamp},
/*disabled_features=*/{});
}
~FocusModeFeaturePodControllerTest() override = default;
// AshTestBase:
void SetUp() override {
AshTestBase::SetUp();
CreateFakeFocusModeTile();
}
void TearDown() override {
controller_.reset();
tile_.reset();
AshTestBase::TearDown();
}
void CreateFakeFocusModeTile() {
// We need to show the bubble in order to get the
// `unified_system_tray_controller`.
GetPrimaryUnifiedSystemTray()->ShowBubble();
controller_ = std::make_unique<FocusModeFeaturePodController>(
GetPrimaryUnifiedSystemTray()
->bubble()
->unified_system_tray_controller());
tile_ = controller_->CreateTile();
}
void ExpectFocusModeDetailedViewShown() {
TrayDetailedView* detailed_view = GetPrimaryUnifiedSystemTray()
->bubble()
->quick_settings_view()
->GetDetailedViewForTest();
ASSERT_TRUE(detailed_view);
EXPECT_TRUE(views::IsViewClass<FocusModeDetailedView>(detailed_view));
}
protected:
base::test::ScopedFeatureList feature_list_;
std::unique_ptr<FocusModeFeaturePodController> controller_;
std::unique_ptr<FeatureTile> tile_;
};
// Tests that the tile is normally visible, and is not visible when the screen
// is locked.
TEST_F(FocusModeFeaturePodControllerTest, TileVisibility) {
// The tile is visible in an active session.
EXPECT_TRUE(tile_->GetVisible());
// Locking the screen closes the system tray bubble, so we need to create the
// tile again.
GetSessionControllerClient()->LockScreen();
CreateFakeFocusModeTile();
// Verify that the tile should not be visible at the lock screen.
EXPECT_FALSE(tile_->GetVisible());
}
// Tests that pressing the icon works and toggles a Focus Mode Session.
TEST_F(FocusModeFeaturePodControllerTest, PressIconTogglesFocusModeSession) {
auto* controller = FocusModeController::Get();
EXPECT_FALSE(controller->in_focus_session());
EXPECT_TRUE(tile_->GetVisible());
EXPECT_TRUE(tile_->GetEnabled());
controller_->OnIconPressed();
EXPECT_TRUE(tile_->IsToggled());
EXPECT_TRUE(controller->in_focus_session());
controller_->OnIconPressed();
EXPECT_FALSE(tile_->IsToggled());
EXPECT_FALSE(controller->in_focus_session());
}
// Tests that pressing the label works and shows the `FocusModeDetailedView`.
TEST_F(FocusModeFeaturePodControllerTest, PressLabelEntersFocusPanel) {
controller_->OnLabelPressed();
ExpectFocusModeDetailedViewShown();
}
} // namespace ash

@ -702,9 +702,6 @@ void UnifiedSystemTrayController::InitFeaturePods() {
AddFeaturePodItem(std::make_unique<NetworkFeaturePodController>(this));
AddFeaturePodItem(std::make_unique<BluetoothFeaturePodController>(this));
AddFeaturePodItem(std::make_unique<AccessibilityFeaturePodController>(this));
if (base::FeatureList::IsEnabled(features::kFocusMode)) {
AddFeaturePodItem(std::make_unique<FocusModeFeaturePodController>(this));
}
AddFeaturePodItem(std::make_unique<QuietModeFeaturePodController>(this));
AddFeaturePodItem(std::make_unique<RotationLockFeaturePodController>());
AddFeaturePodItem(std::make_unique<PrivacyScreenFeaturePodController>());