blob: 2bdba5e3d028756be9d0637718e0d05a49e387b9 [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 <unistd.h>
18
Svet Ganov5b81f552018-03-02 09:21:30 -080019#include <binder/PermissionController.h>
Andy Hung4ef19fa2018-05-15 19:35:29 -070020#include <cutils/multiuser.h>
21#include <private/android_filesystem_config.h>
Svet Ganov5b81f552018-03-02 09:21:30 -080022
Glenn Kasten44deb052012-02-05 18:09:08 -080023namespace android {
24
Andy Hungab7ef302018-05-15 19:35:29 -070025// Audio permission utilities
26
Andy Hung4ef19fa2018-05-15 19:35:29 -070027// Used for calls that should originate from system services.
28// We allow that some services might have separate processes to
29// handle multiple users, e.g. u10_system, u10_bluetooth, u10_radio.
30static inline bool isServiceUid(uid_t uid) {
31 return multiuser_get_app_id(uid) < AID_APP_START;
32}
33
34// Used for calls that should originate from audioserver.
35static inline bool isAudioServerUid(uid_t uid) {
36 return uid == AID_AUDIOSERVER;
37}
38
39// Used for some permission checks.
40// AID_ROOT is OK for command-line tests. Native audioserver always OK.
41static inline bool isAudioServerOrRootUid(uid_t uid) {
42 return uid == AID_AUDIOSERVER || uid == AID_ROOT;
43}
44
45// Used for calls that should come from system server or internal.
46// Note: system server is multiprocess for multiple users. audioserver is not.
47static inline bool isAudioServerOrSystemServerUid(uid_t uid) {
48 return multiuser_get_app_id(uid) == AID_SYSTEM || uid == AID_AUDIOSERVER;
49}
50
51// Mediaserver may forward the client PID and UID as part of a binder interface call;
52// otherwise the calling UID must be equal to the client UID.
53static inline bool isAudioServerOrMediaServerUid(uid_t uid) {
54 switch (uid) {
55 case AID_MEDIA:
56 case AID_AUDIOSERVER:
57 return true;
58 default:
59 return false;
60 }
61}
62
Marco Nelissendcb346b2015-09-09 10:47:29 -070063bool recordingAllowed(const String16& opPackageName, pid_t pid, uid_t uid);
Svet Ganov5b81f552018-03-02 09:21:30 -080064bool startRecording(const String16& opPackageName, pid_t pid, uid_t uid);
65void finishRecording(const String16& opPackageName, uid_t uid);
Eric Laurentb2379ba2016-05-23 17:42:12 -070066bool captureAudioOutputAllowed(pid_t pid, uid_t uid);
Eric Laurent7504b9e2017-08-15 18:17:26 -070067bool captureHotwordAllowed(pid_t pid, uid_t uid);
Glenn Kasten44deb052012-02-05 18:09:08 -080068bool settingsAllowed();
Eric Laurent5284ed52014-05-29 14:37:38 -070069bool modifyAudioRoutingAllowed();
Glenn Kasten44deb052012-02-05 18:09:08 -080070bool dumpAllowed();
Nadav Bar766fb022018-01-07 12:18:03 +020071bool modifyPhoneStateAllowed(pid_t pid, uid_t uid);
Glenn Kasten44deb052012-02-05 18:09:08 -080072}