blob: 6ae27dee1de026b271e8a00d75cddb983508e536 [file] [log] [blame]
Marin Shalamanov359a7e72020-02-17 17:03:07 +01001/*
2 * Copyright 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dominik Laskowskie70461a2022-08-30 14:42:01 -070017#include <ftl/match.h>
Marin Shalamanov359a7e72020-02-17 17:03:07 +010018#include <ui/DeviceProductInfo.h>
19
Marin Shalamanove5cceea2020-04-30 18:13:10 +020020#include <android-base/stringprintf.h>
Marin Shalamanov896e6302020-04-06 16:11:25 +020021
Marin Shalamanov359a7e72020-02-17 17:03:07 +010022namespace android {
23
Dominik Laskowskie70461a2022-08-30 14:42:01 -070024std::string to_string(const DeviceProductInfo& info) {
25 using base::StringAppendF;
Marin Shalamanove5cceea2020-04-30 18:13:10 +020026
Dominik Laskowskie70461a2022-08-30 14:42:01 -070027 std::string result;
28 StringAppendF(&result, "{name=\"%s\", ", info.name.c_str());
29 StringAppendF(&result, "manufacturerPnpId=%s, ", info.manufacturerPnpId.data());
30 StringAppendF(&result, "productId=%s, ", info.productId.c_str());
Marin Shalamanove5cceea2020-04-30 18:13:10 +020031
Dominik Laskowskie70461a2022-08-30 14:42:01 -070032 ftl::match(
33 info.manufactureOrModelDate,
34 [&](DeviceProductInfo::ModelYear model) {
35 StringAppendF(&result, "modelYear=%u, ", model.year);
36 },
37 [&](DeviceProductInfo::ManufactureWeekAndYear manufacture) {
38 StringAppendF(&result, "manufactureWeek=%u, ", manufacture.week);
39 StringAppendF(&result, "manufactureYear=%d, ", manufacture.year);
40 },
41 [&](DeviceProductInfo::ManufactureYear manufacture) {
42 StringAppendF(&result, "manufactureYear=%d, ", manufacture.year);
43 });
Marin Shalamanove5cceea2020-04-30 18:13:10 +020044
45 result.append("relativeAddress=[");
Dominik Laskowskie70461a2022-08-30 14:42:01 -070046 for (size_t i = 0; i < info.relativeAddress.size(); i++) {
Marin Shalamanove5cceea2020-04-30 18:13:10 +020047 if (i != 0) {
48 result.append(", ");
49 }
Dominik Laskowskie70461a2022-08-30 14:42:01 -070050 StringAppendF(&result, "%u", info.relativeAddress[i]);
Marin Shalamanove5cceea2020-04-30 18:13:10 +020051 }
52 result.append("]}");
Dominik Laskowskie70461a2022-08-30 14:42:01 -070053 return result;
Marin Shalamanove5cceea2020-04-30 18:13:10 +020054}
55
Marin Shalamanov359a7e72020-02-17 17:03:07 +010056} // namespace android