Revert "Add functions to allow update over cellular (including tethered connection)"

This reverts commit 4b0d6032cbb86ce488c03b31936cda31283f97e3.

Bug: 62366504
Test: GmsCore sees the old status code (i.e. UPDATED_NEED_REBOOT == 6).
Change-Id: I9185614a41bd621ad85e7f773b0f96919b0f70d5
diff --git a/common_service.cc b/common_service.cc
index ee890e1..1a41b63 100644
--- a/common_service.cc
+++ b/common_service.cc
@@ -16,6 +16,7 @@
 
 #include "update_engine/common_service.h"
 
+#include <set>
 #include <string>
 
 #include <base/location.h>
@@ -40,6 +41,7 @@
 using base::StringPrintf;
 using brillo::ErrorPtr;
 using brillo::string_utils::ToString;
+using std::set;
 using std::string;
 
 namespace chromeos_update_engine {
@@ -246,12 +248,24 @@
 
 bool UpdateEngineService::SetUpdateOverCellularPermission(ErrorPtr* error,
                                                           bool in_allowed) {
-  ConnectionManagerInterface* connection_manager =
-      system_state_->connection_manager();
+  set<string> allowed_types;
+  const policy::DevicePolicy* device_policy = system_state_->device_policy();
+
+  // The device_policy is loaded in a lazy way before an update check. Load it
+  // now from the libbrillo cache if it wasn't already loaded.
+  if (!device_policy) {
+    UpdateAttempter* update_attempter = system_state_->update_attempter();
+    if (update_attempter) {
+      update_attempter->RefreshDevicePolicy();
+      device_policy = system_state_->device_policy();
+    }
+  }
 
   // Check if this setting is allowed by the device policy.
-  if (connection_manager->IsAllowedConnectionTypesForUpdateSet()) {
-    LogAndSetError(error, FROM_HERE,
+  if (device_policy &&
+      device_policy->GetAllowedConnectionTypesForUpdate(&allowed_types)) {
+    LogAndSetError(error,
+                   FROM_HERE,
                    "Ignoring the update over cellular setting since there's "
                    "a device policy enforcing this setting.");
     return false;
@@ -262,9 +276,9 @@
 
   PrefsInterface* prefs = system_state_->prefs();
 
-  if (!prefs ||
-      !prefs->SetBoolean(kPrefsUpdateOverCellularPermission, in_allowed)) {
-    LogAndSetError(error, FROM_HERE,
+  if (!prefs->SetBoolean(kPrefsUpdateOverCellularPermission, in_allowed)) {
+    LogAndSetError(error,
+                   FROM_HERE,
                    string("Error setting the update over cellular to ") +
                        (in_allowed ? "true" : "false"));
     return false;
@@ -272,63 +286,24 @@
   return true;
 }
 
-bool UpdateEngineService::SetUpdateOverCellularTarget(
-    brillo::ErrorPtr* error, const std::string &target_version,
-    int64_t target_size) {
-  ConnectionManagerInterface* connection_manager =
-      system_state_->connection_manager();
-
-  // Check if this setting is allowed by the device policy.
-  if (connection_manager->IsAllowedConnectionTypesForUpdateSet()) {
-    LogAndSetError(error, FROM_HERE,
-                   "Ignoring the update over cellular setting since there's "
-                   "a device policy enforcing this setting.");
-    return false;
-  }
-
-  // If the policy wasn't loaded yet, then it is still OK to change the local
-  // setting because the policy will be checked again during the update check.
-
-  PrefsInterface* prefs = system_state_->prefs();
-
-  if (!prefs ||
-      !prefs->SetString(kPrefsUpdateOverCellularTargetVersion,
-                        target_version) ||
-      !prefs->SetInt64(kPrefsUpdateOverCellularTargetSize, target_size)) {
-    LogAndSetError(error, FROM_HERE,
-                   "Error setting the target for update over cellular.");
-    return false;
-  }
-  return true;
-}
-
-bool UpdateEngineService::GetUpdateOverCellularPermission(ErrorPtr* error,
+bool UpdateEngineService::GetUpdateOverCellularPermission(ErrorPtr* /* error */,
                                                           bool* out_allowed) {
-  ConnectionManagerInterface* connection_manager =
-      system_state_->connection_manager();
+  ConnectionManagerInterface* cm = system_state_->connection_manager();
 
-  if (connection_manager->IsAllowedConnectionTypesForUpdateSet()) {
-    // We have device policy, so ignore the user preferences.
-    *out_allowed = connection_manager->IsUpdateAllowedOver(
-        ConnectionType::kCellular, ConnectionTethering::kUnknown);
-  } else {
-    PrefsInterface* prefs = system_state_->prefs();
-
-    if (!prefs || !prefs->Exists(kPrefsUpdateOverCellularPermission)) {
-      // Update is not allowed as user preference is not set or not available.
-      *out_allowed = false;
-      return true;
-    }
-
-    bool is_allowed;
-
-    if (!prefs->GetBoolean(kPrefsUpdateOverCellularPermission, &is_allowed)) {
-      LogAndSetError(error, FROM_HERE,
-                     "Error getting the update over cellular preference.");
-      return false;
-    }
-    *out_allowed = is_allowed;
+  // The device_policy is loaded in a lazy way before an update check and is
+  // used to determine if an update is allowed over cellular. Load the device
+  // policy now from the libbrillo cache if it wasn't already loaded.
+  if (!system_state_->device_policy()) {
+    UpdateAttempter* update_attempter = system_state_->update_attempter();
+    if (update_attempter)
+      update_attempter->RefreshDevicePolicy();
   }
+
+  // Return the current setting based on the same logic used while checking for
+  // updates. A log message could be printed as the result of this test.
+  LOG(INFO) << "Checking if updates over cellular networks are allowed:";
+  *out_allowed = cm->IsUpdateAllowedOver(ConnectionType::kCellular,
+                                         ConnectionTethering::kUnknown);
   return true;
 }