blob: 98f54c2b8ba66053162c355ad9d0cff44e191b3c [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
Eric Laurent9b11c022018-06-06 19:19:22 -070019#include <binder/IMemory.h>
Svet Ganov5b81f552018-03-02 09:21:30 -080020#include <binder/PermissionController.h>
Andy Hung4ef19fa2018-05-15 19:35:29 -070021#include <cutils/multiuser.h>
22#include <private/android_filesystem_config.h>
Svet Ganov5b81f552018-03-02 09:21:30 -080023
Glenn Kasten44deb052012-02-05 18:09:08 -080024namespace android {
25
Andy Hungab7ef302018-05-15 19:35:29 -070026// Audio permission utilities
27
Andy Hung4ef19fa2018-05-15 19:35:29 -070028// Used for calls that should originate from system services.
29// We allow that some services might have separate processes to
30// handle multiple users, e.g. u10_system, u10_bluetooth, u10_radio.
31static inline bool isServiceUid(uid_t uid) {
32 return multiuser_get_app_id(uid) < AID_APP_START;
33}
34
35// Used for calls that should originate from audioserver.
36static inline bool isAudioServerUid(uid_t uid) {
37 return uid == AID_AUDIOSERVER;
38}
39
40// Used for some permission checks.
41// AID_ROOT is OK for command-line tests. Native audioserver always OK.
42static inline bool isAudioServerOrRootUid(uid_t uid) {
43 return uid == AID_AUDIOSERVER || uid == AID_ROOT;
44}
45
46// Used for calls that should come from system server or internal.
47// Note: system server is multiprocess for multiple users. audioserver is not.
48static inline bool isAudioServerOrSystemServerUid(uid_t uid) {
49 return multiuser_get_app_id(uid) == AID_SYSTEM || uid == AID_AUDIOSERVER;
50}
51
52// Mediaserver may forward the client PID and UID as part of a binder interface call;
53// otherwise the calling UID must be equal to the client UID.
54static inline bool isAudioServerOrMediaServerUid(uid_t uid) {
55 switch (uid) {
56 case AID_MEDIA:
57 case AID_AUDIOSERVER:
58 return true;
59 default:
60 return false;
61 }
62}
63
Marco Nelissendcb346b2015-09-09 10:47:29 -070064bool recordingAllowed(const String16& opPackageName, pid_t pid, uid_t uid);
Svet Ganov5b81f552018-03-02 09:21:30 -080065bool startRecording(const String16& opPackageName, pid_t pid, uid_t uid);
66void finishRecording(const String16& opPackageName, uid_t uid);
Eric Laurentb2379ba2016-05-23 17:42:12 -070067bool captureAudioOutputAllowed(pid_t pid, uid_t uid);
Eric Laurent7504b9e2017-08-15 18:17:26 -070068bool captureHotwordAllowed(pid_t pid, uid_t uid);
Glenn Kasten44deb052012-02-05 18:09:08 -080069bool settingsAllowed();
Eric Laurent5284ed52014-05-29 14:37:38 -070070bool modifyAudioRoutingAllowed();
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -070071bool modifyDefaultAudioEffectsAllowed();
Glenn Kasten44deb052012-02-05 18:09:08 -080072bool dumpAllowed();
Nadav Bar766fb022018-01-07 12:18:03 +020073bool modifyPhoneStateAllowed(pid_t pid, uid_t uid);
Eric Laurent9b11c022018-06-06 19:19:22 -070074status_t checkIMemory(const sp<IMemory>& iMemory);
Glenn Kasten44deb052012-02-05 18:09:08 -080075}