| 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 |  | 
| Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 17 | #include <ftl/match.h> | 
| Marin Shalamanov | 359a7e7 | 2020-02-17 17:03:07 +0100 | [diff] [blame] | 18 | #include <ui/DeviceProductInfo.h> | 
|  | 19 |  | 
| Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 20 | #include <android-base/stringprintf.h> | 
| Marin Shalamanov | 896e630 | 2020-04-06 16:11:25 +0200 | [diff] [blame] | 21 |  | 
| Marin Shalamanov | 359a7e7 | 2020-02-17 17:03:07 +0100 | [diff] [blame] | 22 | namespace android { | 
|  | 23 |  | 
| Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 24 | std::string to_string(const DeviceProductInfo& info) { | 
|  | 25 | using base::StringAppendF; | 
| Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 26 |  | 
| Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 27 | 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 Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 31 |  | 
| Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 32 | 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 Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 44 |  | 
|  | 45 | result.append("relativeAddress=["); | 
| Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 46 | for (size_t i = 0; i < info.relativeAddress.size(); i++) { | 
| Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 47 | if (i != 0) { | 
|  | 48 | result.append(", "); | 
|  | 49 | } | 
| Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 50 | StringAppendF(&result, "%u", info.relativeAddress[i]); | 
| Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 51 | } | 
|  | 52 | result.append("]}"); | 
| Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 53 | return result; | 
| Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 54 | } | 
|  | 55 |  | 
| Marin Shalamanov | 359a7e7 | 2020-02-17 17:03:07 +0100 | [diff] [blame] | 56 | } // namespace android |