1 /* 2 * Copyright 2019 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 <binder/Parcelable.h> 20 21 #include <unordered_map> 22 23 namespace android { 24 25 enum { 26 METADATA_OWNER_UID = 1, 27 METADATA_WINDOW_TYPE = 2, 28 METADATA_TASK_ID = 3, 29 METADATA_MOUSE_CURSOR = 4, 30 METADATA_ACCESSIBILITY_ID = 5, 31 METADATA_OWNER_PID = 6, 32 METADATA_DEQUEUE_TIME = 7, 33 METADATA_GAME_MODE = 8 34 }; 35 36 struct LayerMetadata : public Parcelable { 37 std::unordered_map<uint32_t, std::vector<uint8_t>> mMap; 38 39 LayerMetadata(); 40 LayerMetadata(const LayerMetadata& other); 41 LayerMetadata(LayerMetadata&& other); 42 explicit LayerMetadata(std::unordered_map<uint32_t, std::vector<uint8_t>> map); 43 LayerMetadata& operator=(const LayerMetadata& other); 44 LayerMetadata& operator=(LayerMetadata&& other); 45 46 // Merges other into this LayerMetadata. If eraseEmpty is true, any entries in 47 // in this whose keys are paired with empty values in other will be erased. 48 bool merge(const LayerMetadata& other, bool eraseEmpty = false); 49 50 status_t writeToParcel(Parcel* parcel) const override; 51 status_t readFromParcel(const Parcel* parcel) override; 52 53 bool has(uint32_t key) const; 54 int32_t getInt32(uint32_t key, int32_t fallback) const; 55 void setInt32(uint32_t key, int32_t value); 56 std::optional<int64_t> getInt64(uint32_t key) const; 57 void setInt64(uint32_t key, int64_t value); 58 59 std::string itemToString(uint32_t key, const char* separator) const; 60 }; 61 62 } // namespace android 63