Merge "Update annotation gen script." into main
diff --git a/audio/policy/1.0/vts/functional/Android.bp b/audio/policy/1.0/vts/functional/Android.bp
index c2335e4..ccdd771 100644
--- a/audio/policy/1.0/vts/functional/Android.bp
+++ b/audio/policy/1.0/vts/functional/Android.bp
@@ -10,6 +10,11 @@
 
 cc_test {
     name: "VtsHalAudioPolicyV1_0TargetTest",
+    defaults: [
+        "latest_android_hardware_audio_common_ndk_static",
+        "latest_android_hardware_audio_core_ndk_static",
+        "latest_android_media_audio_common_types_ndk_static",
+    ],
     srcs: [
         "ValidateEngineConfiguration.cpp",
     ],
@@ -17,6 +22,7 @@
         "libxml2",
         "liblog",
         "libmedia_helper",
+        "libaidlvintf_gtest_helper",
         "libaudiopolicycapengine_config",
         "libaudiopolicycomponents",
         "libaudiopolicyengine_config",
@@ -33,6 +39,8 @@
     ],
     shared_libs: [
         "libaudiofoundation",
+        "libbinder_ndk",
+        "libvintf",
     ],
     // Use test_config for vts suite.
     // TODO(b/146104851): Add auto-gen rules and remove it.
diff --git a/audio/policy/1.0/vts/functional/ValidateEngineConfiguration.cpp b/audio/policy/1.0/vts/functional/ValidateEngineConfiguration.cpp
index 5741fa9..0472174 100644
--- a/audio/policy/1.0/vts/functional/ValidateEngineConfiguration.cpp
+++ b/audio/policy/1.0/vts/functional/ValidateEngineConfiguration.cpp
@@ -16,6 +16,9 @@
 
 #include <EngineConfig.h>
 #include <ParameterManagerWrapper.h>
+#include <aidl/Vintf.h>
+#include <aidl/android/hardware/audio/core/IConfig.h>
+#include <android/binder_manager.h>
 
 #include <gtest/gtest.h>
 
@@ -34,12 +37,30 @@
 static const std::string configurableConfig =
         "parameter-framework/ParameterFrameworkConfigurationPolicy.xml";
 
+static bool deviceUsesAidlHal() {
+    using aidl::android::hardware::audio::core::IConfig;
+
+    const auto configName = android::getAidlHalInstanceNames(IConfig::descriptor);
+    if (!configName.empty()) {
+        ndk::SpAIBinder binder =
+                ndk::SpAIBinder(AServiceManager_waitForService(configName[0].c_str()));
+        if (binder != nullptr) {
+            std::shared_ptr<IConfig> configItf = IConfig::fromBinder(binder);
+            return configItf != nullptr;
+        }
+    }
+    return false;
+}
+
 /**
  * @brief TEST to ensure the audio policy engine configuration file is validating schemas.
  * Note: this configuration file is not mandatory, an hardcoded fallback is provided, so
  * it does not fail if not found.
  */
 TEST(ValidateConfiguration, audioPolicyEngineConfiguration) {
+    if (deviceUsesAidlHal()) {
+        GTEST_SKIP() << "Device uses AIDL HAL, n-op.";
+    }
     RecordProperty("description",
                    "Verify that the audio policy engine configuration file "
                    "is valid according to the schemas");
@@ -48,11 +69,12 @@
 }
 
 /**
- * @brief deviceUsesConfigurableEngine checks if the configuration file for
- * the engine presents on the device AND
- * for the configurable engine (aka Parameter-Framework top configuration file) presents.
+ * @brief deviceUsesHidlConfigurableEngine checks if there is no AIDL HAL,
+ * AND the configuration file for the engine presents on the device
+ * AND for the configurable engine (aka Parameter-Framework top configuration file) presents.
  */
-static bool deviceUsesConfigurableEngine() {
+static bool deviceUsesHidlConfigurableEngine() {
+    if (deviceUsesAidlHal()) return false;
     return android::hardware::audio::common::test::utility::validateXmlMultipleLocations<true>(
                    "", "", "", config.c_str(), android::audio_get_configuration_paths(),
                    schema.c_str()) &&
@@ -62,8 +84,8 @@
 }
 
 TEST(ValidateConfiguration, audioPolicyEngineConfigurable) {
-    if (!deviceUsesConfigurableEngine()) {
-        GTEST_SKIP() << "Device using legacy engine without parameter-framework, n-op.";
+    if (!deviceUsesHidlConfigurableEngine()) {
+        GTEST_SKIP() << "Device uses AIDL HAL or legacy engine without parameter-framework, n-op.";
     }
     RecordProperty("description",
                    "Verify that the audio policy engine PFW configuration files "
@@ -78,7 +100,8 @@
         ASSERT_EQ(result.nbSkippedElement, 0) << "skipped %zu elements " << result.nbSkippedElement;
 
         std::unique_ptr<android::audio_policy::ParameterManagerWrapper> policyParameterMgr(
-                new android::audio_policy::ParameterManagerWrapper(validateSchema, schemasUri));
+                new android::audio_policy::ParameterManagerWrapper(
+                        true /*useLegacyConfigurationFile*/, validateSchema, schemasUri));
         ASSERT_NE(nullptr, policyParameterMgr) << "failed to create Audio Policy Engine PFW";
 
         // Load the criterion types and criteria
diff --git a/biometrics/face/aidl/vts/Android.bp b/biometrics/face/aidl/vts/Android.bp
index e037eac..1b3a93a 100644
--- a/biometrics/face/aidl/vts/Android.bp
+++ b/biometrics/face/aidl/vts/Android.bp
@@ -28,4 +28,5 @@
         "general-tests",
         "vts",
     ],
+    disable_framework: false,
 }
diff --git a/biometrics/face/aidl/vts/VtsHalBiometricsFaceTargetTest.cpp b/biometrics/face/aidl/vts/VtsHalBiometricsFaceTargetTest.cpp
index 08ab5d6..686f61e 100644
--- a/biometrics/face/aidl/vts/VtsHalBiometricsFaceTargetTest.cpp
+++ b/biometrics/face/aidl/vts/VtsHalBiometricsFaceTargetTest.cpp
@@ -186,6 +186,7 @@
 
     void TearDown() override {
         // Close the mSession.
+        ASSERT_NE(mSession, nullptr);
         ASSERT_TRUE(mSession->close().isOk());
 
         // Make sure the mSession is closed.
diff --git a/biometrics/fingerprint/aidl/vts/Android.bp b/biometrics/fingerprint/aidl/vts/Android.bp
index 7c9cd8c..2b4f657 100644
--- a/biometrics/fingerprint/aidl/vts/Android.bp
+++ b/biometrics/fingerprint/aidl/vts/Android.bp
@@ -27,5 +27,5 @@
         "general-tests",
         "vts",
     ],
-    disable_framework: true,
+    disable_framework: false,
 }
diff --git a/bluetooth/aidl/default/net_bluetooth_mgmt.cpp b/bluetooth/aidl/default/net_bluetooth_mgmt.cpp
index 24693ef..6b0cd63 100644
--- a/bluetooth/aidl/default/net_bluetooth_mgmt.cpp
+++ b/bluetooth/aidl/default/net_bluetooth_mgmt.cpp
@@ -259,8 +259,8 @@
 int NetBluetoothMgmt::openHci(int hci_interface) {
   ALOGI("opening hci interface %d", hci_interface);
 
-  // Block Bluetooth.
-  rfkill(1);
+  // Unblock Bluetooth.
+  rfkill(0);
 
   // Wait for the HCI interface to complete initialization or to come online.
   int hci = waitHciDev(hci_interface);
@@ -300,8 +300,8 @@
     bt_fd_ = -1;
   }
 
-  // Unblock Bluetooth.
-  rfkill(0);
+  // Block Bluetooth.
+  rfkill(1);
 }
 
 }  // namespace aidl::android::hardware::bluetooth::impl
diff --git a/gnss/aidl/default/Gnss.cpp b/gnss/aidl/default/Gnss.cpp
index 41720c0..1fd21d8 100644
--- a/gnss/aidl/default/Gnss.cpp
+++ b/gnss/aidl/default/Gnss.cpp
@@ -298,8 +298,14 @@
 ScopedAStatus Gnss::setPositionMode(const PositionModeOptions& options) {
     ALOGD("setPositionMode. minIntervalMs:%d, lowPowerMode:%d", options.minIntervalMs,
           (int)options.lowPowerMode);
-    mMinIntervalMs = std::max(1000, options.minIntervalMs);
-    mGnssMeasurementInterface->setLocationInterval(mMinIntervalMs);
+    if (std::max(1000, options.minIntervalMs) != mMinIntervalMs) {
+        mMinIntervalMs = std::max(1000, options.minIntervalMs);
+        mGnssMeasurementInterface->setLocationInterval(mMinIntervalMs);
+        if (mIsActive) {
+            stop();
+            start();
+        }
+    }
     return ScopedAStatus::ok();
 }
 
diff --git a/gnss/common/utils/default/MockLocation.cpp b/gnss/common/utils/default/MockLocation.cpp
index c90075f..512af21 100644
--- a/gnss/common/utils/default/MockLocation.cpp
+++ b/gnss/common/utils/default/MockLocation.cpp
@@ -21,7 +21,7 @@
 float gMockLatitudeDegrees{37.4219999};
 float gMockLongitudeDegrees{-122.0840575};
 float gMockAltitudeMeters{1.60062531};
-float gMockBearingDegrees{0};
-float gMockSpeedMetersPerSec{0};
+float gMockBearingDegrees{0.0001};  // a real location rarely has exactly zero bearing
+float gMockSpeedMetersPerSec{0.0001};
 
 }  // namespace android::hardware::gnss::common
diff --git a/nfc/aidl/vts/functional/VtsNfcBehaviorChangesTest.cpp b/nfc/aidl/vts/functional/VtsNfcBehaviorChangesTest.cpp
index a0c9436..6db7e14 100644
--- a/nfc/aidl/vts/functional/VtsNfcBehaviorChangesTest.cpp
+++ b/nfc/aidl/vts/functional/VtsNfcBehaviorChangesTest.cpp
@@ -46,6 +46,7 @@
 static SyncEvent sNfaEnableDisablePollingEvent;
 static SyncEvent sNfaPowerChangeEvent;
 static std::vector<uint8_t> sCaps(0);
+static uint8_t sObserveModeState;
 static bool sIsNfaEnabled;
 static tNFA_STATUS sVSCmdStatus;
 
@@ -145,6 +146,13 @@
         case NCI_MSG_PROP_ANDROID: {
             uint8_t android_sub_opcode = p_param[3];
             switch (android_sub_opcode) {
+                case NCI_QUERY_ANDROID_PASSIVE_OBSERVE: {
+                    sObserveModeState = p_param[5];
+                    LOG(INFO) << StringPrintf("Query observe mode state response is %x",
+                                              sObserveModeState);
+                    SyncEventGuard guard(sNfaVsCommand);
+                    sNfaVsCommand.notifyOne();
+                } break;
                 case NCI_ANDROID_SET_PASSIVE_OBSERVER_TECH:
                 case NCI_ANDROID_PASSIVE_OBSERVE: {
                     if (param_len == 5) {
@@ -212,6 +220,26 @@
 }
 
 /*
+ * Get observe mode state.
+ */
+tNFA_STATUS static nfaQueryObserveModeState() {
+    tNFA_STATUS status = NFA_STATUS_FAILED;
+
+    uint8_t cmd[] = {NCI_QUERY_ANDROID_PASSIVE_OBSERVE};
+
+    status = NFA_SendVsCommand(NCI_MSG_PROP_ANDROID, sizeof(cmd), cmd, nfaVSCallback);
+
+    if (status == NFA_STATUS_OK) {
+        if (!sNfaVsCommand.wait(1000)) {
+            LOG(WARNING) << "Timeout waiting for query observe mode response";
+            return NFA_STATUS_TIMEOUT;
+        }
+    }
+
+    return status;
+}
+
+/*
  * Enable per-technology observe mode.
  */
 tNFA_STATUS static nfaSetPassiveObserverTech(uint8_t tech_mask) {
@@ -223,7 +251,7 @@
 
     if (status == NFA_STATUS_OK) {
         if (!sNfaVsCommand.wait(SET_PASSIVE_OBSERVER_TECH_TIMEOUT_MS)) {
-            LOG(WARNING) << "Timeout waiting for set observer tech command response";
+            LOG(WARNING) << "Timeout waiting for set observer tech response";
             return NFA_STATUS_TIMEOUT;
         }
     }
@@ -235,7 +263,6 @@
  * Get chipset capabilities.
  */
 tNFA_STATUS static nfaGetCaps() {
-    LOG(ERROR) << "getting caps";
     tNFA_STATUS status = NFA_STATUS_FAILED;
 
     uint8_t cmd[] = {NCI_ANDROID_GET_CAPS};
@@ -309,8 +336,16 @@
     tNFA_STATUS status = nfaObserveModeEnable(true);
     ASSERT_EQ(status, NFA_STATUS_OK);
 
+    status = nfaQueryObserveModeState();
+    ASSERT_EQ(status, NFA_STATUS_OK);
+    ASSERT_NE(sObserveModeState, 0);
+
     status = nfaObserveModeEnable(false);
     ASSERT_EQ(status, NFA_STATUS_OK);
+
+    status = nfaQueryObserveModeState();
+    ASSERT_EQ(status, NFA_STATUS_OK);
+    ASSERT_EQ(sObserveModeState, 0);
 }
 
 /*
@@ -331,15 +366,27 @@
 
     status = nfaSetPassiveObserverTech(NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_A);
     ASSERT_EQ(status, NFA_STATUS_OK);
+    status = nfaQueryObserveModeState();
+    ASSERT_EQ(status, NFA_STATUS_OK);
+    ASSERT_EQ(sObserveModeState, NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_A);
 
     status = nfaSetPassiveObserverTech(NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_B);
     ASSERT_EQ(status, NFA_STATUS_OK);
+    status = nfaQueryObserveModeState();
+    ASSERT_EQ(status, NFA_STATUS_OK);
+    ASSERT_EQ(sObserveModeState, NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_B);
 
     status = nfaSetPassiveObserverTech(NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_V);
     ASSERT_EQ(status, NFA_STATUS_OK);
+    status = nfaQueryObserveModeState();
+    ASSERT_EQ(status, NFA_STATUS_OK);
+    ASSERT_EQ(sObserveModeState, NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_V);
 
     status = nfaSetPassiveObserverTech(NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_F);
     ASSERT_EQ(status, NFA_STATUS_OK);
+    status = nfaQueryObserveModeState();
+    ASSERT_EQ(status, NFA_STATUS_OK);
+    ASSERT_EQ(sObserveModeState, NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_F);
 }
 
 /*
@@ -357,6 +404,11 @@
                                        NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_B |
                                        NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_V);
     ASSERT_EQ(status, NFA_STATUS_OK);
+    status = nfaQueryObserveModeState();
+    ASSERT_EQ(status, NFA_STATUS_OK);
+    ASSERT_EQ(sObserveModeState, NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_A |
+                        NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_B |
+                        NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_V);
 }
 
 /*
@@ -366,16 +418,41 @@
  * @VsrTest = GMS-VSR-3.2.8-002
  */
 TEST_P(NfcBehaviorChanges, SetPassiveObserverTech_allOnAndOff) {
-    LOG(ERROR) << "starting new test";
     if (get_vsr_api_level() < 202504) {
         GTEST_SKIP() << "Skipping test for board API level < 202504";
     }
 
     tNFC_STATUS status = nfaSetPassiveObserverTech(0x0F);
     ASSERT_EQ(status, NFA_STATUS_OK);
+    status = nfaQueryObserveModeState();
+    ASSERT_EQ(status, NFA_STATUS_OK);
+    ASSERT_EQ(sObserveModeState, 0x0F);
 
     status = nfaSetPassiveObserverTech(0x00);
     ASSERT_EQ(status, NFA_STATUS_OK);
+    status = nfaQueryObserveModeState();
+    ASSERT_EQ(status, NFA_STATUS_OK);
+    ASSERT_EQ(sObserveModeState, 0x00);
+}
+
+/*
+ * SetPassiveObserverTech_testThroughput:
+ * Verifies observe mode can be enabled and disabled repeatedly without timing out or erroring.
+ *
+ * @VsrTest = GMS-VSR-3.2.8-002
+ */
+TEST_P(NfcBehaviorChanges, SetPassiveObserverTech_testThroughput) {
+    if (get_vsr_api_level() < 202504) {
+        GTEST_SKIP() << "Skipping test for board API level < 202504";
+    }
+
+    for (int i = 0; i < 100; ++i) {
+        tNFC_STATUS status = nfaSetPassiveObserverTech(0x0F);
+        ASSERT_EQ(status, NFA_STATUS_OK);
+
+        status = nfaSetPassiveObserverTech(0x00);
+        ASSERT_EQ(status, NFA_STATUS_OK);
+    }
 }
 
 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NfcBehaviorChanges);
diff --git a/wifi/aidl/default/wifi_legacy_hal.cpp b/wifi/aidl/default/wifi_legacy_hal.cpp
index c6d6177..812c419 100644
--- a/wifi/aidl/default/wifi_legacy_hal.cpp
+++ b/wifi/aidl/default/wifi_legacy_hal.cpp
@@ -1931,6 +1931,16 @@
     return {capabs, status};
 }
 
+void invalidateTwtInternalCallbacks() {
+    on_twt_failure_internal_callback = nullptr;
+    on_twt_session_create_internal_callback = nullptr;
+    on_twt_session_update_internal_callback = nullptr;
+    on_twt_session_teardown_internal_callback = nullptr;
+    on_twt_session_stats_internal_callback = nullptr;
+    on_twt_session_suspend_internal_callback = nullptr;
+    on_twt_session_resume_internal_callback = nullptr;
+}
+
 wifi_error WifiLegacyHal::twtRegisterEvents(
         const std::string& ifaceName, const on_twt_failure& on_twt_failure_user_callback,
         const on_twt_session_create& on_twt_session_create_user_callback,
@@ -1984,11 +1994,15 @@
         on_twt_session_resume_user_callback(id, session_id);
     };
 
-    return global_func_table_.wifi_twt_register_events(
+    wifi_error status = global_func_table_.wifi_twt_register_events(
             getIfaceHandle(ifaceName),
             {onAsyncTwtError, onAsyncTwtSessionCreate, onAsyncTwtSessionUpdate,
              onAsyncTwtSessionTeardown, onAsyncTwtSessionStats, onAsyncTwtSessionSuspend,
              onAsyncTwtSessionResume});
+    if (status != WIFI_SUCCESS) {
+        invalidateTwtInternalCallbacks();
+    }
+    return status;
 }
 
 wifi_error WifiLegacyHal::twtSessionSetup(const std::string& ifaceName, uint32_t cmdId,
@@ -2226,6 +2240,7 @@
     on_twt_event_device_notify_callback = nullptr;
     on_chre_nan_rtt_internal_callback = nullptr;
     on_cached_scan_results_internal_callback = nullptr;
+    invalidateTwtInternalCallbacks();
 }
 
 }  // namespace legacy_hal
diff --git a/wifi/aidl/vts/functional/wifi_sta_iface_aidl_test.cpp b/wifi/aidl/vts/functional/wifi_sta_iface_aidl_test.cpp
index 4f25171..29c47f5 100644
--- a/wifi/aidl/vts/functional/wifi_sta_iface_aidl_test.cpp
+++ b/wifi/aidl/vts/functional/wifi_sta_iface_aidl_test.cpp
@@ -535,7 +535,12 @@
  */
 TEST_P(WifiStaIfaceAidlTest, SetDtimMultiplier) {
     // Multiplied value
-    EXPECT_TRUE(wifi_sta_iface_->setDtimMultiplier(2).isOk());
+    auto status = wifi_sta_iface_->setDtimMultiplier(2);
+    if (checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)) {
+        GTEST_SKIP() << "SetDtimMultiplier is not supported";
+    }
+    EXPECT_TRUE(status.isOk());
+
     // Driver default value
     EXPECT_TRUE(wifi_sta_iface_->setDtimMultiplier(0).isOk());
 }
@@ -560,12 +565,17 @@
     uint16_t etherType = 0x0800;  // IPv4
     uint32_t periodInMs = 1000;   // 1 sec
 
-    // Expected to fail with test values
-    EXPECT_FALSE(wifi_sta_iface_
-                         ->startSendingKeepAlivePackets(kTestCmdId, ipPacketData, etherType,
-                                                        kTestMacAddr1, kTestMacAddr2, periodInMs)
-                         .isOk());
-    EXPECT_FALSE(wifi_sta_iface_->stopSendingKeepAlivePackets(kTestCmdId).isOk());
+    auto status = wifi_sta_iface_->startSendingKeepAlivePackets(
+            kTestCmdId, ipPacketData, etherType, kTestMacAddr1, kTestMacAddr2, periodInMs);
+    if (!status.isOk()) {
+        // The device may not support this operation or the specific test values
+        GTEST_SKIP() << "StartAndStopSendingKeepAlivePackets is not supported"
+                     << ", status=" << status.getServiceSpecificError();
+    }
+    EXPECT_TRUE(status.isOk());
+
+    // If start was successful, then stop should also work
+    EXPECT_TRUE(wifi_sta_iface_->stopSendingKeepAlivePackets(kTestCmdId).isOk());
 }
 
 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiStaIfaceAidlTest);