blob: c467cfdc6889962730b99cd80fb8c1773e69c21d [file] [log] [blame]
Chavi Weingartenc78f53c2023-04-14 18:50:53 +00001/*
2 * Copyright (C) 2023 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 <binder/IPCThreadState.h>
18#include <gui/LayerStatePermissions.h>
19#include <private/android_filesystem_config.h>
20#ifndef __ANDROID_VNDK__
21#include <binder/PermissionCache.h>
22#endif // __ANDROID_VNDK__
23#include <gui/LayerState.h>
24
25namespace android {
Vishnu Nair01b92c72024-04-15 21:53:56 +000026std::vector<std::pair<String16, int>> LayerStatePermissions::mPermissionMap = {
Chavi Weingartenc78f53c2023-04-14 18:50:53 +000027 // If caller has ACCESS_SURFACE_FLINGER, they automatically get ROTATE_SURFACE_FLINGER
28 // permission, as well
Vishnu Nair01b92c72024-04-15 21:53:56 +000029 {String16("android.permission.ACCESS_SURFACE_FLINGER"),
Chavi Weingartenc78f53c2023-04-14 18:50:53 +000030 layer_state_t::Permission::ACCESS_SURFACE_FLINGER |
31 layer_state_t::Permission::ROTATE_SURFACE_FLINGER},
Vishnu Nair01b92c72024-04-15 21:53:56 +000032 {String16("android.permission.ROTATE_SURFACE_FLINGER"),
Chavi Weingartenc78f53c2023-04-14 18:50:53 +000033 layer_state_t::Permission::ROTATE_SURFACE_FLINGER},
Vishnu Nair01b92c72024-04-15 21:53:56 +000034 {String16("android.permission.INTERNAL_SYSTEM_WINDOW"),
Chavi Weingartenc78f53c2023-04-14 18:50:53 +000035 layer_state_t::Permission::INTERNAL_SYSTEM_WINDOW},
36};
37
Vishnu Nair01b92c72024-04-15 21:53:56 +000038static bool callingThreadHasPermission(const String16& permission __attribute__((unused)),
Chavi Weingartenc78f53c2023-04-14 18:50:53 +000039 int pid __attribute__((unused)),
40 int uid __attribute__((unused))) {
41#ifndef __ANDROID_VNDK__
42 return uid == AID_GRAPHICS || uid == AID_SYSTEM ||
Vishnu Nair01b92c72024-04-15 21:53:56 +000043 PermissionCache::checkPermission(permission, pid, uid);
Chavi Weingartenc78f53c2023-04-14 18:50:53 +000044#endif // __ANDROID_VNDK__
45 return false;
46}
47
48uint32_t LayerStatePermissions::getTransactionPermissions(int pid, int uid) {
49 uint32_t permissions = 0;
Vishnu Nair01b92c72024-04-15 21:53:56 +000050 for (const auto& [permissionName, permissionVal] : mPermissionMap) {
Chavi Weingartenc78f53c2023-04-14 18:50:53 +000051 if (callingThreadHasPermission(permissionName, pid, uid)) {
52 permissions |= permissionVal;
53 }
54 }
55
56 return permissions;
57}
58} // namespace android