1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <aidl/android/adpf/BnSessionManager.h>
#include <sys/types.h>
#include <utils/Thread.h>
#include "Common.h"
#include "SessionLayerMap.h"
#include <string>
namespace android {
class Layer;
namespace adpf {
namespace impl {
class PowerAdvisor;
}
// Talks to HMS to manage sessions for PowerHAL
class SessionManager : public BnSessionManager {
public:
SessionManager(uid_t uid);
// ISessionManager binder methods
ndk::ScopedAStatus trackedSessionsDied(const std::vector<int32_t>& in_sessionId) override;
ndk::ScopedAStatus associateSessionToLayers(
int32_t sessionId, int32_t ownerUid,
const std::vector<::ndk::SpAIBinder>& layers) override;
// Update the lifecycles of any tracked sessions or layers. This is intended to accepts the
// "destroyedHandles" object from updateLayerSnapshots in SF, and should reflect that type
void updateTrackingState(const std::vector<std::pair<uint32_t, std::string>>& handles);
private:
// Session metadata tracked by the mTrackedSessionData map
struct SessionData {
int32_t sessionId;
int uid;
};
// Layer metadata tracked by the mTrackedSessionData map
struct LayerData {
int32_t layerId;
};
// Checks if the layer is currently associated with a specific session in the SessionLayerMap
// This helps us know which layers might be included in an update for the HAL
bool isLayerRelevant(int32_t layerId);
// The UID of whoever created our ISessionManager connection
// FIXME: This is set but is not used anywhere.
[[maybe_unused]] const uid_t mUid;
// State owned by the main thread
// Set of layers that are currently being tracked in the SessionLayerMap. This is used to
// filter out which layers we actually care about during the latching process
std::unordered_set<int32_t> mCurrentlyRelevantLayers;
// Tracks active associations between sessions and layers. Items in this map can be thought of
// as "active" connections, and any session or layer not in this map will not receive updates or
// be collected in SurfaceFlinger
SessionLayerMap mMap;
// The list of currently-living layers which have ever been tracked, this is used to persist any
// data we want to track across potential mapping disconnects, and to determine when to send
// death updates
std::unordered_map<int32_t, LayerData> mTrackedLayerData;
// The list of currently-living sessions which have ever been tracked, this is used to persist
// any data we want to track across mapping disconnects
std::unordered_map<int32_t, SessionData> mTrackedSessionData;
// State owned by mSessionManagerMutex
std::mutex mSessionManagerMutex;
// The list of sessions that have died since we last called updateTrackingState
std::vector<int32_t> mDeadSessions GUARDED_BY(mSessionManagerMutex);
};
} // namespace adpf
} // namespace android
|