audio policy: check permissions for AUDIO_INPUT_FLAG_HW_HOTWORD

Allow audio capture with AUDIO_INPUT_FLAG_HW_HOTWORD only if the
caller has CAPTURE_AUDIO_HOTWORD permission granted. While at it,
update the return code to PERMISSION_DENIED for other permission
checks as well.

Bug: 178654411
Test: tested by setting hotword mode from AGSA application that has the
required permission. Able to see hal opened with correct flag.
Test: Forced to always return error if flag was set and verified
AudioRecord starting in application fails.

Merged-In: I827ab5933621bff71a96164e40026ecccf1ba44f
Change-Id: I827ab5933621bff71a96164e40026ecccf1ba44f
(cherry picked from commit 499faed90b16ce8a09eff353ab71b6383f8b9908)
diff --git a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
index fed88a4..0ab63cf 100644
--- a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
+++ b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
@@ -590,7 +590,14 @@
 
     bool canCaptureHotword = captureHotwordAllowed(opPackageName, pid, uid);
     if ((inputSource == AUDIO_SOURCE_HOTWORD) && !canCaptureHotword) {
-        return binderStatusFromStatusT(BAD_VALUE);
+        return binderStatusFromStatusT(PERMISSION_DENIED);
+    }
+
+    if (((flags & AUDIO_INPUT_FLAG_HW_HOTWORD) != 0)
+            && !canCaptureHotword) {
+        ALOGE("%s: permission denied: hotword mode not allowed"
+              " for uid %d pid %d", __func__, uid, pid);
+        return binderStatusFromStatusT(PERMISSION_DENIED);
     }
 
     sp<AudioPolicyEffects>audioPolicyEffects;