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