xref: /aosp_15_r20/hardware/interfaces/broadcastradio/common/utilsaidl/src/UtilsV3.cpp (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1 /*
2  * Copyright (C) 2024 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 #define LOG_TAG "BcRadioAidlDef.utilsV3"
18 
19 #include "broadcastradio-utils-aidl/Utils.h"
20 
21 #include <android-base/strings.h>
22 
23 namespace aidl::android::hardware::broadcastradio {
24 
25 namespace utils {
26 
27 namespace {
28 
29 using ::android::base::EqualsIgnoreCase;
30 using ::std::vector;
31 }  // namespace
32 
parseAlertStatus(const std::string & s,AlertStatus & out)33 bool parseAlertStatus(const std::string& s, AlertStatus& out) {
34     if (EqualsIgnoreCase(s, toString(AlertStatus::ACTUAL))) {
35         out = AlertStatus::ACTUAL;
36     } else if (EqualsIgnoreCase(s, toString(AlertStatus::EXERCISE))) {
37         out = AlertStatus::EXERCISE;
38     } else if (EqualsIgnoreCase(s, toString(AlertStatus::TEST))) {
39         out = AlertStatus::TEST;
40     } else {
41         return false;
42     }
43     return true;
44 }
45 
parseAlertMessageType(const std::string & s,AlertMessageType & out)46 bool parseAlertMessageType(const std::string& s, AlertMessageType& out) {
47     if (EqualsIgnoreCase(s, toString(AlertMessageType::ALERT))) {
48         out = AlertMessageType::ALERT;
49     } else if (EqualsIgnoreCase(s, toString(AlertMessageType::UPDATE))) {
50         out = AlertMessageType::UPDATE;
51     } else if (EqualsIgnoreCase(s, toString(AlertMessageType::CANCEL))) {
52         out = AlertMessageType::CANCEL;
53     } else {
54         return false;
55     }
56     return true;
57 }
58 
parseAlertCategory(const std::string & s,AlertCategory & out)59 bool parseAlertCategory(const std::string& s, AlertCategory& out) {
60     if (EqualsIgnoreCase(s, toString(AlertCategory::GEO))) {
61         out = AlertCategory::GEO;
62     } else if (EqualsIgnoreCase(s, toString(AlertCategory::MET))) {
63         out = AlertCategory::MET;
64     } else if (EqualsIgnoreCase(s, toString(AlertCategory::SAFETY))) {
65         out = AlertCategory::SAFETY;
66     } else if (EqualsIgnoreCase(s, toString(AlertCategory::SECURITY))) {
67         out = AlertCategory::SECURITY;
68     } else if (EqualsIgnoreCase(s, toString(AlertCategory::RESCUE))) {
69         out = AlertCategory::RESCUE;
70     } else if (EqualsIgnoreCase(s, toString(AlertCategory::FIRE))) {
71         out = AlertCategory::FIRE;
72     } else if (EqualsIgnoreCase(s, toString(AlertCategory::HEALTH))) {
73         out = AlertCategory::HEALTH;
74     } else if (EqualsIgnoreCase(s, toString(AlertCategory::ENV))) {
75         out = AlertCategory::ENV;
76     } else if (EqualsIgnoreCase(s, toString(AlertCategory::TRANSPORT))) {
77         out = AlertCategory::TRANSPORT;
78     } else if (EqualsIgnoreCase(s, toString(AlertCategory::INFRA))) {
79         out = AlertCategory::INFRA;
80     } else if (EqualsIgnoreCase(s, toString(AlertCategory::CBRNE))) {
81         out = AlertCategory::CBRNE;
82     } else if (EqualsIgnoreCase(s, toString(AlertCategory::OTHER))) {
83         out = AlertCategory::OTHER;
84     } else {
85         return false;
86     }
87     return true;
88 }
89 
parseAlertUrgency(const std::string & s,AlertUrgency & out)90 bool parseAlertUrgency(const std::string& s, AlertUrgency& out) {
91     if (EqualsIgnoreCase(s, toString(AlertUrgency::IMMEDIATE))) {
92         out = AlertUrgency::IMMEDIATE;
93     } else if (EqualsIgnoreCase(s, toString(AlertUrgency::EXPECTED))) {
94         out = AlertUrgency::EXPECTED;
95     } else if (EqualsIgnoreCase(s, toString(AlertUrgency::FUTURE))) {
96         out = AlertUrgency::FUTURE;
97     } else if (EqualsIgnoreCase(s, toString(AlertUrgency::PAST))) {
98         out = AlertUrgency::PAST;
99     } else if (EqualsIgnoreCase(s, toString(AlertUrgency::UNKNOWN))) {
100         out = AlertUrgency::UNKNOWN;
101     } else {
102         return false;
103     }
104     return true;
105 }
106 
parseAlertSeverity(const std::string & s,AlertSeverity & out)107 bool parseAlertSeverity(const std::string& s, AlertSeverity& out) {
108     if (EqualsIgnoreCase(s, toString(AlertSeverity::EXTREME))) {
109         out = AlertSeverity::EXTREME;
110     } else if (EqualsIgnoreCase(s, toString(AlertSeverity::SEVERE))) {
111         out = AlertSeverity::SEVERE;
112     } else if (EqualsIgnoreCase(s, toString(AlertSeverity::MODERATE))) {
113         out = AlertSeverity::MODERATE;
114     } else if (EqualsIgnoreCase(s, toString(AlertSeverity::MINOR))) {
115         out = AlertSeverity::MINOR;
116     } else if (EqualsIgnoreCase(s, toString(AlertSeverity::UNKNOWN))) {
117         out = AlertSeverity::UNKNOWN;
118     } else {
119         return false;
120     }
121     return true;
122 }
123 
parseAlertCertainty(const std::string & s,AlertCertainty & out)124 bool parseAlertCertainty(const std::string& s, AlertCertainty& out) {
125     if (EqualsIgnoreCase(s, toString(AlertCertainty::OBSERVED))) {
126         out = AlertCertainty::OBSERVED;
127     } else if (EqualsIgnoreCase(s, toString(AlertCertainty::LIKELY))) {
128         out = AlertCertainty::LIKELY;
129     } else if (EqualsIgnoreCase(s, toString(AlertCertainty::POSSIBLE))) {
130         out = AlertCertainty::POSSIBLE;
131     } else if (EqualsIgnoreCase(s, toString(AlertCertainty::UNLIKELY))) {
132         out = AlertCertainty::UNLIKELY;
133     } else if (EqualsIgnoreCase(s, toString(AlertCertainty::UNKNOWN))) {
134         out = AlertCertainty::UNKNOWN;
135     } else {
136         return false;
137     }
138     return true;
139 }
140 
141 }  // namespace utils
142 }  // namespace aidl::android::hardware::broadcastradio
143