• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     // Note: `default` is not feasible because Parcelable does not provide ==.
48     bool operator==(const LayerMetadata& rhs) const { return mMap == rhs.mMap; }
49     bool operator!=(const LayerMetadata&) const = default;
50 
51     // Merges other into this LayerMetadata. If eraseEmpty is true, any entries in
52     // in this whose keys are paired with empty values in other will be erased.
53     bool merge(const LayerMetadata& other, bool eraseEmpty = false);
54 
55     status_t writeToParcel(Parcel* parcel) const override;
56     status_t readFromParcel(const Parcel* parcel) override;
57 
58     bool has(uint32_t key) const;
59     int32_t getInt32(uint32_t key, int32_t fallback) const;
60     void setInt32(uint32_t key, int32_t value);
61     std::optional<int64_t> getInt64(uint32_t key) const;
62     void setInt64(uint32_t key, int64_t value);
63 
64     std::string itemToString(uint32_t key, const char* separator) const;
65 };
66 
67 // Keep in sync with the GameManager.java constants.
68 enum class GameMode : int32_t {
69     Unsupported = 0,
70     Standard = 1,
71     Performance = 2,
72     Battery = 3,
73     Custom = 4,
74 
75     ftl_last = Custom
76 };
77 
78 } // namespace android::gui
79 
80 using android::gui::METADATA_ACCESSIBILITY_ID;
81 using android::gui::METADATA_CALLING_UID;
82 using android::gui::METADATA_DEQUEUE_TIME;
83 using android::gui::METADATA_GAME_MODE;
84 using android::gui::METADATA_MOUSE_CURSOR;
85 using android::gui::METADATA_OWNER_PID;
86 using android::gui::METADATA_OWNER_UID;
87 using android::gui::METADATA_TASK_ID;
88 using android::gui::METADATA_WINDOW_TYPE;
89