1 /*
2 * Copyright (C) 2025 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 #pragma once
18
19 #include <android-base/thread_annotations.h>
20 #include <cutils/android_filesystem_config.h>
21 #include <log/log.h>
22 #include <system/audio.h>
23 #include <utils/RefBase.h>
24
25 namespace android::media::permission {
26
27 /**
28 * Tracking ops for the following uids are pointless -- system always has ops and isn't tracked,
29 * and native only services don't have packages which is what appops tracks over.
30 * So, we skip tracking, and always permit access.
31 * Notable omissions are AID_SHELL, AID_RADIO, and AID_BLUETOOTH, which are non-app uids which
32 * interface with us, but are associated with packages so can still be attributed to.
33 */
skipOpsForUid(uid_t uid)34 inline bool skipOpsForUid(uid_t uid) {
35 switch (uid % AID_USER_OFFSET) {
36 case AID_ROOT:
37 case AID_SYSTEM:
38 case AID_MEDIA:
39 case AID_AUDIOSERVER:
40 case AID_CAMERASERVER:
41 return true;
42 default:
43 return false;
44 }
45 }
46
isSystemUsage(audio_usage_t usage)47 inline bool isSystemUsage(audio_usage_t usage) {
48 const std::array SYSTEM_USAGES{AUDIO_USAGE_CALL_ASSISTANT, AUDIO_USAGE_EMERGENCY,
49 AUDIO_USAGE_SAFETY, AUDIO_USAGE_VEHICLE_STATUS,
50 AUDIO_USAGE_ANNOUNCEMENT, AUDIO_USAGE_SPEAKER_CLEANUP};
51 return std::find(std::begin(SYSTEM_USAGES), std::end(SYSTEM_USAGES), usage) !=
52 std::end(SYSTEM_USAGES);
53 }
54
55 } // namespace android::media::permission
56