Commit 1c24c38c authored by Mia Bergeron's avatar Mia Bergeron Committed by Commit Bot

Only show lock screen media controls if active media

The lock screen media controls should only be displayed if there is an
active media session. This is done by making
LockScreenMediaControlsView a MediaControllerObserver.

Bug: 965567
Change-Id: I2106bc265e233e6c96fbb86b22469b91d9ba6a3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1665551Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Commit-Queue: Mia Bergeron <miaber@google.com>
Cr-Commit-Position: refs/heads/master@{#671451}
parent 189b3802
......@@ -26,6 +26,7 @@
#include "ash/login/ui/parent_access_view.h"
#include "ash/login/ui/scrollable_users_list_view.h"
#include "ash/login/ui/views_utils.h"
#include "ash/media/media_controller_impl.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/ash_switches.h"
#include "ash/shelf/shelf.h"
......@@ -322,7 +323,7 @@ ScrollableUsersListView* LockContentsView::TestApi::users_list() const {
LockScreenMediaControlsView* LockContentsView::TestApi::media_controls_view()
const {
return view_->media_controls_view_;
return view_->media_controls_view_.get();
}
views::View* LockContentsView::TestApi::note_action() const {
......@@ -626,7 +627,7 @@ void LockContentsView::OnUsersChanged(const std::vector<LoginUserInfo>& users) {
primary_big_view_ = nullptr;
opt_secondary_big_view_ = nullptr;
users_list_ = nullptr;
media_controls_view_ = nullptr;
media_controls_view_.reset();
layout_actions_.clear();
// Removing child views can change focus, which may result in LockContentsView
// getting focused. Make sure to clear internal references before that happens
......@@ -1207,16 +1208,51 @@ void LockContentsView::SetLowDensitySpacing(views::View* spacing_middle,
std::min(available_width, desired_width));
}
bool LockContentsView::AreMediaControlsEnabled() const {
return Shell::Get()->media_controller()->AreLockScreenMediaKeysEnabled() &&
base::FeatureList::IsEnabled(features::kLockScreenMediaControls) &&
screen_type_ == LockScreen::ScreenType::kLock &&
!expanded_view_->GetVisible();
}
void LockContentsView::HideMediaControlsLayout() {
main_view_->RemoveChildView(media_controls_view_->GetMiddleSpacingView());
main_view_->RemoveChildView(media_controls_view_.get());
// Don't allow media keys to be used on lock screen since controls are hidden.
Shell::Get()->media_controller()->SetMediaControlsDismissed(true);
Layout();
}
void LockContentsView::CreateMediaControlsLayout() {
// |media_controls_view_| should not be attached to a parent.
DCHECK(!media_controls_view_->parent());
// Space between primary user and media controls.
main_view_->AddChildView(media_controls_view_->GetMiddleSpacingView());
// Media controls view.
main_view_->AddChildView(media_controls_view_.get());
// Set |spacing_middle|.
AddDisplayLayoutAction(base::BindRepeating(
&LockContentsView::SetLowDensitySpacing, base::Unretained(this),
media_controls_view_->GetMiddleSpacingView(), media_controls_view_.get(),
kDistanceBetweenAuthUserAndMediaControlsLandscapeDp,
kDistanceBetweenAuthUserAndMediaControlsPortraitDp));
}
void LockContentsView::CreateLowDensityLayout(
const std::vector<LoginUserInfo>& users) {
DCHECK_LE(users.size(), 2u);
main_view_->AddChildView(primary_big_view_);
// If the lock screen media controls view should be shown.
const bool media_controls_enabled =
LockScreenMediaControlsView::AreMediaControlsEnabled(screen_type_,
expanded_view_);
// Build media controls view.
media_controls_view_ = std::make_unique<LockScreenMediaControlsView>(
Shell::Get()->connector(), this);
media_controls_view_->set_owned_by_client();
if (users.size() > 1) {
// Space between primary user and secondary user.
......@@ -1234,21 +1270,6 @@ void LockContentsView::CreateLowDensityLayout(
spacing_middle, opt_secondary_big_view_,
kLowDensityDistanceBetweenUsersInLandscapeDp,
kLowDensityDistanceBetweenUsersInPortraitDp));
} else if (media_controls_enabled) {
// Space between primary user and media controls.
auto* spacing_middle = new NonAccessibleView();
main_view_->AddChildView(spacing_middle);
// Build media controls view.
media_controls_view_ = new LockScreenMediaControlsView();
main_view_->AddChildView(media_controls_view_);
// Set |spacing_middle|.
AddDisplayLayoutAction(base::BindRepeating(
&LockContentsView::SetLowDensitySpacing, base::Unretained(this),
spacing_middle, media_controls_view_,
kDistanceBetweenAuthUserAndMediaControlsLandscapeDp,
kDistanceBetweenAuthUserAndMediaControlsPortraitDp));
}
}
......
......@@ -199,6 +199,11 @@ class ASH_EXPORT LockContentsView
void ShowAuthErrorMessageForDebug(int unlock_attempt);
// Called by LockScreenMediaControlsView.
void CreateMediaControlsLayout();
void HideMediaControlsLayout();
bool AreMediaControlsEnabled() const;
private:
class UserState {
public:
......@@ -355,7 +360,7 @@ class ASH_EXPORT LockContentsView
ScrollableUsersListView* users_list_ = nullptr;
// View for media controls that appear on the lock screen if user enabled.
LockScreenMediaControlsView* media_controls_view_ = nullptr;
std::unique_ptr<LockScreenMediaControlsView> media_controls_view_;
// View that contains the note action button and the system info labels,
// placed on the top right corner of the screen without affecting layout of
......
......@@ -15,6 +15,7 @@
#include "ash/login/ui/arrow_button_view.h"
#include "ash/login/ui/fake_login_detachable_base_model.h"
#include "ash/login/ui/lock_screen.h"
#include "ash/login/ui/lock_screen_media_controls_view.h"
#include "ash/login/ui/login_auth_user_view.h"
#include "ash/login/ui/login_big_user_view.h"
#include "ash/login/ui/login_display_style.h"
......@@ -41,9 +42,11 @@
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/timer/mock_timer.h"
#include "chromeos/dbus/power/fake_power_manager_client.h"
#include "chromeos/dbus/power_manager/suspend.pb.h"
#include "components/prefs/pref_service.h"
#include "services/media_session/public/mojom/media_session.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/test/display_manager_test_api.h"
......@@ -76,6 +79,18 @@ void PressAndReleasePowerButton() {
PowerButtonController::kIgnoreRepeatedButtonUpDelay, false /*down*/);
}
void SimulateMediaSessionInfoChanged(
LockScreenMediaControlsView* media_controls,
media_session::mojom::MediaPlaybackState playback_state) {
// Create media session information.
media_session::mojom::MediaSessionInfoPtr session_info(
media_session::mojom::MediaSessionInfo::New());
session_info->playback_state = playback_state;
// Simulate media session information change.
media_controls->MediaSessionInfoChanged(std::move(session_info));
}
} // namespace
using LockContentsViewUnitTest = LoginTestBase;
......@@ -2393,8 +2408,7 @@ TEST_F(LockContentsViewUnitTest, LoginNotReactingOnEventsWithOobeDialogShown) {
list_user_view->current_user().basic_user_info.account_id);
}
TEST_F(LockContentsViewUnitTest,
LockScreenMediaControlsShownIfFeaturesEnabled) {
TEST_F(LockContentsViewUnitTest, LockScreenMediaControlsShownIfMediaPlaying) {
// Enable media controls.
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures(
......@@ -2409,15 +2423,61 @@ TEST_F(LockContentsViewUnitTest,
std::unique_ptr<views::Widget> widget = CreateWidgetWithContent(contents);
LockContentsView::TestApi lock_contents(contents);
// Simulate playing media session.
SimulateMediaSessionInfoChanged(
lock_contents.media_controls_view(),
media_session::mojom::MediaPlaybackState::kPlaying);
// Verify media controls are shown.
EXPECT_TRUE(lock_contents.media_controls_view());
EXPECT_TRUE(lock_contents.media_controls_view()->IsDrawn());
}
TEST_F(LockContentsViewUnitTest, LockScreenMediaControlsHiddenAfterDelay) {
// Enable media controls.
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures(
{features::kLockScreenMediaKeys, features::kLockScreenMediaControls}, {});
// Build lock screen with 1 user.
auto* contents = new LockContentsView(
mojom::TrayActionState::kNotAvailable, LockScreen::ScreenType::kLock,
DataDispatcher(),
std::make_unique<FakeLoginDetachableBaseModel>(DataDispatcher()));
SetUserCount(1);
std::unique_ptr<views::Widget> widget = CreateWidgetWithContent(contents);
LockContentsView::TestApi lock_contents(contents);
// Test timer
auto mock_timer_unique = std::make_unique<base::MockOneShotTimer>();
base::MockOneShotTimer* mock_timer = mock_timer_unique.get();
lock_contents.media_controls_view()->set_timer_for_testing(
std::move(mock_timer_unique));
// Simulate playing media session.
SimulateMediaSessionInfoChanged(
lock_contents.media_controls_view(),
media_session::mojom::MediaPlaybackState::kPlaying);
// Simulate media session stopping and delay.
lock_contents.media_controls_view()->MediaSessionInfoChanged(nullptr);
mock_timer->Fire();
base::RunLoop().RunUntilIdle();
// Simulate playing media session.
SimulateMediaSessionInfoChanged(
lock_contents.media_controls_view(),
media_session::mojom::MediaPlaybackState::kPlaying);
// Verify media controls are hidden.
EXPECT_FALSE(lock_contents.media_controls_view()->IsDrawn());
}
TEST_F(LockContentsViewUnitTest,
LockScreenMediaControlsHiddenIfFeaturesDisabled) {
// Disable media controls.
MediaControlsHiddenIfScreenLockedWhileMediaPaused) {
// Enable media controls.
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures({}, {features::kLockScreenMediaControls});
feature_list.InitWithFeatures(
{features::kLockScreenMediaKeys, features::kLockScreenMediaControls}, {});
// Build lock screen with 1 user.
auto* contents = new LockContentsView(
......@@ -2428,8 +2488,96 @@ TEST_F(LockContentsViewUnitTest,
std::unique_ptr<views::Widget> widget = CreateWidgetWithContent(contents);
LockContentsView::TestApi lock_contents(contents);
// Simulate paused media session.
SimulateMediaSessionInfoChanged(
lock_contents.media_controls_view(),
media_session::mojom::MediaPlaybackState::kPaused);
// Verify media controls are hidden.
EXPECT_EQ(nullptr, lock_contents.media_controls_view());
EXPECT_FALSE(lock_contents.media_controls_view()->IsDrawn());
}
TEST_F(LockContentsViewUnitTest, KeepMediaControlsShownWithinDelay) {
// Enable media controls.
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures(
{features::kLockScreenMediaKeys, features::kLockScreenMediaControls}, {});
// Build lock screen with 1 user.
auto* contents = new LockContentsView(
mojom::TrayActionState::kNotAvailable, LockScreen::ScreenType::kLock,
DataDispatcher(),
std::make_unique<FakeLoginDetachableBaseModel>(DataDispatcher()));
SetUserCount(1);
std::unique_ptr<views::Widget> widget = CreateWidgetWithContent(contents);
LockContentsView::TestApi lock_contents(contents);
// Simulate playing media session.
SimulateMediaSessionInfoChanged(
lock_contents.media_controls_view(),
media_session::mojom::MediaPlaybackState::kPlaying);
// Simulate media session stopping.
lock_contents.media_controls_view()->MediaSessionInfoChanged(nullptr);
// Simulate playing media session.
SimulateMediaSessionInfoChanged(
lock_contents.media_controls_view(),
media_session::mojom::MediaPlaybackState::kPlaying);
// Verify media controls are shown.
EXPECT_TRUE(lock_contents.media_controls_view()->IsDrawn());
}
TEST_F(LockContentsViewUnitTest, LockScreenMediaControlsHiddenNoMedia) {
// Enable media controls.
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures(
{features::kLockScreenMediaKeys, features::kLockScreenMediaControls}, {});
// Build lock screen with 1 user.
auto* contents = new LockContentsView(
mojom::TrayActionState::kNotAvailable, LockScreen::ScreenType::kLock,
DataDispatcher(),
std::make_unique<FakeLoginDetachableBaseModel>(DataDispatcher()));
SetUserCount(1);
std::unique_ptr<views::Widget> widget = CreateWidgetWithContent(contents);
LockContentsView::TestApi lock_contents(contents);
// Simulate no media session on lock screen.
lock_contents.media_controls_view()->MediaSessionInfoChanged(nullptr);
// Verify media controls are hidden.
EXPECT_FALSE(lock_contents.media_controls_view()->IsDrawn());
}
TEST_F(LockContentsViewUnitTest, ShowMediaControlsIfPausedAndAlreadyShowing) {
// Enable media controls.
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures(
{features::kLockScreenMediaKeys, features::kLockScreenMediaControls}, {});
// Build lock screen with 1 user.
auto* contents = new LockContentsView(
mojom::TrayActionState::kNotAvailable, LockScreen::ScreenType::kLock,
DataDispatcher(),
std::make_unique<FakeLoginDetachableBaseModel>(DataDispatcher()));
SetUserCount(1);
std::unique_ptr<views::Widget> widget = CreateWidgetWithContent(contents);
LockContentsView::TestApi lock_contents(contents);
// Simulate playing media session.
SimulateMediaSessionInfoChanged(
lock_contents.media_controls_view(),
media_session::mojom::MediaPlaybackState::kPlaying);
// Simulate media session paused.
SimulateMediaSessionInfoChanged(
lock_contents.media_controls_view(),
media_session::mojom::MediaPlaybackState::kPaused);
// Verify media controls are shown.
EXPECT_TRUE(lock_contents.media_controls_view()->IsDrawn());
}
TEST_F(LockContentsViewUnitTest,
......@@ -2453,8 +2601,13 @@ TEST_F(LockContentsViewUnitTest,
std::unique_ptr<views::Widget> widget = CreateWidgetWithContent(contents);
LockContentsView::TestApi lock_contents(contents);
// Simulate active and playing media session.
SimulateMediaSessionInfoChanged(
lock_contents.media_controls_view(),
media_session::mojom::MediaPlaybackState::kPlaying);
// Verify media controls are hidden.
EXPECT_EQ(nullptr, lock_contents.media_controls_view());
EXPECT_FALSE(lock_contents.media_controls_view()->IsDrawn());
}
TEST_F(LockContentsViewUnitTest, MediaControlsHiddenOnLoginScreen) {
......@@ -2472,12 +2625,17 @@ TEST_F(LockContentsViewUnitTest, MediaControlsHiddenOnLoginScreen) {
std::unique_ptr<views::Widget> widget = CreateWidgetWithContent(contents);
LockContentsView::TestApi lock_contents(contents);
// Simulate active and playing media session.
SimulateMediaSessionInfoChanged(
lock_contents.media_controls_view(),
media_session::mojom::MediaPlaybackState::kPlaying);
// Verify media controls are hidden on login screen for one user.
EXPECT_EQ(nullptr, lock_contents.media_controls_view());
EXPECT_FALSE(lock_contents.media_controls_view()->IsDrawn());
SetUserCount(5);
// Verify media controls are hidden on login screen for multiple users.
// Verify that media controls view isn't created for non low-density layouts.
EXPECT_EQ(nullptr, lock_contents.media_controls_view());
}
......
......@@ -3,41 +3,64 @@
// found in the LICENSE file.
#include "ash/login/ui/lock_screen_media_controls_view.h"
#include "ash/login/ui/login_expanded_public_account_view.h"
#include "ash/login/ui/lock_contents_view.h"
#include "ash/media/media_controller_impl.h"
#include "ash/public/cpp/ash_features.h"
#include "ui/base/ui_base_features.h"
#include "ash/shell.h"
#include "services/media_session/public/mojom/constants.mojom.h"
#include "services/media_session/public/mojom/media_session.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
#include "ui/views/background.h"
namespace ash {
namespace {
// Total width of the media controls view.
constexpr int kMediaControlsTotalWidthDp = 320;
const int kMediaControlsTotalWidthDp = 320;
// Total height of the media controls view.
constexpr int kMediaControlsTotalHeightDp = 400;
const int kMediaControlsTotalHeightDp = 400;
// How long to wait (in milliseconds) for a new media session to begin.
constexpr base::TimeDelta kNextMediaDelay =
base::TimeDelta::FromMilliseconds(2500);
constexpr const char kLockScreenMediaControlsViewName[] =
"LockScreenMediaControlsView";
} // namespace
LockScreenMediaControlsView::LockScreenMediaControlsView() {
LockScreenMediaControlsView::LockScreenMediaControlsView(
service_manager::Connector* connector,
LockContentsView* view)
: view_(view),
connector_(connector),
hide_controls_timer_(new base::OneShotTimer()) {
SetBackground(views::CreateSolidBackground(SK_ColorBLACK));
}
middle_spacing_ = std::make_unique<NonAccessibleView>();
middle_spacing_->set_owned_by_client();
LockScreenMediaControlsView::~LockScreenMediaControlsView() = default;
// Media controls have not been dismissed initially.
Shell::Get()->media_controller()->SetMediaControlsDismissed(false);
// static
bool LockScreenMediaControlsView::AreMediaControlsEnabled(
LockScreen::ScreenType screen_type,
LoginExpandedPublicAccountView* expanded_view) {
return MediaControllerImpl::AreLockScreenMediaKeysEnabled() &&
base::FeatureList::IsEnabled(features::kLockScreenMediaControls) &&
screen_type == LockScreen::ScreenType::kLock &&
!expanded_view->GetVisible();
// |connector_| can be null in tests.
if (!connector_)
return;
// Connect to the MediaControllerManager and create a MediaController that
// controls the active session so we can observe it.
media_session::mojom::MediaControllerManagerPtr controller_manager_ptr;
connector_->BindInterface(media_session::mojom::kServiceName,
mojo::MakeRequest(&controller_manager_ptr));
controller_manager_ptr->CreateActiveMediaController(
mojo::MakeRequest(&media_controller_ptr_));
// Observe the active media controller for changes.
media_session::mojom::MediaControllerObserverPtr media_controller_observer;
observer_binding_.Bind(mojo::MakeRequest(&media_controller_observer));
media_controller_ptr_->AddObserver(std::move(media_controller_observer));
}
LockScreenMediaControlsView::~LockScreenMediaControlsView() = default;
// views::View:
gfx::Size LockScreenMediaControlsView::CalculatePreferredSize() const {
return gfx::Size(kMediaControlsTotalWidthDp, kMediaControlsTotalHeightDp);
......@@ -47,4 +70,37 @@ const char* LockScreenMediaControlsView::GetClassName() const {
return kLockScreenMediaControlsViewName;
}
views::View* LockScreenMediaControlsView::GetMiddleSpacingView() {
return middle_spacing_.get();
}
void LockScreenMediaControlsView::MediaSessionInfoChanged(
media_session::mojom::MediaSessionInfoPtr session_info) {
// If a new media session began while waiting, keep showing the controls.
if (hide_controls_timer_->IsRunning() && session_info)
hide_controls_timer_->Stop();
// If controls aren't enabled or there is no session to show, don't show the
// controls.
if (!view_->AreMediaControlsEnabled() ||
(!session_info && !media_session_info_)) {
view_->HideMediaControlsLayout();
} else if (!session_info && media_session_info_) {
// If there is no current session but there was a previous one, wait to see
// if a new session starts before hiding the controls.
hide_controls_timer_->Start(
FROM_HERE, kNextMediaDelay,
base::BindOnce(&LockContentsView::HideMediaControlsLayout,
base::Unretained(view_)));
} else if (!IsDrawn() &&
session_info->playback_state ==
media_session::mojom::MediaPlaybackState::kPaused) {
// If the screen is locked while media is paused, don't show the controls.
view_->HideMediaControlsLayout();
} else if (!IsDrawn()) {
view_->CreateMediaControlsLayout();
}
media_session_info_ = std::move(session_info);
}
} // namespace ash
......@@ -6,27 +6,72 @@
#define ASH_LOGIN_UI_LOCK_SCREEN_MEDIA_CONTROLS_VIEW_H_
#include "ash/ash_export.h"
#include "ash/login/ui/lock_screen.h"
#include "base/timer/timer.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/media_session/public/mojom/media_controller.mojom.h"
#include "ui/views/view.h"
namespace service_manager {
class Connector;
} // namespace service_manager
namespace ash {
class LoginExpandedPublicAccountView;
class LockContentsView;
class LockScreenMediaControlsView : public views::View {
class LockScreenMediaControlsView
: public views::View,
public media_session::mojom::MediaControllerObserver {
public:
LockScreenMediaControlsView();
LockScreenMediaControlsView(service_manager::Connector* connector,
LockContentsView* view);
~LockScreenMediaControlsView() override;
static bool AreMediaControlsEnabled(
LockScreen::ScreenType screen_type,
LoginExpandedPublicAccountView* expanded_view);
// views::View:
gfx::Size CalculatePreferredSize() const override;
const char* GetClassName() const override;
views::View* GetMiddleSpacingView();
// media_session::mojom::MediaControllerObserver:
void MediaSessionInfoChanged(
media_session::mojom::MediaSessionInfoPtr session_info) override;
void MediaSessionMetadataChanged(
const base::Optional<media_session::MediaMetadata>& metadata) override {}
void MediaSessionActionsChanged(
const std::vector<media_session::mojom::MediaSessionAction>& actions)
override {}
void MediaSessionChanged(
const base::Optional<base::UnguessableToken>& request_id) override {}
void set_timer_for_testing(std::unique_ptr<base::OneShotTimer> test_timer) {
hide_controls_timer_ = std::move(test_timer);
}
private:
// Lock screen view which this view belongs to.
LockContentsView* const view_;
// Used to connect to the Media Session service.
service_manager::Connector* const connector_;
// Used to control the active session.
media_session::mojom::MediaControllerPtr media_controller_ptr_;
// Used to receive updates to the active media controller.
mojo::Binding<media_session::mojom::MediaControllerObserver>
observer_binding_{this};
// The info about the current media session. It will be null if there is not
// a current session.
media_session::mojom::MediaSessionInfoPtr media_session_info_;
// Spacing between controls and user.
std::unique_ptr<views::View> middle_spacing_;
// Automatically hides the controls a few seconds if no media playing.
std::unique_ptr<base::OneShotTimer> hide_controls_timer_;
DISALLOW_COPY_AND_ASSIGN(LockScreenMediaControlsView);
};
......
......@@ -50,12 +50,17 @@ void MediaControllerImpl::RegisterProfilePrefs(PrefRegistrySimple* registry) {
PrefRegistry::PUBLIC);
}
// static
bool MediaControllerImpl::AreLockScreenMediaKeysEnabled() {
bool MediaControllerImpl::AreLockScreenMediaKeysEnabled() const {
PrefService* prefs =
Shell::Get()->session_controller()->GetPrimaryUserPrefService();
return base::FeatureList::IsEnabled(features::kLockScreenMediaKeys) &&
prefs->GetBoolean(prefs::kLockScreenMediaKeysEnabled);
prefs->GetBoolean(prefs::kLockScreenMediaKeysEnabled) &&
!media_controls_dismissed_;
}
void MediaControllerImpl::SetMediaControlsDismissed(
bool media_controls_dismissed) {
media_controls_dismissed_ = media_controls_dismissed;
}
void MediaControllerImpl::AddObserver(MediaCaptureObserver* observer) {
......
......@@ -47,9 +47,9 @@ class ASH_EXPORT MediaControllerImpl
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
// Determine if lock screen media keys are enabled based on feature flag and
// user preference.
static bool AreLockScreenMediaKeysEnabled();
// Determine if lock screen media keys are enabled.
bool AreLockScreenMediaKeysEnabled() const;
void SetMediaControlsDismissed(bool media_controls_dismissed);
void AddObserver(MediaCaptureObserver* observer);
void RemoveObserver(MediaCaptureObserver* observer);
......@@ -130,6 +130,9 @@ class ASH_EXPORT MediaControllerImpl
// being handled in ash.
bool force_media_client_key_handling_ = false;
// Whether the lock screen media controls are dismissed.
bool media_controls_dismissed_ = false;
// Mojo pointer to the active media session controller.
media_session::mojom::MediaControllerPtr media_session_controller_ptr_;
......
......@@ -104,7 +104,8 @@ TEST_F(MediaControllerTest, EnableLockScreenMediaKeys) {
Shell::Get()->session_controller()->GetLastActiveUserPrefService();
prefs->SetBoolean(prefs::kLockScreenMediaKeysEnabled, true);
EXPECT_TRUE(MediaControllerImpl::AreLockScreenMediaKeysEnabled());
EXPECT_TRUE(
Shell::Get()->media_controller()->AreLockScreenMediaKeysEnabled());
}
TEST_F(MediaControllerTest, DisableLockScreenMediaKeysIfFeatureDisabled) {
......@@ -115,11 +116,13 @@ TEST_F(MediaControllerTest, DisableLockScreenMediaKeysIfFeatureDisabled) {
Shell::Get()->session_controller()->GetPrimaryUserPrefService();
prefs->SetBoolean(prefs::kLockScreenMediaKeysEnabled, true);
EXPECT_FALSE(MediaControllerImpl::AreLockScreenMediaKeysEnabled());
EXPECT_FALSE(
Shell::Get()->media_controller()->AreLockScreenMediaKeysEnabled());
prefs->SetBoolean(prefs::kLockScreenMediaKeysEnabled, false);
EXPECT_FALSE(MediaControllerImpl::AreLockScreenMediaKeysEnabled());
EXPECT_FALSE(
Shell::Get()->media_controller()->AreLockScreenMediaKeysEnabled());
}
TEST_F(MediaControllerTest, DisableLockScreenMediaKeysIfPreferenceDisabled) {
......@@ -130,7 +133,8 @@ TEST_F(MediaControllerTest, DisableLockScreenMediaKeysIfPreferenceDisabled) {
Shell::Get()->session_controller()->GetPrimaryUserPrefService();
prefs->SetBoolean(prefs::kLockScreenMediaKeysEnabled, false);
EXPECT_FALSE(MediaControllerImpl::AreLockScreenMediaKeysEnabled());
EXPECT_FALSE(
Shell::Get()->media_controller()->AreLockScreenMediaKeysEnabled());
}
TEST_F(MediaControllerTest, EnableMediaKeysWhenLockedAndKeysEnabled) {
......
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