update_engine: Remove unused binder_service_brillo.*

Chrome OS is not using this class. Just remove it.

Also cleanup the use cases of USE_OMAHA and USE_BINDER. USE_OMAHA is
only used in Chrome OS, and USE_BINDER is only used in Android, So it
doesn't make sense to have USE_OMAHA macros inside USE_BINDER.

BUG=chromium:977320
TEST=unittest

Change-Id: I4e302273585b7e105b177da01fe6dab07ad41676
Reviewed-on: https://chromium-review.googlesource.com/1669973
Tested-by: Amin Hassani <ahassani@chromium.org>
Commit-Ready: Amin Hassani <ahassani@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Sen Jiang <senj@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index 3e54eef..2ee0b9e 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -69,7 +69,7 @@
     "__CHROMEOS__",
     "_FILE_OFFSET_BITS=64",
     "_POSIX_C_SOURCE=199309L",
-    "USE_BINDER=${use.binder}",
+    "USE_BINDER=0",
     "USE_DBUS=${use.dbus}",
     "USE_FEC=0",
     "USE_HWID_OVERRIDE=${use.hwid_override}",
diff --git a/binder_service_brillo.cc b/binder_service_brillo.cc
deleted file mode 100644
index cc74763..0000000
--- a/binder_service_brillo.cc
+++ /dev/null
@@ -1,247 +0,0 @@
-//
-// Copyright (C) 2015 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-#include "update_engine/binder_service_brillo.h"
-
-#include <base/bind.h>
-
-#include <binderwrapper/binder_wrapper.h>
-
-#include <utils/String16.h>
-#include <utils/StrongPointer.h>
-
-#include "update_engine/update_status_utils.h"
-
-using android::sp;
-using android::String16;
-using android::String8;
-using android::binder::Status;
-using android::brillo::IUpdateEngineStatusCallback;
-using android::brillo::ParcelableUpdateEngineStatus;
-using brillo::ErrorPtr;
-using std::string;
-using update_engine::UpdateEngineStatus;
-
-namespace chromeos_update_engine {
-
-namespace {
-string NormalString(const String16& in) {
-  return string{String8{in}.string()};
-}
-
-Status ToStatus(ErrorPtr* error) {
-  return Status::fromServiceSpecificError(
-      1, String8{error->get()->GetMessage().c_str()});
-}
-}  // namespace
-
-template <typename... Parameters, typename... Arguments>
-Status BinderUpdateEngineBrilloService::CallCommonHandler(
-    bool (UpdateEngineService::*Handler)(ErrorPtr*, Parameters...),
-    Arguments... arguments) {
-  ErrorPtr error;
-  if (((common_.get())->*Handler)(&error, arguments...))
-    return Status::ok();
-  return ToStatus(&error);
-}
-
-Status BinderUpdateEngineBrilloService::SetUpdateAttemptFlags(int flags) {
-  return CallCommonHandler(&UpdateEngineService::SetUpdateAttemptFlags, flags);
-}
-
-Status BinderUpdateEngineBrilloService::AttemptUpdate(
-    const String16& app_version,
-    const String16& omaha_url,
-    int flags,
-    bool* out_result) {
-  return CallCommonHandler(&UpdateEngineService::AttemptUpdate,
-                           NormalString(app_version),
-                           NormalString(omaha_url),
-                           flags,
-                           out_result);
-}
-
-Status BinderUpdateEngineBrilloService::AttemptRollback(bool powerwash) {
-  return CallCommonHandler(&UpdateEngineService::AttemptRollback, powerwash);
-}
-
-Status BinderUpdateEngineBrilloService::CanRollback(bool* out_can_rollback) {
-  return CallCommonHandler(&UpdateEngineService::CanRollback, out_can_rollback);
-}
-
-Status BinderUpdateEngineBrilloService::ResetStatus() {
-  return CallCommonHandler(&UpdateEngineService::ResetStatus);
-}
-
-Status BinderUpdateEngineBrilloService::GetStatus(
-    ParcelableUpdateEngineStatus* status) {
-  UpdateEngineStatus update_engine_status;
-  auto ret =
-      CallCommonHandler(&UpdateEngineService::GetStatus, &update_engine_status);
-
-  if (ret.isOk()) {
-    *status = ParcelableUpdateEngineStatus(update_engine_status);
-  }
-
-  return ret;
-}
-
-Status BinderUpdateEngineBrilloService::RebootIfNeeded() {
-  return CallCommonHandler(&UpdateEngineService::RebootIfNeeded);
-}
-
-Status BinderUpdateEngineBrilloService::SetChannel(
-    const String16& target_channel, bool powerwash) {
-  return CallCommonHandler(&UpdateEngineService::SetChannel,
-                           NormalString(target_channel),
-                           powerwash);
-}
-
-Status BinderUpdateEngineBrilloService::GetChannel(bool get_current_channel,
-                                                   String16* out_channel) {
-  string channel_string;
-  auto ret = CallCommonHandler(
-      &UpdateEngineService::GetChannel, get_current_channel, &channel_string);
-
-  *out_channel = String16(channel_string.c_str());
-  return ret;
-}
-
-Status BinderUpdateEngineBrilloService::SetCohortHint(
-    const String16& in_cohort_hint) {
-  return CallCommonHandler(&UpdateEngineService::SetCohortHint,
-                           NormalString(in_cohort_hint));
-}
-
-Status BinderUpdateEngineBrilloService::GetCohortHint(
-    String16* out_cohort_hint) {
-  string cohort_hint;
-  auto ret =
-      CallCommonHandler(&UpdateEngineService::GetCohortHint, &cohort_hint);
-
-  *out_cohort_hint = String16(cohort_hint.c_str());
-  return ret;
-}
-
-Status BinderUpdateEngineBrilloService::SetP2PUpdatePermission(bool enabled) {
-  return CallCommonHandler(&UpdateEngineService::SetP2PUpdatePermission,
-                           enabled);
-}
-
-Status BinderUpdateEngineBrilloService::GetP2PUpdatePermission(
-    bool* out_p2p_permission) {
-  return CallCommonHandler(&UpdateEngineService::GetP2PUpdatePermission,
-                           out_p2p_permission);
-}
-
-Status BinderUpdateEngineBrilloService::SetUpdateOverCellularPermission(
-    bool enabled) {
-  return CallCommonHandler(
-      &UpdateEngineService::SetUpdateOverCellularPermission, enabled);
-}
-
-Status BinderUpdateEngineBrilloService::SetUpdateOverCellularTarget(
-    const String16& target_version, int64_t target_size) {
-  return CallCommonHandler(&UpdateEngineService::SetUpdateOverCellularTarget,
-                           NormalString(target_version),
-                           target_size);
-}
-
-Status BinderUpdateEngineBrilloService::GetUpdateOverCellularPermission(
-    bool* out_cellular_permission) {
-  return CallCommonHandler(
-      &UpdateEngineService::GetUpdateOverCellularPermission,
-      out_cellular_permission);
-}
-
-Status BinderUpdateEngineBrilloService::GetDurationSinceUpdate(
-    int64_t* out_duration) {
-  return CallCommonHandler(&UpdateEngineService::GetDurationSinceUpdate,
-                           out_duration);
-}
-
-Status BinderUpdateEngineBrilloService::GetPrevVersion(
-    String16* out_prev_version) {
-  string version_string;
-  auto ret =
-      CallCommonHandler(&UpdateEngineService::GetPrevVersion, &version_string);
-
-  *out_prev_version = String16(version_string.c_str());
-  return ret;
-}
-
-Status BinderUpdateEngineBrilloService::GetRollbackPartition(
-    String16* out_rollback_partition) {
-  string partition_string;
-  auto ret = CallCommonHandler(&UpdateEngineService::GetRollbackPartition,
-                               &partition_string);
-
-  if (ret.isOk()) {
-    *out_rollback_partition = String16(partition_string.c_str());
-  }
-
-  return ret;
-}
-
-Status BinderUpdateEngineBrilloService::RegisterStatusCallback(
-    const sp<IUpdateEngineStatusCallback>& callback) {
-  callbacks_.emplace_back(callback);
-
-  auto binder_wrapper = android::BinderWrapper::Get();
-
-  binder_wrapper->RegisterForDeathNotifications(
-      IUpdateEngineStatusCallback::asBinder(callback),
-      base::Bind(&BinderUpdateEngineBrilloService::UnregisterStatusCallback,
-                 base::Unretained(this),
-                 base::Unretained(callback.get())));
-
-  return Status::ok();
-}
-
-Status BinderUpdateEngineBrilloService::GetLastAttemptError(
-    int* out_last_attempt_error) {
-  return CallCommonHandler(&UpdateEngineService::GetLastAttemptError,
-                           out_last_attempt_error);
-}
-
-Status BinderUpdateEngineBrilloService::GetEolStatus(int* out_eol_status) {
-  return CallCommonHandler(&UpdateEngineService::GetEolStatus, out_eol_status);
-}
-
-void BinderUpdateEngineBrilloService::UnregisterStatusCallback(
-    IUpdateEngineStatusCallback* callback) {
-  auto it = callbacks_.begin();
-  while (it != callbacks_.end() && it->get() != callback)
-    it++;
-
-  if (it == callbacks_.end()) {
-    LOG(ERROR) << "Got death notification for unknown callback.";
-    return;
-  }
-
-  LOG(INFO) << "Erasing orphan callback";
-  callbacks_.erase(it);
-}
-
-void BinderUpdateEngineBrilloService::SendStatusUpdate(
-    const UpdateEngineStatus& update_engine_status) {
-  ParcelableUpdateEngineStatus parcelable_status(update_engine_status);
-  for (auto& callback : callbacks_) {
-    callback->HandleStatusUpdate(parcelable_status);
-  }
-}
-
-}  // namespace chromeos_update_engine
diff --git a/binder_service_brillo.h b/binder_service_brillo.h
deleted file mode 100644
index d0d0dc9..0000000
--- a/binder_service_brillo.h
+++ /dev/null
@@ -1,114 +0,0 @@
-//
-// Copyright (C) 2016 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-#ifndef UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_
-#define UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_
-
-#include <utils/Errors.h>
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include <utils/RefBase.h>
-
-#include "update_engine/common_service.h"
-#include "update_engine/parcelable_update_engine_status.h"
-#include "update_engine/service_observer_interface.h"
-
-#include "android/brillo/BnUpdateEngine.h"
-#include "android/brillo/IUpdateEngineStatusCallback.h"
-
-namespace chromeos_update_engine {
-
-class BinderUpdateEngineBrilloService : public android::brillo::BnUpdateEngine,
-                                        public ServiceObserverInterface {
- public:
-  explicit BinderUpdateEngineBrilloService(SystemState* system_state)
-      : common_(new UpdateEngineService(system_state)) {}
-  virtual ~BinderUpdateEngineBrilloService() = default;
-
-  const char* ServiceName() const {
-    return "android.brillo.UpdateEngineService";
-  }
-
-  // ServiceObserverInterface overrides.
-  void SendStatusUpdate(
-      const update_engine::UpdateEngineStatus& update_engine_status) override;
-  void SendPayloadApplicationComplete(ErrorCode error_code) override {}
-
-  // android::brillo::BnUpdateEngine overrides.
-  android::binder::Status SetUpdateAttemptFlags(int flags) override;
-  android::binder::Status AttemptUpdate(const android::String16& app_version,
-                                        const android::String16& omaha_url,
-                                        int flags,
-                                        bool* out_result) override;
-  android::binder::Status AttemptRollback(bool powerwash) override;
-  android::binder::Status CanRollback(bool* out_can_rollback) override;
-  android::binder::Status ResetStatus() override;
-  android::binder::Status GetStatus(
-      android::brillo::ParcelableUpdateEngineStatus* status);
-  android::binder::Status RebootIfNeeded() override;
-  android::binder::Status SetChannel(const android::String16& target_channel,
-                                     bool powerwash) override;
-  android::binder::Status GetChannel(bool get_current_channel,
-                                     android::String16* out_channel) override;
-  android::binder::Status SetCohortHint(
-      const android::String16& cohort_hint) override;
-  android::binder::Status GetCohortHint(
-      android::String16* out_cohort_hint) override;
-  android::binder::Status SetP2PUpdatePermission(bool enabled) override;
-  android::binder::Status GetP2PUpdatePermission(
-      bool* out_p2p_permission) override;
-  android::binder::Status SetUpdateOverCellularPermission(
-      bool enabled) override;
-  android::binder::Status SetUpdateOverCellularTarget(
-      const android::String16& target_version, int64_t target_size) override;
-  android::binder::Status GetUpdateOverCellularPermission(
-      bool* out_cellular_permission) override;
-  android::binder::Status GetDurationSinceUpdate(
-      int64_t* out_duration) override;
-  android::binder::Status GetPrevVersion(
-      android::String16* out_prev_version) override;
-  android::binder::Status GetRollbackPartition(
-      android::String16* out_rollback_partition) override;
-  android::binder::Status RegisterStatusCallback(
-      const android::sp<android::brillo::IUpdateEngineStatusCallback>& callback)
-      override;
-  android::binder::Status GetLastAttemptError(
-      int* out_last_attempt_error) override;
-  android::binder::Status GetEolStatus(int* out_eol_status) override;
-
- private:
-  // Generic function for dispatching to the common service.
-  template <typename... Parameters, typename... Arguments>
-  android::binder::Status CallCommonHandler(
-      bool (UpdateEngineService::*Handler)(brillo::ErrorPtr*, Parameters...),
-      Arguments... arguments);
-
-  // To be used as a death notification handler only.
-  void UnregisterStatusCallback(
-      android::brillo::IUpdateEngineStatusCallback* callback);
-
-  std::unique_ptr<UpdateEngineService> common_;
-
-  std::vector<android::sp<android::brillo::IUpdateEngineStatusCallback>>
-      callbacks_;
-};
-
-}  // namespace chromeos_update_engine
-
-#endif  // UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_
diff --git a/daemon.cc b/daemon.cc
index d42344a..f370564 100644
--- a/daemon.cc
+++ b/daemon.cc
@@ -64,12 +64,8 @@
 
 #if USE_BINDER
   // Create the Binder Service.
-#if USE_OMAHA
-  binder_service_ = new BinderUpdateEngineBrilloService{real_system_state};
-#else   // !USE_OMAHA
   binder_service_ = new BinderUpdateEngineAndroidService{
       daemon_state_android->service_delegate()};
-#endif  // USE_OMAHA
   auto binder_wrapper = android::BinderWrapper::Get();
   if (!binder_wrapper->RegisterService(binder_service_->ServiceName(),
                                        binder_service_)) {
diff --git a/daemon.h b/daemon.h
index c10bb28..3c896bc 100644
--- a/daemon.h
+++ b/daemon.h
@@ -26,11 +26,7 @@
 #include <brillo/daemons/daemon.h>
 
 #if USE_BINDER
-#if USE_OMAHA
-#include "update_engine/binder_service_brillo.h"
-#else  // !USE_OMAHA
 #include "update_engine/binder_service_android.h"
-#endif  // USE_OMAHA
 #endif  // USE_BINDER
 #include "update_engine/common/subprocess.h"
 #include "update_engine/daemon_state_interface.h"
@@ -65,14 +61,7 @@
 
 #if USE_BINDER
   brillo::BinderWatcher binder_watcher_;
-#endif  // USE_BINDER
-
-#if USE_BINDER
-#if USE_OMAHA
-  android::sp<BinderUpdateEngineBrilloService> binder_service_;
-#else  // !USE_OMAHA
   android::sp<BinderUpdateEngineAndroidService> binder_service_;
-#endif  // USE_OMAHA
 #endif  // USE_BINDER
 
   // The daemon state with all the required daemon classes for the configured