aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRahul Chaturvedi <rkc@google.com>2018-01-04 22:18:13 +0000
committerandroid-build-merger <android-build-merger@google.com>2018-01-04 22:18:13 +0000
commit957cd3c9291476b163ef5428e746cf39ac6ad379 (patch)
tree198fb283364f16d599e1d5ce7a8ff2551c35a732
parentc75c1f294f97ffc108e62ed4460a3b9aad754719 (diff)
parentb91af3b238d0e3dc69a736f4977b65ce6bb264ff (diff)
downloadlibbrillo-957cd3c9291476b163ef5428e746cf39ac6ad379.tar.gz
libbrillo: Add functionality to get the app id of a kiosk app.
am: b91af3b238 Change-Id: Ifa9fe2cab7a734d3526f6cf02a43505e85e620d6
-rw-r--r--PRESUBMIT.cfg6
-rw-r--r--policy/device_policy.h5
-rw-r--r--policy/device_policy_impl.cc35
-rw-r--r--policy/device_policy_impl.h73
-rw-r--r--policy/mock_device_policy.h1
-rw-r--r--policy/tests/libpolicy_unittest.cc3
-rw-r--r--policy/tests/whitelist/owner.keybin301 -> 294 bytes
-rw-r--r--policy/tests/whitelist/policy_allbin876 -> 929 bytes
-rw-r--r--policy/tests/whitelist/policy_nonebin660 -> 653 bytes
9 files changed, 88 insertions, 35 deletions
diff --git a/PRESUBMIT.cfg b/PRESUBMIT.cfg
new file mode 100644
index 0000000..60456a2
--- /dev/null
+++ b/PRESUBMIT.cfg
@@ -0,0 +1,6 @@
+[Hook Overrides]
+cros_license_check: true
+
+[Hook Overrides Options]
+# policy_all and policy_none files are data files
+cros_license_check: --exclude_regex=\bpolicy_(?:all|none)$
diff --git a/policy/device_policy.h b/policy/device_policy.h
index 840e7e5..fbebeaa 100644
--- a/policy/device_policy.h
+++ b/policy/device_policy.h
@@ -150,6 +150,11 @@ class DevicePolicy {
virtual bool GetUsbDetachableWhitelist(
std::vector<UsbDeviceId>* usb_whitelist) const = 0;
+ // Writes the value of the kiosk app id into |app_id_out|.
+ // Only succeeds if the device is in auto-launched kiosk mode.
+ virtual bool GetAutoLaunchedKioskAppId(
+ std::string* app_id_out) const = 0;
+
private:
// Verifies that the policy files are owned by root and exist.
virtual bool VerifyPolicyFiles() = 0;
diff --git a/policy/device_policy_impl.cc b/policy/device_policy_impl.cc
index 784cace..de29b39 100644
--- a/policy/device_policy_impl.cc
+++ b/policy/device_policy_impl.cc
@@ -422,6 +422,41 @@ bool DevicePolicyImpl::GetUsbDetachableWhitelist(
return true;
}
+bool DevicePolicyImpl::GetAutoLaunchedKioskAppId(
+ std::string* app_id_out) const {
+ if (!device_policy_.has_device_local_accounts())
+ return false;
+
+ const enterprise_management::DeviceLocalAccountsProto& local_accounts =
+ device_policy_.device_local_accounts();
+
+ // For auto-launched kiosk apps, the delay needs to be 0.
+ if (local_accounts.has_auto_login_delay() &&
+ local_accounts.auto_login_delay() != 0)
+ return false;
+
+ for (const enterprise_management::DeviceLocalAccountInfoProto& account :
+ local_accounts.account()) {
+ // If this isn't an auto-login account, move to the next one.
+ if (account.account_id() != local_accounts.auto_login_id())
+ continue;
+
+ // If the auto-launched account is not a kiosk app, bail out, we aren't
+ // running in auto-launched kiosk mode.
+ if (account.type() !=
+ enterprise_management::DeviceLocalAccountInfoProto::
+ ACCOUNT_TYPE_KIOSK_APP) {
+ return false;
+ }
+
+ *app_id_out = account.kiosk_app().app_id();
+ return true;
+ }
+
+ // No auto-launched account found.
+ return false;
+}
+
bool DevicePolicyImpl::VerifyPolicyFiles() {
// Both the policy and its signature have to exist.
if (!base::PathExists(policy_path_) || !base::PathExists(keyfile_path_)) {
diff --git a/policy/device_policy_impl.h b/policy/device_policy_impl.h
index db22475..da7626a 100644
--- a/policy/device_policy_impl.h
+++ b/policy/device_policy_impl.h
@@ -28,51 +28,54 @@ namespace policy {
class DevicePolicyImpl : public DevicePolicy {
public:
DevicePolicyImpl();
- virtual ~DevicePolicyImpl();
+ ~DevicePolicyImpl() override;
- virtual bool LoadPolicy();
- virtual bool GetPolicyRefreshRate(int* rate) const;
- virtual bool GetUserWhitelist(std::vector<std::string>* user_whitelist) const;
- virtual bool GetGuestModeEnabled(bool* guest_mode_enabled) const;
- virtual bool GetCameraEnabled(bool* camera_enabled) const;
- virtual bool GetShowUserNames(bool* show_user_names) const;
- virtual bool GetDataRoamingEnabled(bool* data_roaming_enabled) const;
- virtual bool GetAllowNewUsers(bool* allow_new_users) const;
- virtual bool GetMetricsEnabled(bool* metrics_enabled) const;
- virtual bool GetReportVersionInfo(bool* report_version_info) const;
- virtual bool GetReportActivityTimes(bool* report_activity_times) const;
- virtual bool GetReportBootMode(bool* report_boot_mode) const;
- virtual bool GetEphemeralUsersEnabled(bool* ephemeral_users_enabled) const;
- virtual bool GetReleaseChannel(std::string* release_channel) const;
- virtual bool GetReleaseChannelDelegated(
- bool* release_channel_delegated) const;
- virtual bool GetUpdateDisabled(bool* update_disabled) const;
- virtual bool GetTargetVersionPrefix(
- std::string* target_version_prefix) const;
- virtual bool GetScatterFactorInSeconds(
- int64_t* scatter_factor_in_seconds) const;
- virtual bool GetAllowedConnectionTypesForUpdate(
- std::set<std::string>* connection_types) const;
- virtual bool GetOpenNetworkConfiguration(
- std::string* open_network_configuration) const;
- virtual bool GetOwner(std::string* owner) const;
- virtual bool GetHttpDownloadsEnabled(bool* http_downloads_enabled) const;
- virtual bool GetAuP2PEnabled(bool* au_p2p_enabled) const;
- virtual bool GetAllowKioskAppControlChromeVersion(
- bool* allow_kiosk_app_control_chrome_version) const;
- virtual bool GetUsbDetachableWhitelist(
- std::vector<UsbDeviceId>* usb_whitelist) const;
+ bool LoadPolicy() override;
+ bool GetPolicyRefreshRate(int* rate) const override;
+ bool GetUserWhitelist(
+ std::vector<std::string>* user_whitelist) const override;
+ bool GetGuestModeEnabled(bool* guest_mode_enabled) const override;
+ bool GetCameraEnabled(bool* camera_enabled) const override;
+ bool GetShowUserNames(bool* show_user_names) const override;
+ bool GetDataRoamingEnabled(bool* data_roaming_enabled) const override;
+ bool GetAllowNewUsers(bool* allow_new_users) const override;
+ bool GetMetricsEnabled(bool* metrics_enabled) const override;
+ bool GetReportVersionInfo(bool* report_version_info) const override;
+ bool GetReportActivityTimes(bool* report_activity_times) const override;
+ bool GetReportBootMode(bool* report_boot_mode) const override;
+ bool GetEphemeralUsersEnabled(bool* ephemeral_users_enabled) const override;
+ bool GetReleaseChannel(std::string* release_channel) const override;
+ bool GetReleaseChannelDelegated(
+ bool* release_channel_delegated) const override;
+ bool GetUpdateDisabled(bool* update_disabled) const override;
+ bool GetTargetVersionPrefix(
+ std::string* target_version_prefix) const override;
+ bool GetScatterFactorInSeconds(
+ int64_t* scatter_factor_in_seconds) const override;
+ bool GetAllowedConnectionTypesForUpdate(
+ std::set<std::string>* connection_types) const override;
+ bool GetOpenNetworkConfiguration(
+ std::string* open_network_configuration) const override;
+ bool GetOwner(std::string* owner) const override;
+ bool GetHttpDownloadsEnabled(bool* http_downloads_enabled) const override;
+ bool GetAuP2PEnabled(bool* au_p2p_enabled) const override;
+ bool GetAllowKioskAppControlChromeVersion(
+ bool* allow_kiosk_app_control_chrome_version) const override;
+ bool GetUsbDetachableWhitelist(
+ std::vector<UsbDeviceId>* usb_whitelist) const override;
+ bool GetAutoLaunchedKioskAppId(
+ std::string* app_id_out) const override;
protected:
// Verifies that the policy files are owned by root and exist.
- virtual bool VerifyPolicyFiles();
+ bool VerifyPolicyFiles() override;
base::FilePath policy_path_;
base::FilePath keyfile_path_;
private:
// Verifies that the policy signature is correct.
- virtual bool VerifyPolicySignature();
+ bool VerifyPolicySignature() override;
enterprise_management::PolicyFetchResponse policy_;
enterprise_management::PolicyData policy_data_;
diff --git a/policy/mock_device_policy.h b/policy/mock_device_policy.h
index cabba91..23e8147 100644
--- a/policy/mock_device_policy.h
+++ b/policy/mock_device_policy.h
@@ -96,6 +96,7 @@ class MockDevicePolicy : public DevicePolicy {
bool(bool*)); // NOLINT(readability/function)
MOCK_CONST_METHOD1(GetUsbDetachableWhitelist,
bool(std::vector<DevicePolicy::UsbDeviceId>*));
+ MOCK_CONST_METHOD1(GetAutoLaunchedKioskAppId, bool(std::string*));
MOCK_METHOD0(VerifyPolicyFiles, bool(void));
MOCK_METHOD0(VerifyPolicySignature, bool(void));
diff --git a/policy/tests/libpolicy_unittest.cc b/policy/tests/libpolicy_unittest.cc
index 2946ee7..4b80e7a 100644
--- a/policy/tests/libpolicy_unittest.cc
+++ b/policy/tests/libpolicy_unittest.cc
@@ -162,6 +162,9 @@ TEST(PolicyTest, DevicePolicyAllSetTest) {
ASSERT_EQ(0x0403, list_device[1].vendor_id);
ASSERT_EQ(0x6001, list_device[1].product_id);
+ ASSERT_TRUE(policy.GetAutoLaunchedKioskAppId(&string_value));
+ ASSERT_EQ("my_kiosk_app", string_value);
+
// Reloading the protobuf should succeed.
ASSERT_TRUE(provider.Reload());
}
diff --git a/policy/tests/whitelist/owner.key b/policy/tests/whitelist/owner.key
index 352c42c..94ef466 100644
--- a/policy/tests/whitelist/owner.key
+++ b/policy/tests/whitelist/owner.key
Binary files differ
diff --git a/policy/tests/whitelist/policy_all b/policy/tests/whitelist/policy_all
index b2b8f10..ff197cd 100644
--- a/policy/tests/whitelist/policy_all
+++ b/policy/tests/whitelist/policy_all
Binary files differ
diff --git a/policy/tests/whitelist/policy_none b/policy/tests/whitelist/policy_none
index 5d1cf1f..7f250f6 100644
--- a/policy/tests/whitelist/policy_none
+++ b/policy/tests/whitelist/policy_none
Binary files differ