Merge "Secretkeeper: test sealing policy update" into main
diff --git a/audio/aidl/default/EffectContext.cpp b/audio/aidl/default/EffectContext.cpp
index 2e12918..4f226c4 100644
--- a/audio/aidl/default/EffectContext.cpp
+++ b/audio/aidl/default/EffectContext.cpp
@@ -46,7 +46,7 @@
     ::android::status_t status =
             EventFlag::createEventFlag(mStatusMQ->getEventFlagWord(), &mEfGroup);
     LOG_ALWAYS_FATAL_IF(status != ::android::OK || !mEfGroup, " create EventFlagGroup failed ");
-    mWorkBuffer.reserve(std::max(inBufferSizeInFloat, outBufferSizeInFloat));
+    mWorkBuffer.resize(std::max(inBufferSizeInFloat, outBufferSizeInFloat));
 }
 
 // reset buffer status by abandon input data in FMQ
@@ -82,6 +82,10 @@
     return static_cast<float*>(mWorkBuffer.data());
 }
 
+size_t EffectContext::getWorkBufferSize() const {
+    return mWorkBuffer.size();
+}
+
 std::shared_ptr<EffectContext::StatusMQ> EffectContext::getStatusFmq() const {
     return mStatusMQ;
 }
@@ -206,6 +210,8 @@
     mInputFrameSize = iFrameSize;
     mOutputFrameSize = oFrameSize;
     if (needUpdateMq) {
+        mWorkBuffer.resize(std::max(common.input.frameCount * mInputFrameSize / sizeof(float),
+                                    common.output.frameCount * mOutputFrameSize / sizeof(float)));
         return notifyDataMqUpdate();
     }
     return RetCode::SUCCESS;
diff --git a/audio/aidl/default/EffectImpl.cpp b/audio/aidl/default/EffectImpl.cpp
index b76269a..c29bf79 100644
--- a/audio/aidl/default/EffectImpl.cpp
+++ b/audio/aidl/default/EffectImpl.cpp
@@ -327,7 +327,9 @@
             return;
         }
 
-        auto processSamples = inputMQ->availableToRead();
+        assert(mImplContext->getWorkBufferSize() >=
+               std::max(inputMQ->availableToRead(), outputMQ->availableToWrite()));
+        auto processSamples = std::min(inputMQ->availableToRead(), outputMQ->availableToWrite());
         if (processSamples) {
             inputMQ->read(buffer, processSamples);
             IEffect::Status status = effectProcessImpl(buffer, buffer, processSamples);
diff --git a/audio/aidl/default/bluetooth/ModuleBluetooth.cpp b/audio/aidl/default/bluetooth/ModuleBluetooth.cpp
index 9084b30..ac375a0 100644
--- a/audio/aidl/default/bluetooth/ModuleBluetooth.cpp
+++ b/audio/aidl/default/bluetooth/ModuleBluetooth.cpp
@@ -299,7 +299,13 @@
                         : std::shared_ptr<BluetoothAudioPortAidl>(
                                   std::make_shared<BluetoothAudioPortAidlOut>());
     const auto& devicePort = audioPort.ext.get<AudioPortExt::device>();
-    if (const auto device = devicePort.device.type; !proxy.ptr->registerPort(device)) {
+    const auto device = devicePort.device.type;
+    bool registrationSuccess = false;
+    for (int i = 0; i < kCreateProxyRetries && !registrationSuccess; ++i) {
+        registrationSuccess = proxy.ptr->registerPort(device);
+        usleep(kCreateProxyRetrySleepMs * 1000);
+    }
+    if (!registrationSuccess) {
         LOG(ERROR) << __func__ << ": failed to register BT port for " << device.toString();
         return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
     }
diff --git a/audio/aidl/default/include/core-impl/ModuleBluetooth.h b/audio/aidl/default/include/core-impl/ModuleBluetooth.h
index 9451411..4e68d72 100644
--- a/audio/aidl/default/include/core-impl/ModuleBluetooth.h
+++ b/audio/aidl/default/include/core-impl/ModuleBluetooth.h
@@ -85,6 +85,8 @@
     ndk::ScopedAStatus findOrCreateProxy(
             const ::aidl::android::media::audio::common::AudioPort& audioPort, CachedProxy& proxy);
 
+    static constexpr int kCreateProxyRetries = 5;
+    static constexpr int kCreateProxyRetrySleepMs = 75;
     ChildInterface<BluetoothA2dp> mBluetoothA2dp;
     ChildInterface<BluetoothLe> mBluetoothLe;
     std::map<int32_t /*instantiated device port ID*/, CachedProxy> mProxies;
diff --git a/audio/aidl/default/include/effect-impl/EffectContext.h b/audio/aidl/default/include/effect-impl/EffectContext.h
index 24f3b5d..b3d730d 100644
--- a/audio/aidl/default/include/effect-impl/EffectContext.h
+++ b/audio/aidl/default/include/effect-impl/EffectContext.h
@@ -49,6 +49,7 @@
     std::shared_ptr<DataMQ> getOutputDataFmq() const;
 
     float* getWorkBuffer();
+    size_t getWorkBufferSize() const;
 
     // reset buffer status by abandon input data in FMQ
     void resetBuffer();
diff --git a/bluetooth/finder/aidl/default/service.cpp b/bluetooth/finder/aidl/default/service.cpp
index a117df8..fe8904b 100644
--- a/bluetooth/finder/aidl/default/service.cpp
+++ b/bluetooth/finder/aidl/default/service.cpp
@@ -35,12 +35,16 @@
       ndk::SharedRefBase::make<BluetoothFinder>();
   std::string instance =
       std::string() + BluetoothFinder::descriptor + "/default";
-  auto result =
-      AServiceManager_addService(service->asBinder().get(), instance.c_str());
-  if (result == STATUS_OK) {
-    ABinderProcess_joinThreadPool();
+  if (AServiceManager_isDeclared(instance.c_str())) {
+    auto result =
+        AServiceManager_addService(service->asBinder().get(), instance.c_str());
+    if (result != STATUS_OK) {
+      ALOGE("Could not register as a service!");
+    }
   } else {
-    ALOGE("Could not register as a service!");
+    ALOGE("Could not register as a service because it's not declared.");
   }
+  // Keep running
+  ABinderProcess_joinThreadPool();
   return 0;
 }
diff --git a/bluetooth/lmp_event/aidl/default/src/main.rs b/bluetooth/lmp_event/aidl/default/src/main.rs
index cbdd4d1..dfb097f 100644
--- a/bluetooth/lmp_event/aidl/default/src/main.rs
+++ b/bluetooth/lmp_event/aidl/default/src/main.rs
@@ -41,10 +41,11 @@
     let lmp_event_service = lmp_event::LmpEvent::new();
     let lmp_event_service_binder = BnBluetoothLmpEvent::new_binder(lmp_event_service, BinderFeatures::default());
 
-    binder::add_service(
-        &format!("{}/default", lmp_event::LmpEvent::get_descriptor()),
-        lmp_event_service_binder.as_binder(),
-    ).expect("Failed to register service");
-
+    let descriptor = format!("{}/default", lmp_event::LmpEvent::get_descriptor());
+    if binder::is_declared(&descriptor).expect("Failed to check if declared") {
+        binder::add_service(&descriptor, lmp_event_service_binder.as_binder()).expect("Failed to register service");
+    } else {
+        info!("{LOG_TAG}: Failed to register service. Not declared.");
+    }
     binder::ProcessState::join_thread_pool()
 }
diff --git a/bluetooth/ranging/aidl/default/service.cpp b/bluetooth/ranging/aidl/default/service.cpp
index 83e539e..35a3f55 100644
--- a/bluetooth/ranging/aidl/default/service.cpp
+++ b/bluetooth/ranging/aidl/default/service.cpp
@@ -37,12 +37,16 @@
       ndk::SharedRefBase::make<BluetoothChannelSounding>();
   std::string instance =
       std::string() + BluetoothChannelSounding::descriptor + "/default";
-  auto result =
-      AServiceManager_addService(service->asBinder().get(), instance.c_str());
-  if (result == STATUS_OK) {
-    ABinderProcess_joinThreadPool();
+  if (AServiceManager_isDeclared(instance.c_str())) {
+    auto result =
+        AServiceManager_addService(service->asBinder().get(), instance.c_str());
+    if (result != STATUS_OK) {
+      ALOGE("Could not register as a service!");
+    }
   } else {
-    ALOGE("Could not register as a service!");
+    ALOGE("Could not register as a service because it's not declared.");
   }
+  // Keep running
+  ABinderProcess_joinThreadPool();
   return 0;
 }
diff --git a/compatibility_matrices/Android.bp b/compatibility_matrices/Android.bp
index eefca39..a3e1cd4 100644
--- a/compatibility_matrices/Android.bp
+++ b/compatibility_matrices/Android.bp
@@ -94,3 +94,11 @@
         "kernel_config_v_6.6",
     ],
 }
+
+vintf_compatibility_matrix {
+    name: "framework_compatibility_matrix.tmp.xml",
+    stem: "compatibility_matrix.tmp.xml",
+    srcs: [
+        "compatibility_matrix.tmp.xml",
+    ],
+}
diff --git a/compatibility_matrices/Android.mk b/compatibility_matrices/Android.mk
index 72ead58..7abf35e 100644
--- a/compatibility_matrices/Android.mk
+++ b/compatibility_matrices/Android.mk
@@ -112,7 +112,8 @@
 # interfaces (in the `next` release configuration).
 ifeq ($(RELEASE_AIDL_USE_UNFROZEN),true)
 my_system_matrix_deps += \
-    framework_compatibility_matrix.202404.xml
+    framework_compatibility_matrix.202404.xml \
+    framework_compatibility_matrix.tmp.xml
 endif
 
 my_framework_matrix_deps += \
diff --git a/compatibility_matrices/compatibility_matrix.202404.xml b/compatibility_matrices/compatibility_matrix.202404.xml
index 490498e..b34011e 100644
--- a/compatibility_matrices/compatibility_matrix.202404.xml
+++ b/compatibility_matrices/compatibility_matrix.202404.xml
@@ -343,25 +343,6 @@
             <instance>default</instance>
         </interface>
     </hal>
-    <hal format="hidl">
-        <name>android.hardware.media.c2</name>
-        <version>1.0-2</version>
-        <interface>
-            <name>IComponentStore</name>
-            <instance>software</instance>
-            <regex-instance>default[0-9]*</regex-instance>
-            <regex-instance>vendor[0-9]*_software</regex-instance>
-        </interface>
-    </hal>
-    <hal format="hidl">
-        <name>android.hardware.media.c2</name>
-        <version>1.0</version>
-        <interface>
-            <name>IConfigurable</name>
-            <instance>default</instance>
-            <instance>software</instance>
-        </interface>
-    </hal>
     <hal format="aidl">
         <name>android.hardware.media.c2</name>
         <version>1</version>
diff --git a/compatibility_matrices/compatibility_matrix.tmp.xml b/compatibility_matrices/compatibility_matrix.tmp.xml
new file mode 100644
index 0000000..85e3c4c
--- /dev/null
+++ b/compatibility_matrices/compatibility_matrix.tmp.xml
@@ -0,0 +1,24 @@
+<compatibility-matrix version="1.0" type="framework" level="202404">
+  <!-- This file holds the HIDL media.c2 interface while it
+  is being deprecated. This will be removed after the flag ramping
+  complete. This interface is not allowed in the 202404 vendor interface -->
+    <hal format="hidl" optional="true">
+        <name>android.hardware.media.c2</name>
+        <version>1.0-2</version>
+        <interface>
+            <name>IComponentStore</name>
+            <instance>software</instance>
+            <regex-instance>default[0-9]*</regex-instance>
+            <regex-instance>vendor[0-9]*_software</regex-instance>
+        </interface>
+    </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.media.c2</name>
+        <version>1.0</version>
+        <interface>
+            <name>IConfigurable</name>
+            <instance>default</instance>
+            <instance>software</instance>
+        </interface>
+    </hal>
+</compatibility-matrix>
diff --git a/contexthub/OWNERS b/contexthub/OWNERS
index d5cfc2e..ee25833 100644
--- a/contexthub/OWNERS
+++ b/contexthub/OWNERS
@@ -1,4 +1,3 @@
 # Bug component: 156070
 arthuri@google.com
 bduddie@google.com
-stange@google.com
diff --git a/security/secretkeeper/aidl/vts/Android.bp b/security/secretkeeper/aidl/vts/Android.bp
index 9d1701a..0061e88 100644
--- a/security/secretkeeper/aidl/vts/Android.bp
+++ b/security/secretkeeper/aidl/vts/Android.bp
@@ -50,7 +50,7 @@
         "libbinder_rs",
         "libciborium",
         "libcoset",
-        "libdice_policy",
+        "libdice_policy_builder",
         "liblog_rust",
         "libsecretkeeper_client",
         "libsecretkeeper_comm_nostd",
@@ -72,7 +72,7 @@
         "libbinder_rs",
         "libclap",
         "libcoset",
-        "libdice_policy",
+        "libdice_policy_builder",
         "libhex",
         "liblog_rust",
         "libsecretkeeper_client",
diff --git a/security/secretkeeper/aidl/vts/secretkeeper_cli.rs b/security/secretkeeper/aidl/vts/secretkeeper_cli.rs
index 5f08482..0c13811 100644
--- a/security/secretkeeper/aidl/vts/secretkeeper_cli.rs
+++ b/security/secretkeeper/aidl/vts/secretkeeper_cli.rs
@@ -24,7 +24,8 @@
 use authgraph_core::traits::Sha256;
 use clap::{Args, Parser, Subcommand};
 use coset::CborSerializable;
-use dice_policy::{ConstraintSpec, ConstraintType, DicePolicy, MissingAction};
+use dice_policy_builder::{ConstraintSpec, ConstraintType, MissingAction, policy_for_dice_chain};
+
 use secretkeeper_client::{dice::OwnedDiceArtifactsWithExplicitKey, SkSession};
 use secretkeeper_comm::data_types::{
     error::SecretkeeperError,
@@ -146,7 +147,7 @@
                 MissingAction::Ignore,
             ),
         ];
-        DicePolicy::from_dice_chain(dice, &constraint_spec)
+        policy_for_dice_chain(dice, &constraint_spec)
             .unwrap()
             .to_vec()
             .context("serialize DICE policy")
diff --git a/security/secretkeeper/aidl/vts/secretkeeper_test_client.rs b/security/secretkeeper/aidl/vts/secretkeeper_test_client.rs
index 439883f..e4f7b51 100644
--- a/security/secretkeeper/aidl/vts/secretkeeper_test_client.rs
+++ b/security/secretkeeper/aidl/vts/secretkeeper_test_client.rs
@@ -20,7 +20,7 @@
 use authgraph_boringssl as boring;
 use authgraph_core::key;
 use coset::{CborSerializable, CoseEncrypt0};
-use dice_policy::{ConstraintSpec, ConstraintType, DicePolicy, MissingAction};
+use dice_policy_builder::{ConstraintSpec, ConstraintType, MissingAction, policy_for_dice_chain};
 use rdroidtest::{ignore_if, rdroidtest};
 use secretkeeper_client::dice::OwnedDiceArtifactsWithExplicitKey;
 use secretkeeper_client::SkSession;
@@ -267,7 +267,7 @@
         ),
     ];
 
-    DicePolicy::from_dice_chain(dice, &constraint_spec).unwrap().to_vec().unwrap()
+    policy_for_dice_chain(dice, &constraint_spec).unwrap().to_vec().unwrap()
 }
 
 /// Perform AuthGraph key exchange, returning the session keys and session ID.
diff --git a/tv/tuner/aidl/vts/functional/VtsHalTvTunerTestConfigurations.h b/tv/tuner/aidl/vts/functional/VtsHalTvTunerTestConfigurations.h
index 5c13ed0..ff94639 100644
--- a/tv/tuner/aidl/vts/functional/VtsHalTvTunerTestConfigurations.h
+++ b/tv/tuner/aidl/vts/functional/VtsHalTvTunerTestConfigurations.h
@@ -731,9 +731,20 @@
     if (videoFilterIds.empty() || audioFilterIds.empty() || frontendMap.empty()) {
         return;
     }
-    if (hasSwFe && !hasHwFe && dvrMap.empty()) {
-        ALOGD("Cannot configure Live. Only software frontends and no dvr connections");
-        return;
+    if (!hasHwFe) {
+        if (hasSwFe) {
+            if (dvrMap.empty()) {
+                ALOGD("Cannot configure Live. Only software frontends and no dvr connections.");
+                return;
+            }
+            // Live is available if there is SW FE and some DVR is attached.
+        } else {
+            // We will arrive here because frontendMap won't be empty since
+            // there will be at least a default frontend declared. But the
+            // default frontend doesn't count as "hasSwFe".
+            ALOGD("Cannot configure Live. No frontend declared at all.");
+            return;
+        }
     }
     ALOGD("Can support live");
     live.hasFrontendConnection = true;
diff --git a/weaver/vts/VtsHalWeaverTargetTest.cpp b/weaver/vts/VtsHalWeaverTargetTest.cpp
index 754d467..40e9558 100644
--- a/weaver/vts/VtsHalWeaverTargetTest.cpp
+++ b/weaver/vts/VtsHalWeaverTargetTest.cpp
@@ -222,9 +222,8 @@
     }
     // Starting in Android 14, the system will always use at least one Weaver slot if Weaver is
     // supported at all.  Make sure we saw at least one.
-    // TODO: uncomment after Android 14 is merged into AOSP
-    // ASSERT_FALSE(used_slots.empty())
-    //<< "Could not determine which Weaver slots are in use by the system";
+    ASSERT_FALSE(used_slots.empty())
+            << "Could not determine which Weaver slots are in use by the system";
 
     // Find the first free slot.
     int found = 0;