Commit 2ccae209 authored by Xiqi Ruan's avatar Xiqi Ruan Committed by Commit Bot

cros: Use the preferred clock format in child lock screen

In Child lock screen, set time to 24 hour clock format if the
child user turn on "Use 24-hour clock" in preference.

Bug: 945186
Change-Id: I760387e8e58041f23529c24641362eec5de6a9b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2225864
Commit-Queue: Xiqi Ruan <xiqiruan@chromium.org>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779978}
parent 0973c7d0
......@@ -544,6 +544,22 @@ std::string LoginScreenTestApi::GetDisplayedName(const AccountId& account_id) {
return base::UTF16ToUTF8(user_view_test.displayed_name());
}
// static
base::string16 LoginScreenTestApi::GetDisabledAuthMessage(
const AccountId& account_id) {
LockScreen::TestApi lock_screen_test(LockScreen::Get());
LockContentsView::TestApi lock_contents_test(
lock_screen_test.contents_view());
LoginBigUserView* big_user_view = lock_contents_test.FindBigUser(account_id);
if (!big_user_view) {
ADD_FAILURE() << "Could not find user " << account_id.Serialize();
return base::string16();
}
LoginAuthUserView::TestApi auth_test(big_user_view->auth_user());
return auth_test.GetDisabledAuthMessageContent();
}
// static
bool LoginScreenTestApi::IsOobeDialogVisible() {
LockScreen::TestApi lock_screen_test(LockScreen::Get());
......
......@@ -26,6 +26,8 @@
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/model/clock_model.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/night_light/time_of_day.h"
#include "ash/wallpaper/wallpaper_controller_impl.h"
#include "base/bind.h"
......@@ -268,27 +270,35 @@ struct LockScreenMessage {
// Returns the message used when the device was locked due to a time window
// limit.
LockScreenMessage GetWindowLimitMessage(const base::Time& unlock_time) {
LockScreenMessage GetWindowLimitMessage(const base::Time& unlock_time,
bool use_24hour_clock) {
LockScreenMessage message;
message.title = l10n_util::GetStringUTF16(IDS_ASH_LOGIN_TIME_FOR_BED_MESSAGE);
base::Time local_midnight = base::Time::Now().LocalMidnight();
const std::string time_of_day = TimeOfDay::FromTime(unlock_time).ToString();
base::string16 time_to_display;
if (use_24hour_clock) {
time_to_display = base::TimeFormatTimeOfDayWithHourClockType(
unlock_time, base::k24HourClock, base::kDropAmPm);
} else {
time_to_display = base::TimeFormatTimeOfDayWithHourClockType(
unlock_time, base::k12HourClock, base::kKeepAmPm);
}
if (unlock_time < local_midnight + base::TimeDelta::FromDays(1)) {
// Unlock time is today.
message.content = l10n_util::GetStringFUTF16(
IDS_ASH_LOGIN_COME_BACK_MESSAGE, base::UTF8ToUTF16(time_of_day));
IDS_ASH_LOGIN_COME_BACK_MESSAGE, time_to_display);
} else if (unlock_time < local_midnight + base::TimeDelta::FromDays(2)) {
// Unlock time is tomorrow.
message.content =
l10n_util::GetStringFUTF16(IDS_ASH_LOGIN_COME_BACK_TOMORROW_MESSAGE,
base::UTF8ToUTF16(time_of_day));
message.content = l10n_util::GetStringFUTF16(
IDS_ASH_LOGIN_COME_BACK_TOMORROW_MESSAGE, time_to_display);
} else {
message.content = l10n_util::GetStringFUTF16(
IDS_ASH_LOGIN_COME_BACK_DAY_OF_WEEK_MESSAGE,
base::TimeFormatWithPattern(unlock_time, kDayOfWeekOnlyTimeFormat),
base::UTF8ToUTF16(time_of_day));
time_to_display);
}
message.icon = &kLockScreenTimeLimitMoonIcon;
return message;
......@@ -341,10 +351,11 @@ LockScreenMessage GetOverrideMessage() {
LockScreenMessage GetLockScreenMessage(AuthDisabledReason lock_reason,
const base::Time& unlock_time,
const base::TimeDelta& used_time) {
const base::TimeDelta& used_time,
bool use_24hour_clock) {
switch (lock_reason) {
case AuthDisabledReason::kTimeWindowLimit:
return GetWindowLimitMessage(unlock_time);
return GetWindowLimitMessage(unlock_time, use_24hour_clock);
case AuthDisabledReason::kTimeUsageLimit:
return GetUsageLimitMessage(used_time);
case AuthDisabledReason::kTimeLimitOverride:
......@@ -631,6 +642,19 @@ class LoginAuthUserView::ChallengeResponseView : public views::View,
// The message shown to user when the auth method is |AUTH_DISABLED|.
class LoginAuthUserView::DisabledAuthMessageView : public views::View {
public:
class ASH_EXPORT TestApi {
public:
explicit TestApi(DisabledAuthMessageView* view) : view_(view) {}
~TestApi() = default;
const base::string16& GetDisabledAuthMessageContent() const {
return view_->message_contents_->GetText();
}
private:
DisabledAuthMessageView* const view_;
};
DisabledAuthMessageView() {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
......@@ -679,10 +703,11 @@ class LoginAuthUserView::DisabledAuthMessageView : public views::View {
~DisabledAuthMessageView() override = default;
// Set the parameters needed to render the message.
void SetAuthDisabledMessage(const AuthDisabledData& auth_disabled_data) {
void SetAuthDisabledMessage(const AuthDisabledData& auth_disabled_data,
bool use_24hour_clock) {
LockScreenMessage message = GetLockScreenMessage(
auth_disabled_data.reason, auth_disabled_data.auth_reenabled_time,
auth_disabled_data.device_used_time);
auth_disabled_data.device_used_time, use_24hour_clock);
message_icon_->SetImage(gfx::CreateVectorIcon(
*message.icon, kDisabledAuthMessageIconSizeDp, SK_ColorWHITE));
message_title_->SetText(message.title);
......@@ -758,6 +783,13 @@ bool LoginAuthUserView::TestApi::HasAuthMethod(AuthMethods auth_method) const {
return view_->HasAuthMethod(auth_method);
}
const base::string16&
LoginAuthUserView::TestApi::GetDisabledAuthMessageContent() const {
return LoginAuthUserView::DisabledAuthMessageView::TestApi(
view_->disabled_auth_message_)
.GetDisabledAuthMessageContent();
}
LoginAuthUserView::Callbacks::Callbacks() = default;
LoginAuthUserView::Callbacks::Callbacks(const Callbacks& other) = default;
......@@ -1189,7 +1221,8 @@ void LoginAuthUserView::NotifyFingerprintAuthResult(bool success) {
void LoginAuthUserView::SetAuthDisabledMessage(
const AuthDisabledData& auth_disabled_data) {
disabled_auth_message_->SetAuthDisabledMessage(auth_disabled_data);
disabled_auth_message_->SetAuthDisabledMessage(
auth_disabled_data, current_user().use_24hour_clock);
Layout();
}
......
......@@ -67,6 +67,7 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
views::Button* external_binary_auth_button() const;
views::Button* external_binary_enrollment_button() const;
bool HasAuthMethod(AuthMethods auth_method) const;
const base::string16& GetDisabledAuthMessageContent() const;
private:
LoginAuthUserView* const view_;
......
......@@ -50,6 +50,7 @@ class ASH_PUBLIC_EXPORT LoginScreenTestApi {
static bool RemoveUser(const AccountId& account_id);
static std::string GetDisplayedName(const AccountId& account_id);
static base::string16 GetDisabledAuthMessage(const AccountId& account_id);
static bool ExpandPublicSessionPod(const AccountId& account_id);
static bool HidePublicSessionExpandedPod();
......
......@@ -282,6 +282,9 @@ struct ASH_PUBLIC_EXPORT LoginUserInfo {
// Contains the public account information if user type is PUBLIC_ACCOUNT.
base::Optional<PublicAccountInfo> public_account_info;
// True if this user chooses to use 24 hour clock in preference.
bool use_24hour_clock = false;
};
enum class AuthDisabledReason {
......
......@@ -4,6 +4,7 @@
#include <memory>
#include "ash/public/cpp/login_screen_test_api.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
......@@ -116,6 +117,10 @@ class ScreenTimeControllerTest : public MixinBasedInProcessBrowserTest {
logged_in_user_mixin_.GetAccountId());
}
const AccountId& GetAccountId() {
return logged_in_user_mixin_.GetAccountId();
}
void MockChildScreenTime(base::TimeDelta used_time) {
child_profile_->GetPrefs()->SetInteger(prefs::kChildScreenTimeMilliseconds,
used_time.InMilliseconds());
......@@ -666,6 +671,33 @@ IN_PROC_BROWSER_TEST_F(ScreenTimeControllerTest, BedtimeOnTimezoneChange) {
EXPECT_TRUE(IsAuthEnabled());
}
IN_PROC_BROWSER_TEST_F(ScreenTimeControllerTest, BedtimeLockScreen24HourClock) {
LogInChildAndSetupClockWithTime("1 Jan 2018 22:00:00 GMT");
// Set preference of using 24 hour clock to be true.
child_profile_->GetPrefs()->SetBoolean(prefs::kUse24HourClock, true);
ScreenLockerTester().Lock();
system::TimezoneSettings::GetInstance()->SetTimezoneFromID(
base::UTF8ToUTF16("GMT"));
// Set new policy.
base::Time last_updated = utils::TimeFromString("1 Jan 2018 0:00 GMT");
base::Value policy_content =
utils::CreateTimeLimitPolicy(utils::CreateTime(6, 0));
utils::AddTimeWindowLimit(&policy_content, utils::kMonday,
utils::CreateTime(21, 0), utils::CreateTime(17, 0),
last_updated);
SetUsageTimeLimitPolicy(policy_content);
// Check that auth is disabled, since the bedtime has already started.
EXPECT_FALSE(IsAuthEnabled());
EXPECT_EQ(base::UTF8ToUTF16("Come back at 17:00."),
ash::LoginScreenTestApi::GetDisabledAuthMessage(GetAccountId()));
}
// Tests bedtime during timezone changes that make the clock go back in time.
IN_PROC_BROWSER_TEST_F(ScreenTimeControllerTest,
BedtimeOnEastToWestTimezoneChanges) {
......
......@@ -941,6 +941,15 @@ UserSelectionScreen::UpdateAndReturnUserListForAsh() {
ash::LoginUserInfo user_info;
user_info.basic_user_info.type = user->GetType();
user_info.basic_user_info.account_id = user->GetAccountId();
if (!user_manager::known_user::GetBooleanPref(
account_id, ::prefs::kUse24HourClock,
&user_info.use_24hour_clock)) {
// Fallback to system default in case pref was not found.
user_info.use_24hour_clock =
base::GetHourClockType() == base::k24HourClock;
}
user_info.basic_user_info.display_name =
base::UTF16ToUTF8(user->GetDisplayName());
user_info.basic_user_info.display_email = user->display_email();
......
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