Merge changes from topic "aidl_freeze_tm" into tm-dev

* changes:
  Implement getInterfaceHash/Version for SoundTrigger
  Add -Wno-missing-permission-annotation for soundtrigger3
  V3 is the latest version of keymaster HAL interface
  Freeze AIDL APIs for TM
diff --git a/graphics/allocator/aidl/vts/Android.bp b/graphics/allocator/aidl/vts/Android.bp
index d74129b..99ffb24 100644
--- a/graphics/allocator/aidl/vts/Android.bp
+++ b/graphics/allocator/aidl/vts/Android.bp
@@ -28,6 +28,7 @@
     defaults: [
         "VtsHalTargetTestDefaults",
         "use_libaidlvintf_gtest_helper_static",
+        "hwui_defaults",
     ],
     srcs: [
         "VtsHalGraphicsAllocatorAidl_TargetTest.cpp",
@@ -46,10 +47,15 @@
         "libgui",
         "libhidlbase",
         "libvndksupport",
+        "libnativewindow",
     ],
     static_libs: [
         "libaidlcommonsupport",
         "libgtest",
+        "libhwui",
+    ],
+    header_libs: [
+        "libhwui_internal_headers",
     ],
     cflags: [
         "-Wall",
diff --git a/graphics/allocator/aidl/vts/VtsHalGraphicsAllocatorAidl_TargetTest.cpp b/graphics/allocator/aidl/vts/VtsHalGraphicsAllocatorAidl_TargetTest.cpp
index 784bc66..c9d058d 100644
--- a/graphics/allocator/aidl/vts/VtsHalGraphicsAllocatorAidl_TargetTest.cpp
+++ b/graphics/allocator/aidl/vts/VtsHalGraphicsAllocatorAidl_TargetTest.cpp
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#undef LOG_TAG
 #define LOG_TAG "VtsHalGraphicsAllocatorAidl_TargetTest"
 
 #include <aidl/Vintf.h>
@@ -28,6 +29,10 @@
 #include <gtest/gtest.h>
 #include <hidl/GtestPrinter.h>
 #include <hidl/ServiceManagement.h>
+#include <hwui/Bitmap.h>
+#include <renderthread/EglManager.h>
+#include <utils/GLUtils.h>
+#include <vndk/hardware_buffer.h>
 #include <initializer_list>
 #include <optional>
 #include <string>
@@ -38,6 +43,10 @@
 using namespace android;
 using namespace android::hardware;
 using namespace android::hardware::graphics::mapper::V4_0;
+using android::uirenderer::AutoEglImage;
+using android::uirenderer::AutoGLFramebuffer;
+using android::uirenderer::AutoSkiaGlTexture;
+using android::uirenderer::renderthread::EglManager;
 
 static constexpr uint64_t pack(const std::initializer_list<BufferUsage>& usages) {
     uint64_t ret = 0;
@@ -56,13 +65,15 @@
     native_handle_t* mRawHandle;
     bool mImported = false;
     uint32_t mStride;
+    const IMapper::BufferDescriptorInfo mInfo;
 
     BufferHandle(const BufferHandle&) = delete;
     void operator=(const BufferHandle&) = delete;
 
   public:
-    BufferHandle(const sp<IMapper> mapper, native_handle_t* handle, bool imported, uint32_t stride)
-        : mMapper(mapper), mRawHandle(handle), mImported(imported), mStride(stride) {}
+    BufferHandle(const sp<IMapper> mapper, native_handle_t* handle, bool imported, uint32_t stride,
+                 const IMapper::BufferDescriptorInfo& info)
+        : mMapper(mapper), mRawHandle(handle), mImported(imported), mStride(stride), mInfo(info) {}
 
     ~BufferHandle() {
         if (mRawHandle == nullptr) return;
@@ -77,27 +88,47 @@
     }
 
     uint32_t stride() const { return mStride; }
+
+    AHardwareBuffer_Desc describe() const {
+        return {
+                .width = mInfo.width,
+                .height = mInfo.height,
+                .layers = mInfo.layerCount,
+                .format = static_cast<uint32_t>(mInfo.format),
+                .usage = mInfo.usage,
+                .stride = stride(),
+                .rfu0 = 0,
+                .rfu1 = 0,
+        };
+    }
+
+    AHardwareBuffer* createAHardwareBuffer() const {
+        auto desc = describe();
+        AHardwareBuffer* buffer = nullptr;
+        int err = AHardwareBuffer_createFromHandle(
+                &desc, mRawHandle, AHARDWAREBUFFER_CREATE_FROM_HANDLE_METHOD_CLONE, &buffer);
+        EXPECT_EQ(0, err) << "Failed to AHardwareBuffer_createFromHandle";
+        return err ? nullptr : buffer;
+    }
 };
 
-class GraphicsAllocatorAidlTests
-    : public ::testing::TestWithParam<std::tuple<std::string, std::string>> {
+class GraphicsTestsBase {
   private:
     std::shared_ptr<IAllocator> mAllocator;
     sp<IMapper> mMapper;
 
-  public:
-    void SetUp() override {
+  protected:
+    void Initialize(std::string allocatorService, std::string mapperService) {
         mAllocator = IAllocator::fromBinder(
-                ndk::SpAIBinder(AServiceManager_checkService(std::get<0>(GetParam()).c_str())));
-        mMapper = IMapper::getService(std::get<1>(GetParam()));
+                ndk::SpAIBinder(AServiceManager_checkService(allocatorService.c_str())));
+        mMapper = IMapper::getService(mapperService);
 
         ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service";
         ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service";
         ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode";
     }
 
-    void TearDown() override {}
-
+  public:
     BufferDescriptor createDescriptor(const IMapper::BufferDescriptorInfo& descriptorInfo) {
         BufferDescriptor descriptor;
         mMapper->createDescriptor(
@@ -109,18 +140,7 @@
         return descriptor;
     }
 
-    native_handle_t* importBuffer(const hidl_handle& rawHandle) {
-        native_handle_t* bufferHandle = nullptr;
-        mMapper->importBuffer(rawHandle, [&](const auto& tmpError, const auto& tmpBuffer) {
-            ASSERT_EQ(Error::NONE, tmpError)
-                    << "failed to import buffer %p" << rawHandle.getNativeHandle();
-            bufferHandle = static_cast<native_handle_t*>(tmpBuffer);
-        });
-        return bufferHandle;
-    }
-
-    std::unique_ptr<BufferHandle> allocate(const IMapper::BufferDescriptorInfo& descriptorInfo,
-                                           bool import = false) {
+    std::unique_ptr<BufferHandle> allocate(const IMapper::BufferDescriptorInfo& descriptorInfo) {
         auto descriptor = createDescriptor(descriptorInfo);
         if (::testing::Test::HasFatalFailure()) {
             return nullptr;
@@ -139,20 +159,81 @@
             }
             return nullptr;
         } else {
-            if (import) {
-                native_handle_t* importedHandle = importBuffer(makeFromAidl(result.buffers[0]));
-                if (importedHandle) {
-                    return std::make_unique<BufferHandle>(mMapper, importedHandle, true,
-                                                          result.stride);
-                } else {
-                    return nullptr;
-                }
-            } else {
-                return std::make_unique<BufferHandle>(mMapper, dupFromAidl(result.buffers[0]),
-                                                      false, result.stride);
-            }
+            return std::make_unique<BufferHandle>(mMapper, dupFromAidl(result.buffers[0]), false,
+                                                  result.stride, descriptorInfo);
         }
     }
+
+    bool isSupported(const IMapper::BufferDescriptorInfo& descriptorInfo) {
+        bool ret = false;
+        EXPECT_TRUE(mMapper->isSupported(descriptorInfo,
+                                         [&](auto error, bool supported) {
+                                             ASSERT_EQ(Error::NONE, error);
+                                             ret = supported;
+                                         })
+                            .isOk());
+        return ret;
+    }
+};
+
+class GraphicsAllocatorAidlTests
+    : public GraphicsTestsBase,
+      public ::testing::TestWithParam<std::tuple<std::string, std::string>> {
+  public:
+    void SetUp() override { Initialize(std::get<0>(GetParam()), std::get<1>(GetParam())); }
+
+    void TearDown() override {}
+};
+
+struct FlushMethod {
+    std::string name;
+    std::function<void(EglManager&)> func;
+};
+
+class GraphicsFrontBufferTests
+    : public GraphicsTestsBase,
+      public ::testing::TestWithParam<std::tuple<std::string, std::string, FlushMethod>> {
+  private:
+    EglManager eglManager;
+    std::function<void(EglManager&)> flush;
+
+  public:
+    void SetUp() override {
+        Initialize(std::get<0>(GetParam()), std::get<1>(GetParam()));
+        flush = std::get<2>(GetParam()).func;
+        eglManager.initialize();
+    }
+
+    void TearDown() override { eglManager.destroy(); }
+
+    void fillWithGpu(AHardwareBuffer* buffer, float red, float green, float blue, float alpha) {
+        const EGLClientBuffer clientBuffer = eglGetNativeClientBufferANDROID(buffer);
+        AutoEglImage eglImage(eglManager.eglDisplay(), clientBuffer);
+        AutoSkiaGlTexture glTexture;
+        AutoGLFramebuffer glFbo;
+        glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, eglImage.image);
+        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
+                               glTexture.mTexture, 0);
+
+        AHardwareBuffer_Desc desc;
+        AHardwareBuffer_describe(buffer, &desc);
+        glViewport(0, 0, desc.width, desc.height);
+        glDisable(GL_STENCIL_TEST);
+        glDisable(GL_SCISSOR_TEST);
+        glClearColor(red, green, blue, alpha);
+        glClear(GL_COLOR_BUFFER_BIT);
+        flush(eglManager);
+    }
+
+    void fillWithGpu(AHardwareBuffer* buffer, /*RGBA*/ uint32_t color) {
+        // Keep it simple for now
+        static_assert(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__);
+        float a = float((color >> 24) & 0xff) / 255.0f;
+        float b = float((color >> 16) & 0xff) / 255.0f;
+        float g = float((color >> 8) & 0xff) / 255.0f;
+        float r = float((color)&0xff) / 255.0f;
+        fillWithGpu(buffer, r, g, b, a);
+    }
 };
 
 TEST_P(GraphicsAllocatorAidlTests, CreateDescriptorBasic) {
@@ -181,9 +262,117 @@
     EXPECT_GE(buffer->stride(), 64);
 }
 
+TEST_P(GraphicsFrontBufferTests, FrontBufferGpuToCpu) {
+    IMapper::BufferDescriptorInfo info{
+            .name = "CPU_8888",
+            .width = 64,
+            .height = 64,
+            .layerCount = 1,
+            .format = cast(PixelFormat::RGBA_8888),
+            .usage = pack({BufferUsage::GPU_RENDER_TARGET, BufferUsage::CPU_READ_OFTEN,
+                           BufferUsage::FRONT_BUFFER}),
+            .reservedSize = 0,
+    };
+    const bool supported = isSupported(info);
+    auto buffer = allocate(info);
+    if (!supported) {
+        ASSERT_EQ(nullptr, buffer.get())
+                << "Allocation succeeded, but IMapper::isSupported was false";
+    } else {
+        ASSERT_NE(nullptr, buffer.get()) << "Allocation failed, but IMapper::isSupported was true";
+    }
+
+    AHardwareBuffer* ahb = buffer->createAHardwareBuffer();
+    ASSERT_NE(nullptr, ahb);
+
+    // We draw 3 times with 3 different colors to ensure the flush is consistently flushing.
+    // Particularly for glFlush() there's occasions where it seems something triggers a flush
+    // to happen even though glFlush itself isn't consistently doing so, but for FRONT_BUFFER
+    // bound buffers it is supposed to consistently flush.
+    for (uint32_t color : {0xFF0000FFu, 0x00FF00FFu, 0x0000FFFFu}) {
+        fillWithGpu(ahb, color);
+        uint32_t* addr;
+        ASSERT_EQ(0, AHardwareBuffer_lock(ahb, AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, -1, nullptr,
+                                          (void**)&addr));
+        // Spot check a few pixels
+        EXPECT_EQ(color, addr[0]);
+        EXPECT_EQ(color, addr[32 + (32 * buffer->stride())]);
+        AHardwareBuffer_unlock(ahb, nullptr);
+    }
+
+    AHardwareBuffer_release(ahb);
+}
+
+TEST_P(GraphicsFrontBufferTests, FrontBufferGpuToGpu) {
+    IMapper::BufferDescriptorInfo info{
+            .name = "CPU_8888",
+            .width = 64,
+            .height = 64,
+            .layerCount = 1,
+            .format = cast(PixelFormat::RGBA_8888),
+            .usage = pack({BufferUsage::GPU_RENDER_TARGET, BufferUsage::GPU_TEXTURE,
+                           BufferUsage::FRONT_BUFFER}),
+            .reservedSize = 0,
+    };
+    const bool supported = isSupported(info);
+    auto buffer = allocate(info);
+    if (!supported) {
+        ASSERT_EQ(nullptr, buffer.get())
+                << "Allocation succeeded, but IMapper::isSupported was false";
+    } else {
+        ASSERT_NE(nullptr, buffer.get()) << "Allocation failed, but IMapper::isSupported was true";
+    }
+
+    AHardwareBuffer* ahb = buffer->createAHardwareBuffer();
+    ASSERT_NE(nullptr, ahb);
+
+    // We draw 3 times with 3 different colors to ensure the flush is consistently flushing.
+    // Particularly for glFlush() there's occasions where it seems something triggers a flush
+    // to happen even though glFlush itself isn't consistently doing so, but for FRONT_BUFFER
+    // bound buffers it is supposed to consistently flush.
+    for (uint32_t color : {0xFF0000FFu, 0x00FF00FFu, 0x0000FFFFu}) {
+        fillWithGpu(ahb, color);
+        sk_sp<Bitmap> hwBitmap = Bitmap::createFrom(ahb, SkColorSpace::MakeSRGB());
+        SkBitmap cpuBitmap = hwBitmap->getSkBitmap();
+        // Spot check a few pixels
+        EXPECT_EQ(color, *cpuBitmap.getAddr32(0, 0));
+        EXPECT_EQ(color, *cpuBitmap.getAddr32(16, 30));
+    }
+
+    AHardwareBuffer_release(ahb);
+}
+
 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsAllocatorAidlTests);
 INSTANTIATE_TEST_CASE_P(
         PerInstance, GraphicsAllocatorAidlTests,
         testing::Combine(testing::ValuesIn(getAidlHalInstanceNames(IAllocator::descriptor)),
                          testing::ValuesIn(getAllHalInstanceNames(IMapper::descriptor))),
-        PrintInstanceTupleNameToString<>);
\ No newline at end of file
+        PrintInstanceTupleNameToString<>);
+
+const auto FlushMethodsValues = testing::Values(
+        FlushMethod{"glFinish", [](EglManager&) { glFinish(); }},
+        FlushMethod{"glFlush",
+                    [](EglManager&) {
+                        glFlush();
+                        // Since the goal is to verify that glFlush() actually flushes, we can't
+                        // wait on any sort of fence since that will change behavior So instead we
+                        // just sleep & hope
+                        sleep(1);
+                    }},
+        FlushMethod{"eglClientWaitSync", [](EglManager& eglManager) {
+                        EGLDisplay display = eglManager.eglDisplay();
+                        EGLSyncKHR fence = eglCreateSyncKHR(display, EGL_SYNC_FENCE_KHR, NULL);
+                        eglClientWaitSyncKHR(display, fence, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR,
+                                             EGL_FOREVER_KHR);
+                        eglDestroySyncKHR(display, fence);
+                    }});
+GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsFrontBufferTests);
+INSTANTIATE_TEST_CASE_P(
+        PerInstance, GraphicsFrontBufferTests,
+        testing::Combine(testing::ValuesIn(getAidlHalInstanceNames(IAllocator::descriptor)),
+                         testing::ValuesIn(getAllHalInstanceNames(IMapper::descriptor)),
+                         FlushMethodsValues),
+        [](auto info) -> std::string {
+            std::string name = std::to_string(info.index) + "/" + std::get<2>(info.param).name;
+            return Sanitize(name);
+        });
\ No newline at end of file
diff --git a/radio/aidl/vts/radio_aidl_hal_utils.cpp b/radio/aidl/vts/radio_aidl_hal_utils.cpp
index 8618851..efc4f26 100644
--- a/radio/aidl/vts/radio_aidl_hal_utils.cpp
+++ b/radio/aidl/vts/radio_aidl_hal_utils.cpp
@@ -206,7 +206,7 @@
     EXPECT_EQ(RadioError::NONE, radioSimRsp->rspInfo.error);
 }
 
-void RadioServiceTest::updateSimSlotStatus() {
+void RadioServiceTest::updateSimSlotStatus(int physicalSlotId) {
     // Update SimSlotStatus from RadioConfig
     std::shared_ptr<RadioConfigResponse> radioConfigRsp =
             ndk::SharedRefBase::make<RadioConfigResponse>(*this);
@@ -219,8 +219,7 @@
     EXPECT_EQ(RadioResponseType::SOLICITED, radioConfigRsp->rspInfo.type);
     EXPECT_EQ(serial, radioConfigRsp->rspInfo.serial);
     EXPECT_EQ(RadioError::NONE, radioConfigRsp->rspInfo.error);
-    // assuming only 1 slot
-    for (const SimSlotStatus& slotStatusResponse : radioConfigRsp->simSlotStatus) {
-        slotStatus = slotStatusResponse;
+    if (radioConfigRsp->simSlotStatus.size() > physicalSlotId) {
+        slotStatus = radioConfigRsp->simSlotStatus[physicalSlotId];
     }
 }
diff --git a/radio/aidl/vts/radio_aidl_hal_utils.h b/radio/aidl/vts/radio_aidl_hal_utils.h
index d6f7bf7..47976b9 100644
--- a/radio/aidl/vts/radio_aidl_hal_utils.h
+++ b/radio/aidl/vts/radio_aidl_hal_utils.h
@@ -70,6 +70,7 @@
 #define MODEM_EMERGENCY_CALL_ESTABLISH_TIME 3
 #define MODEM_EMERGENCY_CALL_DISCONNECT_TIME 3
 #define MODEM_SET_SIM_POWER_DELAY_IN_SECONDS 2
+#define MODEM_SET_SIM_SLOT_MAPPING_DELAY_IN_SECONDS 6
 
 #define RADIO_SERVICE_SLOT1_NAME "slot1"  // HAL instance name for SIM slot 1 or single SIM device
 #define RADIO_SERVICE_SLOT2_NAME "slot2"  // HAL instance name for SIM slot 2 on dual SIM device
@@ -146,5 +147,5 @@
     void updateSimCardStatus();
 
     /* Update SIM slot status */
-    void updateSimSlotStatus();
+    void updateSimSlotStatus(int physicalSlotId);
 };
diff --git a/radio/aidl/vts/radio_config_test.cpp b/radio/aidl/vts/radio_config_test.cpp
index 83c4de0..5e1c811 100644
--- a/radio/aidl/vts/radio_config_test.cpp
+++ b/radio/aidl/vts/radio_config_test.cpp
@@ -171,6 +171,15 @@
     slotPortMapping.physicalSlotId = 0;
     slotPortMapping.portId = 0;
     std::vector<SlotPortMapping> slotPortMappingList = {slotPortMapping};
+    if (isDsDsEnabled()) {
+        slotPortMapping.physicalSlotId = 1;
+        slotPortMappingList.push_back(slotPortMapping);
+    } else if (isTsTsEnabled()) {
+        slotPortMapping.physicalSlotId = 1;
+        slotPortMappingList.push_back(slotPortMapping);
+        slotPortMapping.physicalSlotId = 2;
+        slotPortMappingList.push_back(slotPortMapping);
+    }
     ndk::ScopedAStatus res = radio_config->setSimSlotsMapping(serial, slotPortMappingList);
     ASSERT_OK(res);
     EXPECT_EQ(std::cv_status::no_timeout, wait());
@@ -179,6 +188,9 @@
     ALOGI("setSimSlotsMapping, rspInfo.error = %s\n",
           toString(radioRsp_config->rspInfo.error).c_str());
     ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error, {RadioError::NONE}));
+
+    // Give some time for modem to fully switch SIM configuration
+    sleep(MODEM_SET_SIM_SLOT_MAPPING_DELAY_IN_SECONDS);
 }
 
 /*
diff --git a/radio/aidl/vts/radio_sim_test.cpp b/radio/aidl/vts/radio_sim_test.cpp
index f94a2a0..e69247d 100644
--- a/radio/aidl/vts/radio_sim_test.cpp
+++ b/radio/aidl/vts/radio_sim_test.cpp
@@ -108,7 +108,7 @@
     // have CardStatus::STATE_PRESENT after turning the power back on
     if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
         updateSimCardStatus();
-        updateSimSlotStatus();
+        updateSimSlotStatus(cardStatus.slotMap.physicalSlotId);
         EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState);
         EXPECT_EQ(CardStatus::STATE_PRESENT, slotStatus.cardState);
         if (CardStatus::STATE_PRESENT == slotStatus.cardState) {
diff --git a/security/keymint/aidl/vts/functional/AttestKeyTest.cpp b/security/keymint/aidl/vts/functional/AttestKeyTest.cpp
index 0bab54c..5cdea93 100644
--- a/security/keymint/aidl/vts/functional/AttestKeyTest.cpp
+++ b/security/keymint/aidl/vts/functional/AttestKeyTest.cpp
@@ -783,7 +783,7 @@
         vector<Certificate> attested_key_cert_chain;
         auto result = GenerateKey(builder, attest_key, &attested_key_blob,
                                   &attested_key_characteristics, &attested_key_cert_chain);
-        if (result == ErrorCode::CANNOT_ATTEST_IDS) {
+        if (result == ErrorCode::CANNOT_ATTEST_IDS && !isDeviceIdAttestationRequired()) {
             continue;
         }
 
diff --git a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp
index f9510d3..943c692 100644
--- a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp
+++ b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp
@@ -207,6 +207,14 @@
     return boot_patch_level(key_characteristics_);
 }
 
+/**
+ * An API to determine device IDs attestation is required or not,
+ * which is mandatory for KeyMint version 2 or first_api_level 33 or greater.
+ */
+bool KeyMintAidlTestBase::isDeviceIdAttestationRequired() {
+    return AidlVersion() >= 2 || property_get_int32("ro.vendor.api_level", 0) >= 33;
+}
+
 bool KeyMintAidlTestBase::Curve25519Supported() {
     // Strongbox never supports curve 25519.
     if (SecLevel() == SecurityLevel::STRONGBOX) {
diff --git a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h
index 602dcaf..7279c95 100644
--- a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h
+++ b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h
@@ -79,6 +79,7 @@
     uint32_t vendor_patch_level() { return vendor_patch_level_; }
     uint32_t boot_patch_level(const vector<KeyCharacteristics>& key_characteristics);
     uint32_t boot_patch_level();
+    bool isDeviceIdAttestationRequired();
 
     bool Curve25519Supported();
 
diff --git a/security/keymint/aidl/vts/functional/KeyMintTest.cpp b/security/keymint/aidl/vts/functional/KeyMintTest.cpp
index 3aa09fa..e73f46c 100644
--- a/security/keymint/aidl/vts/functional/KeyMintTest.cpp
+++ b/security/keymint/aidl/vts/functional/KeyMintTest.cpp
@@ -1986,8 +1986,8 @@
         if (SecLevel() == SecurityLevel::STRONGBOX) {
             if (result == ErrorCode::ATTESTATION_KEYS_NOT_PROVISIONED) return;
         }
-        if (result == ErrorCode::CANNOT_ATTEST_IDS) {
-            // Device ID attestation is optional; KeyMint may not support it at all.
+        if (result == ErrorCode::CANNOT_ATTEST_IDS && !isDeviceIdAttestationRequired()) {
+            // ID attestation was optional till api level 32, from api level 33 it is mandatory.
             continue;
         }
         ASSERT_EQ(result, ErrorCode::OK);
diff --git a/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp b/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
index abb80a2..3841715 100644
--- a/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
+++ b/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
@@ -196,7 +196,7 @@
     active.startFrequency = frequencyHz;
     active.endAmplitude = (getAmplitudeMin() + getAmplitudeMax()) / 2;
     active.endFrequency = frequencyHz;
-    active.duration = 1000;
+    vibrator->getPwlePrimitiveDurationMax(&(active.duration));
 
     return active;
 }
@@ -759,7 +759,9 @@
     std::future<void> completionFuture{completionPromise.get_future()};
     sp<CompletionCallback> callback =
         new CompletionCallback([&completionPromise] { completionPromise.set_value(); });
-    uint32_t durationMs = 2100;  // Sum of 2 active and 1 braking below
+    int32_t segmentDurationMaxMs;
+    vibrator->getPwlePrimitiveDurationMax(&segmentDurationMaxMs);
+    uint32_t durationMs = segmentDurationMaxMs * 2 + 100;  // Sum of 2 active and 1 braking below
     //TODO(b/187207798): revert back to conservative timeout values once
     //latencies have been fixed
     std::chrono::milliseconds timeout{durationMs * 4};
@@ -863,7 +865,7 @@
     if (capabilities & IVibrator::CAP_COMPOSE_PWLE_EFFECTS) {
         ActivePwle active = composeValidActivePwle(vibrator, capabilities);
 
-        int segmentDurationMaxMs;
+        int32_t segmentDurationMaxMs;
         vibrator->getPwlePrimitiveDurationMax(&segmentDurationMaxMs);
         active.duration = segmentDurationMaxMs + 10;  // Segment duration greater than allowed
 
diff --git a/wifi/1.6/default/hidl_struct_util.cpp b/wifi/1.6/default/hidl_struct_util.cpp
index 45459e2..2112b26 100644
--- a/wifi/1.6/default/hidl_struct_util.cpp
+++ b/wifi/1.6/default/hidl_struct_util.cpp
@@ -1881,7 +1881,7 @@
                       "ifaceName too long";
         return false;
     }
-    strncpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
+    strlcpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
     legacy_request->ndp_cfg.security_cfg =
             (hidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN)
                     ? legacy_hal::NAN_DP_CONFIG_SECURITY
@@ -1958,7 +1958,7 @@
                       "ifaceName too long";
         return false;
     }
-    strncpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
+    strlcpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
     legacy_request->ndp_cfg.security_cfg =
             (hidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN)
                     ? legacy_hal::NAN_DP_CONFIG_SECURITY
@@ -2039,7 +2039,7 @@
                       "ifaceName too long";
         return false;
     }
-    strncpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
+    strlcpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
     legacy_request->ndp_cfg.security_cfg =
             (hidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN)
                     ? legacy_hal::NAN_DP_CONFIG_SECURITY
@@ -2114,7 +2114,7 @@
                       "ifaceName too long";
         return false;
     }
-    strncpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
+    strlcpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
     legacy_request->ndp_cfg.security_cfg =
             (hidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN)
                     ? legacy_hal::NAN_DP_CONFIG_SECURITY
diff --git a/wifi/1.6/default/wifi_chip.cpp b/wifi/1.6/default/wifi_chip.cpp
index 6cc1235..7f0e97d 100644
--- a/wifi/1.6/default/wifi_chip.cpp
+++ b/wifi/1.6/default/wifi_chip.cpp
@@ -131,7 +131,7 @@
     if (strncmp(buffer.data(), P2P_MGMT_DEVICE_PREFIX, strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) {
         /* Get the p2p parent interface name from p2p device interface name set
          * in property */
-        strncpy(p2pParentIfname, buffer.data() + strlen(P2P_MGMT_DEVICE_PREFIX),
+        strlcpy(p2pParentIfname, buffer.data() + strlen(P2P_MGMT_DEVICE_PREFIX),
                 strlen(buffer.data()) - strlen(P2P_MGMT_DEVICE_PREFIX));
         if (property_get(kActiveWlanIfaceNameProperty, primaryIfaceName.data(), nullptr) == 0) {
             return buffer.data();
@@ -217,14 +217,15 @@
 
 // Helper function for |cpioArchiveFilesInDir|
 bool cpioWriteHeader(int out_fd, struct stat& st, const char* file_name, size_t file_name_len) {
-    std::array<char, 32 * 1024> read_buf;
-    ssize_t llen =
-            sprintf(read_buf.data(), "%s%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X",
-                    kCpioMagic, static_cast<int>(st.st_ino), st.st_mode, st.st_uid, st.st_gid,
-                    static_cast<int>(st.st_nlink), static_cast<int>(st.st_mtime),
-                    static_cast<int>(st.st_size), major(st.st_dev), minor(st.st_dev),
-                    major(st.st_rdev), minor(st.st_rdev), static_cast<uint32_t>(file_name_len), 0);
-    if (write(out_fd, read_buf.data(), llen) == -1) {
+    const int buf_size = 32 * 1024;
+    std::array<char, buf_size> read_buf;
+    ssize_t llen = snprintf(
+            read_buf.data(), buf_size, "%s%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X",
+            kCpioMagic, static_cast<int>(st.st_ino), st.st_mode, st.st_uid, st.st_gid,
+            static_cast<int>(st.st_nlink), static_cast<int>(st.st_mtime),
+            static_cast<int>(st.st_size), major(st.st_dev), minor(st.st_dev), major(st.st_rdev),
+            minor(st.st_rdev), static_cast<uint32_t>(file_name_len), 0);
+    if (write(out_fd, read_buf.data(), llen < buf_size ? llen : buf_size - 1) == -1) {
         PLOG(ERROR) << "Error writing cpio header to file " << file_name;
         return false;
     }
@@ -282,10 +283,11 @@
 
 // Helper function for |cpioArchiveFilesInDir|
 bool cpioWriteFileTrailer(int out_fd) {
-    std::array<char, 4096> read_buf;
+    const int buf_size = 4096;
+    std::array<char, buf_size> read_buf;
     read_buf.fill(0);
-    if (write(out_fd, read_buf.data(),
-              sprintf(read_buf.data(), "070701%040X%056X%08XTRAILER!!!", 1, 0x0b, 0) + 4) == -1) {
+    ssize_t llen = snprintf(read_buf.data(), 4096, "070701%040X%056X%08XTRAILER!!!", 1, 0x0b, 0);
+    if (write(out_fd, read_buf.data(), (llen < buf_size ? llen : buf_size - 1) + 4) == -1) {
         PLOG(ERROR) << "Error writing trailing bytes";
         return false;
     }
diff --git a/wifi/hostapd/aidl/vts/functional/VtsHalHostapdTargetTest.cpp b/wifi/hostapd/aidl/vts/functional/VtsHalHostapdTargetTest.cpp
index c1f2bb7..bd2649f 100644
--- a/wifi/hostapd/aidl/vts/functional/VtsHalHostapdTargetTest.cpp
+++ b/wifi/hostapd/aidl/vts/functional/VtsHalHostapdTargetTest.cpp
@@ -32,6 +32,7 @@
 
 using aidl::android::hardware::wifi::hostapd::BandMask;
 using aidl::android::hardware::wifi::hostapd::BnHostapdCallback;
+using aidl::android::hardware::wifi::hostapd::ChannelBandwidth;
 using aidl::android::hardware::wifi::hostapd::ChannelParams;
 using aidl::android::hardware::wifi::hostapd::DebugLevel;
 using aidl::android::hardware::wifi::hostapd::EncryptionType;
@@ -44,7 +45,6 @@
 
 namespace {
 const unsigned char kNwSsid[] = {'t', 'e', 's', 't', '1', '2', '3', '4', '5'};
-const std::string kIfaceName = "wlan0";
 const std::string kPassphrase = "test12345";
 const std::string kInvalidMinPassphrase = "test";
 const std::string kInvalidMaxPassphrase =
@@ -123,6 +123,7 @@
         iface_params.hwModeParams.enable80211AC = false;
         iface_params.hwModeParams.enable80211AX = false;
         iface_params.hwModeParams.enable6GhzBand = false;
+        iface_params.hwModeParams.maximumChannelBandwidth = ChannelBandwidth::BANDWIDTH_20;
 
         channelParams.enableAcs = false;
         channelParams.acsShouldExcludeDfs = false;
@@ -284,8 +285,8 @@
  */
 TEST_P(HostapdAidl, AddPskAccessPointWithAcs) {
     if (!isAcsSupport) GTEST_SKIP() << "Missing ACS support";
-    auto status = hostapd->addAccessPoint(getIfaceParamsWithAcs(kIfaceName),
-                                          getPskNwParams());
+    std::string ifname = setupApIfaceAndGetName(false);
+    auto status = hostapd->addAccessPoint(getIfaceParamsWithAcs(ifname), getPskNwParams());
     EXPECT_TRUE(status.isOk());
 }
 
@@ -295,8 +296,9 @@
  */
 TEST_P(HostapdAidl, AddPskAccessPointWithAcsAndFreqRange) {
     if (!isAcsSupport) GTEST_SKIP() << "Missing ACS support";
-    auto status = hostapd->addAccessPoint(
-        getIfaceParamsWithAcsAndFreqRange(kIfaceName), getPskNwParams());
+    std::string ifname = setupApIfaceAndGetName(false);
+    auto status =
+            hostapd->addAccessPoint(getIfaceParamsWithAcsAndFreqRange(ifname), getPskNwParams());
     EXPECT_TRUE(status.isOk());
 }
 
@@ -306,8 +308,9 @@
  */
 TEST_P(HostapdAidl, AddPskAccessPointWithAcsAndInvalidFreqRange) {
     if (!isAcsSupport) GTEST_SKIP() << "Missing ACS support";
-    auto status = hostapd->addAccessPoint(
-        getIfaceParamsWithAcsAndInvalidFreqRange(kIfaceName), getPskNwParams());
+    std::string ifname = setupApIfaceAndGetName(false);
+    auto status = hostapd->addAccessPoint(getIfaceParamsWithAcsAndInvalidFreqRange(ifname),
+                                          getPskNwParams());
     EXPECT_FALSE(status.isOk());
 }
 
@@ -317,8 +320,8 @@
  */
 TEST_P(HostapdAidl, AddOpenAccessPointWithAcs) {
     if (!isAcsSupport) GTEST_SKIP() << "Missing ACS support";
-    auto status = hostapd->addAccessPoint(getIfaceParamsWithAcs(kIfaceName),
-                                          getOpenNwParams());
+    std::string ifname = setupApIfaceAndGetName(false);
+    auto status = hostapd->addAccessPoint(getIfaceParamsWithAcs(ifname), getOpenNwParams());
     EXPECT_TRUE(status.isOk());
 }
 
@@ -327,8 +330,8 @@
  * Access point creation should pass.
  */
 TEST_P(HostapdAidl, AddPskAccessPointWithoutAcs) {
-    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(kIfaceName),
-                                          getPskNwParams());
+    std::string ifname = setupApIfaceAndGetName(false);
+    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getPskNwParams());
     EXPECT_TRUE(status.isOk());
 }
 
@@ -337,7 +340,8 @@
  * Access point creation should pass.
  */
 TEST_P(HostapdAidl, AddPskAccessPointWithoutAcsAndNonMetered) {
-    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(kIfaceName),
+    std::string ifname = setupApIfaceAndGetName(false);
+    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname),
                                           getPskNwParamsWithNonMetered());
     EXPECT_TRUE(status.isOk());
 }
@@ -347,8 +351,8 @@
  * Access point creation should pass.
  */
 TEST_P(HostapdAidl, AddOpenAccessPointWithoutAcs) {
-    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(kIfaceName),
-                                          getOpenNwParams());
+    std::string ifname = setupApIfaceAndGetName(false);
+    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getOpenNwParams());
     EXPECT_TRUE(status.isOk());
 }
 
@@ -358,8 +362,9 @@
  */
 TEST_P(HostapdAidl, AddSaeTransitionAccessPointWithoutAcs) {
     if (!isWpa3SaeSupport) GTEST_SKIP() << "Missing SAE support";
-    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(kIfaceName),
-                                          getSaeTransitionNwParams());
+    std::string ifname = setupApIfaceAndGetName(false);
+    auto status =
+            hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getSaeTransitionNwParams());
     EXPECT_TRUE(status.isOk());
 }
 
@@ -369,8 +374,8 @@
  */
 TEST_P(HostapdAidl, AddSAEAccessPointWithoutAcs) {
     if (!isWpa3SaeSupport) GTEST_SKIP() << "Missing SAE support";
-    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(kIfaceName),
-                                          getSaeNwParams());
+    std::string ifname = setupApIfaceAndGetName(false);
+    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getSaeNwParams());
     EXPECT_TRUE(status.isOk());
 }
 
@@ -380,10 +385,10 @@
  */
 TEST_P(HostapdAidl, RemoveAccessPointWithAcs) {
     if (!isAcsSupport) GTEST_SKIP() << "Missing ACS support";
-    auto status = hostapd->addAccessPoint(getIfaceParamsWithAcs(kIfaceName),
-                                          getPskNwParams());
+    std::string ifname = setupApIfaceAndGetName(false);
+    auto status = hostapd->addAccessPoint(getIfaceParamsWithAcs(ifname), getPskNwParams());
     EXPECT_TRUE(status.isOk());
-    EXPECT_TRUE(hostapd->removeAccessPoint(kIfaceName).isOk());
+    EXPECT_TRUE(hostapd->removeAccessPoint(ifname).isOk());
 }
 
 /**
@@ -391,10 +396,10 @@
  * Access point creation & removal should pass.
  */
 TEST_P(HostapdAidl, RemoveAccessPointWithoutAcs) {
-    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(kIfaceName),
-                                          getPskNwParams());
+    std::string ifname = setupApIfaceAndGetName(false);
+    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getPskNwParams());
     EXPECT_TRUE(status.isOk());
-    EXPECT_TRUE(hostapd->removeAccessPoint(kIfaceName).isOk());
+    EXPECT_TRUE(hostapd->removeAccessPoint(ifname).isOk());
 }
 
 /**
@@ -402,8 +407,9 @@
  * Access point creation should fail.
  */
 TEST_P(HostapdAidl, AddPskAccessPointWithInvalidChannel) {
-    auto status = hostapd->addAccessPoint(
-        getIfaceParamsWithInvalidChannel(kIfaceName), getPskNwParams());
+    std::string ifname = setupApIfaceAndGetName(false);
+    auto status =
+            hostapd->addAccessPoint(getIfaceParamsWithInvalidChannel(ifname), getPskNwParams());
     EXPECT_FALSE(status.isOk());
 }
 
@@ -412,8 +418,9 @@
  * Access point creation should fail.
  */
 TEST_P(HostapdAidl, AddInvalidPskAccessPointWithoutAcs) {
-    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(kIfaceName),
-                                          getInvalidPskNwParams());
+    std::string ifname = setupApIfaceAndGetName(false);
+    auto status =
+            hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getInvalidPskNwParams());
     EXPECT_FALSE(status.isOk());
 }
 
@@ -422,8 +429,9 @@
  * Access point creation should fail.
  */
 TEST_P(HostapdAidl, AddInvalidSaeTransitionAccessPointWithoutAcs) {
+    std::string ifname = setupApIfaceAndGetName(false);
     if (!isWpa3SaeSupport) GTEST_SKIP() << "Missing SAE support";
-    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(kIfaceName),
+    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname),
                                           getInvalidSaeTransitionNwParams());
     EXPECT_FALSE(status.isOk());
 }
@@ -433,9 +441,10 @@
  * Access point creation should fail.
  */
 TEST_P(HostapdAidl, AddInvalidSaeAccessPointWithoutAcs) {
+    std::string ifname = setupApIfaceAndGetName(false);
     if (!isWpa3SaeSupport) GTEST_SKIP() << "Missing SAE support";
-    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(kIfaceName),
-                                          getInvalidSaeNwParams());
+    auto status =
+            hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getInvalidSaeNwParams());
     EXPECT_FALSE(status.isOk());
 }
 
@@ -443,12 +452,11 @@
  * forceClientDisconnect should fail when hotspot interface available.
  */
 TEST_P(HostapdAidl, DisconnectClientWhenIfacAvailable) {
-    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(kIfaceName),
-                                          getOpenNwParams());
+    std::string ifname = setupApIfaceAndGetName(false);
+    auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getOpenNwParams());
     EXPECT_TRUE(status.isOk());
 
-    status = hostapd->forceClientDisconnect(kIfaceName, kTestZeroMacAddr,
-                                            kTestDisconnectReasonCode);
+    status = hostapd->forceClientDisconnect(ifname, kTestZeroMacAddr, kTestDisconnectReasonCode);
     EXPECT_FALSE(status.isOk());
 }