Commit 57f73fd3 authored by Meilin Wang's avatar Meilin Wang Committed by Commit Bot

ambient: show media string based on user pref.

We should keep the same user policy as lock-screen media controls:
namely, the ambient media string should only be available on lock-screen
when the corresponding pref has been enabled.

Bug: b/167488694.
Test: unittested.
Change-Id: I26256f1160ab869054fa18ec4360ab2cfd6f1815
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2380143
Commit-Queue: Meilin Wang <meilinw@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804114}
parent c945c7fb
......@@ -9,10 +9,13 @@
#include "ash/ambient/util/ambient_util.h"
#include "ash/assistant/ui/assistant_view_ids.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "components/prefs/pref_service.h"
#include "services/media_session/public/mojom/media_session.mojom.h"
#include "services/media_session/public/mojom/media_session_service.mojom.h"
#include "third_party/skia/include/core/SkColor.h"
......@@ -30,6 +33,18 @@ constexpr char kPreceedingEighthNoteSymbol[] = "\u266A ";
constexpr int kDefaultFontSizeDip = 64;
constexpr int kMediaStringFontSizeDip = 16;
// Returns true if we should show media string for ambient mode on lock-screen
// based on user pref. We should keep the same user policy here as the
// lock-screen media controls to avoid exposing user data on lock-screen without
// consent.
bool ShouldShowOnLockScreen() {
PrefService* pref =
Shell::Get()->session_controller()->GetPrimaryUserPrefService();
DCHECK(pref);
return pref->GetBoolean(prefs::kLockScreenMediaControlsEnabled);
}
} // namespace
MediaStringView::MediaStringView() {
......@@ -45,6 +60,11 @@ const char* MediaStringView::GetClassName() const {
void MediaStringView::MediaSessionInfoChanged(
media_session::mojom::MediaSessionInfoPtr session_info) {
if (ambient::util::IsShowing(LockScreen::ScreenType::kLock) &&
!ShouldShowOnLockScreen()) {
return;
}
// Don't show the media string if session info is unavailable, or the active
// session is marked as sensitive.
if (!session_info || session_info->is_sensitive) {
......
......@@ -5,13 +5,25 @@
#include "ash/ambient/ui/media_string_view.h"
#include "ash/ambient/test/ambient_ash_test_base.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "ash/shell.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "services/media_session/public/mojom/media_session.mojom.h"
namespace ash {
using MediaStringViewTest = AmbientAshTestBase;
class MediaStringViewTest : public AmbientAshTestBase {
public:
MediaStringViewTest() : AmbientAshTestBase() {}
~MediaStringViewTest() override = default;
// AmbientAshTestBase:
void SetUp() override {
AmbientAshTestBase::SetUp();
GetSessionControllerClient()->set_show_lock_screen_views(true);
}
};
TEST_F(MediaStringViewTest, ShowMediaTitleAndArtist) {
ShowAmbientScreen();
......@@ -53,4 +65,22 @@ TEST_F(MediaStringViewTest, DoNotShowWhenMediaIsPaused) {
EXPECT_FALSE(GetMediaStringView()->GetVisible());
}
TEST_F(MediaStringViewTest, DoNotShowOnLockScreenIfPrefIsDisabled) {
// Disables user preference for media controls.
PrefService* pref =
Shell::Get()->session_controller()->GetPrimaryUserPrefService();
pref->SetBoolean(prefs::kLockScreenMediaControlsEnabled, false);
// Simulates Ambient Mode shown on lock-screen.
LockScreen();
FastForwardToInactivity();
// Simulates active and playing media session.
SimulateMediaPlaybackStateChanged(
media_session::mojom::MediaPlaybackState::kPlaying);
// Verifies media string is hidden.
EXPECT_FALSE(GetMediaStringView()->GetVisible());
}
} // namespace ash
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