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::gui {
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     METADATA_CALLING_UID = 9,
35 };
36 
37 struct LayerMetadata : public Parcelable {
38     std::unordered_map<uint32_t, std::vector<uint8_t>> mMap;
39 
40     LayerMetadata();
41     LayerMetadata(const LayerMetadata& other);
42     LayerMetadata(LayerMetadata&& other);
43     explicit LayerMetadata(std::unordered_map<uint32_t, std::vector<uint8_t>> map);
44     LayerMetadata& operator=(const LayerMetadata& other);
45     LayerMetadata& operator=(LayerMetadata&& other);
46 
47     // Merges other into this LayerMetadata. If eraseEmpty is true, any entries in
48     // in this whose keys are paired with empty values in other will be erased.
49     bool merge(const LayerMetadata& other, bool eraseEmpty = false);
50 
51     status_t writeToParcel(Parcel* parcel) const override;
52     status_t readFromParcel(const Parcel* parcel) override;
53 
54     bool has(uint32_t key) const;
55     int32_t getInt32(uint32_t key, int32_t fallback) const;
56     void setInt32(uint32_t key, int32_t value);
57     std::optional<int64_t> getInt64(uint32_t key) const;
58     void setInt64(uint32_t key, int64_t value);
59 
60     std::string itemToString(uint32_t key, const char* separator) const;
61 };
62 
63 // Keep in sync with the GameManager.java constants.
64 enum class GameMode : int32_t {
65     Unsupported = 0,
66     Standard = 1,
67     Performance = 2,
68     Battery = 3,
69     Custom = 4,
70 
71     ftl_last = Custom
72 };
73 
74 } // namespace android::gui
75 
76 using android::gui::METADATA_ACCESSIBILITY_ID;
77 using android::gui::METADATA_DEQUEUE_TIME;
78 using android::gui::METADATA_GAME_MODE;
79 using android::gui::METADATA_MOUSE_CURSOR;
80 using android::gui::METADATA_OWNER_PID;
81 using android::gui::METADATA_OWNER_UID;
82 using android::gui::METADATA_TASK_ID;
83 using android::gui::METADATA_WINDOW_TYPE;
84