• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 #ifndef ANDROID_MEDIA_TRANSCODING_UID_POLICY_H
18 #define ANDROID_MEDIA_TRANSCODING_UID_POLICY_H
19 
20 #include <aidl/android/media/ITranscodingClient.h>
21 #include <aidl/android/media/ITranscodingClientCallback.h>
22 #include <media/UidPolicyInterface.h>
23 #include <sys/types.h>
24 #include <utils/Condition.h>
25 
26 #include <map>
27 #include <mutex>
28 #include <unordered_map>
29 #include <unordered_set>
30 
31 struct AActivityManager_UidImportanceListener;
32 
33 namespace android {
34 
35 // Observer for UID lifecycle and provide information about the uid's app
36 // priority used by the session controller.
37 class TranscodingUidPolicy : public UidPolicyInterface {
38 public:
39     explicit TranscodingUidPolicy();
40     ~TranscodingUidPolicy();
41 
42     // UidPolicyInterface
43     bool isUidOnTop(uid_t uid) override;
44     void registerMonitorUid(uid_t uid) override;
45     void unregisterMonitorUid(uid_t uid) override;
46     std::unordered_set<uid_t> getTopUids() const override;
47     void setCallback(const std::shared_ptr<UidPolicyCallbackInterface>& cb) override;
48     // ~UidPolicyInterface
49 
50 private:
51     void onUidStateChanged(uid_t uid, int32_t procState);
52     void registerSelf();
53     void unregisterSelf();
54     int32_t getProcState_l(uid_t uid) NO_THREAD_SAFETY_ANALYSIS;
55     void updateTopUid_l() NO_THREAD_SAFETY_ANALYSIS;
56 
57     static void OnUidImportance(uid_t uid, int32_t uidImportance, void* cookie);
58 
59     struct ResourceManagerClient;
60     mutable Mutex mUidLock;
61     AActivityManager_UidImportanceListener* mUidObserver;
62 
63     bool mRegistered GUARDED_BY(mUidLock);
64     int32_t mTopUidState GUARDED_BY(mUidLock);
65     std::unordered_map<uid_t, int32_t> mUidStateMap GUARDED_BY(mUidLock);
66     std::map<int32_t, std::unordered_set<uid_t>> mStateUidMap GUARDED_BY(mUidLock);
67     std::weak_ptr<UidPolicyCallbackInterface> mUidPolicyCallback;
68 };  // class TranscodingUidPolicy
69 
70 }  // namespace android
71 #endif  // ANDROID_MEDIA_TRANSCODING_SERVICE_H
72