blob: fae19a16ed0de940d8d29db3afa8014c2e864669 [file] [log] [blame]
Glenn Kasten44deb052012-02-05 18:09:08 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <binder/IPCThreadState.h>
18#include <binder/IServiceManager.h>
19#include <binder/PermissionCache.h>
20#include "ServiceUtilities.h"
21
22namespace android {
23
Glenn Kasten949a9262013-04-16 12:35:20 -070024// Not valid until initialized by AudioFlinger constructor. It would have to be
25// re-initialized if the process containing AudioFlinger service forks (which it doesn't).
26pid_t getpid_cached;
Glenn Kasten44deb052012-02-05 18:09:08 -080027
28bool recordingAllowed() {
29 if (getpid_cached == IPCThreadState::self()->getCallingPid()) return true;
30 static const String16 sRecordAudio("android.permission.RECORD_AUDIO");
31 // don't use PermissionCache; this is not a system permission
32 bool ok = checkCallingPermission(sRecordAudio);
33 if (!ok) ALOGE("Request requires android.permission.RECORD_AUDIO");
34 return ok;
35}
36
Jeff Brown893a5642013-08-16 20:19:26 -070037bool captureAudioOutputAllowed() {
38 if (getpid_cached == IPCThreadState::self()->getCallingPid()) return true;
39 static const String16 sCaptureAudioOutput("android.permission.CAPTURE_AUDIO_OUTPUT");
40 // don't use PermissionCache; this is not a system permission
41 bool ok = checkCallingPermission(sCaptureAudioOutput);
42 if (!ok) ALOGE("Request requires android.permission.CAPTURE_AUDIO_OUTPUT");
43 return ok;
44}
45
Eric Laurent9a54bc22013-09-09 09:08:44 -070046bool captureHotwordAllowed() {
47 static const String16 sCaptureHotwordAllowed("android.permission.CAPTURE_AUDIO_HOTWORD");
48 bool ok = checkCallingPermission(sCaptureHotwordAllowed);
49 if (!ok) ALOGE("android.permission.CAPTURE_AUDIO_HOTWORD");
50 return ok;
51}
52
Hochi Huangf53eaf42014-10-09 11:36:22 +080053bool captureFmTunerAllowed() {
54 static const String16 sCaptureFmTunerAllowed("android.permission.ACCESS_FM_RADIO");
55 bool ok = checkCallingPermission(sCaptureFmTunerAllowed);
56 if (!ok) ALOGE("android.permission.ACCESS_FM_RADIO");
57 return ok;
58}
59
Glenn Kasten44deb052012-02-05 18:09:08 -080060bool settingsAllowed() {
61 if (getpid_cached == IPCThreadState::self()->getCallingPid()) return true;
62 static const String16 sAudioSettings("android.permission.MODIFY_AUDIO_SETTINGS");
63 // don't use PermissionCache; this is not a system permission
64 bool ok = checkCallingPermission(sAudioSettings);
65 if (!ok) ALOGE("Request requires android.permission.MODIFY_AUDIO_SETTINGS");
66 return ok;
67}
68
Eric Laurent5284ed52014-05-29 14:37:38 -070069bool modifyAudioRoutingAllowed() {
70 static const String16 sModifyAudioRoutingAllowed("android.permission.MODIFY_AUDIO_ROUTING");
71 bool ok = checkCallingPermission(sModifyAudioRoutingAllowed);
72 if (!ok) ALOGE("android.permission.MODIFY_AUDIO_ROUTING");
73 return ok;
74}
75
Glenn Kasten44deb052012-02-05 18:09:08 -080076bool dumpAllowed() {
77 // don't optimize for same pid, since mediaserver never dumps itself
78 static const String16 sDump("android.permission.DUMP");
79 // OK to use PermissionCache; this is a system permission
80 bool ok = PermissionCache::checkCallingPermission(sDump);
81 // convention is for caller to dump an error message to fd instead of logging here
82 //if (!ok) ALOGE("Request requires android.permission.DUMP");
83 return ok;
84}
85
86} // namespace android