Skip to content

Commit e87856f

Browse files
Toni BarzicToni Barzic
authored andcommitted
Policy to disable/whitelist lock screen note taking apps
Adds a policy to control whether/which note taking apps are allowed on the lock screen - the policy is implemented as a white-list of apps that will be allowed as lock screen note taking apps (provided the user enables them in settings). The policy value is saved as kNoteTakingAppsAllowedOnLockScreen pref that's being added in https://chromium-review.googlesource.com/c/572842 BUG=741053 [email protected] (cherry picked from commit c45d9b1) Change-Id: Ib1beb5ee3c7f4efad0eb8be99f894345adaf7530 Reviewed-on: https://chromium-review.googlesource.com/567556 Commit-Queue: Toni Barzic <[email protected]> Reviewed-by: Maksim Ivanov <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#489199} Reviewed-on: https://chromium-review.googlesource.com/588382 Reviewed-by: Toni Barzic <[email protected]> Cr-Commit-Position: refs/branch-heads/3163@{#73} Cr-Branched-From: ff259ba-refs/heads/master@{#488528}
1 parent 7270d2d commit e87856f

File tree

5 files changed

+148
-3
lines changed

5 files changed

+148
-3
lines changed

chrome/browser/policy/configuration_policy_handler_list_factory.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,9 @@ std::unique_ptr<ConfigurationPolicyHandlerList> BuildHandlerList(
10481048
handlers->AddHandler(
10491049
base::MakeUnique<chromeos::KeyPermissionsPolicyHandler>(chrome_schema));
10501050
handlers->AddHandler(base::WrapUnique(new DefaultGeolocationPolicyHandler()));
1051+
handlers->AddHandler(base::MakeUnique<extensions::ExtensionListPolicyHandler>(
1052+
key::kNoteTakingAppsLockScreenWhitelist,
1053+
prefs::kNoteTakingAppsLockScreenWhitelist, false /*allow_wildcards*/));
10511054
#endif // defined(OS_CHROMEOS)
10521055

10531056
#if BUILDFLAG(ENABLE_PLUGINS)

chrome/browser/policy/policy_browsertest.cc

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
#include "extensions/common/extension_set.h"
176176
#include "extensions/common/features/feature_channel.h"
177177
#include "extensions/common/manifest_handlers/shared_module_info.h"
178+
#include "extensions/common/switches.h"
178179
#include "media/media_features.h"
179180
#include "net/base/net_errors.h"
180181
#include "net/base/url_util.h"
@@ -208,6 +209,7 @@
208209
#include "chrome/browser/chromeos/accessibility/magnification_manager.h"
209210
#include "chrome/browser/chromeos/arc/arc_session_manager.h"
210211
#include "chrome/browser/chromeos/login/test/js_checker.h"
212+
#include "chrome/browser/chromeos/note_taking_helper.h"
211213
#include "chrome/browser/chromeos/system/timezone_resolver_manager.h"
212214
#include "chrome/browser/profiles/profile_manager.h"
213215
#include "chrome/browser/ui/ash/chrome_screenshot_grabber.h"
@@ -4446,4 +4448,106 @@ IN_PROC_BROWSER_TEST_F(NetworkTimePolicyTest, NetworkTimeQueriesDisabled) {
44464448
EXPECT_EQ(1u, num_requests());
44474449
}
44484450

4451+
#if defined(OS_CHROMEOS)
4452+
4453+
class NoteTakingOnLockScreenPolicyTest : public PolicyTest {
4454+
public:
4455+
NoteTakingOnLockScreenPolicyTest() = default;
4456+
~NoteTakingOnLockScreenPolicyTest() override = default;
4457+
4458+
void SetUpCommandLine(base::CommandLine* command_line) override {
4459+
command_line->AppendSwitch(chromeos::switches::kEnableLockScreenApps);
4460+
// An app requires lockScreen permission to be enabled as a lock screen app.
4461+
// This permission is protected by a whitelist, so the test app has to be
4462+
// whitelisted as well.
4463+
command_line->AppendSwitchASCII(
4464+
extensions::switches::kWhitelistedExtensionID, kTestAppId);
4465+
PolicyTest::SetUpCommandLine(command_line);
4466+
}
4467+
4468+
void SetUserLevelPrefValue(const std::string& app_id,
4469+
bool enabled_on_lock_screen) {
4470+
chromeos::NoteTakingHelper* helper = chromeos::NoteTakingHelper::Get();
4471+
ASSERT_TRUE(helper);
4472+
4473+
helper->SetPreferredApp(browser()->profile(), app_id);
4474+
helper->SetPreferredAppEnabledOnLockScreen(browser()->profile(),
4475+
enabled_on_lock_screen);
4476+
}
4477+
4478+
void SetPolicyValue(std::unique_ptr<base::Value> value) {
4479+
PolicyMap policies;
4480+
if (value) {
4481+
policies.Set(key::kNoteTakingAppsLockScreenWhitelist,
4482+
POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
4483+
POLICY_SOURCE_CLOUD, std::move(value), nullptr);
4484+
}
4485+
UpdateProviderPolicy(policies);
4486+
}
4487+
4488+
chromeos::NoteTakingLockScreenSupport GetAppLockScreenStatus(
4489+
const std::string& app_id) {
4490+
std::unique_ptr<chromeos::NoteTakingAppInfo> info =
4491+
chromeos::NoteTakingHelper::Get()->GetPreferredChromeAppInfo(
4492+
browser()->profile());
4493+
if (!info || info->app_id != app_id)
4494+
return chromeos::NoteTakingLockScreenSupport::kNotSupported;
4495+
return info->lock_screen_support;
4496+
}
4497+
4498+
// The test app ID.
4499+
static const char kTestAppId[];
4500+
4501+
private:
4502+
DISALLOW_COPY_AND_ASSIGN(NoteTakingOnLockScreenPolicyTest);
4503+
};
4504+
4505+
const char NoteTakingOnLockScreenPolicyTest::kTestAppId[] =
4506+
"cadfeochfldmbdgoccgbeianhamecbae";
4507+
4508+
IN_PROC_BROWSER_TEST_F(NoteTakingOnLockScreenPolicyTest,
4509+
DisableLockScreenNoteTakingByPolicy) {
4510+
scoped_refptr<const extensions::Extension> app =
4511+
LoadUnpackedExtension("lock_screen_apps/app_launch");
4512+
ASSERT_TRUE(app);
4513+
ASSERT_EQ(kTestAppId, app->id());
4514+
4515+
SetUserLevelPrefValue(app->id(), true);
4516+
EXPECT_EQ(chromeos::NoteTakingLockScreenSupport::kEnabled,
4517+
GetAppLockScreenStatus(app->id()));
4518+
4519+
SetPolicyValue(base::MakeUnique<base::ListValue>());
4520+
EXPECT_EQ(chromeos::NoteTakingLockScreenSupport::kNotAllowedByPolicy,
4521+
GetAppLockScreenStatus(app->id()));
4522+
4523+
SetPolicyValue(nullptr);
4524+
EXPECT_EQ(chromeos::NoteTakingLockScreenSupport::kEnabled,
4525+
GetAppLockScreenStatus(app->id()));
4526+
}
4527+
4528+
IN_PROC_BROWSER_TEST_F(NoteTakingOnLockScreenPolicyTest,
4529+
WhitelistLockScreenNoteTakingAppByPolicy) {
4530+
scoped_refptr<const extensions::Extension> app =
4531+
LoadUnpackedExtension("lock_screen_apps/app_launch");
4532+
ASSERT_TRUE(app);
4533+
ASSERT_EQ(kTestAppId, app->id());
4534+
4535+
SetUserLevelPrefValue(app->id(), false);
4536+
EXPECT_EQ(chromeos::NoteTakingLockScreenSupport::kSupported,
4537+
GetAppLockScreenStatus(app->id()));
4538+
4539+
auto policy = base::MakeUnique<base::ListValue>();
4540+
policy->GetList().emplace_back(base::Value(kTestAppId));
4541+
SetPolicyValue(std::move(policy));
4542+
4543+
EXPECT_EQ(chromeos::NoteTakingLockScreenSupport::kSupported,
4544+
GetAppLockScreenStatus(app->id()));
4545+
4546+
SetUserLevelPrefValue(app->id(), true);
4547+
EXPECT_EQ(chromeos::NoteTakingLockScreenSupport::kEnabled,
4548+
GetAppLockScreenStatus(app->id()));
4549+
}
4550+
4551+
#endif // defined(OS_CHROMEOS)
4552+
44494553
} // namespace policy

chrome/test/data/policy/policy_test_cases.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,6 +3128,14 @@
31283128
"test_policy": { "DeviceEcryptfsMigrationStrategy": 1 }
31293129
},
31303130

3131+
"NoteTakingAppsLockScreenWhitelist": {
3132+
"os": ["chromeos"],
3133+
"test_policy": { "NoteTakingAppsLockScreenWhitelist": [] },
3134+
"pref_mappings": [
3135+
{"pref": "settings.note_taking_apps_lock_screen_whitelist"}
3136+
]
3137+
},
3138+
31313139
"----- Chrome Frame policies -------------------------------------------": {},
31323140

31333141
"ChromeFrameRendererSettings": {

components/policy/resources/policy_templates.json

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
# persistent IDs for all fields (but not for groups!) are needed. These are
144144
# specified by the 'id' keys of each policy. NEVER CHANGE EXISTING IDs,
145145
# because doing so would break the deployed wire format!
146-
# For your editing convenience: highest ID currently used: 376
146+
# For your editing convenience: highest ID currently used: 377
147147
# And don't forget to also update the EnterprisePolicies enum of
148148
# histograms.xml (run 'python tools/metrics/histograms/update_policies.py').
149149
#
@@ -9782,6 +9782,35 @@
97829782

97839783
This policy does not apply to kiosk users. If this policy is left not set, the device will behave as if 'DisallowArc' was chosen.''',
97849784
},
9785+
{
9786+
'name': 'NoteTakingAppsLockScreenWhitelist',
9787+
'type': 'list',
9788+
'schema': {
9789+
'type': 'array',
9790+
'items': { 'type': 'string' },
9791+
},
9792+
'supported_on': [
9793+
'chrome_os:61-',
9794+
],
9795+
'features': {
9796+
'dynamic_refresh': True,
9797+
'per_profile': True
9798+
},
9799+
'example_value': ['abcdefghabcdefghabcdefghabcdefgh'],
9800+
'id': 377,
9801+
'caption': '''Whitelist note-taking apps allowed on the <ph name="PRODUCT_OS_NAME">$2<ex>Google Chrome OS</ex></ph> lock screen''',
9802+
'tags': [],
9803+
'desc': '''Specifies list of apps that can be enabled as a note-taking app on the <ph name="PRODUCT_OS_NAME">$2<ex>Google Chrome OS</ex></ph> lock screen.
9804+
9805+
If the preferred note-taking app is enabled on the lock screen, the lock screen will contain UI element for launching the preferred note taking app.
9806+
When launched, the app will be able to create an app window on top of the lock screen, and create data items (notes) in the lock screen context. The app will be able to import created notes to the primary user session, when the session is unlocked. Currently, only Chrome note-taking apps are supported on the lock screen.
9807+
9808+
If the policy is set, the user will be allowed to enable an app on the lock screen only if the app's extension ID is contained in the policy list value.
9809+
As a consequence, setting this policy to an empty list will disable note-taking on the lock screen entirely.
9810+
Note that the policy containing an app ID does not necessarily mean that the user will be able to enable the app as a note-taking app on the lock screen - for example, on Chrome 61, the set of available apps is additionally restricted by the platform.
9811+
9812+
If the policy is left unset, there will be no restrictions on the set of apps the user can enable on the lock screen imposed by the policy.'''
9813+
},
97859814
],
97869815
'messages': {
97879816
# Messages that are not associated to any policies.

tools/metrics/histograms/enums.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11085,13 +11085,14 @@ uploading your change for review. These are checked by presubmit scripts.
1108511085
<int value="367" label="InstantTetheringAllowed"/>
1108611086
<int value="368" label="RemoteAccessHostDomainList"/>
1108711087
<int value="369" label="RemoteAccessHostClientDomainList"/>
11088-
<int value="370" label="NetworkTimeQueriesEnabled"/>
11088+
<int value="370" label="BrowserNetworkTimeQueriesEnabled"/>
1108911089
<int value="371" label="DownloadRestrictions"/>
1109011090
<int value="372" label="DeviceSecondFactorAuthentication"/>
11091-
<int value="373" label="UseSystemDefaultPrinterAsDefault"/>
11091+
<int value="373" label="PrintPreviewUseSystemDefaultPrinter"/>
1109211092
<int value="374" label="DeviceEcryptfsMigrationStrategy"/>
1109311093
<int value="375" label="SafeBrowsingForTrustedSourcesEnabled"/>
1109411094
<int value="376" label="EcryptfsMigrationStrategy"/>
11095+
<int value="377" label="NoteTakingAppsLockScreenWhitelist"/>
1109511096
</enum>
1109611097

1109711098
<enum name="EnterprisePolicyInvalidations">

0 commit comments

Comments
 (0)