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 | //#define LOG_NDEBUG 0 |
| 19 | #define LOG_TAG "ResourceManagerService" |
| 20 | #include <utils/Log.h> |
| 21 | |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 22 | #include <android/binder_manager.h> |
| 23 | #include <android/binder_process.h> |
Dongwon Kang | fe508d3 | 2015-12-15 14:22:05 +0900 | [diff] [blame] | 24 | #include <binder/IMediaResourceMonitor.h> |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 25 | #include <binder/IServiceManager.h> |
Chong Zhang | ee33d64 | 2019-08-08 14:26:43 -0700 | [diff] [blame] | 26 | #include <cutils/sched_policy.h> |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 27 | #include <dirent.h> |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 28 | #include <media/MediaResourcePolicy.h> |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 29 | #include <media/stagefright/ProcessInfo.h> |
Chong Zhang | ee33d64 | 2019-08-08 14:26:43 -0700 | [diff] [blame] | 30 | #include <mediautils/BatteryNotifier.h> |
| 31 | #include <mediautils/SchedulingPolicyService.h> |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 32 | #include <string.h> |
| 33 | #include <sys/types.h> |
| 34 | #include <sys/stat.h> |
| 35 | #include <sys/time.h> |
| 36 | #include <unistd.h> |
| 37 | |
| 38 | #include "ResourceManagerService.h" |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 39 | #include "ResourceObserverService.h" |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 40 | #include "ServiceLog.h" |
Chong Zhang | ee33d64 | 2019-08-08 14:26:43 -0700 | [diff] [blame] | 41 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 42 | namespace android { |
| 43 | |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 44 | DeathNotifier::DeathNotifier(const std::shared_ptr<ResourceManagerService> &service, |
| 45 | int pid, int64_t clientId) |
| 46 | : mService(service), mPid(pid), mClientId(clientId) {} |
Wonsik Kim | 3e37896 | 2017-01-05 17:00:02 +0900 | [diff] [blame] | 47 | |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 48 | //static |
| 49 | void DeathNotifier::BinderDiedCallback(void* cookie) { |
| 50 | auto thiz = static_cast<DeathNotifier*>(cookie); |
| 51 | thiz->binderDied(); |
| 52 | } |
Wonsik Kim | 3e37896 | 2017-01-05 17:00:02 +0900 | [diff] [blame] | 53 | |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 54 | void DeathNotifier::binderDied() { |
| 55 | // Don't check for pid validity since we know it's already dead. |
| 56 | std::shared_ptr<ResourceManagerService> service = mService.lock(); |
| 57 | if (service == nullptr) { |
| 58 | ALOGW("ResourceManagerService is dead as well."); |
| 59 | return; |
Wonsik Kim | 3e37896 | 2017-01-05 17:00:02 +0900 | [diff] [blame] | 60 | } |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 61 | |
| 62 | service->overridePid(mPid, -1); |
Henry Fang | b35141c | 2020-06-29 13:11:39 -0700 | [diff] [blame] | 63 | // thiz is freed in the call below, so it must be last call referring thiz |
| 64 | service->removeResource(mPid, mClientId, false); |
| 65 | |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 66 | } |
Wonsik Kim | 3e37896 | 2017-01-05 17:00:02 +0900 | [diff] [blame] | 67 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 68 | template <typename T> |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 69 | static String8 getString(const std::vector<T> &items) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 70 | String8 itemsStr; |
| 71 | for (size_t i = 0; i < items.size(); ++i) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 72 | itemsStr.appendFormat("%s ", toString(items[i]).string()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 73 | } |
| 74 | return itemsStr; |
| 75 | } |
| 76 | |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 77 | static bool hasResourceType(MediaResource::Type type, const ResourceList& resources) { |
| 78 | for (auto it = resources.begin(); it != resources.end(); it++) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 79 | if (it->second.type == type) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 80 | return true; |
| 81 | } |
| 82 | } |
| 83 | return false; |
| 84 | } |
| 85 | |
Chih-Hung Hsieh | 51873d8 | 2016-08-09 14:18:51 -0700 | [diff] [blame] | 86 | static bool hasResourceType(MediaResource::Type type, const ResourceInfos& infos) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 87 | for (size_t i = 0; i < infos.size(); ++i) { |
| 88 | if (hasResourceType(type, infos[i].resources)) { |
| 89 | return true; |
| 90 | } |
| 91 | } |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | static ResourceInfos& getResourceInfosForEdit( |
| 96 | int pid, |
| 97 | PidResourceInfosMap& map) { |
| 98 | ssize_t index = map.indexOfKey(pid); |
| 99 | if (index < 0) { |
| 100 | // new pid |
| 101 | ResourceInfos infosForPid; |
| 102 | map.add(pid, infosForPid); |
| 103 | } |
| 104 | |
| 105 | return map.editValueFor(pid); |
| 106 | } |
| 107 | |
| 108 | static ResourceInfo& getResourceInfoForEdit( |
Chong Zhang | ee33d64 | 2019-08-08 14:26:43 -0700 | [diff] [blame] | 109 | uid_t uid, |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 110 | int64_t clientId, |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 111 | const std::shared_ptr<IResourceManagerClient>& client, |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 112 | ResourceInfos& infos) { |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 113 | ssize_t index = infos.indexOfKey(clientId); |
| 114 | |
| 115 | if (index < 0) { |
| 116 | ResourceInfo info; |
| 117 | info.uid = uid; |
| 118 | info.clientId = clientId; |
| 119 | info.client = client; |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 120 | info.pendingRemoval = false; |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 121 | |
| 122 | index = infos.add(clientId, info); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 123 | } |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 124 | |
| 125 | return infos.editValueAt(index); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 128 | static void notifyResourceGranted(int pid, const std::vector<MediaResourceParcel> &resources) { |
Dongwon Kang | fe508d3 | 2015-12-15 14:22:05 +0900 | [diff] [blame] | 129 | static const char* const kServiceName = "media_resource_monitor"; |
Dongwon Kang | 2642c84 | 2016-03-23 18:07:29 -0700 | [diff] [blame] | 130 | sp<IBinder> binder = defaultServiceManager()->checkService(String16(kServiceName)); |
Dongwon Kang | fe508d3 | 2015-12-15 14:22:05 +0900 | [diff] [blame] | 131 | if (binder != NULL) { |
| 132 | sp<IMediaResourceMonitor> service = interface_cast<IMediaResourceMonitor>(binder); |
| 133 | for (size_t i = 0; i < resources.size(); ++i) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 134 | if (resources[i].subType == MediaResource::SubType::kAudioCodec) { |
Dongwon Kang | 69c23dd | 2016-03-22 15:22:45 -0700 | [diff] [blame] | 135 | service->notifyResourceGranted(pid, IMediaResourceMonitor::TYPE_AUDIO_CODEC); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 136 | } else if (resources[i].subType == MediaResource::SubType::kVideoCodec) { |
Dongwon Kang | 69c23dd | 2016-03-22 15:22:45 -0700 | [diff] [blame] | 137 | service->notifyResourceGranted(pid, IMediaResourceMonitor::TYPE_VIDEO_CODEC); |
| 138 | } |
Dongwon Kang | fe508d3 | 2015-12-15 14:22:05 +0900 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 143 | binder_status_t ResourceManagerService::dump( |
| 144 | int fd, const char** /*args*/, uint32_t /*numArgs*/) { |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 145 | String8 result; |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 146 | |
dcashman | 014e91e | 2015-09-11 09:33:01 -0700 | [diff] [blame] | 147 | if (checkCallingPermission(String16("android.permission.DUMP")) == false) { |
| 148 | result.format("Permission Denial: " |
| 149 | "can't dump ResourceManagerService from pid=%d, uid=%d\n", |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 150 | AIBinder_getCallingPid(), |
| 151 | AIBinder_getCallingUid()); |
dcashman | 014e91e | 2015-09-11 09:33:01 -0700 | [diff] [blame] | 152 | write(fd, result.string(), result.size()); |
| 153 | return PERMISSION_DENIED; |
| 154 | } |
| 155 | |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 156 | PidResourceInfosMap mapCopy; |
| 157 | bool supportsMultipleSecureCodecs; |
| 158 | bool supportsSecureWithNonSecureCodec; |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 159 | std::map<int, int> overridePidMapCopy; |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 160 | String8 serviceLog; |
| 161 | { |
| 162 | Mutex::Autolock lock(mLock); |
| 163 | mapCopy = mMap; // Shadow copy, real copy will happen on write. |
| 164 | supportsMultipleSecureCodecs = mSupportsMultipleSecureCodecs; |
| 165 | supportsSecureWithNonSecureCodec = mSupportsSecureWithNonSecureCodec; |
| 166 | serviceLog = mServiceLog->toString(" " /* linePrefix */); |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 167 | overridePidMapCopy = mOverridePidMap; |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | const size_t SIZE = 256; |
| 171 | char buffer[SIZE]; |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 172 | snprintf(buffer, SIZE, "ResourceManagerService: %p\n", this); |
| 173 | result.append(buffer); |
| 174 | result.append(" Policies:\n"); |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 175 | snprintf(buffer, SIZE, " SupportsMultipleSecureCodecs: %d\n", supportsMultipleSecureCodecs); |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 176 | result.append(buffer); |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 177 | snprintf(buffer, SIZE, " SupportsSecureWithNonSecureCodec: %d\n", |
| 178 | supportsSecureWithNonSecureCodec); |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 179 | result.append(buffer); |
| 180 | |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 181 | result.append(" Processes:\n"); |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 182 | for (size_t i = 0; i < mapCopy.size(); ++i) { |
| 183 | snprintf(buffer, SIZE, " Pid: %d\n", mapCopy.keyAt(i)); |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 184 | result.append(buffer); |
| 185 | |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 186 | const ResourceInfos &infos = mapCopy.valueAt(i); |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 187 | for (size_t j = 0; j < infos.size(); ++j) { |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 188 | result.append(" Client:\n"); |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 189 | snprintf(buffer, SIZE, " Id: %lld\n", (long long)infos[j].clientId); |
| 190 | result.append(buffer); |
| 191 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 192 | std::string clientName; |
| 193 | Status status = infos[j].client->getName(&clientName); |
| 194 | if (!status.isOk()) { |
| 195 | clientName = "<unknown client>"; |
| 196 | } |
| 197 | snprintf(buffer, SIZE, " Name: %s\n", clientName.c_str()); |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 198 | result.append(buffer); |
| 199 | |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 200 | const ResourceList &resources = infos[j].resources; |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 201 | result.append(" Resources:\n"); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 202 | for (auto it = resources.begin(); it != resources.end(); it++) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 203 | snprintf(buffer, SIZE, " %s\n", toString(it->second).string()); |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 204 | result.append(buffer); |
| 205 | } |
| 206 | } |
| 207 | } |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 208 | result.append(" Process Pid override:\n"); |
| 209 | for (auto it = overridePidMapCopy.begin(); it != overridePidMapCopy.end(); ++it) { |
| 210 | snprintf(buffer, SIZE, " Original Pid: %d, Override Pid: %d\n", |
| 211 | it->first, it->second); |
| 212 | result.append(buffer); |
| 213 | } |
Ronghua Wu | 022ed72 | 2015-05-11 15:15:09 -0700 | [diff] [blame] | 214 | result.append(" Events logs (most recent at top):\n"); |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 215 | result.append(serviceLog); |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 216 | |
| 217 | write(fd, result.string(), result.size()); |
| 218 | return OK; |
| 219 | } |
| 220 | |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 221 | struct SystemCallbackImpl : |
| 222 | public ResourceManagerService::SystemCallbackInterface { |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 223 | SystemCallbackImpl() : mClientToken(new BBinder()) {} |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 224 | |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 225 | virtual void noteStartVideo(int uid) override { |
| 226 | BatteryNotifier::getInstance().noteStartVideo(uid); |
| 227 | } |
| 228 | virtual void noteStopVideo(int uid) override { |
| 229 | BatteryNotifier::getInstance().noteStopVideo(uid); |
| 230 | } |
| 231 | virtual void noteResetVideo() override { |
| 232 | BatteryNotifier::getInstance().noteResetVideo(); |
| 233 | } |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 234 | virtual bool requestCpusetBoost(bool enable) override { |
| 235 | return android::requestCpusetBoost(enable, mClientToken); |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | protected: |
| 239 | virtual ~SystemCallbackImpl() {} |
| 240 | |
| 241 | private: |
| 242 | DISALLOW_EVIL_CONSTRUCTORS(SystemCallbackImpl); |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 243 | sp<IBinder> mClientToken; |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | ResourceManagerService::ResourceManagerService() |
| 247 | : ResourceManagerService(new ProcessInfo(), new SystemCallbackImpl()) {} |
| 248 | |
| 249 | ResourceManagerService::ResourceManagerService( |
| 250 | const sp<ProcessInfoInterface> &processInfo, |
| 251 | const sp<SystemCallbackInterface> &systemResource) |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 252 | : mProcessInfo(processInfo), |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 253 | mSystemCB(systemResource), |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 254 | mServiceLog(new ServiceLog()), |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 255 | mSupportsMultipleSecureCodecs(true), |
Chong Zhang | 79d2b28 | 2018-04-17 14:14:31 -0700 | [diff] [blame] | 256 | mSupportsSecureWithNonSecureCodec(true), |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 257 | mCpuBoostCount(0), |
| 258 | mDeathRecipient(AIBinder_DeathRecipient_new(DeathNotifier::BinderDiedCallback)) { |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 259 | mSystemCB->noteResetVideo(); |
Chong Zhang | ee33d64 | 2019-08-08 14:26:43 -0700 | [diff] [blame] | 260 | } |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 261 | |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 262 | //static |
| 263 | void ResourceManagerService::instantiate() { |
| 264 | std::shared_ptr<ResourceManagerService> service = |
| 265 | ::ndk::SharedRefBase::make<ResourceManagerService>(); |
| 266 | binder_status_t status = |
| 267 | AServiceManager_addService(service->asBinder().get(), getServiceName()); |
| 268 | if (status != STATUS_OK) { |
| 269 | return; |
| 270 | } |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 271 | |
| 272 | std::shared_ptr<ResourceObserverService> observerService = |
| 273 | ResourceObserverService::instantiate(); |
| 274 | |
| 275 | if (observerService != nullptr) { |
| 276 | service->setObserverService(observerService); |
| 277 | } |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 278 | // TODO: mediaserver main() is already starting the thread pool, |
| 279 | // move this to mediaserver main() when other services in mediaserver |
| 280 | // are converted to ndk-platform aidl. |
| 281 | //ABinderProcess_startThreadPool(); |
| 282 | } |
| 283 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 284 | ResourceManagerService::~ResourceManagerService() {} |
| 285 | |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 286 | void ResourceManagerService::setObserverService( |
| 287 | const std::shared_ptr<ResourceObserverService>& observerService) { |
| 288 | mObserverService = observerService; |
| 289 | } |
| 290 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 291 | Status ResourceManagerService::config(const std::vector<MediaResourcePolicyParcel>& policies) { |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 292 | String8 log = String8::format("config(%s)", getString(policies).string()); |
| 293 | mServiceLog->add(log); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 294 | |
| 295 | Mutex::Autolock lock(mLock); |
| 296 | for (size_t i = 0; i < policies.size(); ++i) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 297 | const std::string &type = policies[i].type; |
| 298 | const std::string &value = policies[i].value; |
| 299 | if (type == MediaResourcePolicy::kPolicySupportsMultipleSecureCodecs()) { |
Ronghua Wu | 9ba21b9 | 2015-04-21 14:23:06 -0700 | [diff] [blame] | 300 | mSupportsMultipleSecureCodecs = (value == "true"); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 301 | } else if (type == MediaResourcePolicy::kPolicySupportsSecureWithNonSecureCodec()) { |
Ronghua Wu | 9ba21b9 | 2015-04-21 14:23:06 -0700 | [diff] [blame] | 302 | mSupportsSecureWithNonSecureCodec = (value == "true"); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 303 | } |
| 304 | } |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 305 | return Status::ok(); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 308 | void ResourceManagerService::onFirstAdded( |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 309 | const MediaResourceParcel& resource, const ResourceInfo& clientInfo) { |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 310 | // first time added |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 311 | if (resource.type == MediaResource::Type::kCpuBoost |
| 312 | && resource.subType == MediaResource::SubType::kUnspecifiedSubType) { |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 313 | // Request it on every new instance of kCpuBoost, as the media.codec |
| 314 | // could have died, if we only do it the first time subsequent instances |
| 315 | // never gets the boost. |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 316 | if (mSystemCB->requestCpusetBoost(true) != OK) { |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 317 | ALOGW("couldn't request cpuset boost"); |
| 318 | } |
| 319 | mCpuBoostCount++; |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 320 | } else if (resource.type == MediaResource::Type::kBattery |
| 321 | && resource.subType == MediaResource::SubType::kVideoCodec) { |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 322 | mSystemCB->noteStartVideo(clientInfo.uid); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
| 326 | void ResourceManagerService::onLastRemoved( |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 327 | const MediaResourceParcel& resource, const ResourceInfo& clientInfo) { |
| 328 | if (resource.type == MediaResource::Type::kCpuBoost |
| 329 | && resource.subType == MediaResource::SubType::kUnspecifiedSubType |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 330 | && mCpuBoostCount > 0) { |
| 331 | if (--mCpuBoostCount == 0) { |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 332 | mSystemCB->requestCpusetBoost(false); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 333 | } |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 334 | } else if (resource.type == MediaResource::Type::kBattery |
| 335 | && resource.subType == MediaResource::SubType::kVideoCodec) { |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 336 | mSystemCB->noteStopVideo(clientInfo.uid); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 340 | void ResourceManagerService::mergeResources( |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 341 | MediaResourceParcel& r1, const MediaResourceParcel& r2) { |
| 342 | // The resource entry on record is maintained to be in [0,INT64_MAX]. |
| 343 | // Clamp if merging in the new resource value causes it to go out of bound. |
| 344 | // Note that the new resource value could be negative, eg.DrmSession, the |
| 345 | // value goes lower when the session is used more often. During reclaim |
| 346 | // the session with the highest value (lowest usage) would be closed. |
| 347 | if (r2.value < INT64_MAX - r1.value) { |
| 348 | r1.value += r2.value; |
| 349 | if (r1.value < 0) { |
| 350 | r1.value = 0; |
| 351 | } |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 352 | } else { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 353 | r1.value = INT64_MAX; |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 357 | Status ResourceManagerService::addResource( |
| 358 | int32_t pid, |
| 359 | int32_t uid, |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 360 | int64_t clientId, |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 361 | const std::shared_ptr<IResourceManagerClient>& client, |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 362 | const std::vector<MediaResourceParcel>& resources) { |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 363 | String8 log = String8::format("addResource(pid %d, clientId %lld, resources %s)", |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 364 | pid, (long long) clientId, getString(resources).string()); |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 365 | mServiceLog->add(log); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 366 | |
| 367 | Mutex::Autolock lock(mLock); |
Ronghua Wu | d11c43a | 2016-01-27 16:26:12 -0800 | [diff] [blame] | 368 | if (!mProcessInfo->isValidPid(pid)) { |
| 369 | ALOGE("Rejected addResource call with invalid pid."); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 370 | return Status::fromServiceSpecificError(BAD_VALUE); |
Ronghua Wu | d11c43a | 2016-01-27 16:26:12 -0800 | [diff] [blame] | 371 | } |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 372 | ResourceInfos& infos = getResourceInfosForEdit(pid, mMap); |
Chong Zhang | ee33d64 | 2019-08-08 14:26:43 -0700 | [diff] [blame] | 373 | ResourceInfo& info = getResourceInfoForEdit(uid, clientId, client, infos); |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 374 | ResourceList resourceAdded; |
Chong Zhang | 79d2b28 | 2018-04-17 14:14:31 -0700 | [diff] [blame] | 375 | |
| 376 | for (size_t i = 0; i < resources.size(); ++i) { |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 377 | const auto &res = resources[i]; |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 378 | const auto resType = std::tuple(res.type, res.subType, res.id); |
| 379 | |
| 380 | if (res.value < 0 && res.type != MediaResource::Type::kDrmSession) { |
| 381 | ALOGW("Ignoring request to remove negative value of non-drm resource"); |
| 382 | continue; |
| 383 | } |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 384 | if (info.resources.find(resType) == info.resources.end()) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 385 | if (res.value <= 0) { |
| 386 | // We can't init a new entry with negative value, although it's allowed |
| 387 | // to merge in negative values after the initial add. |
| 388 | ALOGW("Ignoring request to add new resource entry with value <= 0"); |
| 389 | continue; |
| 390 | } |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 391 | onFirstAdded(res, info); |
| 392 | info.resources[resType] = res; |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 393 | } else { |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 394 | mergeResources(info.resources[resType], res); |
Chong Zhang | 79d2b28 | 2018-04-17 14:14:31 -0700 | [diff] [blame] | 395 | } |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 396 | // Add it to the list of added resources for observers. |
| 397 | auto it = resourceAdded.find(resType); |
| 398 | if (it == resourceAdded.end()) { |
| 399 | resourceAdded[resType] = res; |
| 400 | } else { |
| 401 | mergeResources(it->second, res); |
| 402 | } |
Chong Zhang | 79d2b28 | 2018-04-17 14:14:31 -0700 | [diff] [blame] | 403 | } |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 404 | if (info.deathNotifier == nullptr && client != nullptr) { |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 405 | info.deathNotifier = new DeathNotifier(ref<ResourceManagerService>(), pid, clientId); |
| 406 | AIBinder_linkToDeath(client->asBinder().get(), |
| 407 | mDeathRecipient.get(), info.deathNotifier.get()); |
Wonsik Kim | 3e37896 | 2017-01-05 17:00:02 +0900 | [diff] [blame] | 408 | } |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 409 | if (mObserverService != nullptr && !resourceAdded.empty()) { |
| 410 | mObserverService->onResourceAdded(uid, pid, resourceAdded); |
| 411 | } |
Dongwon Kang | fe508d3 | 2015-12-15 14:22:05 +0900 | [diff] [blame] | 412 | notifyResourceGranted(pid, resources); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 413 | return Status::ok(); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 416 | Status ResourceManagerService::removeResource( |
| 417 | int32_t pid, int64_t clientId, |
| 418 | const std::vector<MediaResourceParcel>& resources) { |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 419 | String8 log = String8::format("removeResource(pid %d, clientId %lld, resources %s)", |
| 420 | pid, (long long) clientId, getString(resources).string()); |
| 421 | mServiceLog->add(log); |
| 422 | |
| 423 | Mutex::Autolock lock(mLock); |
| 424 | if (!mProcessInfo->isValidPid(pid)) { |
| 425 | ALOGE("Rejected removeResource call with invalid pid."); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 426 | return Status::fromServiceSpecificError(BAD_VALUE); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 427 | } |
| 428 | ssize_t index = mMap.indexOfKey(pid); |
| 429 | if (index < 0) { |
| 430 | ALOGV("removeResource: didn't find pid %d for clientId %lld", pid, (long long) clientId); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 431 | return Status::ok(); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 432 | } |
| 433 | ResourceInfos &infos = mMap.editValueAt(index); |
| 434 | |
| 435 | index = infos.indexOfKey(clientId); |
| 436 | if (index < 0) { |
| 437 | ALOGV("removeResource: didn't find clientId %lld", (long long) clientId); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 438 | return Status::ok(); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | ResourceInfo &info = infos.editValueAt(index); |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 442 | ResourceList resourceRemoved; |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 443 | for (size_t i = 0; i < resources.size(); ++i) { |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 444 | const auto &res = resources[i]; |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 445 | const auto resType = std::tuple(res.type, res.subType, res.id); |
| 446 | |
| 447 | if (res.value < 0) { |
| 448 | ALOGW("Ignoring request to remove negative value of resource"); |
| 449 | continue; |
| 450 | } |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 451 | // ignore if we don't have it |
| 452 | if (info.resources.find(resType) != info.resources.end()) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 453 | MediaResourceParcel &resource = info.resources[resType]; |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 454 | MediaResourceParcel actualRemoved = res; |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 455 | if (resource.value > res.value) { |
| 456 | resource.value -= res.value; |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 457 | } else { |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 458 | onLastRemoved(res, info); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 459 | info.resources.erase(resType); |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 460 | actualRemoved.value = resource.value; |
| 461 | } |
| 462 | |
| 463 | // Add it to the list of removed resources for observers. |
| 464 | auto it = resourceRemoved.find(resType); |
| 465 | if (it == resourceRemoved.end()) { |
| 466 | resourceRemoved[resType] = actualRemoved; |
| 467 | } else { |
| 468 | mergeResources(it->second, actualRemoved); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | } |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 472 | if (mObserverService != nullptr && !resourceRemoved.empty()) { |
| 473 | mObserverService->onResourceRemoved(info.uid, pid, resourceRemoved); |
| 474 | } |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 475 | return Status::ok(); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 478 | Status ResourceManagerService::removeClient(int32_t pid, int64_t clientId) { |
Wonsik Kim | 3e37896 | 2017-01-05 17:00:02 +0900 | [diff] [blame] | 479 | removeResource(pid, clientId, true); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 480 | return Status::ok(); |
Wonsik Kim | 3e37896 | 2017-01-05 17:00:02 +0900 | [diff] [blame] | 481 | } |
| 482 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 483 | Status ResourceManagerService::removeResource(int pid, int64_t clientId, bool checkValid) { |
Ronghua Wu | 37c8924 | 2015-07-15 12:23:48 -0700 | [diff] [blame] | 484 | String8 log = String8::format( |
| 485 | "removeResource(pid %d, clientId %lld)", |
| 486 | pid, (long long) clientId); |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 487 | mServiceLog->add(log); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 488 | |
| 489 | Mutex::Autolock lock(mLock); |
Wonsik Kim | 3e37896 | 2017-01-05 17:00:02 +0900 | [diff] [blame] | 490 | if (checkValid && !mProcessInfo->isValidPid(pid)) { |
Ronghua Wu | d11c43a | 2016-01-27 16:26:12 -0800 | [diff] [blame] | 491 | ALOGE("Rejected removeResource call with invalid pid."); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 492 | return Status::fromServiceSpecificError(BAD_VALUE); |
Ronghua Wu | d11c43a | 2016-01-27 16:26:12 -0800 | [diff] [blame] | 493 | } |
Ronghua Wu | 37c8924 | 2015-07-15 12:23:48 -0700 | [diff] [blame] | 494 | ssize_t index = mMap.indexOfKey(pid); |
| 495 | if (index < 0) { |
| 496 | ALOGV("removeResource: didn't find pid %d for clientId %lld", pid, (long long) clientId); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 497 | return Status::ok(); |
Ronghua Wu | 37c8924 | 2015-07-15 12:23:48 -0700 | [diff] [blame] | 498 | } |
Ronghua Wu | 37c8924 | 2015-07-15 12:23:48 -0700 | [diff] [blame] | 499 | ResourceInfos &infos = mMap.editValueAt(index); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 500 | |
| 501 | index = infos.indexOfKey(clientId); |
| 502 | if (index < 0) { |
| 503 | ALOGV("removeResource: didn't find clientId %lld", (long long) clientId); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 504 | return Status::ok(); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 505 | } |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 506 | |
| 507 | const ResourceInfo &info = infos[index]; |
| 508 | for (auto it = info.resources.begin(); it != info.resources.end(); it++) { |
| 509 | onLastRemoved(it->second, info); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 510 | } |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 511 | |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 512 | AIBinder_unlinkToDeath(info.client->asBinder().get(), |
| 513 | mDeathRecipient.get(), info.deathNotifier.get()); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 514 | |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 515 | if (mObserverService != nullptr && !info.resources.empty()) { |
| 516 | mObserverService->onResourceRemoved(info.uid, pid, info.resources); |
| 517 | } |
| 518 | |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 519 | infos.removeItemsAt(index); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 520 | return Status::ok(); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 523 | void ResourceManagerService::getClientForResource_l( |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 524 | int callingPid, const MediaResourceParcel *res, |
| 525 | Vector<std::shared_ptr<IResourceManagerClient>> *clients) { |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 526 | if (res == NULL) { |
| 527 | return; |
| 528 | } |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 529 | std::shared_ptr<IResourceManagerClient> client; |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 530 | if (getLowestPriorityBiggestClient_l(callingPid, res->type, &client)) { |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 531 | clients->push_back(client); |
| 532 | } |
| 533 | } |
| 534 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 535 | Status ResourceManagerService::reclaimResource( |
| 536 | int32_t callingPid, |
| 537 | const std::vector<MediaResourceParcel>& resources, |
| 538 | bool* _aidl_return) { |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 539 | String8 log = String8::format("reclaimResource(callingPid %d, resources %s)", |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 540 | callingPid, getString(resources).string()); |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 541 | mServiceLog->add(log); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 542 | *_aidl_return = false; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 543 | |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 544 | Vector<std::shared_ptr<IResourceManagerClient>> clients; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 545 | { |
| 546 | Mutex::Autolock lock(mLock); |
Ronghua Wu | d11c43a | 2016-01-27 16:26:12 -0800 | [diff] [blame] | 547 | if (!mProcessInfo->isValidPid(callingPid)) { |
| 548 | ALOGE("Rejected reclaimResource call with invalid callingPid."); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 549 | return Status::fromServiceSpecificError(BAD_VALUE); |
Ronghua Wu | d11c43a | 2016-01-27 16:26:12 -0800 | [diff] [blame] | 550 | } |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 551 | const MediaResourceParcel *secureCodec = NULL; |
| 552 | const MediaResourceParcel *nonSecureCodec = NULL; |
| 553 | const MediaResourceParcel *graphicMemory = NULL; |
| 554 | const MediaResourceParcel *drmSession = NULL; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 555 | for (size_t i = 0; i < resources.size(); ++i) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 556 | MediaResource::Type type = resources[i].type; |
| 557 | if (resources[i].type == MediaResource::Type::kSecureCodec) { |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 558 | secureCodec = &resources[i]; |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 559 | } else if (type == MediaResource::Type::kNonSecureCodec) { |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 560 | nonSecureCodec = &resources[i]; |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 561 | } else if (type == MediaResource::Type::kGraphicMemory) { |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 562 | graphicMemory = &resources[i]; |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 563 | } else if (type == MediaResource::Type::kDrmSession) { |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 564 | drmSession = &resources[i]; |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
| 568 | // first pass to handle secure/non-secure codec conflict |
| 569 | if (secureCodec != NULL) { |
| 570 | if (!mSupportsMultipleSecureCodecs) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 571 | if (!getAllClients_l(callingPid, MediaResource::Type::kSecureCodec, &clients)) { |
| 572 | return Status::ok(); |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 573 | } |
| 574 | } |
| 575 | if (!mSupportsSecureWithNonSecureCodec) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 576 | if (!getAllClients_l(callingPid, MediaResource::Type::kNonSecureCodec, &clients)) { |
| 577 | return Status::ok(); |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | } |
| 581 | if (nonSecureCodec != NULL) { |
| 582 | if (!mSupportsSecureWithNonSecureCodec) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 583 | if (!getAllClients_l(callingPid, MediaResource::Type::kSecureCodec, &clients)) { |
| 584 | return Status::ok(); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 585 | } |
| 586 | } |
| 587 | } |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 588 | if (drmSession != NULL) { |
| 589 | getClientForResource_l(callingPid, drmSession, &clients); |
| 590 | if (clients.size() == 0) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 591 | return Status::ok(); |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 592 | } |
| 593 | } |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 594 | |
| 595 | if (clients.size() == 0) { |
| 596 | // if no secure/non-secure codec conflict, run second pass to handle other resources. |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 597 | getClientForResource_l(callingPid, graphicMemory, &clients); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 598 | } |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 599 | |
| 600 | if (clients.size() == 0) { |
| 601 | // if we are here, run the third pass to free one codec with the same type. |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 602 | getClientForResource_l(callingPid, secureCodec, &clients); |
| 603 | getClientForResource_l(callingPid, nonSecureCodec, &clients); |
| 604 | } |
| 605 | |
| 606 | if (clients.size() == 0) { |
| 607 | // if we are here, run the fourth pass to free one codec with the different type. |
| 608 | if (secureCodec != NULL) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 609 | MediaResource temp(MediaResource::Type::kNonSecureCodec, 1); |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 610 | getClientForResource_l(callingPid, &temp, &clients); |
| 611 | } |
| 612 | if (nonSecureCodec != NULL) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 613 | MediaResource temp(MediaResource::Type::kSecureCodec, 1); |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 614 | getClientForResource_l(callingPid, &temp, &clients); |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 615 | } |
| 616 | } |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | if (clients.size() == 0) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 620 | return Status::ok(); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 623 | std::shared_ptr<IResourceManagerClient> failedClient; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 624 | for (size_t i = 0; i < clients.size(); ++i) { |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 625 | log = String8::format("reclaimResource from client %p", clients[i].get()); |
| 626 | mServiceLog->add(log); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 627 | bool success; |
| 628 | Status status = clients[i]->reclaimResource(&success); |
| 629 | if (!status.isOk() || !success) { |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 630 | failedClient = clients[i]; |
| 631 | break; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 632 | } |
| 633 | } |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 634 | |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 635 | if (failedClient == NULL) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 636 | *_aidl_return = true; |
| 637 | return Status::ok(); |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 640 | { |
| 641 | Mutex::Autolock lock(mLock); |
| 642 | bool found = false; |
| 643 | for (size_t i = 0; i < mMap.size(); ++i) { |
| 644 | ResourceInfos &infos = mMap.editValueAt(i); |
| 645 | for (size_t j = 0; j < infos.size();) { |
| 646 | if (infos[j].client == failedClient) { |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 647 | j = infos.removeItemsAt(j); |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 648 | found = true; |
| 649 | } else { |
| 650 | ++j; |
| 651 | } |
| 652 | } |
| 653 | if (found) { |
| 654 | break; |
| 655 | } |
| 656 | } |
| 657 | if (!found) { |
| 658 | ALOGV("didn't find failed client"); |
| 659 | } |
| 660 | } |
| 661 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 662 | return Status::ok(); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 665 | Status ResourceManagerService::overridePid( |
| 666 | int originalPid, |
| 667 | int newPid) { |
| 668 | String8 log = String8::format("overridePid(originalPid %d, newPid %d)", |
| 669 | originalPid, newPid); |
| 670 | mServiceLog->add(log); |
| 671 | |
| 672 | // allow if this is called from the same process or the process has |
| 673 | // permission. |
| 674 | if ((AIBinder_getCallingPid() != getpid()) && |
| 675 | (checkCallingPermission(String16( |
| 676 | "android.permission.MEDIA_RESOURCE_OVERRIDE_PID")) == false)) { |
| 677 | ALOGE( |
| 678 | "Permission Denial: can't access overridePid method from pid=%d, " |
| 679 | "self pid=%d\n", |
| 680 | AIBinder_getCallingPid(), getpid()); |
| 681 | return Status::fromServiceSpecificError(PERMISSION_DENIED); |
| 682 | } |
| 683 | |
| 684 | { |
| 685 | Mutex::Autolock lock(mLock); |
| 686 | mOverridePidMap.erase(originalPid); |
| 687 | if (newPid != -1) { |
| 688 | mOverridePidMap.emplace(originalPid, newPid); |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | return Status::ok(); |
| 693 | } |
| 694 | |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 695 | Status ResourceManagerService::markClientForPendingRemoval(int32_t pid, int64_t clientId) { |
| 696 | String8 log = String8::format( |
| 697 | "markClientForPendingRemoval(pid %d, clientId %lld)", |
| 698 | pid, (long long) clientId); |
| 699 | mServiceLog->add(log); |
| 700 | |
| 701 | Mutex::Autolock lock(mLock); |
| 702 | if (!mProcessInfo->isValidPid(pid)) { |
| 703 | ALOGE("Rejected markClientForPendingRemoval call with invalid pid."); |
| 704 | return Status::fromServiceSpecificError(BAD_VALUE); |
| 705 | } |
| 706 | ssize_t index = mMap.indexOfKey(pid); |
| 707 | if (index < 0) { |
| 708 | ALOGV("markClientForPendingRemoval: didn't find pid %d for clientId %lld", |
| 709 | pid, (long long)clientId); |
| 710 | return Status::ok(); |
| 711 | } |
| 712 | ResourceInfos &infos = mMap.editValueAt(index); |
| 713 | |
| 714 | index = infos.indexOfKey(clientId); |
| 715 | if (index < 0) { |
| 716 | ALOGV("markClientForPendingRemoval: didn't find clientId %lld", (long long) clientId); |
| 717 | return Status::ok(); |
| 718 | } |
| 719 | |
| 720 | ResourceInfo &info = infos.editValueAt(index); |
| 721 | info.pendingRemoval = true; |
| 722 | return Status::ok(); |
| 723 | } |
| 724 | |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 725 | bool ResourceManagerService::getPriority_l(int pid, int* priority) { |
| 726 | int newPid = pid; |
| 727 | |
| 728 | if (mOverridePidMap.find(pid) != mOverridePidMap.end()) { |
| 729 | newPid = mOverridePidMap[pid]; |
| 730 | ALOGD("getPriority_l: use override pid %d instead original pid %d", |
| 731 | newPid, pid); |
| 732 | } |
| 733 | |
| 734 | return mProcessInfo->getPriority(newPid, priority); |
| 735 | } |
| 736 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 737 | bool ResourceManagerService::getAllClients_l( |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 738 | int callingPid, MediaResource::Type type, |
| 739 | Vector<std::shared_ptr<IResourceManagerClient>> *clients) { |
| 740 | Vector<std::shared_ptr<IResourceManagerClient>> temp; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 741 | for (size_t i = 0; i < mMap.size(); ++i) { |
| 742 | ResourceInfos &infos = mMap.editValueAt(i); |
| 743 | for (size_t j = 0; j < infos.size(); ++j) { |
| 744 | if (hasResourceType(type, infos[j].resources)) { |
| 745 | if (!isCallingPriorityHigher_l(callingPid, mMap.keyAt(i))) { |
| 746 | // some higher/equal priority process owns the resource, |
| 747 | // this request can't be fulfilled. |
| 748 | ALOGE("getAllClients_l: can't reclaim resource %s from pid %d", |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame] | 749 | asString(type), mMap.keyAt(i)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 750 | return false; |
| 751 | } |
| 752 | temp.push_back(infos[j].client); |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | if (temp.size() == 0) { |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame] | 757 | ALOGV("getAllClients_l: didn't find any resource %s", asString(type)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 758 | return true; |
| 759 | } |
| 760 | clients->appendVector(temp); |
| 761 | return true; |
| 762 | } |
| 763 | |
| 764 | bool ResourceManagerService::getLowestPriorityBiggestClient_l( |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 765 | int callingPid, MediaResource::Type type, |
| 766 | std::shared_ptr<IResourceManagerClient> *client) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 767 | int lowestPriorityPid; |
| 768 | int lowestPriority; |
| 769 | int callingPriority; |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 770 | |
| 771 | // Before looking into other processes, check if we have clients marked for |
| 772 | // pending removal in the same process. |
| 773 | if (getBiggestClient_l(callingPid, type, client, true /* pendingRemovalOnly */)) { |
| 774 | return true; |
| 775 | } |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 776 | if (!getPriority_l(callingPid, &callingPriority)) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 777 | ALOGE("getLowestPriorityBiggestClient_l: can't get process priority for pid %d", |
| 778 | callingPid); |
| 779 | return false; |
| 780 | } |
| 781 | if (!getLowestPriorityPid_l(type, &lowestPriorityPid, &lowestPriority)) { |
| 782 | return false; |
| 783 | } |
| 784 | if (lowestPriority <= callingPriority) { |
| 785 | ALOGE("getLowestPriorityBiggestClient_l: lowest priority %d vs caller priority %d", |
| 786 | lowestPriority, callingPriority); |
| 787 | return false; |
| 788 | } |
| 789 | |
| 790 | if (!getBiggestClient_l(lowestPriorityPid, type, client)) { |
| 791 | return false; |
| 792 | } |
| 793 | return true; |
| 794 | } |
| 795 | |
| 796 | bool ResourceManagerService::getLowestPriorityPid_l( |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame] | 797 | MediaResource::Type type, int *lowestPriorityPid, int *lowestPriority) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 798 | int pid = -1; |
| 799 | int priority = -1; |
| 800 | for (size_t i = 0; i < mMap.size(); ++i) { |
| 801 | if (mMap.valueAt(i).size() == 0) { |
| 802 | // no client on this process. |
| 803 | continue; |
| 804 | } |
| 805 | if (!hasResourceType(type, mMap.valueAt(i))) { |
| 806 | // doesn't have the requested resource type |
| 807 | continue; |
| 808 | } |
| 809 | int tempPid = mMap.keyAt(i); |
| 810 | int tempPriority; |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 811 | if (!getPriority_l(tempPid, &tempPriority)) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 812 | ALOGV("getLowestPriorityPid_l: can't get priority of pid %d, skipped", tempPid); |
| 813 | // TODO: remove this pid from mMap? |
| 814 | continue; |
| 815 | } |
| 816 | if (pid == -1 || tempPriority > priority) { |
| 817 | // initial the value |
| 818 | pid = tempPid; |
| 819 | priority = tempPriority; |
| 820 | } |
| 821 | } |
| 822 | if (pid != -1) { |
| 823 | *lowestPriorityPid = pid; |
| 824 | *lowestPriority = priority; |
| 825 | } |
| 826 | return (pid != -1); |
| 827 | } |
| 828 | |
| 829 | bool ResourceManagerService::isCallingPriorityHigher_l(int callingPid, int pid) { |
| 830 | int callingPidPriority; |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 831 | if (!getPriority_l(callingPid, &callingPidPriority)) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 832 | return false; |
| 833 | } |
| 834 | |
| 835 | int priority; |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 836 | if (!getPriority_l(pid, &priority)) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 837 | return false; |
| 838 | } |
| 839 | |
| 840 | return (callingPidPriority < priority); |
| 841 | } |
| 842 | |
| 843 | bool ResourceManagerService::getBiggestClient_l( |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 844 | int pid, MediaResource::Type type, std::shared_ptr<IResourceManagerClient> *client, |
| 845 | bool pendingRemovalOnly) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 846 | ssize_t index = mMap.indexOfKey(pid); |
| 847 | if (index < 0) { |
| 848 | ALOGE("getBiggestClient_l: can't find resource info for pid %d", pid); |
| 849 | return false; |
| 850 | } |
| 851 | |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 852 | std::shared_ptr<IResourceManagerClient> clientTemp; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 853 | uint64_t largestValue = 0; |
| 854 | const ResourceInfos &infos = mMap.valueAt(index); |
| 855 | for (size_t i = 0; i < infos.size(); ++i) { |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 856 | const ResourceList &resources = infos[i].resources; |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 857 | if (pendingRemovalOnly && !infos[i].pendingRemoval) { |
| 858 | continue; |
| 859 | } |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 860 | for (auto it = resources.begin(); it != resources.end(); it++) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 861 | const MediaResourceParcel &resource = it->second; |
| 862 | if (resource.type == type) { |
| 863 | if (resource.value > largestValue) { |
| 864 | largestValue = resource.value; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 865 | clientTemp = infos[i].client; |
| 866 | } |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | if (clientTemp == NULL) { |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame] | 872 | ALOGE("getBiggestClient_l: can't find resource type %s for pid %d", asString(type), pid); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 873 | return false; |
| 874 | } |
| 875 | |
| 876 | *client = clientTemp; |
| 877 | return true; |
| 878 | } |
| 879 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 880 | } // namespace android |