blob: 2ed9bf87e9373aa66bf74789722c34030c7bb2aa [file] [log] [blame]
Ronghua Wu231c3d12015-03-11 15:10:32 -07001/*
2**
3** Copyright 2015, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#ifndef ANDROID_RESOURCEMANAGERSERVICE_H
19#define ANDROID_RESOURCEMANAGERSERVICE_H
20
21#include <arpa/inet.h>
22#include <binder/BinderService.h>
23#include <utils/Errors.h>
24#include <utils/KeyedVector.h>
25#include <utils/String8.h>
26#include <utils/threads.h>
27#include <utils/Vector.h>
28
29#include <media/IResourceManagerService.h>
30
31namespace android {
32
33struct ProcessInfoInterface;
34
35struct ResourceInfo {
36 int64_t clientId;
37 sp<IResourceManagerClient> client;
38 Vector<MediaResource> resources;
39};
40
41typedef Vector<ResourceInfo> ResourceInfos;
42typedef KeyedVector<int, ResourceInfos> PidResourceInfosMap;
43
44class ResourceManagerService
45 : public BinderService<ResourceManagerService>,
46 public BnResourceManagerService
47{
48public:
49 static char const *getServiceName() { return "media.resource_manager"; }
50
51 ResourceManagerService();
52 ResourceManagerService(sp<ProcessInfoInterface> processInfo);
53
54 // IResourceManagerService interface
55 virtual void config(const Vector<MediaResourcePolicy> &policies);
56
57 virtual void addResource(
58 int pid,
59 int64_t clientId,
60 const sp<IResourceManagerClient> client,
61 const Vector<MediaResource> &resources);
62
63 virtual void removeResource(int64_t clientId);
64
65 virtual bool reclaimResource(int callingPid, const Vector<MediaResource> &resources);
66
67protected:
68 virtual ~ResourceManagerService();
69
70private:
71 friend class ResourceManagerServiceTest;
72
73 // Gets the list of all the clients who own the specified resource type.
74 // Returns false if any client belongs to a process with higher priority than the
75 // calling process. The clients will remain unchanged if returns false.
76 bool getAllClients_l(int callingPid, const String8 &type,
77 Vector<sp<IResourceManagerClient>> *clients);
78
79 // Gets the client who owns specified resource type from lowest possible priority process.
80 // Returns false if the calling process priority is not higher than the lowest process
81 // priority. The client will remain unchanged if returns false.
82 bool getLowestPriorityBiggestClient_l(int callingPid, const String8 &type,
83 sp<IResourceManagerClient> *client);
84
85 // Gets lowest priority process that has the specified resource type.
86 // Returns false if failed. The output parameters will remain unchanged if failed.
87 bool getLowestPriorityPid_l(const String8 &type, int *pid, int *priority);
88
89 // Gets the client who owns biggest piece of specified resource type from pid.
90 // Returns false if failed. The client will remain unchanged if failed.
91 bool getBiggestClient_l(int pid, const String8 &type, sp<IResourceManagerClient> *client);
92
93 bool isCallingPriorityHigher_l(int callingPid, int pid);
94
95 mutable Mutex mLock;
96 sp<ProcessInfoInterface> mProcessInfo;
97 PidResourceInfosMap mMap;
98 bool mSupportsMultipleSecureCodecs;
99 bool mSupportsSecureWithNonSecureCodec;
100};
101
102// ----------------------------------------------------------------------------
103
104}; // namespace android
105
106#endif // ANDROID_RESOURCEMANAGERSERVICE_H