Implement emergency radio in default HAL

Implemented adb shell command in default broadcast radio HAL to
simulate an emergency alert.

Bug: 361348719
Flag: EXEMPT HAL interface change
Test: adb root
Test: adb shell dumpsys android.hardware.broadcastradio.IBroadcastRadio/amfm --simulateAlert actual alert geo,transport future severe possible "alertmessage" en-US geocode:SAME,006109_geocode:SAME,006209_polygon:-38.47,-120.14,38.34,-119.95,38.52,-119.74,38.62,-119.89,-38.47,-120.14+geocode:SAME,006009
Change-Id: Idbfdb47a65c88bc3dc1839729b772bb285c563b4
diff --git a/broadcastradio/common/utilsaidl/Android.bp b/broadcastradio/common/utilsaidl/Android.bp
index d88081f..2245492 100644
--- a/broadcastradio/common/utilsaidl/Android.bp
+++ b/broadcastradio/common/utilsaidl/Android.bp
@@ -24,7 +24,7 @@
     default_applicable_licenses: ["hardware_interfaces_license"],
 }
 
-cc_library_static {
+cc_library {
     name: "android.hardware.broadcastradio@common-utils-aidl-lib",
     defaults: [
         "BroadcastRadioUtilsDefaults",
@@ -34,7 +34,7 @@
     ],
 }
 
-cc_library_static {
+cc_library {
     name: "android.hardware.broadcastradio@common-utils-aidl-lib-V2",
     defaults: [
         "BroadcastRadioUtilsDefaults",
@@ -47,7 +47,21 @@
     ],
 }
 
-cc_library_static {
+cc_library {
+    name: "android.hardware.broadcastradio@common-utils-aidl-lib-V3",
+    defaults: [
+        "BroadcastRadioUtilsDefaults",
+    ],
+    srcs: [
+        "src/UtilsV2.cpp",
+        "src/UtilsV3.cpp",
+    ],
+    shared_libs: [
+        "android.hardware.broadcastradio-V3-ndk",
+    ],
+}
+
+cc_library {
     name: "android.hardware.broadcastradio@common-utils-aidl-lib-latest",
     defaults: [
         "BroadcastRadioUtilsDefaults",
@@ -55,6 +69,7 @@
     ],
     srcs: [
         "src/UtilsV2.cpp",
+        "src/UtilsV3.cpp",
     ],
 }
 
diff --git a/broadcastradio/common/utilsaidl/include/broadcastradio-utils-aidl/Utils.h b/broadcastradio/common/utilsaidl/include/broadcastradio-utils-aidl/Utils.h
index a34ee10..f5b71b2 100644
--- a/broadcastradio/common/utilsaidl/include/broadcastradio-utils-aidl/Utils.h
+++ b/broadcastradio/common/utilsaidl/include/broadcastradio-utils-aidl/Utils.h
@@ -197,6 +197,8 @@
 
 bool parseArgLong(const std::string& s, long* out);
 
+bool parseArgDouble(const std::string& s, double* out);
+
 bool parseArgBool(const std::string& s, bool* out);
 
 bool parseArgDirection(const std::string& s, bool* out);
diff --git a/broadcastradio/common/utilsaidl/include/broadcastradio-utils-aidl/UtilsV3.h b/broadcastradio/common/utilsaidl/include/broadcastradio-utils-aidl/UtilsV3.h
new file mode 100644
index 0000000..250e217
--- /dev/null
+++ b/broadcastradio/common/utilsaidl/include/broadcastradio-utils-aidl/UtilsV3.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <aidl/android/hardware/broadcastradio/ProgramInfo.h>
+
+namespace aidl::android::hardware::broadcastradio {
+
+namespace utils {
+
+bool parseAlertStatus(const std::string& s, AlertStatus& out);
+
+bool parseAlertMessageType(const std::string& s, AlertMessageType& out);
+
+bool parseAlertCategory(const std::string& s, AlertCategory& out);
+
+bool parseAlertUrgency(const std::string& s, AlertUrgency& out);
+
+bool parseAlertSeverity(const std::string& s, AlertSeverity& out);
+
+bool parseAlertCertainty(const std::string& s, AlertCertainty& out);
+}  // namespace utils
+}  // namespace aidl::android::hardware::broadcastradio
\ No newline at end of file
diff --git a/broadcastradio/common/utilsaidl/src/Utils.cpp b/broadcastradio/common/utilsaidl/src/Utils.cpp
index 3de1866..bfa93a5 100644
--- a/broadcastradio/common/utilsaidl/src/Utils.cpp
+++ b/broadcastradio/common/utilsaidl/src/Utils.cpp
@@ -19,6 +19,7 @@
 #include "broadcastradio-utils-aidl/Utils.h"
 
 #include <android-base/logging.h>
+#include <android-base/parsedouble.h>
 #include <android-base/parseint.h>
 #include <android-base/strings.h>
 
@@ -631,6 +632,10 @@
     return ::android::base::ParseInt(s, out);
 }
 
+bool parseArgDouble(const std::string& s, double* out) {
+    return ::android::base::ParseDouble(s, out);
+}
+
 bool parseArgBool(const std::string& s, bool* out) {
     if (EqualsIgnoreCase(s, "true")) {
         *out = true;
diff --git a/broadcastradio/common/utilsaidl/src/UtilsV3.cpp b/broadcastradio/common/utilsaidl/src/UtilsV3.cpp
new file mode 100644
index 0000000..bf694da
--- /dev/null
+++ b/broadcastradio/common/utilsaidl/src/UtilsV3.cpp
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "BcRadioAidlDef.utilsV3"
+
+#include "broadcastradio-utils-aidl/Utils.h"
+
+#include <android-base/strings.h>
+
+namespace aidl::android::hardware::broadcastradio {
+
+namespace utils {
+
+namespace {
+
+using ::android::base::EqualsIgnoreCase;
+using ::std::vector;
+}  // namespace
+
+bool parseAlertStatus(const std::string& s, AlertStatus& out) {
+    if (EqualsIgnoreCase(s, toString(AlertStatus::ACTUAL))) {
+        out = AlertStatus::ACTUAL;
+    } else if (EqualsIgnoreCase(s, toString(AlertStatus::EXERCISE))) {
+        out = AlertStatus::EXERCISE;
+    } else if (EqualsIgnoreCase(s, toString(AlertStatus::TEST))) {
+        out = AlertStatus::TEST;
+    } else {
+        return false;
+    }
+    return true;
+}
+
+bool parseAlertMessageType(const std::string& s, AlertMessageType& out) {
+    if (EqualsIgnoreCase(s, toString(AlertMessageType::ALERT))) {
+        out = AlertMessageType::ALERT;
+    } else if (EqualsIgnoreCase(s, toString(AlertMessageType::UPDATE))) {
+        out = AlertMessageType::UPDATE;
+    } else if (EqualsIgnoreCase(s, toString(AlertMessageType::CANCEL))) {
+        out = AlertMessageType::CANCEL;
+    } else {
+        return false;
+    }
+    return true;
+}
+
+bool parseAlertCategory(const std::string& s, AlertCategory& out) {
+    if (EqualsIgnoreCase(s, toString(AlertCategory::GEO))) {
+        out = AlertCategory::GEO;
+    } else if (EqualsIgnoreCase(s, toString(AlertCategory::MET))) {
+        out = AlertCategory::MET;
+    } else if (EqualsIgnoreCase(s, toString(AlertCategory::SAFETY))) {
+        out = AlertCategory::SAFETY;
+    } else if (EqualsIgnoreCase(s, toString(AlertCategory::SECURITY))) {
+        out = AlertCategory::SECURITY;
+    } else if (EqualsIgnoreCase(s, toString(AlertCategory::RESCUE))) {
+        out = AlertCategory::RESCUE;
+    } else if (EqualsIgnoreCase(s, toString(AlertCategory::FIRE))) {
+        out = AlertCategory::FIRE;
+    } else if (EqualsIgnoreCase(s, toString(AlertCategory::HEALTH))) {
+        out = AlertCategory::HEALTH;
+    } else if (EqualsIgnoreCase(s, toString(AlertCategory::ENV))) {
+        out = AlertCategory::ENV;
+    } else if (EqualsIgnoreCase(s, toString(AlertCategory::TRANSPORT))) {
+        out = AlertCategory::TRANSPORT;
+    } else if (EqualsIgnoreCase(s, toString(AlertCategory::INFRA))) {
+        out = AlertCategory::INFRA;
+    } else if (EqualsIgnoreCase(s, toString(AlertCategory::CBRNE))) {
+        out = AlertCategory::CBRNE;
+    } else if (EqualsIgnoreCase(s, toString(AlertCategory::OTHER))) {
+        out = AlertCategory::OTHER;
+    } else {
+        return false;
+    }
+    return true;
+}
+
+bool parseAlertUrgency(const std::string& s, AlertUrgency& out) {
+    if (EqualsIgnoreCase(s, toString(AlertUrgency::IMMEDIATE))) {
+        out = AlertUrgency::IMMEDIATE;
+    } else if (EqualsIgnoreCase(s, toString(AlertUrgency::EXPECTED))) {
+        out = AlertUrgency::EXPECTED;
+    } else if (EqualsIgnoreCase(s, toString(AlertUrgency::FUTURE))) {
+        out = AlertUrgency::FUTURE;
+    } else if (EqualsIgnoreCase(s, toString(AlertUrgency::PAST))) {
+        out = AlertUrgency::PAST;
+    } else if (EqualsIgnoreCase(s, toString(AlertUrgency::UNKNOWN))) {
+        out = AlertUrgency::UNKNOWN;
+    } else {
+        return false;
+    }
+    return true;
+}
+
+bool parseAlertSeverity(const std::string& s, AlertSeverity& out) {
+    if (EqualsIgnoreCase(s, toString(AlertSeverity::EXTREME))) {
+        out = AlertSeverity::EXTREME;
+    } else if (EqualsIgnoreCase(s, toString(AlertSeverity::SEVERE))) {
+        out = AlertSeverity::SEVERE;
+    } else if (EqualsIgnoreCase(s, toString(AlertSeverity::MODERATE))) {
+        out = AlertSeverity::MODERATE;
+    } else if (EqualsIgnoreCase(s, toString(AlertSeverity::MINOR))) {
+        out = AlertSeverity::MINOR;
+    } else if (EqualsIgnoreCase(s, toString(AlertSeverity::UNKNOWN))) {
+        out = AlertSeverity::UNKNOWN;
+    } else {
+        return false;
+    }
+    return true;
+}
+
+bool parseAlertCertainty(const std::string& s, AlertCertainty& out) {
+    if (EqualsIgnoreCase(s, toString(AlertCertainty::OBSERVED))) {
+        out = AlertCertainty::OBSERVED;
+    } else if (EqualsIgnoreCase(s, toString(AlertCertainty::LIKELY))) {
+        out = AlertCertainty::LIKELY;
+    } else if (EqualsIgnoreCase(s, toString(AlertCertainty::POSSIBLE))) {
+        out = AlertCertainty::POSSIBLE;
+    } else if (EqualsIgnoreCase(s, toString(AlertCertainty::UNLIKELY))) {
+        out = AlertCertainty::UNLIKELY;
+    } else if (EqualsIgnoreCase(s, toString(AlertCertainty::UNKNOWN))) {
+        out = AlertCertainty::UNKNOWN;
+    } else {
+        return false;
+    }
+    return true;
+}
+
+}  // namespace utils
+}  // namespace aidl::android::hardware::broadcastradio