• 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_UID_POLICY_INTERFACE_H
18 #define ANDROID_MEDIA_UID_POLICY_INTERFACE_H
19 
20 #include <unordered_set>
21 
22 namespace android {
23 
24 class UidPolicyCallbackInterface;
25 
26 // Interface for the controller to query a uid's info.
27 class UidPolicyInterface {
28 public:
29     // Instruct the uid policy to start monitoring a uid.
30     virtual void registerMonitorUid(uid_t uid) = 0;
31     // Instruct the uid policy to stop monitoring a uid.
32     virtual void unregisterMonitorUid(uid_t uid) = 0;
33     // Whether a uid is among the set of uids that's currently top priority.
34     virtual bool isUidOnTop(uid_t uid) = 0;
35     // Retrieves the set of uids that's currently top priority.
36     virtual std::unordered_set<uid_t> getTopUids() const = 0;
37     // Set the associated callback interface to send the events when uid states change.
38     virtual void setCallback(const std::shared_ptr<UidPolicyCallbackInterface>& cb) = 0;
39 
40 protected:
41     virtual ~UidPolicyInterface() = default;
42 };
43 
44 // Interface for notifying the controller of a change in uid states.
45 class UidPolicyCallbackInterface {
46 public:
47     // Called when the set of uids that's top priority among the uids of interest
48     // has changed. The receiver of this callback should adjust accordingly.
49     virtual void onTopUidsChanged(const std::unordered_set<uid_t>& uids) = 0;
50 
51     // Called when a uid is gone.
52     virtual void onUidGone(uid_t goneUid) = 0;
53 
54 protected:
55     virtual ~UidPolicyCallbackInterface() = default;
56 };
57 
58 }  // namespace android
59 #endif  // ANDROID_MEDIA_UID_POLICY_INTERFACE_H
60