Merge "aaudio: reduce aaudio.min_sleep_usec default" into tm-dev
diff --git a/drm/libmediadrm/CryptoHalAidl.cpp b/drm/libmediadrm/CryptoHalAidl.cpp
index 642264f..3dc62e9 100644
--- a/drm/libmediadrm/CryptoHalAidl.cpp
+++ b/drm/libmediadrm/CryptoHalAidl.cpp
@@ -355,8 +355,7 @@
     std::string msgStr(statusAidl.getMessage());
     *errorDetailMsg = toString8(msgStr);
     if (err != OK) {
-        ALOGE("Failed on decrypt, error message:%s, bytes written:%d", statusAidl.getMessage(),
-              result);
+        ALOGE("Failed on decrypt, error description:%s", statusAidl.getDescription().c_str());
         return err;
     }
 
@@ -376,7 +375,7 @@
     mHeapSizes.add(seqNum, heap->size());
 
     SharedBufferAidl memAidl;
-    memAidl.handle = ::android::makeToAidl(heap->handle());
+    memAidl.handle = ::android::dupToAidl(heap->handle());
     memAidl.size = heap->size();
     memAidl.bufferId = bufferId;
 
diff --git a/drm/libmediadrm/DrmHalAidl.cpp b/drm/libmediadrm/DrmHalAidl.cpp
index dc6d23e..284abd5 100644
--- a/drm/libmediadrm/DrmHalAidl.cpp
+++ b/drm/libmediadrm/DrmHalAidl.cpp
@@ -19,6 +19,7 @@
 
 #include <array>
 #include <algorithm>
+#include <map>
 #include <android/binder_auto_utils.h>
 #include <android/binder_manager.h>
 #include <media/PluginMetricsReporting.h>
@@ -52,6 +53,7 @@
 using ::aidl::android::hardware::drm::SecureStopId;
 using ::aidl::android::hardware::drm::SecurityLevel;
 using ::aidl::android::hardware::drm::Status;
+using ::aidl::android::hardware::drm::SupportedContentType;
 using ::aidl::android::hardware::drm::Uuid;
 using DrmMetricGroupAidl = ::aidl::android::hardware::drm::DrmMetricGroup;
 using DrmMetricGroupHidl = ::android::hardware::drm::V1_1::DrmMetricGroup;
@@ -420,16 +422,30 @@
             continue;
         }
 
-        if (levelAidl != SecurityLevel::DEFAULT && levelAidl != SecurityLevel::UNKNOWN) {
-            if (levelAidl > schemes.maxLevel || levelAidl < schemes.minLevel) {
-                continue;
-            }
+        ALOGV("supported schemes: %s; query: level %d mime %s",
+              schemes.toString().c_str(), levelAidl, mimeType.c_str());
+        std::map<std::string, SupportedContentType> contentTypes;
+        for (auto ct : schemes.mimeTypes) {
+            contentTypes[ct.mime] = ct;
         }
 
-        if (!mimeTypeStr.empty()) {
-            if (!std::count(schemes.mimeTypes.begin(), schemes.mimeTypes.end(), mimeTypeStr)) {
-                continue;
+        // handle default value cases
+        if (levelAidl == SecurityLevel::DEFAULT || levelAidl == SecurityLevel::UNKNOWN) {
+            if (mimeType == "") {
+                // isCryptoSchemeSupported(uuid)
+                *isSupported = true;
+            } else {
+                // isCryptoSchemeSupported(uuid, mimeType)
+                *isSupported = contentTypes.count(mimeTypeStr);
             }
+            return OK;
+        } else if (mimeType == "") {
+            return BAD_VALUE;
+        }
+
+        auto ct = contentTypes[mimeTypeStr];
+        if (levelAidl > ct.maxLevel || levelAidl < ct.minLevel) {
+              continue;
         }
 
         *isSupported = true;
diff --git a/drm/mediadrm/plugins/clearkey/aidl/CryptoPlugin.cpp b/drm/mediadrm/plugins/clearkey/aidl/CryptoPlugin.cpp
index 651d8f5..201cf02 100644
--- a/drm/mediadrm/plugins/clearkey/aidl/CryptoPlugin.cpp
+++ b/drm/mediadrm/plugins/clearkey/aidl/CryptoPlugin.cpp
@@ -227,7 +227,7 @@
 }
 
 SharedBufferBase::~SharedBufferBase() {
-    if (munmap(mBase, mSize)) {
+    if (mBase && munmap(mBase, mSize)) {
         ALOGE("munmap err: base %p; errno %s",
               mBase, strerror(errno));
     }
diff --git a/drm/mediadrm/plugins/clearkey/aidl/DrmFactory.cpp b/drm/mediadrm/plugins/clearkey/aidl/DrmFactory.cpp
index bef05ec..30db4c0 100644
--- a/drm/mediadrm/plugins/clearkey/aidl/DrmFactory.cpp
+++ b/drm/mediadrm/plugins/clearkey/aidl/DrmFactory.cpp
@@ -82,10 +82,12 @@
     for (const auto& uuid : ::aidl::android::hardware::drm::clearkey::getSupportedCryptoSchemes()) {
         schemes.uuids.push_back({uuid});
     }
-    schemes.minLevel = SecurityLevel::SW_SECURE_CRYPTO;
-    schemes.maxLevel = SecurityLevel::SW_SECURE_CRYPTO;
-    schemes.mimeTypes = {kIsoBmffVideoMimeType, kIsoBmffAudioMimeType, kCencInitDataFormat,
-                         kWebmVideoMimeType, kWebmAudioMimeType, kWebmInitDataFormat};
+    for (auto mime : {kIsoBmffVideoMimeType, kIsoBmffAudioMimeType, kCencInitDataFormat,
+                      kWebmVideoMimeType, kWebmAudioMimeType, kWebmInitDataFormat}) {
+        const auto minLevel = SecurityLevel::SW_SECURE_CRYPTO;
+        const auto maxLevel = SecurityLevel::SW_SECURE_CRYPTO;
+        schemes.mimeTypes.push_back({mime, minLevel, maxLevel});
+    }
     *_aidl_return = schemes;
     return ndk::ScopedAStatus::ok();
 }
diff --git a/media/codec2/sfplugin/CCodec.cpp b/media/codec2/sfplugin/CCodec.cpp
index 5df28f0..def8a18 100644
--- a/media/codec2/sfplugin/CCodec.cpp
+++ b/media/codec2/sfplugin/CCodec.cpp
@@ -2619,7 +2619,10 @@
         std::vector<std::unique_ptr<C2Param>> params;
         err = intf->query(
                 {&mApiFeatures},
-                {C2PortAllocatorsTuning::input::PARAM_TYPE},
+                {
+                    C2StreamBufferTypeSetting::input::PARAM_TYPE,
+                    C2PortAllocatorsTuning::input::PARAM_TYPE
+                },
                 C2_MAY_BLOCK,
                 &params);
         if (err != C2_OK && err != C2_BAD_INDEX) {
@@ -2632,7 +2635,10 @@
             if (!param) {
                 continue;
             }
-            if (param->type() == C2PortAllocatorsTuning::input::PARAM_TYPE) {
+            if (param->type() == C2StreamBufferTypeSetting::input::PARAM_TYPE) {
+                mInputStreamFormat.reset(
+                        C2StreamBufferTypeSetting::input::From(param));
+            } else if (param->type() == C2PortAllocatorsTuning::input::PARAM_TYPE) {
                 mInputAllocators.reset(
                         C2PortAllocatorsTuning::input::From(param));
             }
@@ -2652,6 +2658,16 @@
         return mApiFeatures;
     }
 
+    const C2StreamBufferTypeSetting::input &getInputStreamFormat() const {
+        static std::unique_ptr<C2StreamBufferTypeSetting::input> sInvalidated = []{
+            std::unique_ptr<C2StreamBufferTypeSetting::input> param;
+            param.reset(new C2StreamBufferTypeSetting::input(0u, C2BufferData::INVALID));
+            param->invalidate();
+            return param;
+        }();
+        return mInputStreamFormat ? *mInputStreamFormat : *sInvalidated;
+    }
+
     const C2PortAllocatorsTuning::input &getInputAllocators() const {
         static std::unique_ptr<C2PortAllocatorsTuning::input> sInvalidated = []{
             std::unique_ptr<C2PortAllocatorsTuning::input> param =
@@ -2667,6 +2683,7 @@
 
     std::vector<C2FieldSupportedValuesQuery> mFields;
     C2ApiFeaturesSetting mApiFeatures;
+    std::unique_ptr<C2StreamBufferTypeSetting::input> mInputStreamFormat;
     std::unique_ptr<C2PortAllocatorsTuning::input> mInputAllocators;
 };
 
@@ -2708,6 +2725,24 @@
         if (intfCache.initCheck() != OK) {
             continue;
         }
+        const C2StreamBufferTypeSetting::input &streamFormat = intfCache.getInputStreamFormat();
+        if (streamFormat) {
+            C2Allocator::type_t allocatorType = C2Allocator::LINEAR;
+            if (streamFormat.value == C2BufferData::GRAPHIC
+                    || streamFormat.value == C2BufferData::GRAPHIC_CHUNKS) {
+                allocatorType = C2Allocator::GRAPHIC;
+            }
+
+            if (type != allocatorType) {
+                // requested type is not supported at input allocators
+                ids->clear();
+                ids->insert(defaultAllocatorId);
+                ALOGV("name(%s) does not support a type(0x%x) as input allocator."
+                        " uses default allocator id(%d)", name.c_str(), type, defaultAllocatorId);
+                break;
+            }
+        }
+
         const C2PortAllocatorsTuning::input &allocators = intfCache.getInputAllocators();
         if (firstIteration) {
             firstIteration = false;
diff --git a/services/audiopolicy/service/SpatializerPoseController.cpp b/services/audiopolicy/service/SpatializerPoseController.cpp
index 6a3c9d1..58a57ac 100644
--- a/services/audiopolicy/service/SpatializerPoseController.cpp
+++ b/services/audiopolicy/service/SpatializerPoseController.cpp
@@ -57,7 +57,7 @@
 constexpr float kAutoRecenterTranslationThreshold = 0.1f;
 
 // Auto-recenter considers head not still if rotated by this much (in radians, approx).
-constexpr float kAutoRecenterRotationThreshold = 7.0f / 180 * M_PI;
+constexpr float kAutoRecenterRotationThreshold = 10.5f / 180 * M_PI;
 
 // Screen is considered to be unstable (not still) if it has moved significantly within the last
 // time window of this duration.