Add interface to query the mmap support.
Currently, the mmap support is defined in system property. But the
system property only indicates if the mmap is supported or not. It
doesn't indicate on which device mmap is supported. In that case, adding
an interface to query the mmap support can help make things clear.
Test: atest AAudioTests
Test: Run OboeTester TEST OUTPUT
Test: Verify that MMAP is showed as enabled if supported
Test: Try toggling MMAP on and off when opening streams
Bug: 193275465
Change-Id: Iac289c1a02e6e2ab4076ab6f2b5045efecad97ac
diff --git a/services/audioflinger/PropertyUtils.cpp b/services/audioflinger/PropertyUtils.cpp
new file mode 100644
index 0000000..b8abb8e
--- /dev/null
+++ b/services/audioflinger/PropertyUtils.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#include <aaudio/AAudio.h>
+#include <aaudio/AAudioTesting.h>
+#include <android/media/AudioMMapPolicy.h>
+#include <cutils/properties.h>
+
+#include "PropertyUtils.h"
+
+namespace android {
+
+std::string getMmapPolicyProperty(media::AudioMMapPolicyType policyType) {
+ switch (policyType) {
+ case media::AudioMMapPolicyType::DEFAULT:
+ return "aaudio.mmap_policy";
+ case media::AudioMMapPolicyType::EXCLUSIVE:
+ return "aaudio.mmap_exclusive_policy";
+ default:
+ return "";
+ }
+}
+
+int getDefaultPolicyFromType(media::AudioMMapPolicyType policyType) {
+ switch (policyType) {
+ case media::AudioMMapPolicyType::EXCLUSIVE:
+ return AAUDIO_UNSPECIFIED;
+ case media::AudioMMapPolicyType::DEFAULT:
+ default:
+ return AAUDIO_POLICY_NEVER;
+ }
+}
+
+media::AudioMMapPolicy legacy2aidl_aaudio_policy_t_AudioMMapPolicy(aaudio_policy_t legacy) {
+ switch (legacy) {
+ case AAUDIO_POLICY_NEVER:
+ return media::AudioMMapPolicy::NEVER;
+ case AAUDIO_POLICY_AUTO:
+ return media::AudioMMapPolicy::AUTO;
+ case AAUDIO_POLICY_ALWAYS:
+ return media::AudioMMapPolicy::ALWAYS;
+ case AAUDIO_UNSPECIFIED:
+ return media::AudioMMapPolicy::UNSPECIFIED;
+ default:
+ ALOGE("%s unknown aaudio policy: %d", __func__, legacy);
+ return media::AudioMMapPolicy::UNSPECIFIED;
+ }
+}
+
+status_t getMmapPolicyInfosFromSystemProperty(
+ media::AudioMMapPolicyType policyType,
+ std::vector<media::AudioMMapPolicyInfo> *policyInfos) {
+ media::AudioMMapPolicyInfo policyInfo;
+ const std::string propertyStr = getMmapPolicyProperty(policyType);
+ if (propertyStr.empty()) {
+ return BAD_VALUE;
+ }
+ policyInfo.mmapPolicy = legacy2aidl_aaudio_policy_t_AudioMMapPolicy(
+ property_get_int32(propertyStr.c_str(), getDefaultPolicyFromType(policyType)));
+ policyInfos->push_back(policyInfo);
+ return NO_ERROR;
+}
+
+} // namespace android