blob: 0d9d8788be7a81aa626267686733e7c7eade527a [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
Ronghua Wua8ec8fc2015-05-07 13:58:22 -070033class ServiceLog;
Ronghua Wu231c3d12015-03-11 15:10:32 -070034struct ProcessInfoInterface;
35
36struct ResourceInfo {
37 int64_t clientId;
38 sp<IResourceManagerClient> client;
39 Vector<MediaResource> resources;
40};
41
42typedef Vector<ResourceInfo> ResourceInfos;
43typedef KeyedVector<int, ResourceInfos> PidResourceInfosMap;
44
45class ResourceManagerService
46 : public BinderService<ResourceManagerService>,
47 public BnResourceManagerService
48{
49public:
50 static char const *getServiceName() { return "media.resource_manager"; }
51
Ronghua Wu8f9dd872015-04-23 15:24:25 -070052 virtual status_t dump(int fd, const Vector<String16>& args);
53
Ronghua Wu231c3d12015-03-11 15:10:32 -070054 ResourceManagerService();
55 ResourceManagerService(sp<ProcessInfoInterface> processInfo);
56
57 // IResourceManagerService interface
58 virtual void config(const Vector<MediaResourcePolicy> &policies);
59
60 virtual void addResource(
61 int pid,
62 int64_t clientId,
63 const sp<IResourceManagerClient> client,
64 const Vector<MediaResource> &resources);
65
66 virtual void removeResource(int64_t clientId);
67
68 virtual bool reclaimResource(int callingPid, const Vector<MediaResource> &resources);
69
70protected:
71 virtual ~ResourceManagerService();
72
73private:
74 friend class ResourceManagerServiceTest;
75
76 // Gets the list of all the clients who own the specified resource type.
77 // Returns false if any client belongs to a process with higher priority than the
78 // calling process. The clients will remain unchanged if returns false.
79 bool getAllClients_l(int callingPid, const String8 &type,
80 Vector<sp<IResourceManagerClient>> *clients);
81
82 // Gets the client who owns specified resource type from lowest possible priority process.
83 // Returns false if the calling process priority is not higher than the lowest process
84 // priority. The client will remain unchanged if returns false.
85 bool getLowestPriorityBiggestClient_l(int callingPid, const String8 &type,
86 sp<IResourceManagerClient> *client);
87
88 // Gets lowest priority process that has the specified resource type.
89 // Returns false if failed. The output parameters will remain unchanged if failed.
90 bool getLowestPriorityPid_l(const String8 &type, int *pid, int *priority);
91
92 // Gets the client who owns biggest piece of specified resource type from pid.
93 // Returns false if failed. The client will remain unchanged if failed.
94 bool getBiggestClient_l(int pid, const String8 &type, sp<IResourceManagerClient> *client);
95
96 bool isCallingPriorityHigher_l(int callingPid, int pid);
97
98 mutable Mutex mLock;
99 sp<ProcessInfoInterface> mProcessInfo;
Ronghua Wua8ec8fc2015-05-07 13:58:22 -0700100 sp<ServiceLog> mServiceLog;
Ronghua Wu231c3d12015-03-11 15:10:32 -0700101 PidResourceInfosMap mMap;
102 bool mSupportsMultipleSecureCodecs;
103 bool mSupportsSecureWithNonSecureCodec;
104};
105
106// ----------------------------------------------------------------------------
107
108}; // namespace android
109
110#endif // ANDROID_RESOURCEMANAGERSERVICE_H