aboutsummaryrefslogtreecommitdiffstats
path: root/policy/libpolicy.cc
diff options
context:
space:
mode:
authorSen Jiang <senj@google.com>2018-08-09 16:52:23 -0700
committerSen Jiang <senj@google.com>2018-08-10 11:07:06 -0700
commit0fa01c38cc2beff8d7e11e4b512692ecdb640ca8 (patch)
tree279e9e692e3a7db704f65e6d3977e43e8e75b46a /policy/libpolicy.cc
parentb5f20f52ab0885f1676b1c2024df541b3e6cc5f5 (diff)
parent904c2c9cd8d5ff06783030fb27ee23dcff743035 (diff)
downloadplatform_external_libbrillo-0fa01c38cc2beff8d7e11e4b512692ecdb640ca8.tar.gz
platform_external_libbrillo-0fa01c38cc2beff8d7e11e4b512692ecdb640ca8.tar.bz2
platform_external_libbrillo-0fa01c38cc2beff8d7e11e4b512692ecdb640ca8.zip
Merge remote-tracking branch 'aosp/upstream-master' into aosp/master.android-o-mr1-iot-release-1.0.4
Merge Chromium ToT to AOSP: git fetch aosp upstream-master git merge -X patience aosp/upstream-master Bug: 112326236 Test: libbrillo_test Change-Id: I35fbbddad556b051ce12b9cdd95bb2afef3cf6af
Diffstat (limited to 'policy/libpolicy.cc')
-rw-r--r--policy/libpolicy.cc48
1 files changed, 40 insertions, 8 deletions
diff --git a/policy/libpolicy.cc b/policy/libpolicy.cc
index 99fa46d..a0b7640 100644
--- a/policy/libpolicy.cc
+++ b/policy/libpolicy.cc
@@ -4,6 +4,8 @@
#include "policy/libpolicy.h"
+#include <memory>
+
#include <base/logging.h>
#include "policy/device_policy.h"
@@ -13,17 +15,23 @@
namespace policy {
-PolicyProvider::PolicyProvider()
- : device_policy_(nullptr),
- device_policy_is_loaded_(false) {
+PolicyProvider::PolicyProvider() {
#ifndef __ANDROID__
- device_policy_.reset(new DevicePolicyImpl());
+ device_policy_ = std::make_unique<DevicePolicyImpl>();
+ install_attributes_reader_ = std::make_unique<InstallAttributesReader>();
#endif
}
PolicyProvider::PolicyProvider(std::unique_ptr<DevicePolicy> device_policy)
: device_policy_(std::move(device_policy)),
- device_policy_is_loaded_(true) {}
+#ifdef __ANDROID__
+ device_policy_is_loaded_(true) {
+}
+#else
+ device_policy_is_loaded_(true),
+ install_attributes_reader_(std::make_unique<InstallAttributesReader>()) {
+}
+#endif // __ANDROID__
PolicyProvider::~PolicyProvider() {}
@@ -42,10 +50,34 @@ bool PolicyProvider::device_policy_is_loaded() const {
}
const DevicePolicy& PolicyProvider::GetDevicePolicy() const {
- if (!device_policy_is_loaded_)
- DCHECK("Trying to get policy data but policy was not loaded!");
-
+ DCHECK(device_policy_is_loaded_)
+ << "Trying to get policy data but policy was not loaded!";
return *device_policy_;
}
+bool PolicyProvider::IsConsumerDevice() const {
+#ifdef __ANDROID__
+ return true;
+#else
+ if (!install_attributes_reader_->IsLocked())
+ return false;
+
+ const std::string& device_mode = install_attributes_reader_->GetAttribute(
+ InstallAttributesReader::kAttrMode);
+ return device_mode != InstallAttributesReader::kDeviceModeEnterprise &&
+ device_mode != InstallAttributesReader::kDeviceModeEnterpriseAD;
+#endif // __ANDROID__
+}
+
+void PolicyProvider::SetDevicePolicyForTesting(
+ std::unique_ptr<DevicePolicy> device_policy) {
+ device_policy_ = std::move(device_policy);
+ device_policy_is_loaded_ = true;
+}
+
+void PolicyProvider::SetInstallAttributesReaderForTesting(
+ std::unique_ptr<InstallAttributesReader> install_attributes_reader) {
+ install_attributes_reader_ = std::move(install_attributes_reader);
+}
+
} // namespace policy