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