Girish | 27365ed | 2023-10-11 20:20:55 +0000 | [diff] [blame^] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2023, 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_MEDIA_RESOURCEMANAGERSERVICEUTILS_H_ |
| 19 | #define ANDROID_MEDIA_RESOURCEMANAGERSERVICEUTILS_H_ |
| 20 | |
| 21 | #include <vector> |
| 22 | #include <utils/String8.h> |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | // templated function to stringify the given vector of items. |
| 27 | template <typename T> |
| 28 | String8 getString(const std::vector<T>& items) { |
| 29 | String8 itemsStr; |
| 30 | for (size_t i = 0; i < items.size(); ++i) { |
| 31 | itemsStr.appendFormat("%s ", toString(items[i]).c_str()); |
| 32 | } |
| 33 | return itemsStr; |
| 34 | } |
| 35 | |
| 36 | // Bunch of utility functions that looks for a specific Resource. |
| 37 | |
| 38 | //Check whether a given resource (of type and subtype) is found in given resource parcel. |
| 39 | bool hasResourceType(MediaResource::Type type, MediaResource::SubType subType, |
| 40 | const MediaResourceParcel& resource); |
| 41 | |
| 42 | //Check whether a given resource (of type and subtype) is found in given resource list. |
| 43 | bool hasResourceType(MediaResource::Type type, MediaResource::SubType subType, |
| 44 | const ResourceList& resources); |
| 45 | |
| 46 | //Check whether a given resource (of type and subtype) is found in given resource info list. |
| 47 | bool hasResourceType(MediaResource::Type type, MediaResource::SubType subType, |
| 48 | const ResourceInfos& infos); |
| 49 | |
| 50 | // Return modifiable list of ResourceInfo for a given process (look up by pid) |
| 51 | // from the map of ResourceInfos. |
| 52 | ResourceInfos& getResourceInfosForEdit(int pid, PidResourceInfosMap& map); |
| 53 | |
| 54 | // Return modifiable ResourceInfo for a given process (look up by pid) |
| 55 | // from the map of ResourceInfos. |
| 56 | // If the item is not in the map, create one and add it to the map. |
| 57 | ResourceInfo& getResourceInfoForEdit(const ClientInfoParcel& clientInfo, |
| 58 | const std::shared_ptr<IResourceManagerClient>& client, ResourceInfos& infos); |
| 59 | |
| 60 | } // namespace android |
| 61 | |
| 62 | #endif //ANDROID_MEDIA_RESOURCEMANAGERSERVICEUTILS_H_ |