Commit 9ea0532d authored by Azeem Arshad's avatar Azeem Arshad Committed by Commit Bot

[CrOS Cellular] Add Hermes Euicc dbus client.

The hermes DBus API is is changing in https://crrev.com/c/2276588.
This change essentially moves all methods from the manager interface
into a new Euicc interface. Each Euicc object corresponds to an euicc
hardware available on the device. The main manager object now simply
holds list of available euiccs.

Bug: 1093185
Change-Id: Ib0b668cf47a9b8c3fb3016847d59024492443d73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2303285
Commit-Queue: Azeem Arshad <azeemarshad@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#793249}
parent 208e0ec6
......@@ -21,6 +21,8 @@ source_set("hermes_clients") {
sources = [
"hermes_clients.cc",
"hermes_clients.h",
"hermes_euicc_client.cc",
"hermes_euicc_client.h",
"hermes_manager_client.cc",
"hermes_manager_client.h",
"hermes_profile_client.cc",
......@@ -40,6 +42,8 @@ source_set("hermes_fakes") {
]
sources = [
"fake_hermes_euicc_client.cc",
"fake_hermes_euicc_client.h",
"fake_hermes_manager_client.cc",
"fake_hermes_manager_client.h",
"fake_hermes_profile_client.cc",
......@@ -64,7 +68,7 @@ source_set("test_support") {
sources = [
"hermes_client_test_base.cc",
"hermes_client_test_base.h",
"hermes_manager_client_unittest.cc",
"hermes_euicc_client_unittest.cc",
"hermes_profile_client_unittest.cc",
"hermes_test_utils.cc",
"hermes_test_utils.h",
......
This diff is collapsed.
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_DBUS_HERMES_FAKE_HERMES_EUICC_CLIENT_H_
#define CHROMEOS_DBUS_HERMES_FAKE_HERMES_EUICC_CLIENT_H_
#include "base/component_export.h"
#include "base/macros.h"
#include "chromeos/dbus/hermes/hermes_euicc_client.h"
#include "third_party/cros_system_api/dbus/hermes/dbus-constants.h"
namespace chromeos {
// Fake implementation for HermesEuiccClient. This class also interacts with
// fake shill clients to setup fake cellular services corresponding to eSIM
// profiles.
class COMPONENT_EXPORT(HERMES_CLIENT) FakeHermesEuiccClient
: public HermesEuiccClient,
public HermesEuiccClient::TestInterface {
public:
class Properties : public HermesEuiccClient::Properties {
public:
explicit Properties(const PropertyChangedCallback& callback);
~Properties() override;
// dbus::PropertySet:
void Get(dbus::PropertyBase* property,
dbus::PropertySet::GetCallback callback) override;
void GetAll() override;
void Set(dbus::PropertyBase* property,
dbus::PropertySet::SetCallback callback) override;
};
FakeHermesEuiccClient();
FakeHermesEuiccClient(const FakeHermesEuiccClient&) = delete;
FakeHermesEuiccClient& operator=(const FakeHermesEuiccClient&) = delete;
~FakeHermesEuiccClient() override;
// HermesEuiccClient::TestInterface:
dbus::ObjectPath AddFakeCarrierProfile(const dbus::ObjectPath& euicc_path,
hermes::profile::State state,
std::string activation_code) override;
void AddCarrierProfile(const dbus::ObjectPath& path,
const dbus::ObjectPath& euicc_path,
const std::string& iccid,
const std::string& name,
const std::string& service_provider,
const std::string& activation_code,
const std::string& network_service_path,
hermes::profile::State state) override;
// HermesEuiccClient:
void InstallProfileFromActivationCode(
const dbus::ObjectPath& euicc_path,
const std::string& activation_code,
const std::string& confirmation_code,
InstallCarrierProfileCallback callback) override;
void InstallPendingProfile(const dbus::ObjectPath& euicc_path,
const dbus::ObjectPath& carrier_profile_path,
const std::string& confirmation_code,
HermesResponseCallback callback) override;
void RequestPendingEvents(const dbus::ObjectPath& euicc_path,
HermesResponseCallback callback) override;
void UninstallProfile(const dbus::ObjectPath& euicc_path,
const dbus::ObjectPath& carrier_profile_path,
HermesResponseCallback callback) override;
Properties* GetProperties(const dbus::ObjectPath& euicc_path) override;
HermesEuiccClient::TestInterface* GetTestInterface() override;
private:
void DoInstallProfileFromActivationCode(
const dbus::ObjectPath& euicc_path,
const std::string& activation_code,
const std::string& confirmation_code,
InstallCarrierProfileCallback callback);
void DoInstallPendingProfile(const dbus::ObjectPath& euicc_path,
const dbus::ObjectPath& carrier_profile_path,
const std::string& confirmation_code,
HermesResponseCallback callback);
void DoRequestPendingEvents(const dbus::ObjectPath& euicc_path,
HermesResponseCallback callback);
void DoUninstallProfile(const dbus::ObjectPath& euicc_path,
const dbus::ObjectPath& carrier_profile_path,
HermesResponseCallback callback);
dbus::ObjectPath AddFakeCarrierProfile(hermes::profile::State state,
std::string activation_code);
void CreateCellularService(const dbus::ObjectPath& carrier_profile_path);
void RemoveCellularService(const dbus::ObjectPath& carrier_profile_path);
void CallNotifyPropertyChanged(const dbus::ObjectPath& object_path,
const std::string& property_name);
void NotifyPropertyChanged(const dbus::ObjectPath& object_path,
const std::string& property_name);
// Indicates whether a pending event request has already been made.
bool pending_event_requested_ = false;
// Counter to generate fake ids and properties for profiles.
int fake_profile_counter_ = 0;
// Mapping between carrier profile objects and their corresponding
// shill network service paths.
std::map<dbus::ObjectPath, std::string> profile_service_path_map_;
using PropertiesMap =
std::map<const dbus::ObjectPath, std::unique_ptr<Properties>>;
PropertiesMap properties_map_;
base::WeakPtrFactory<FakeHermesEuiccClient> weak_ptr_factory_{this};
};
} // namespace chromeos
#endif // CHROMEOS_DBUS_HERMES_FAKE_HERMES_EUICC_CLIENT_H_
......@@ -5,8 +5,6 @@
#ifndef CHROMEOS_DBUS_HERMES_FAKE_HERMES_MANAGER_CLIENT_H_
#define CHROMEOS_DBUS_HERMES_FAKE_HERMES_MANAGER_CLIENT_H_
#include <set>
#include "base/component_export.h"
#include "base/macros.h"
#include "chromeos/dbus/hermes/hermes_manager_client.h"
......@@ -14,75 +12,33 @@
namespace chromeos {
// Fake implementation for HermesManagerClient. This class interacts with
// FakeHermesDeviceClient and FakeShillManagerClient to setup stub carrier
// profile objects and corresponding network services.
// Fake implementation for HermesManagerClient.
class COMPONENT_EXPORT(HERMES_CLIENT) FakeHermesManagerClient
: public HermesManagerClient,
public HermesManagerClient::TestInterface {
public:
FakeHermesManagerClient();
FakeHermesManagerClient(const FakeHermesManagerClient&) = delete;
FakeHermesManagerClient& operator=(const FakeHermesManagerClient&) = delete;
~FakeHermesManagerClient() override;
// HermesManagerClient::TestInterface:
void AddCarrierProfile(const dbus::ObjectPath& path,
const std::string& iccid,
const std::string& name,
const std::string& service_provider,
const std::string& activation_code,
const std::string& network_service_path,
hermes::profile::State state) override;
void AddEuicc(const dbus::ObjectPath& path,
const std::string& eid,
bool is_active) override;
// HermesManagerClient:
void InstallProfileFromActivationCode(
const std::string& activation_code,
const std::string& confirmation_code,
InstallCarrierProfileCallback callback) override;
void InstallPendingProfile(const dbus::ObjectPath& carrier_profile_path,
const std::string& confirmation_code,
InstallCarrierProfileCallback callback) override;
void RequestPendingEvents(HermesResponseCallback callback) override;
void UninstallProfile(const dbus::ObjectPath& carrier_profile_path,
HermesResponseCallback callback) override;
const std::vector<dbus::ObjectPath>& GetInstalledCarrierProfiles() override;
const std::vector<dbus::ObjectPath>& GetPendingCarrierProfiles() override;
const std::vector<dbus::ObjectPath>& GetAvailableEuiccs() override;
HermesManagerClient::TestInterface* GetTestInterface() override;
FakeHermesManagerClient& operator=(const FakeHermesManagerClient&) = delete;
private:
dbus::ObjectPath AddFakeCarrierProfile(hermes::profile::State state,
std::string activation_code);
void ParseCommandLineSwitch();
bool PopPendingProfile(dbus::ObjectPath carrier_profile_path);
dbus::ObjectPath PopPendingProfileWithActivationCode(
const std::string& activation_code);
void CreateCellularService(const dbus::ObjectPath& carrier_profile_path);
void RemoveCellularService(const dbus::ObjectPath& carrier_profile_path);
void CallNotifyInstalledCarrierProfileListChanged();
void CallNotifyPendingCarrierProfileListChanged();
void NotifyInstalledCarrierProfileListChanged();
void NotifyPendingCarrierProfileListChanged();
// Indicates whether a pending event request has already been made.
bool pending_event_requested_ = false;
int fake_profile_counter_ = 0;
void NotifyAvailableEuiccListChanged();
// Mapping between carrier profile objects and their corresponding
// shill network service paths.
std::map<dbus::ObjectPath, std::string> profile_service_path_map_;
// List of paths to available and euicc objects.
std::vector<dbus::ObjectPath> available_euiccs_;
// List of paths to installed and pending profile objects.
std::vector<dbus::ObjectPath> installed_profiles_;
std::vector<dbus::ObjectPath> pending_profiles_;
base::WeakPtrFactory<FakeHermesManagerClient> weak_ptr_factory_{this};
};
} // namespace chromeos
......
......@@ -53,7 +53,7 @@ void FakeHermesProfileClient::Properties::Set(
}
}
FakeHermesProfileClient::FakeHermesProfileClient() {}
FakeHermesProfileClient::FakeHermesProfileClient() = default;
FakeHermesProfileClient::~FakeHermesProfileClient() = default;
void FakeHermesProfileClient::EnableCarrierProfile(
......@@ -75,9 +75,8 @@ void FakeHermesProfileClient::EnableCarrierProfile(
HermesResponseStatus::kErrorAlreadyEnabled));
return;
}
for (PropertiesMap::iterator it = properties_map_.begin();
it != properties_map_.end(); it++) {
it->second.get()->state().ReplaceValue(hermes::profile::State::kInactive);
for (auto& item : properties_map_) {
item.second.get()->state().ReplaceValue(hermes::profile::State::kInactive);
}
properties->state().ReplaceValue(hermes::profile::State::kActive);
......@@ -121,7 +120,7 @@ void FakeHermesProfileClient::DisableCarrierProfile(
HermesProfileClient::Properties* FakeHermesProfileClient::GetProperties(
const dbus::ObjectPath& object_path) {
PropertiesMap::iterator it = properties_map_.find(object_path);
auto it = properties_map_.find(object_path);
if (it != properties_map_.end()) {
return it->second.get();
}
......
......@@ -20,7 +20,8 @@ namespace chromeos {
class COMPONENT_EXPORT(HERMES_CLIENT) FakeHermesProfileClient
: public HermesProfileClient {
public:
struct Properties : public HermesProfileClient::Properties {
class Properties : public HermesProfileClient::Properties {
public:
explicit Properties(const PropertyChangedCallback& callback);
~Properties() override;
......@@ -34,6 +35,7 @@ class COMPONENT_EXPORT(HERMES_CLIENT) FakeHermesProfileClient
FakeHermesProfileClient();
FakeHermesProfileClient(const FakeHermesProfileClient&) = delete;
FakeHermesProfileClient& operator=(const FakeHermesProfileClient&) = delete;
~FakeHermesProfileClient() override;
// HermesProfileClient:
......@@ -41,12 +43,9 @@ class COMPONENT_EXPORT(HERMES_CLIENT) FakeHermesProfileClient
HermesResponseCallback callback) override;
void DisableCarrierProfile(const dbus::ObjectPath& object_path,
HermesResponseCallback callback) override;
HermesProfileClient::Properties* GetProperties(
const dbus::ObjectPath& object_path) override;
FakeHermesProfileClient& operator=(const FakeHermesProfileClient&) = delete;
private:
void UpdateCellularDevice(HermesProfileClient::Properties* properties);
void SetCellularServicesState(const std::string& state);
......
......@@ -4,6 +4,7 @@
#include "chromeos/dbus/hermes/hermes_clients.h"
#include "chromeos/dbus/hermes/fake_hermes_euicc_client.h"
#include "chromeos/dbus/hermes/hermes_manager_client.h"
#include "chromeos/dbus/hermes/hermes_profile_client.h"
......@@ -20,16 +21,19 @@ void Initialize(dbus::Bus* system_bus) {
// to coordinate creating and managing of fake profile objects. The
// following makes sure that they are initialized in the correct order.
HermesProfileClient::Initialize(system_bus);
HermesEuiccClient::Initialize(system_bus);
HermesManagerClient::Initialize(system_bus);
}
void InitializeFakes() {
HermesProfileClient::InitializeFake();
HermesEuiccClient::InitializeFake();
HermesManagerClient::InitializeFake();
}
void Shutdown() {
HermesManagerClient::Shutdown();
HermesEuiccClient::Shutdown();
HermesProfileClient::Shutdown();
}
......
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/dbus/hermes/hermes_euicc_client.h"
#include "base/bind.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/optional.h"
#include "chromeos/dbus/hermes/fake_hermes_euicc_client.h"
#include "chromeos/dbus/hermes/hermes_response_status.h"
#include "components/device_event_log/device_event_log.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_path.h"
#include "dbus/object_proxy.h"
#include "dbus/property.h"
#include "third_party/cros_system_api/dbus/hermes/dbus-constants.h"
namespace hermes {
// TODO(crbug.com/1093185): Remove when hermes/dbus-constants.h is updated.
const char kHermesEuiccInterface[] = "org.chromium.Hermes.Euicc";
namespace euicc {
const char kEidProperty[] = "Eid";
const char kIsActiveProperty[] = "IsActive";
const char kInstalledProfilesProperty[] = "InstalledProfiles";
const char kPendingProfilesProperty[] = "PendingProfiles";
const char kInstallProfileFromActivationCode[] =
"InstallProfileFromActivationCode";
const char kInstallPendingProfile[] = "InstallPendingProfile";
const char kUninstallProfile[] = "UninstallProfile";
const char kRequestPendingEvents[] = "RequestPendingEvents";
} // namespace euicc
} // namespace hermes
namespace chromeos {
namespace {
HermesEuiccClient* g_instance = nullptr;
} // namespace
HermesEuiccClient::Properties::Properties(
dbus::ObjectProxy* object_proxy,
const PropertyChangedCallback& callback)
: dbus::PropertySet(object_proxy, hermes::kHermesEuiccInterface, callback) {
RegisterProperty(hermes::euicc::kEidProperty, &eid_);
RegisterProperty(hermes::euicc::kIsActiveProperty, &is_active_);
RegisterProperty(hermes::euicc::kInstalledProfilesProperty,
&installed_carrier_profiles_);
RegisterProperty(hermes::euicc::kPendingProfilesProperty,
&pending_carrier_profiles_);
}
HermesEuiccClient::Properties::~Properties() = default;
class HermesEuiccClientImpl : public HermesEuiccClient {
public:
explicit HermesEuiccClientImpl(dbus::Bus* bus) : bus_(bus) {}
explicit HermesEuiccClientImpl(const HermesEuiccClient&) = delete;
~HermesEuiccClientImpl() override = default;
using ProxyPropertiesPair = std::pair<dbus::ObjectProxy*, Properties*>;
using ObjectMap = std::map<dbus::ObjectPath, ProxyPropertiesPair>;
// HermesEuiccClient:
void InstallProfileFromActivationCode(
const dbus::ObjectPath& euicc_path,
const std::string& activation_code,
const std::string& confirmation_code,
InstallCarrierProfileCallback callback) override {
dbus::MethodCall method_call(
hermes::kHermesEuiccInterface,
hermes::euicc::kInstallProfileFromActivationCode);
dbus::MessageWriter writer(&method_call);
writer.AppendString(activation_code);
writer.AppendString(confirmation_code);
dbus::ObjectProxy* object_proxy = GetOrCreateProperties(euicc_path).first;
object_proxy->CallMethodWithErrorResponse(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&HermesEuiccClientImpl::OnProfileInstallResponse,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void InstallPendingProfile(const dbus::ObjectPath& euicc_path,
const dbus::ObjectPath& carrier_profile_path,
const std::string& confirmation_code,
HermesResponseCallback callback) override {
dbus::MethodCall method_call(hermes::kHermesEuiccInterface,
hermes::euicc::kInstallPendingProfile);
dbus::MessageWriter writer(&method_call);
writer.AppendObjectPath(carrier_profile_path);
writer.AppendString(confirmation_code);
dbus::ObjectProxy* object_proxy = GetOrCreateProperties(euicc_path).first;
object_proxy->CallMethodWithErrorResponse(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&HermesEuiccClientImpl::OnHermesStatusResponse,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void RequestPendingEvents(const dbus::ObjectPath& euicc_path,
HermesResponseCallback callback) override {
dbus::MethodCall method_call(hermes::kHermesEuiccInterface,
hermes::euicc::kRequestPendingEvents);
dbus::ObjectProxy* object_proxy = GetOrCreateProperties(euicc_path).first;
object_proxy->CallMethodWithErrorResponse(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&HermesEuiccClientImpl::OnHermesStatusResponse,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void UninstallProfile(const dbus::ObjectPath& euicc_path,
const dbus::ObjectPath& carrier_profile_path,
HermesResponseCallback callback) override {
dbus::MethodCall method_call(hermes::kHermesEuiccInterface,
hermes::euicc::kUninstallProfile);
dbus::MessageWriter writer(&method_call);
writer.AppendObjectPath(carrier_profile_path);
dbus::ObjectProxy* object_proxy = GetOrCreateProperties(euicc_path).first;
object_proxy->CallMethodWithErrorResponse(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&HermesEuiccClientImpl::OnHermesStatusResponse,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
Properties* GetProperties(const dbus::ObjectPath& euicc_path) override {
return GetOrCreateProperties(euicc_path).second;
}
TestInterface* GetTestInterface() override { return nullptr; }
HermesEuiccClient& operator=(const HermesEuiccClient&) = delete;
private:
const ProxyPropertiesPair& GetOrCreateProperties(
const dbus::ObjectPath& euicc_path) {
auto it = object_map_.find(euicc_path);
if (it != object_map_.end())
return it->second;
dbus::ObjectProxy* object_proxy =
bus_->GetObjectProxy(hermes::kHermesServiceName, euicc_path);
Properties* properties = new Properties(
object_proxy,
base::BindRepeating(&HermesEuiccClientImpl::OnPropertyChanged,
weak_ptr_factory_.GetWeakPtr(), euicc_path));
properties->ConnectSignals();
properties->GetAll();
ProxyPropertiesPair object = std::make_pair(object_proxy, properties);
object_map_[euicc_path] = object;
return object_map_[euicc_path];
}
void OnPropertyChanged(const dbus::ObjectPath& euicc_path,
const std::string& property_name) {
for (auto& observer : observers()) {
observer.OnEuiccPropertyChanged(euicc_path, property_name);
}
}
void OnProfileInstallResponse(InstallCarrierProfileCallback callback,
dbus::Response* response,
dbus::ErrorResponse* error_response) {
if (error_response) {
std::move(callback).Run(
HermesResponseStatusFromErrorName(error_response->GetErrorName()),
nullptr);
return;
}
if (!response) {
// No Error or Response received.
NET_LOG(ERROR) << "Carrier profile installation Error: No error or "
"response received.";
std::move(callback).Run(HermesResponseStatus::kErrorNoResponse, nullptr);
return;
}
dbus::MessageReader reader(response);
dbus::ObjectPath profile_path;
reader.PopObjectPath(&profile_path);
std::move(callback).Run(HermesResponseStatus::kSuccess, &profile_path);
}
void OnHermesStatusResponse(HermesResponseCallback callback,
dbus::Response* response,
dbus::ErrorResponse* error_response) {
if (error_response) {
std::move(callback).Run(
HermesResponseStatusFromErrorName(error_response->GetErrorName()));
return;
}
std::move(callback).Run(HermesResponseStatus::kSuccess);
}
dbus::Bus* bus_;
ObjectMap object_map_;
base::WeakPtrFactory<HermesEuiccClientImpl> weak_ptr_factory_{this};
};
HermesEuiccClient::HermesEuiccClient() {
DCHECK(!g_instance);
g_instance = this;
}
HermesEuiccClient::~HermesEuiccClient() {
DCHECK_EQ(g_instance, this);
g_instance = nullptr;
}
void HermesEuiccClient::AddObserver(Observer* observer) {
DCHECK(observer);
observers_.AddObserver(observer);
}
void HermesEuiccClient::RemoveObserver(Observer* observer) {
DCHECK(observer);
observers_.RemoveObserver(observer);
}
// static
void HermesEuiccClient::Initialize(dbus::Bus* bus) {
DCHECK(bus);
DCHECK(!g_instance);
new HermesEuiccClientImpl(bus);
}
// static
void HermesEuiccClient::InitializeFake() {
new FakeHermesEuiccClient();
}
// static
void HermesEuiccClient::Shutdown() {
DCHECK(g_instance);
delete g_instance;
}
// static
HermesEuiccClient* HermesEuiccClient::Get() {
return g_instance;
}
} // namespace chromeos
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_DBUS_HERMES_HERMES_EUICC_CLIENT_H_
#define CHROMEOS_DBUS_HERMES_HERMES_EUICC_CLIENT_H_
#include <string>
#include <vector>
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "chromeos/dbus/dbus_method_call_status.h"
#include "chromeos/dbus/hermes/hermes_response_status.h"
#include "dbus/property.h"
#include "third_party/cros_system_api/dbus/hermes/dbus-constants.h"
namespace chromeos {
// HermesEuiccClient is used to talk to the Hermes Euicc objects.
class COMPONENT_EXPORT(HERMES_CLIENT) HermesEuiccClient {
public:
// Callback for profile installation methods. Callback returns status code
// and the object path for the profile that was just successfully installed.
using InstallCarrierProfileCallback =
base::OnceCallback<void(HermesResponseStatus status,
const dbus::ObjectPath* carrier_profile_path)>;
// Interface for setting up and manipulating hermes euicc in a testing
// environment.
class TestInterface {
public:
// Adds a new carrier profiles under given euicc object using faked
// default values for properties. Returns the path to the newly
// added profile.
virtual dbus::ObjectPath AddFakeCarrierProfile(
const dbus::ObjectPath& euicc_path,
hermes::profile::State state,
std::string activation_code) = 0;
// Adds a new carrier profile with given path and properties.
virtual void AddCarrierProfile(const dbus::ObjectPath& path,
const dbus::ObjectPath& euicc_path,
const std::string& iccid,
const std::string& name,
const std::string& service_provider,
const std::string& activation_code,
const std::string& network_service_path,
hermes::profile::State state) = 0;
};
// Hermes Euicc properties.
class Properties : public dbus::PropertySet {
public:
Properties(dbus::ObjectProxy* object_proxy,
const PropertyChangedCallback& callback);
~Properties() override;
dbus::Property<std::string>& eid() { return eid_; }
dbus::Property<bool>& is_active() { return is_active_; }
dbus::Property<std::vector<dbus::ObjectPath>>&
installed_carrier_profiles() {
return installed_carrier_profiles_;
}
dbus::Property<std::vector<dbus::ObjectPath>>& pending_carrier_profiles() {
return pending_carrier_profiles_;
}
private:
// EID of the Euicc.
dbus::Property<std::string> eid_;
// Boolean that indicates whether this euicc is currently active.
dbus::Property<bool> is_active_;
// List of paths to carrier profiles currently installed on the device.
dbus::Property<std::vector<dbus::ObjectPath>> installed_carrier_profiles_;
// List of pending carrier profiles from SMDS available for
// installation on this device.
dbus::Property<std::vector<dbus::ObjectPath>> pending_carrier_profiles_;
};
// Interface for observing Hermes Euicc changes.
class Observer {
public:
virtual ~Observer() = default;
// Called when an euicc property changes.
virtual void OnEuiccPropertyChanged(const dbus::ObjectPath& euicc_path,
const std::string& property_name) = 0;
};
// Adds an observer for carrier profile lists changes on Hermes manager.
virtual void AddObserver(Observer* observer);
// Removes an observer for Hermes manager.
virtual void RemoveObserver(Observer* observer);
// Install a carrier profile in the Euicc at |euicc_path| with given
// |activation_code| and |conirmation_code|. |confirmation_code| can be empty
// if no confirmation is required by carrier. Returns the object path to the
// carrier profile that was just installed.
virtual void InstallProfileFromActivationCode(
const dbus::ObjectPath& euicc_path,
const std::string& activation_code,
const std::string& confirmation_code,
InstallCarrierProfileCallback callback) = 0;
// Installs a pending profile with given |carrier_profile_path| in the Euicc
// at |euicc_path|. |confirmation_code| can be empty if no confirmation is
// required by carrier. Returns a response status indicating the install
// result.
virtual void InstallPendingProfile(
const dbus::ObjectPath& euicc_path,
const dbus::ObjectPath& carrier_profile_path,
const std::string& confirmation_code,
HermesResponseCallback callback) = 0;
// Updates pending profiles for Euicc at |euicc_path| from the SMDS server.
// This updates pending profiles list prior to returning.
virtual void RequestPendingEvents(const dbus::ObjectPath& euicc_path,
HermesResponseCallback callback) = 0;
// Removes the carrier profile with the given |carrier_profile_path| from
// the Euicc at |euicc_path|. Returns a response status indicating the result
// of the operation.
virtual void UninstallProfile(const dbus::ObjectPath& euicc_path,
const dbus::ObjectPath& carrier_profile_path,
HermesResponseCallback callback) = 0;
// Returns properties for the Euicc with given |euicc_path|.
virtual Properties* GetProperties(const dbus::ObjectPath& euicc_path) = 0;
// Returns an instance of Hermes Euicc Test interface.
virtual TestInterface* GetTestInterface() = 0;
// Creates and initializes the global instance.
static void Initialize(dbus::Bus* bus);
// Creates and initializes a global fake instance.
static void InitializeFake();
// Destroys the global instance.
static void Shutdown();
// Returns the global instance.
static HermesEuiccClient* Get();
protected:
HermesEuiccClient();
virtual ~HermesEuiccClient();
const base::ObserverList<Observer>::Unchecked& observers() {
return observers_;
}
private:
base::ObserverList<Observer>::Unchecked observers_;
};
} // namespace chromeos
#endif // CHROMEOS_DBUS_HERMES_HERMES_EUICC_CLIENT_H_
......@@ -7,10 +7,8 @@
#include "base/bind.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/optional.h"
#include "chromeos/dbus/hermes/fake_hermes_manager_client.h"
#include "chromeos/dbus/hermes/hermes_response_status.h"
#include "components/device_event_log/device_event_log.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_path.h"
......@@ -21,7 +19,7 @@
namespace hermes {
namespace manager {
// TODO(crbug.com/1093185): Remove when hermes/dbus-constants.h is updated.
const char kPendingProfilesProperty[] = "PendingProfiles";
const char kAvailableEuiccsProperty[] = "AvailableEuiccs";
} // namespace manager
} // namespace hermes
......@@ -48,75 +46,17 @@ class HermesManagerClientImpl : public HermesManagerClient {
properties_->ConnectSignals();
properties_->GetAll();
}
explicit HermesManagerClientImpl(const HermesManagerClient&) = delete;
HermesManagerClientImpl& operator=(const HermesManagerClient&) = delete;
~HermesManagerClientImpl() override = default;
// HermesManagerClient:
void InstallProfileFromActivationCode(
const std::string& activation_code,
const std::string& confirmation_code,
InstallCarrierProfileCallback callback) override {
dbus::MethodCall method_call(
hermes::kHermesManagerInterface,
hermes::manager::kInstallProfileFromActivationCode);
dbus::MessageWriter writer(&method_call);
writer.AppendString(activation_code);
writer.AppendString(confirmation_code);
object_proxy_->CallMethodWithErrorResponse(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&HermesManagerClientImpl::OnProfileInstallResponse,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void InstallPendingProfile(const dbus::ObjectPath& carrier_profile_path,
const std::string& confirmation_code,
InstallCarrierProfileCallback callback) override {
dbus::MethodCall method_call(hermes::kHermesManagerInterface,
hermes::manager::kInstallPendingProfile);
dbus::MessageWriter writer(&method_call);
writer.AppendObjectPath(carrier_profile_path);
writer.AppendString(confirmation_code);
object_proxy_->CallMethodWithErrorResponse(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&HermesManagerClientImpl::OnProfileInstallResponse,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void RequestPendingEvents(HermesResponseCallback callback) override {
dbus::MethodCall method_call(hermes::kHermesManagerInterface,
hermes::manager::kRequestPendingEvents);
object_proxy_->CallMethodWithErrorResponse(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&HermesManagerClientImpl::OnHermesStatusResponse,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void UninstallProfile(const dbus::ObjectPath& carrier_profile_path,
HermesResponseCallback callback) override {
dbus::MethodCall method_call(hermes::kHermesManagerInterface,
hermes::manager::kUninstallProfile);
dbus::MessageWriter writer(&method_call);
writer.AppendObjectPath(carrier_profile_path);
object_proxy_->CallMethodWithErrorResponse(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&HermesManagerClientImpl::OnHermesStatusResponse,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
const std::vector<dbus::ObjectPath>& GetInstalledCarrierProfiles() override {
return properties_->installed_carrier_profiles().value();
}
const std::vector<dbus::ObjectPath>& GetPendingCarrierProfiles() override {
return properties_->pending_carrier_profiles().value();
const std::vector<dbus::ObjectPath>& GetAvailableEuiccs() override {
return properties_->available_euiccs().value();
}
TestInterface* GetTestInterface() override { return nullptr; }
HermesManagerClientImpl& operator=(const HermesManagerClient&) = delete;
private:
// Hermes Manager properties.
class Properties : public dbus::PropertySet {
......@@ -126,76 +66,25 @@ class HermesManagerClientImpl : public HermesManagerClient {
: dbus::PropertySet(object_proxy,
hermes::kHermesManagerInterface,
callback) {
RegisterProperty(hermes::manager::kProfilesProperty,
&installed_carrier_profiles_);
RegisterProperty(hermes::manager::kPendingProfilesProperty,
&pending_carrier_profiles_);
RegisterProperty(hermes::manager::kAvailableEuiccsProperty,
&available_euiccs_);
}
~Properties() override = default;
dbus::Property<std::vector<dbus::ObjectPath>>&
installed_carrier_profiles() {
return installed_carrier_profiles_;
}
dbus::Property<std::vector<dbus::ObjectPath>>& pending_carrier_profiles() {
return pending_carrier_profiles_;
dbus::Property<std::vector<dbus::ObjectPath>>& available_euiccs() {
return available_euiccs_;
}
private:
// List of paths to carrier profiles currently installed on the device.
dbus::Property<std::vector<dbus::ObjectPath>> installed_carrier_profiles_;
// List of pending carrier profiles from SMDS available for
// installation on this device.
dbus::Property<std::vector<dbus::ObjectPath>> pending_carrier_profiles_;
// List of euicc objects available on the device.
dbus::Property<std::vector<dbus::ObjectPath>> available_euiccs_;
};
void OnPropertyChanged(const dbus::ObjectPath& object_path,
const std::string& property_name) {
if (property_name == hermes::manager::kProfilesProperty) {
for (auto& observer : observers()) {
observer.OnInstalledCarrierProfileListChanged();
}
} else {
for (auto& observer : observers()) {
observer.OnPendingCarrierProfileListChanged();
}
}
}
void OnProfileInstallResponse(InstallCarrierProfileCallback callback,
dbus::Response* response,
dbus::ErrorResponse* error_response) {
if (error_response) {
std::move(callback).Run(
HermesResponseStatusFromErrorName(error_response->GetErrorName()),
nullptr);
return;
}
if (!response) {
// No Error or Response received.
NET_LOG(ERROR) << "Carrier profile installation Error: No error or "
"response received.";
std::move(callback).Run(HermesResponseStatus::kErrorNoResponse, nullptr);
return;
}
dbus::MessageReader reader(response);
dbus::ObjectPath profile_path;
reader.PopObjectPath(&profile_path);
std::move(callback).Run(HermesResponseStatus::kSuccess, &profile_path);
}
void OnHermesStatusResponse(HermesResponseCallback callback,
dbus::Response* response,
dbus::ErrorResponse* error_response) {
if (error_response) {
std::move(callback).Run(
HermesResponseStatusFromErrorName(error_response->GetErrorName()));
return;
for (auto& observer : observers()) {
observer.OnAvailableEuiccListChanged();
}
std::move(callback).Run(HermesResponseStatus::kSuccess);
}
dbus::ObjectProxy* object_proxy_;
......
......@@ -12,7 +12,6 @@
#include "base/macros.h"
#include "base/observer_list.h"
#include "chromeos/dbus/dbus_method_call_status.h"
#include "chromeos/dbus/hermes/hermes_response_status.h"
#include "dbus/property.h"
#include "third_party/cros_system_api/dbus/hermes/dbus-constants.h"
......@@ -26,24 +25,14 @@ namespace chromeos {
// HermesManagerClient is used to talk to the main Hermes Manager dbus object.
class COMPONENT_EXPORT(HERMES_CLIENT) HermesManagerClient {
public:
// Callback for profile installation methods. Callback returns status code
// and the object path for the profile that was just successfully installed.
using InstallCarrierProfileCallback =
base::OnceCallback<void(HermesResponseStatus status,
const dbus::ObjectPath* carrier_profile_path)>;
// Interface for setting up and manipulating profiles in a testing
// Interface for setting up and manipulating hermes manager in a testing
// environment.
class TestInterface {
public:
// Adds a new carrier profile with given path and properties.
virtual void AddCarrierProfile(const dbus::ObjectPath& path,
const std::string& iccid,
const std::string& name,
const std::string& service_provider,
const std::string& activation_code,
const std::string& network_service_path,
hermes::profile::State state) = 0;
// Adds a new Euicc object with given path and properties.
virtual void AddEuicc(const dbus::ObjectPath& path,
const std::string& eid,
bool is_actve) = 0;
};
// Interface for observing Hermes Manager changes.
......@@ -51,11 +40,8 @@ class COMPONENT_EXPORT(HERMES_CLIENT) HermesManagerClient {
public:
virtual ~Observer() = default;
// Called when new profiles are installed or removed.
virtual void OnInstalledCarrierProfileListChanged() {}
// Called when new pending profile list is updated.
virtual void OnPendingCarrierProfileListChanged() {}
// Called when a new Euicc objects are added or removed.
virtual void OnAvailableEuiccListChanged() {}
};
// Adds an observer for carrier profile lists changes on Hermes manager.
......@@ -64,39 +50,8 @@ class COMPONENT_EXPORT(HERMES_CLIENT) HermesManagerClient {
// Removes an observer for Hermes manager.
virtual void RemoveObserver(Observer* observer);
// Install a carrier profile given the |activation_code| and
// |conirmation_code|. |confirmation_code| can be empty if no confirmation is
// required by carrier. Returns the object path to the carrier profile that
// was just installed.
virtual void InstallProfileFromActivationCode(
const std::string& activation_code,
const std::string& confirmation_code,
InstallCarrierProfileCallback callback) = 0;
// Installs a pending profile with given |carrier_profile_path|.
// |confirmation_code| can be empty if no confirmation is required by carrier.
// Returns the object path to the carrier profile that was just installed.
virtual void InstallPendingProfile(
const dbus::ObjectPath& carrier_profile_path,
const std::string& confirmation_code,
InstallCarrierProfileCallback callback) = 0;
// Updates pending profiles for the device from the SMDS server. This updates
// pending profiles list prior to returning.
virtual void RequestPendingEvents(HermesResponseCallback callback) = 0;
// Removes the carrier profile with the given |carrier_profile_path| from
// the device. Returns a response status indicating the result of the
// operation.
virtual void UninstallProfile(const dbus::ObjectPath& carrier_profile_path,
HermesResponseCallback callback) = 0;
// Returns the list of all installed carrier profiles.
virtual const std::vector<dbus::ObjectPath>&
GetInstalledCarrierProfiles() = 0;
// Returns the list of carrier profiles that are available for installation.
virtual const std::vector<dbus::ObjectPath>& GetPendingCarrierProfiles() = 0;
// Returns the list of all installed Euiccs.
virtual const std::vector<dbus::ObjectPath>& GetAvailableEuiccs() = 0;
// Returns an instance of Hermes Manager Test interface.
virtual TestInterface* GetTestInterface() = 0;
......
......@@ -42,6 +42,7 @@ class HermesProfileClientImpl : public HermesProfileClient {
public:
explicit HermesProfileClientImpl(dbus::Bus* bus) : bus_(bus) {}
explicit HermesProfileClientImpl(const HermesProfileClient&) = delete;
HermesProfileClient& operator=(const HermesProfileClient&) = delete;
~HermesProfileClientImpl() override = default;
using Object = std::pair<dbus::ObjectProxy*, Properties*>;
......@@ -75,8 +76,6 @@ class HermesProfileClientImpl : public HermesProfileClient {
return GetObject(carrier_profile_path).second;
}
HermesProfileClient& operator=(const HermesProfileClient&) = delete;
private:
Object GetObject(const dbus::ObjectPath& object_path) {
ObjectMap::iterator it = object_map_.find(object_path);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment