Marin Shalamanov | 359a7e7 | 2020-02-17 17:03:07 +0100 | [diff] [blame] | 1 | /* |
| 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 Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 19 | #include <android-base/stringprintf.h> |
Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 20 | #include <utils/Log.h> |
Marin Shalamanov | 359a7e7 | 2020-02-17 17:03:07 +0100 | [diff] [blame] | 21 | |
Marin Shalamanov | 896e630 | 2020-04-06 16:11:25 +0200 | [diff] [blame] | 22 | #define RETURN_IF_ERROR(op) \ |
| 23 | if (const status_t status = (op); status != OK) return status; |
| 24 | |
Marin Shalamanov | 359a7e7 | 2020-02-17 17:03:07 +0100 | [diff] [blame] | 25 | namespace android { |
| 26 | |
Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 27 | using base::StringAppendF; |
| 28 | |
Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 29 | void DeviceProductInfo::dump(std::string& result) const { |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 30 | StringAppendF(&result, "{name=\"%s\", ", name.c_str()); |
Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 31 | 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 Shalamanov | 359a7e7 | 2020-02-17 17:03:07 +0100 | [diff] [blame] | 57 | } // namespace android |