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_unittest.cc b/connection_manager_unittest.cc
index e6a2ef4..724061b 100644
--- a/connection_manager_unittest.cc
+++ b/connection_manager_unittest.cc
@@ -201,7 +201,7 @@
.Times(1)
.WillOnce(Return(&allow_3g_policy));
- // This test tests 3G being the only connection type being allowed.
+ // This test tests cellular (3G) being the only connection type being allowed.
set<string> allowed_set;
allowed_set.insert(cmut_.StringForConnectionType(kNetCellular));
@@ -220,20 +220,24 @@
.WillOnce(Return(&allow_3g_policy));
// This test tests multiple connection types being allowed, with
- // 3G one among them.
+ // 3G one among them. Only Cellular is currently enforced by the policy
+ // setting, the others are ignored (see Bluetooth for example).
set<string> allowed_set;
- allowed_set.insert(cmut_.StringForConnectionType(kNetEthernet));
allowed_set.insert(cmut_.StringForConnectionType(kNetCellular));
- allowed_set.insert(cmut_.StringForConnectionType(kNetWifi));
+ allowed_set.insert(cmut_.StringForConnectionType(kNetBluetooth));
EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
.Times(1)
.WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(true)));
+ EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet));
EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular));
+ EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi));
+ EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWimax));
+ EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetBluetooth));
}
-TEST_F(ConnectionManagerTest, BlockUpdatesOver3GByDefaultTest) {
+TEST_F(ConnectionManagerTest, BlockUpdatesOverCellularByDefaultTest) {
EXPECT_CALL(mock_system_state_, device_policy()).Times(1);
EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular));
}
@@ -279,6 +283,44 @@
EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular));
}
+TEST_F(ConnectionManagerTest, UseUserPrefForUpdatesOverCellularIfNoPolicyTest) {
+ policy::MockDevicePolicy no_policy;
+ testing::NiceMock<PrefsMock>* prefs = mock_system_state_.mock_prefs();
+
+ EXPECT_CALL(mock_system_state_, device_policy())
+ .Times(3)
+ .WillRepeatedly(Return(&no_policy));
+
+ // No setting enforced by the device policy, user prefs should be used.
+ EXPECT_CALL(no_policy, GetAllowedConnectionTypesForUpdate(_))
+ .Times(3)
+ .WillRepeatedly(Return(false));
+
+ // No user pref: block.
+ EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
+ .Times(1)
+ .WillOnce(Return(false));
+ EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular));
+
+ // Allow per user pref.
+ EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
+ .Times(1)
+ .WillOnce(Return(true));
+ EXPECT_CALL(*prefs, GetInt64(kPrefsUpdateOverCellularPermission, _))
+ .Times(1)
+ .WillOnce(DoAll(SetArgumentPointee<1>(1), Return(true)));
+ EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular));
+
+ // Block per user pref.
+ EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
+ .Times(1)
+ .WillOnce(Return(true));
+ EXPECT_CALL(*prefs, GetInt64(kPrefsUpdateOverCellularPermission, _))
+ .Times(1)
+ .WillOnce(DoAll(SetArgumentPointee<1>(0), Return(true)));
+ EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular));
+}
+
TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) {
EXPECT_STREQ(flimflam::kTypeEthernet,
cmut_.StringForConnectionType(kNetEthernet));