blob: 33060126ffee8093db89095e0b44fd0da6b40f44 [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
17#include <ui/DeviceProductInfo.h>
18
Marin Shalamanove5cceea2020-04-30 18:13:10 +020019#include <android-base/stringprintf.h>
Marin Shalamanove5cceea2020-04-30 18:13:10 +020020#include <utils/Log.h>
Marin Shalamanov359a7e72020-02-17 17:03:07 +010021
Marin Shalamanov896e6302020-04-06 16:11:25 +020022#define RETURN_IF_ERROR(op) \
23 if (const status_t status = (op); status != OK) return status;
24
Marin Shalamanov359a7e72020-02-17 17:03:07 +010025namespace android {
26
Marin Shalamanove5cceea2020-04-30 18:13:10 +020027using base::StringAppendF;
28
Marin Shalamanove5cceea2020-04-30 18:13:10 +020029void DeviceProductInfo::dump(std::string& result) const {
Dominik Laskowski0acc3842022-04-07 11:23:42 -070030 StringAppendF(&result, "{name=\"%s\", ", name.c_str());
Marin Shalamanove5cceea2020-04-30 18:13:10 +020031 StringAppendF(&result, "manufacturerPnpId=%s, ", manufacturerPnpId.data());
32 StringAppendF(&result, "productId=%s, ", productId.c_str());
33
34 if (const auto* model = std::get_if<ModelYear>(&manufactureOrModelDate)) {
35 StringAppendF(&result, "modelYear=%u, ", model->year);
36 } else if (const auto* manufactureWeekAndYear =
37 std::get_if<ManufactureWeekAndYear>(&manufactureOrModelDate)) {
38 StringAppendF(&result, "manufactureWeek=%u, ", manufactureWeekAndYear->week);
39 StringAppendF(&result, "manufactureYear=%d, ", manufactureWeekAndYear->year);
40 } else if (const auto* manufactureYear =
41 std::get_if<ManufactureYear>(&manufactureOrModelDate)) {
42 StringAppendF(&result, "manufactureYear=%d, ", manufactureYear->year);
43 } else {
44 ALOGE("Unknown alternative for variant DeviceProductInfo::ManufactureOrModelDate");
45 }
46
47 result.append("relativeAddress=[");
48 for (size_t i = 0; i < relativeAddress.size(); i++) {
49 if (i != 0) {
50 result.append(", ");
51 }
52 StringAppendF(&result, "%u", relativeAddress[i]);
53 }
54 result.append("]}");
55}
56
Marin Shalamanov359a7e72020-02-17 17:03:07 +010057} // namespace android