xref: /aosp_15_r20/frameworks/native/libs/ui/DeviceProductInfo.cpp (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
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 <ftl/match.h>
18 #include <ui/DeviceProductInfo.h>
19 
20 #include <android-base/stringprintf.h>
21 
22 namespace android {
23 
to_string(const DeviceProductInfo & info)24 std::string to_string(const DeviceProductInfo& info) {
25     using base::StringAppendF;
26 
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());
31 
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             });
44 
45     result.append("relativeAddress=[");
46     for (size_t i = 0; i < info.relativeAddress.size(); i++) {
47         if (i != 0) {
48             result.append(", ");
49         }
50         StringAppendF(&result, "%u", info.relativeAddress[i]);
51     }
52     result.append("]}");
53     return result;
54 }
55 
56 } // namespace android
57