Add DBus methods to allow/disallow updates over 3G
This fix adds a new DBus pair of methods to allow/disallow the
updates over cellular networks and get the current state of this
setting. The setting is overridden by the device policy and the
SetUpdateOverCellularPermission() method fails if called on an
enrolled device that has the autoupdate settings in the device
policy.
BUG=chromium:213401
TEST=unittests for connection_manager changes. Manual test for the DBus service, see below.
Manual test procedure.
======================
Run on a shell:
1. Test for the default setting.
$ update_engine_client -show_update_over_cellular
[0701/183633:INFO:update_engine_client.cc(371)] Current update over cellular network setting: DISABLED
[0701/183633:INFO:update_engine_client.cc(443)] Done.
2. Test that enable works.
$ update_engine_client -update_over_cellular=yes -show_update_over_cellular
[0701/183655:INFO:update_engine_client.cc(371)] Current update over cellular network setting: ENABLED
[0701/183655:INFO:update_engine_client.cc(443)] Done.
3. Test that disable works.
$ update_engine_client -update_over_cellular=no -show_update_over_cellular
[0701/183659:INFO:update_engine_client.cc(371)] Current update over cellular network setting: DISABLED
[0701/183659:INFO:update_engine_client.cc(443)] Done.
4. Enable again the update over cellular, connect the chromebook to a 3G
and perform an update check.
Change-Id: Ic234a3ef8898b1e60e26277208276a958b7e0d94
Reviewed-on: https://gerrit.chromium.org/gerrit/60716
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/connection_manager.cc b/connection_manager.cc
index 3044130..185f3b5 100644
--- a/connection_manager.cc
+++ b/connection_manager.cc
@@ -12,6 +12,7 @@
#include <dbus/dbus-glib.h>
#include <glib.h>
+#include "update_engine/prefs.h"
#include "update_engine/system_state.h"
#include "update_engine/utils.h"
@@ -158,26 +159,51 @@
set<string> allowed_types;
const policy::DevicePolicy* device_policy =
system_state_->device_policy();
+
+ // A device_policy is loaded in a lazy way right before an update check,
+ // so the device_policy should be already loaded at this point. If it's
+ // not, return a safe value for this setting.
if (!device_policy) {
- LOG(INFO) << "Disabling updates over cellular connection as there's no "
- "device policy object present";
+ LOG(INFO) << "Disabling updates over cellular networks as there's no "
+ "device policy loaded yet.";
return false;
}
- if (!device_policy->GetAllowedConnectionTypesForUpdate(&allowed_types)) {
- LOG(INFO) << "Disabling updates over cellular connection as there's no "
- "allowed connection types from policy";
- return false;
- }
+ if (device_policy->GetAllowedConnectionTypesForUpdate(&allowed_types)) {
+ // The update setting is enforced by the device policy.
- if (!ContainsKey(allowed_types, flimflam::kTypeCellular)) {
- LOG(INFO) << "Disabling updates over cellular connection as it's not "
- "allowed in the device policy.";
- return false;
- }
+ if ((type == kNetCellular &&
+ !ContainsKey(allowed_types, flimflam::kTypeCellular))) {
+ LOG(INFO) << "Disabling updates over cellular connection as it's not "
+ "allowed in the device policy.";
+ return false;
+ }
- LOG(INFO) << "Allowing updates over cellular per device policy";
- return true;
+ LOG(INFO) << "Allowing updates over cellular per device policy.";
+ return true;
+ } else {
+ // There's no update setting in the device policy, using the local user
+ // setting.
+ PrefsInterface* prefs = system_state_->prefs();
+
+ if (!prefs || !prefs->Exists(kPrefsUpdateOverCellularPermission)) {
+ LOG(INFO) << "Disabling updates over cellular connection as there's "
+ "no device policy setting nor user preference present.";
+ return false;
+ }
+
+ int64_t stored_value;
+ if (!prefs->GetInt64(kPrefsUpdateOverCellularPermission, &stored_value))
+ return false;
+
+ if (!stored_value) {
+ LOG(INFO) << "Disabling updates over cellular connection per user "
+ "setting.";
+ return false;
+ }
+ LOG(INFO) << "Allowing updates over cellular per user setting.";
+ return true;
+ }
}
default: