Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2022 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 "LayerCreationArgs.h" |
| 18 | #include <binder/IPCThreadState.h> |
| 19 | #include <private/android_filesystem_config.h> |
| 20 | #include "Client.h" |
| 21 | #include "gui/LayerMetadata.h" |
| 22 | |
| 23 | namespace android::surfaceflinger { |
| 24 | |
| 25 | std::atomic<uint32_t> LayerCreationArgs::sSequence{1}; |
| 26 | |
| 27 | LayerCreationArgs::LayerCreationArgs(SurfaceFlinger* flinger, sp<Client> client, std::string name, |
| 28 | uint32_t flags, gui::LayerMetadata metadataArg, |
| 29 | std::optional<uint32_t> id) |
| 30 | : flinger(flinger), |
| 31 | client(std::move(client)), |
| 32 | name(std::move(name)), |
| 33 | flags(flags), |
| 34 | metadata(std::move(metadataArg)) { |
| 35 | IPCThreadState* ipc = IPCThreadState::self(); |
| 36 | ownerPid = ipc->getCallingPid(); |
| 37 | uid_t callingUid = ipc->getCallingUid(); |
| 38 | metadata.setInt32(gui::METADATA_CALLING_UID, static_cast<int32_t>(callingUid)); |
| 39 | ownerUid = callingUid; |
| 40 | if (ownerUid == AID_GRAPHICS || ownerUid == AID_SYSTEM) { |
| 41 | // System can override the calling UID/PID since it can create layers on behalf of apps. |
| 42 | ownerPid = metadata.getInt32(gui::METADATA_OWNER_PID, ownerPid); |
| 43 | ownerUid = static_cast<uid_t>( |
| 44 | metadata.getInt32(gui::METADATA_OWNER_UID, static_cast<int32_t>(ownerUid))); |
| 45 | } |
| 46 | |
| 47 | if (id) { |
| 48 | sequence = *id; |
| 49 | sSequence = *id + 1; |
| 50 | } else { |
| 51 | sequence = sSequence++; |
| 52 | if (sequence == UNASSIGNED_LAYER_ID) { |
| 53 | ALOGW("Layer sequence id rolled over."); |
| 54 | sequence = sSequence++; |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | LayerCreationArgs::LayerCreationArgs(const LayerCreationArgs& args) |
| 60 | : LayerCreationArgs(args.flinger, args.client, args.name, args.flags, args.metadata) {} |
| 61 | |
| 62 | } // namespace android::surfaceflinger |