Commit f83ef939 authored by Azeem Arshad's avatar Azeem Arshad Committed by Chromium LUCI CQ

[CrOS Cellular] Add ESimManager EID qr code method.

This CL adds a GetEIDQRCode method in Euicc interface
that returns a qrcode image representing the EID of
the Euicc.

Bug: 1093185
Change-Id: I6dabd595dfb9fd0ba7a8841aed0fe272e62152f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2611992Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarAdam Langley <agl@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Azeem Arshad <azeemarshad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842134}
parent d82af7a9
...@@ -43,6 +43,7 @@ static_library("esim_manager") { ...@@ -43,6 +43,7 @@ static_library("esim_manager") {
"//chromeos/dbus/hermes", "//chromeos/dbus/hermes",
"//chromeos/services/cellular_setup/public/mojom", "//chromeos/services/cellular_setup/public/mojom",
"//components/device_event_log", "//components/device_event_log",
"//components/qr_code_generator",
"//dbus", "//dbus",
] ]
} }
......
include_rules = [ include_rules = [
"+dbus/object_path.h", "+dbus/object_path.h",
"+components/qr_code_generator/qr_code_generator.h",
"+mojo/public", "+mojo/public",
] ]
...@@ -4,15 +4,26 @@ ...@@ -4,15 +4,26 @@
#include "chromeos/services/cellular_setup/euicc.h" #include "chromeos/services/cellular_setup/euicc.h"
#include <cstdint>
#include <memory> #include <memory>
#include "base/optional.h"
#include "base/strings/strcat.h"
#include "chromeos/services/cellular_setup/esim_mojo_utils.h" #include "chromeos/services/cellular_setup/esim_mojo_utils.h"
#include "chromeos/services/cellular_setup/esim_profile.h" #include "chromeos/services/cellular_setup/esim_profile.h"
#include "chromeos/services/cellular_setup/public/mojom/esim_manager.mojom-shared.h" #include "chromeos/services/cellular_setup/public/mojom/esim_manager.mojom-shared.h"
#include "components/device_event_log/device_event_log.h" #include "components/device_event_log/device_event_log.h"
#include "components/qr_code_generator/qr_code_generator.h"
#include "dbus/object_path.h" #include "dbus/object_path.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
namespace {
// Prefix for EID when encoded in QR Code.
const char kEidQrCodePrefix[] = "EID:";
} // namespace
namespace chromeos { namespace chromeos {
namespace cellular_setup { namespace cellular_setup {
...@@ -78,6 +89,35 @@ void Euicc::RequestPendingProfiles(RequestPendingProfilesCallback callback) { ...@@ -78,6 +89,35 @@ void Euicc::RequestPendingProfiles(RequestPendingProfilesCallback callback) {
weak_ptr_factory_.GetWeakPtr(), std::move(callback))); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
} }
void Euicc::GetEidQRCode(GetEidQRCodeCallback callback) {
// Format EID to string that should be encoded in the QRCode.
std::string qr_code_string =
base::StrCat({kEidQrCodePrefix, properties_->eid});
QRCodeGenerator qr_generator;
base::Optional<QRCodeGenerator::GeneratedCode> qr_data =
qr_generator.Generate(base::as_bytes(
base::make_span(qr_code_string.data(), qr_code_string.size())));
if (!qr_data || qr_data->data.data() == nullptr ||
qr_data->data.size() == 0) {
std::move(callback).Run(nullptr);
return;
}
// Data returned from QRCodeGenerator consist of bytes that represents
// tiles. Least significant bit of each byte is set if the tile should be
// filled. Other bit positions indicate QR Code structure and are not required
// for rendering. Convert this data to 0 or 1 values for simpler UI side
// rendering.
for (uint8_t& qr_data_byte : qr_data->data) {
qr_data_byte &= 1;
}
mojom::QRCodePtr qr_code = mojom::QRCode::New();
qr_code->size = qr_data->qr_size;
qr_code->data.assign(qr_data->data.begin(), qr_data->data.end());
std::move(callback).Run(std::move(qr_code));
}
void Euicc::UpdateProfileList() { void Euicc::UpdateProfileList() {
HermesEuiccClient::Properties* euicc_properties = HermesEuiccClient::Properties* euicc_properties =
HermesEuiccClient::Get()->GetProperties(path_); HermesEuiccClient::Get()->GetProperties(path_);
......
...@@ -37,6 +37,7 @@ class Euicc : public mojom::Euicc { ...@@ -37,6 +37,7 @@ class Euicc : public mojom::Euicc {
const std::string& confirmation_code, const std::string& confirmation_code,
InstallProfileFromActivationCodeCallback callback) override; InstallProfileFromActivationCodeCallback callback) override;
void RequestPendingProfiles(RequestPendingProfilesCallback callback) override; void RequestPendingProfiles(RequestPendingProfilesCallback callback) override;
void GetEidQRCode(GetEidQRCodeCallback callback) override;
// Updates list of eSIM profiles for this euicc from D-Bus. // Updates list of eSIM profiles for this euicc from D-Bus.
void UpdateProfileList(); void UpdateProfileList();
......
...@@ -150,5 +150,24 @@ TEST_F(EuiccTest, RequestPendingProfiles) { ...@@ -150,5 +150,24 @@ TEST_F(EuiccTest, RequestPendingProfiles) {
RequestPendingProfiles(euicc)); RequestPendingProfiles(euicc));
} }
TEST_F(EuiccTest, GetEidQRCode) {
mojo::Remote<mojom::Euicc> euicc = GetEuiccForEid(ESimTestBase::kTestEid);
ASSERT_TRUE(euicc.is_bound());
mojom::QRCodePtr qr_code_result;
base::RunLoop run_loop;
euicc->GetEidQRCode(base::BindOnce(
[](mojom::QRCodePtr* out, base::OnceClosure quit_closure,
mojom::QRCodePtr properties) {
*out = std::move(properties);
std::move(quit_closure).Run();
},
&qr_code_result, run_loop.QuitClosure()));
run_loop.Run();
ASSERT_FALSE(qr_code_result.is_null());
EXPECT_LT(0, qr_code_result->size);
}
} // namespace cellular_setup } // namespace cellular_setup
} // namespace chromeos } // namespace chromeos
\ No newline at end of file
...@@ -56,6 +56,17 @@ struct ESimProfileProperties { ...@@ -56,6 +56,17 @@ struct ESimProfileProperties {
string activation_code; string activation_code;
}; };
// Represents a QRCode image.
struct QRCode {
// Width and height (which are equal) of the generated QR Code image in
// number of tiles.
uint8 size;
// QRCode image data. This is an array of bytes representing tiles in the
// QRCode in row major order. Values can be 0 or 1 where 1 indicates that
// the corresponding tile should be filled.
array<uint8> data;
};
// ESimManagerObserver is implemented by any module that // ESimManagerObserver is implemented by any module that
// needs to observe changes to the eSIM module. // needs to observe changes to the eSIM module.
interface ESimManagerObserver { interface ESimManagerObserver {
...@@ -114,6 +125,10 @@ interface Euicc { ...@@ -114,6 +125,10 @@ interface Euicc {
InstallProfileFromActivationCode(string activation_code, InstallProfileFromActivationCode(string activation_code,
string confirmation_code) => string confirmation_code) =>
(ProfileInstallResult result, pending_remote<ESimProfile>? profile); (ProfileInstallResult result, pending_remote<ESimProfile>? profile);
// Returns a QR Code image representing the EID of this Euicc. A null value is
// returned if the QR Code could not be generated.
GetEidQRCode() => (QRCode? qr_code);
}; };
// ESimProfile interface represents and eSIM profile and provides operations // ESimProfile interface represents and eSIM profile and provides operations
......
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