Glenn Kasten | 44deb05 | 2012-02-05 18:09:08 -0800 | [diff] [blame] | 1 | /* |
| 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 Laurent | 9b11c02 | 2018-06-06 19:19:22 -0700 | [diff] [blame] | 19 | #include <binder/IMemory.h> |
Svet Ganov | 5b81f55 | 2018-03-02 09:21:30 -0800 | [diff] [blame] | 20 | #include <binder/PermissionController.h> |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 21 | #include <cutils/multiuser.h> |
| 22 | #include <private/android_filesystem_config.h> |
Svet Ganov | 5b81f55 | 2018-03-02 09:21:30 -0800 | [diff] [blame] | 23 | |
Glenn Kasten | 44deb05 | 2012-02-05 18:09:08 -0800 | [diff] [blame] | 24 | namespace android { |
| 25 | |
Andy Hung | ab7ef30 | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 26 | // Audio permission utilities |
| 27 | |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 28 | // 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. |
| 31 | static 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. |
| 36 | static 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. |
| 42 | static 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. |
| 48 | static 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. |
| 54 | static 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 Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 64 | bool recordingAllowed(const String16& opPackageName, pid_t pid, uid_t uid); |
Svet Ganov | 5b81f55 | 2018-03-02 09:21:30 -0800 | [diff] [blame] | 65 | bool startRecording(const String16& opPackageName, pid_t pid, uid_t uid); |
| 66 | void finishRecording(const String16& opPackageName, uid_t uid); |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 67 | bool captureAudioOutputAllowed(pid_t pid, uid_t uid); |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 68 | bool captureHotwordAllowed(pid_t pid, uid_t uid); |
Glenn Kasten | 44deb05 | 2012-02-05 18:09:08 -0800 | [diff] [blame] | 69 | bool settingsAllowed(); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 70 | bool modifyAudioRoutingAllowed(); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame^] | 71 | bool modifyDefaultAudioEffectsAllowed(); |
Glenn Kasten | 44deb05 | 2012-02-05 18:09:08 -0800 | [diff] [blame] | 72 | bool dumpAllowed(); |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 73 | bool modifyPhoneStateAllowed(pid_t pid, uid_t uid); |
Eric Laurent | 9b11c02 | 2018-06-06 19:19:22 -0700 | [diff] [blame] | 74 | status_t checkIMemory(const sp<IMemory>& iMemory); |
Glenn Kasten | 44deb05 | 2012-02-05 18:09:08 -0800 | [diff] [blame] | 75 | } |