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> |
Chong Zhang | c7303e8 | 2020-12-02 16:38:52 -0800 | [diff] [blame] | 24 | #include <binder/IPCThreadState.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> |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 27 | #include <media/MediaResourcePolicy.h> |
Girish | 1f002cf | 2023-02-17 00:36:29 +0000 | [diff] [blame] | 28 | #include <media/stagefright/foundation/ABase.h> |
Chong Zhang | ee33d64 | 2019-08-08 14:26:43 -0700 | [diff] [blame] | 29 | #include <mediautils/BatteryNotifier.h> |
Girish | 1f002cf | 2023-02-17 00:36:29 +0000 | [diff] [blame] | 30 | #include <mediautils/ProcessInfo.h> |
Chong Zhang | ee33d64 | 2019-08-08 14:26:43 -0700 | [diff] [blame] | 31 | #include <mediautils/SchedulingPolicyService.h> |
Girish | 1484e5d | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 32 | #include <com_android_media_codec_flags.h> |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 33 | |
Girish | 1f002cf | 2023-02-17 00:36:29 +0000 | [diff] [blame] | 34 | #include "ResourceManagerMetrics.h" |
Girish | 1484e5d | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 35 | #include "ResourceManagerServiceNew.h" |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 36 | #include "ResourceObserverService.h" |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 37 | #include "ServiceLog.h" |
Chong Zhang | ee33d64 | 2019-08-08 14:26:43 -0700 | [diff] [blame] | 38 | |
Girish | 1484e5d | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 39 | namespace CodecFeatureFlags = com::android::media::codec::flags; |
| 40 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 41 | namespace android { |
| 42 | |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 43 | void ResourceManagerService::getResourceDump(std::string& resourceLog) const { |
| 44 | PidResourceInfosMap mapCopy; |
| 45 | std::map<int, int> overridePidMapCopy; |
| 46 | { |
| 47 | std::scoped_lock lock{mLock}; |
| 48 | mapCopy = mMap; // Shadow copy, real copy will happen on write. |
| 49 | overridePidMapCopy = mOverridePidMap; |
| 50 | } |
| 51 | |
| 52 | const size_t SIZE = 256; |
| 53 | char buffer[SIZE]; |
| 54 | resourceLog.append(" Processes:\n"); |
| 55 | for (const auto& [pid, infos] : mapCopy) { |
| 56 | snprintf(buffer, SIZE, " Pid: %d\n", pid); |
| 57 | resourceLog.append(buffer); |
| 58 | int priority = 0; |
| 59 | if (getPriority_l(pid, &priority)) { |
| 60 | snprintf(buffer, SIZE, " Priority: %d\n", priority); |
| 61 | } else { |
| 62 | snprintf(buffer, SIZE, " Priority: <unknown>\n"); |
| 63 | } |
| 64 | resourceLog.append(buffer); |
| 65 | |
| 66 | for (const auto& [infoKey, info] : infos) { |
| 67 | resourceLog.append(" Client:\n"); |
| 68 | snprintf(buffer, SIZE, " Id: %lld\n", (long long)info.clientId); |
| 69 | resourceLog.append(buffer); |
| 70 | |
| 71 | std::string clientName = info.name; |
| 72 | snprintf(buffer, SIZE, " Name: %s\n", clientName.c_str()); |
| 73 | resourceLog.append(buffer); |
| 74 | |
| 75 | const ResourceList& resources = info.resources; |
| 76 | resourceLog.append(" Resources:\n"); |
Girish | d11a03a | 2023-11-30 21:17:51 +0000 | [diff] [blame] | 77 | resourceLog.append(resources.toString()); |
Dongwon Kang | fe508d3 | 2015-12-15 14:22:05 +0900 | [diff] [blame] | 78 | } |
| 79 | } |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 80 | |
| 81 | resourceLog.append(" Process Pid override:\n"); |
| 82 | for (auto it = overridePidMapCopy.begin(); it != overridePidMapCopy.end(); ++it) { |
| 83 | snprintf(buffer, SIZE, " Original Pid: %d, Override Pid: %d\n", |
| 84 | it->first, it->second); |
| 85 | resourceLog.append(buffer); |
| 86 | } |
Dongwon Kang | fe508d3 | 2015-12-15 14:22:05 +0900 | [diff] [blame] | 87 | } |
| 88 | |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 89 | binder_status_t ResourceManagerService::dump(int fd, const char** /*args*/, uint32_t /*numArgs*/) { |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 90 | String8 result; |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 91 | |
dcashman | 014e91e | 2015-09-11 09:33:01 -0700 | [diff] [blame] | 92 | if (checkCallingPermission(String16("android.permission.DUMP")) == false) { |
| 93 | result.format("Permission Denial: " |
| 94 | "can't dump ResourceManagerService from pid=%d, uid=%d\n", |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 95 | AIBinder_getCallingPid(), |
| 96 | AIBinder_getCallingUid()); |
Tomasz Wasilczyk | 09977ff | 2023-08-11 15:52:22 +0000 | [diff] [blame] | 97 | write(fd, result.c_str(), result.size()); |
dcashman | 014e91e | 2015-09-11 09:33:01 -0700 | [diff] [blame] | 98 | return PERMISSION_DENIED; |
| 99 | } |
| 100 | |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 101 | bool supportsMultipleSecureCodecs; |
| 102 | bool supportsSecureWithNonSecureCodec; |
| 103 | String8 serviceLog; |
| 104 | { |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 105 | std::scoped_lock lock{mLock}; |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 106 | supportsMultipleSecureCodecs = mSupportsMultipleSecureCodecs; |
| 107 | supportsSecureWithNonSecureCodec = mSupportsSecureWithNonSecureCodec; |
| 108 | serviceLog = mServiceLog->toString(" " /* linePrefix */); |
| 109 | } |
| 110 | |
Girish | dc18755 | 2024-04-02 21:51:46 +0000 | [diff] [blame] | 111 | // Get all the resource (and overload pid) log. |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 112 | std::string resourceLog; |
| 113 | getResourceDump(resourceLog); |
| 114 | |
Girish | dc18755 | 2024-04-02 21:51:46 +0000 | [diff] [blame] | 115 | // Get all the metrics log. |
| 116 | std::string metricsLog; |
| 117 | { |
| 118 | std::scoped_lock lock{mLock}; |
| 119 | metricsLog = mResourceManagerMetrics->dump(); |
| 120 | } |
| 121 | |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 122 | const size_t SIZE = 256; |
| 123 | char buffer[SIZE]; |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 124 | snprintf(buffer, SIZE, "ResourceManagerService: %p\n", this); |
| 125 | result.append(buffer); |
| 126 | result.append(" Policies:\n"); |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 127 | snprintf(buffer, SIZE, " SupportsMultipleSecureCodecs: %d\n", supportsMultipleSecureCodecs); |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 128 | result.append(buffer); |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 129 | snprintf(buffer, SIZE, " SupportsSecureWithNonSecureCodec: %d\n", |
| 130 | supportsSecureWithNonSecureCodec); |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 131 | result.append(buffer); |
| 132 | |
Girish | dc18755 | 2024-04-02 21:51:46 +0000 | [diff] [blame] | 133 | // Add resource log. |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 134 | result.append(resourceLog.c_str()); |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 135 | |
Girish | dc18755 | 2024-04-02 21:51:46 +0000 | [diff] [blame] | 136 | // Add service log. |
Ronghua Wu | 022ed72 | 2015-05-11 15:15:09 -0700 | [diff] [blame] | 137 | result.append(" Events logs (most recent at top):\n"); |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 138 | result.append(serviceLog); |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 139 | |
Girish | dc18755 | 2024-04-02 21:51:46 +0000 | [diff] [blame] | 140 | // Add metrics log. |
| 141 | result.append(metricsLog.c_str()); |
| 142 | |
Tomasz Wasilczyk | 09977ff | 2023-08-11 15:52:22 +0000 | [diff] [blame] | 143 | write(fd, result.c_str(), result.size()); |
Ronghua Wu | 8f9dd87 | 2015-04-23 15:24:25 -0700 | [diff] [blame] | 144 | return OK; |
| 145 | } |
| 146 | |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 147 | struct SystemCallbackImpl : public ResourceManagerService::SystemCallbackInterface { |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 148 | SystemCallbackImpl() : mClientToken(new BBinder()) {} |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 149 | |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 150 | virtual void noteStartVideo(int uid) override { |
| 151 | BatteryNotifier::getInstance().noteStartVideo(uid); |
| 152 | } |
| 153 | virtual void noteStopVideo(int uid) override { |
| 154 | BatteryNotifier::getInstance().noteStopVideo(uid); |
| 155 | } |
| 156 | virtual void noteResetVideo() override { |
| 157 | BatteryNotifier::getInstance().noteResetVideo(); |
| 158 | } |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 159 | virtual bool requestCpusetBoost(bool enable) override { |
| 160 | return android::requestCpusetBoost(enable, mClientToken); |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | protected: |
| 164 | virtual ~SystemCallbackImpl() {} |
| 165 | |
| 166 | private: |
| 167 | DISALLOW_EVIL_CONSTRUCTORS(SystemCallbackImpl); |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 168 | sp<IBinder> mClientToken; |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | ResourceManagerService::ResourceManagerService() |
| 172 | : ResourceManagerService(new ProcessInfo(), new SystemCallbackImpl()) {} |
| 173 | |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 174 | ResourceManagerService::ResourceManagerService(const sp<ProcessInfoInterface> &processInfo, |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 175 | const sp<SystemCallbackInterface> &systemResource) |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 176 | : mProcessInfo(processInfo), |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 177 | mSystemCB(systemResource), |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 178 | mServiceLog(new ServiceLog()), |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 179 | mSupportsMultipleSecureCodecs(true), |
Chong Zhang | 79d2b28 | 2018-04-17 14:14:31 -0700 | [diff] [blame] | 180 | mSupportsSecureWithNonSecureCodec(true), |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 181 | mCpuBoostCount(0) { |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 182 | mSystemCB->noteResetVideo(); |
Girish | 1f002cf | 2023-02-17 00:36:29 +0000 | [diff] [blame] | 183 | // Create ResourceManagerMetrics that handles all the metrics. |
| 184 | mResourceManagerMetrics = std::make_unique<ResourceManagerMetrics>(mProcessInfo); |
Chong Zhang | ee33d64 | 2019-08-08 14:26:43 -0700 | [diff] [blame] | 185 | } |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 186 | |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 187 | //static |
| 188 | void ResourceManagerService::instantiate() { |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 189 | std::shared_ptr<ResourceManagerService> service = Create(); |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 190 | binder_status_t status = |
Charles Chen | 5b097ef | 2023-03-15 01:21:22 +0000 | [diff] [blame] | 191 | AServiceManager_addServiceWithFlags( |
Charles Chen | e55549f | 2023-03-15 01:21:22 +0000 | [diff] [blame] | 192 | service->asBinder().get(), getServiceName(), |
| 193 | AServiceManager_AddServiceFlag::ADD_SERVICE_ALLOW_ISOLATED); |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 194 | if (status != STATUS_OK) { |
| 195 | return; |
| 196 | } |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 197 | |
| 198 | std::shared_ptr<ResourceObserverService> observerService = |
| 199 | ResourceObserverService::instantiate(); |
| 200 | |
| 201 | if (observerService != nullptr) { |
| 202 | service->setObserverService(observerService); |
| 203 | } |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 204 | // TODO: mediaserver main() is already starting the thread pool, |
| 205 | // move this to mediaserver main() when other services in mediaserver |
| 206 | // are converted to ndk-platform aidl. |
| 207 | //ABinderProcess_startThreadPool(); |
| 208 | } |
| 209 | |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 210 | std::shared_ptr<ResourceManagerService> ResourceManagerService::Create() { |
| 211 | return Create(new ProcessInfo(), new SystemCallbackImpl()); |
| 212 | } |
| 213 | |
| 214 | std::shared_ptr<ResourceManagerService> ResourceManagerService::Create( |
| 215 | const sp<ProcessInfoInterface>& processInfo, |
| 216 | const sp<SystemCallbackInterface>& systemResource) { |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 217 | std::shared_ptr<ResourceManagerService> service = nullptr; |
Girish | 1484e5d | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 218 | // If codec importance feature is on, create the refactored implementation. |
| 219 | if (CodecFeatureFlags::codec_importance()) { |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 220 | service = ::ndk::SharedRefBase::make<ResourceManagerServiceNew>(processInfo, |
| 221 | systemResource); |
| 222 | } else { |
| 223 | service = ::ndk::SharedRefBase::make<ResourceManagerService>(processInfo, |
| 224 | systemResource); |
Girish | 1484e5d | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 225 | } |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 226 | |
| 227 | if (service != nullptr) { |
| 228 | service->init(); |
| 229 | } |
| 230 | |
| 231 | return service; |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Girish | 1484e5d | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 234 | // TEST only function. |
| 235 | std::shared_ptr<ResourceManagerService> ResourceManagerService::CreateNew( |
| 236 | const sp<ProcessInfoInterface>& processInfo, |
| 237 | const sp<SystemCallbackInterface>& systemResource) { |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 238 | std::shared_ptr<ResourceManagerService> service = |
| 239 | ::ndk::SharedRefBase::make<ResourceManagerServiceNew>(processInfo, systemResource); |
| 240 | service->init(); |
| 241 | return service; |
Girish | 1484e5d | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 244 | void ResourceManagerService::init() {} |
| 245 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 246 | ResourceManagerService::~ResourceManagerService() {} |
| 247 | |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 248 | void ResourceManagerService::setObserverService( |
| 249 | const std::shared_ptr<ResourceObserverService>& observerService) { |
| 250 | mObserverService = observerService; |
| 251 | } |
| 252 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 253 | Status ResourceManagerService::config(const std::vector<MediaResourcePolicyParcel>& policies) { |
Tomasz Wasilczyk | 09977ff | 2023-08-11 15:52:22 +0000 | [diff] [blame] | 254 | String8 log = String8::format("config(%s)", getString(policies).c_str()); |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 255 | mServiceLog->add(log); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 256 | |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 257 | std::scoped_lock lock{mLock}; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 258 | for (size_t i = 0; i < policies.size(); ++i) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 259 | const std::string &type = policies[i].type; |
| 260 | const std::string &value = policies[i].value; |
| 261 | if (type == MediaResourcePolicy::kPolicySupportsMultipleSecureCodecs()) { |
Ronghua Wu | 9ba21b9 | 2015-04-21 14:23:06 -0700 | [diff] [blame] | 262 | mSupportsMultipleSecureCodecs = (value == "true"); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 263 | } else if (type == MediaResourcePolicy::kPolicySupportsSecureWithNonSecureCodec()) { |
Ronghua Wu | 9ba21b9 | 2015-04-21 14:23:06 -0700 | [diff] [blame] | 264 | mSupportsSecureWithNonSecureCodec = (value == "true"); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 265 | } |
| 266 | } |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 267 | return Status::ok(); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 270 | void ResourceManagerService::onFirstAdded(const MediaResourceParcel& resource, uid_t uid) { |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 271 | // first time added |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 272 | if (resource.type == MediaResource::Type::kCpuBoost |
| 273 | && resource.subType == MediaResource::SubType::kUnspecifiedSubType) { |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 274 | // Request it on every new instance of kCpuBoost, as the media.codec |
| 275 | // could have died, if we only do it the first time subsequent instances |
| 276 | // never gets the boost. |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 277 | if (mSystemCB->requestCpusetBoost(true) != OK) { |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 278 | ALOGW("couldn't request cpuset boost"); |
| 279 | } |
| 280 | mCpuBoostCount++; |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 281 | } else if (resource.type == MediaResource::Type::kBattery |
Girish | a5a2d67 | 2023-09-20 18:40:20 +0000 | [diff] [blame] | 282 | && (resource.subType == MediaResource::SubType::kHwVideoCodec |
| 283 | || resource.subType == MediaResource::SubType::kSwVideoCodec)) { |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 284 | mSystemCB->noteStartVideo(uid); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 288 | void ResourceManagerService::onLastRemoved(const MediaResourceParcel& resource, uid_t uid) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 289 | if (resource.type == MediaResource::Type::kCpuBoost |
| 290 | && resource.subType == MediaResource::SubType::kUnspecifiedSubType |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 291 | && mCpuBoostCount > 0) { |
| 292 | if (--mCpuBoostCount == 0) { |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 293 | mSystemCB->requestCpusetBoost(false); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 294 | } |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 295 | } else if (resource.type == MediaResource::Type::kBattery |
Girish | a5a2d67 | 2023-09-20 18:40:20 +0000 | [diff] [blame] | 296 | && (resource.subType == MediaResource::SubType::kHwVideoCodec |
| 297 | || resource.subType == MediaResource::SubType::kSwVideoCodec)) { |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 298 | mSystemCB->noteStopVideo(uid); |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 302 | Status ResourceManagerService::addResource(const ClientInfoParcel& clientInfo, |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 303 | const std::shared_ptr<IResourceManagerClient>& client, |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 304 | const std::vector<MediaResourceParcel>& resources) { |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 305 | int32_t pid = clientInfo.pid; |
| 306 | int32_t uid = clientInfo.uid; |
| 307 | int64_t clientId = clientInfo.id; |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 308 | String8 log = String8::format("addResource(pid %d, uid %d clientId %lld, resources %s)", |
Tomasz Wasilczyk | 09977ff | 2023-08-11 15:52:22 +0000 | [diff] [blame] | 309 | pid, uid, (long long) clientId, getString(resources).c_str()); |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 310 | mServiceLog->add(log); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 311 | |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 312 | std::scoped_lock lock{mLock}; |
Brian Lindahl | cf3bafb | 2022-01-27 14:21:38 +0100 | [diff] [blame] | 313 | if (!mProcessInfo->isPidUidTrusted(pid, uid)) { |
Chong Zhang | c7303e8 | 2020-12-02 16:38:52 -0800 | [diff] [blame] | 314 | pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
| 315 | uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Brian Lindahl | cf3bafb | 2022-01-27 14:21:38 +0100 | [diff] [blame] | 316 | ALOGW("%s called with untrusted pid %d or uid %d, using calling pid %d, uid %d", |
| 317 | __FUNCTION__, pid, uid, callingPid, callingUid); |
Chong Zhang | c7303e8 | 2020-12-02 16:38:52 -0800 | [diff] [blame] | 318 | pid = callingPid; |
| 319 | uid = callingUid; |
Ronghua Wu | d11c43a | 2016-01-27 16:26:12 -0800 | [diff] [blame] | 320 | } |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 321 | ResourceInfos& infos = getResourceInfosForEdit(pid, mMap); |
Girish | 27365ed | 2023-10-11 20:20:55 +0000 | [diff] [blame] | 322 | ResourceInfo& info = getResourceInfoForEdit(clientInfo, client, infos); |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 323 | ResourceList resourceAdded; |
Chong Zhang | 79d2b28 | 2018-04-17 14:14:31 -0700 | [diff] [blame] | 324 | |
| 325 | for (size_t i = 0; i < resources.size(); ++i) { |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 326 | const auto &res = resources[i]; |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 327 | |
| 328 | if (res.value < 0 && res.type != MediaResource::Type::kDrmSession) { |
| 329 | ALOGW("Ignoring request to remove negative value of non-drm resource"); |
| 330 | continue; |
| 331 | } |
Girish | d11a03a | 2023-11-30 21:17:51 +0000 | [diff] [blame] | 332 | bool isNewEntry = false; |
| 333 | if (!info.resources.add(res, &isNewEntry)) { |
| 334 | continue; |
| 335 | } |
| 336 | if (isNewEntry) { |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 337 | onFirstAdded(res, info.uid); |
Chong Zhang | 79d2b28 | 2018-04-17 14:14:31 -0700 | [diff] [blame] | 338 | } |
Girish | d11a03a | 2023-11-30 21:17:51 +0000 | [diff] [blame] | 339 | |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 340 | // Add it to the list of added resources for observers. |
Girish | d11a03a | 2023-11-30 21:17:51 +0000 | [diff] [blame] | 341 | resourceAdded.add(res); |
Chong Zhang | 79d2b28 | 2018-04-17 14:14:31 -0700 | [diff] [blame] | 342 | } |
Girish | f1d166c | 2023-07-20 22:35:29 +0000 | [diff] [blame] | 343 | if (info.deathNotifier == nullptr && client != nullptr) { |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 344 | info.deathNotifier = DeathNotifier::Create( |
| 345 | client, ref<ResourceManagerService>(), clientInfo); |
Wonsik Kim | 3e37896 | 2017-01-05 17:00:02 +0900 | [diff] [blame] | 346 | } |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 347 | if (mObserverService != nullptr && !resourceAdded.empty()) { |
| 348 | mObserverService->onResourceAdded(uid, pid, resourceAdded); |
| 349 | } |
Dongwon Kang | fe508d3 | 2015-12-15 14:22:05 +0900 | [diff] [blame] | 350 | notifyResourceGranted(pid, resources); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 351 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 352 | return Status::ok(); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 355 | Status ResourceManagerService::removeResource(const ClientInfoParcel& clientInfo, |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 356 | const std::vector<MediaResourceParcel>& resources) { |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 357 | int32_t pid = clientInfo.pid; |
| 358 | int32_t uid = clientInfo.uid; |
| 359 | int64_t clientId = clientInfo.id; |
| 360 | String8 log = String8::format("removeResource(pid %d, uid %d clientId %lld, resources %s)", |
Tomasz Wasilczyk | 09977ff | 2023-08-11 15:52:22 +0000 | [diff] [blame] | 361 | pid, uid, (long long) clientId, getString(resources).c_str()); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 362 | mServiceLog->add(log); |
| 363 | |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 364 | std::scoped_lock lock{mLock}; |
Brian Lindahl | cf3bafb | 2022-01-27 14:21:38 +0100 | [diff] [blame] | 365 | if (!mProcessInfo->isPidTrusted(pid)) { |
Chong Zhang | c7303e8 | 2020-12-02 16:38:52 -0800 | [diff] [blame] | 366 | pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
| 367 | ALOGW("%s called with untrusted pid %d, using calling pid %d", __FUNCTION__, |
| 368 | pid, callingPid); |
| 369 | pid = callingPid; |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 370 | } |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 371 | PidResourceInfosMap::iterator found = mMap.find(pid); |
| 372 | if (found == mMap.end()) { |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 373 | 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] | 374 | return Status::ok(); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 375 | } |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 376 | ResourceInfos& infos = found->second; |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 377 | |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 378 | ResourceInfos::iterator foundClient = infos.find(clientId); |
| 379 | if (foundClient == infos.end()) { |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 380 | ALOGV("removeResource: didn't find clientId %lld", (long long) clientId); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 381 | return Status::ok(); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 384 | ResourceInfo& info = foundClient->second; |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 385 | ResourceList resourceRemoved; |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 386 | for (size_t i = 0; i < resources.size(); ++i) { |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 387 | const auto &res = resources[i]; |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 388 | |
| 389 | if (res.value < 0) { |
| 390 | ALOGW("Ignoring request to remove negative value of resource"); |
| 391 | continue; |
| 392 | } |
Girish | d11a03a | 2023-11-30 21:17:51 +0000 | [diff] [blame] | 393 | |
| 394 | long removedEntryValue = -1; |
| 395 | if (info.resources.remove(res, &removedEntryValue)) { |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 396 | MediaResourceParcel actualRemoved = res; |
Girish | d11a03a | 2023-11-30 21:17:51 +0000 | [diff] [blame] | 397 | if (removedEntryValue != -1) { |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 398 | onLastRemoved(res, info.uid); |
Girish | d11a03a | 2023-11-30 21:17:51 +0000 | [diff] [blame] | 399 | actualRemoved.value = removedEntryValue; |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | // Add it to the list of removed resources for observers. |
Girish | d11a03a | 2023-11-30 21:17:51 +0000 | [diff] [blame] | 403 | resourceRemoved.add(actualRemoved); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 404 | } |
| 405 | } |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 406 | if (mObserverService != nullptr && !resourceRemoved.empty()) { |
| 407 | mObserverService->onResourceRemoved(info.uid, pid, resourceRemoved); |
| 408 | } |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 409 | return Status::ok(); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 412 | Status ResourceManagerService::removeClient(const ClientInfoParcel& clientInfo) { |
| 413 | removeResource(clientInfo, true /*checkValid*/); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 414 | return Status::ok(); |
Wonsik Kim | 3e37896 | 2017-01-05 17:00:02 +0900 | [diff] [blame] | 415 | } |
| 416 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 417 | Status ResourceManagerService::removeResource(const ClientInfoParcel& clientInfo, bool checkValid) { |
| 418 | int32_t pid = clientInfo.pid; |
| 419 | int32_t uid = clientInfo.uid; |
| 420 | int64_t clientId = clientInfo.id; |
| 421 | String8 log = String8::format("removeResource(pid %d, uid %d clientId %lld)", |
| 422 | pid, uid, (long long) clientId); |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 423 | mServiceLog->add(log); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 424 | |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 425 | std::scoped_lock lock{mLock}; |
Brian Lindahl | cf3bafb | 2022-01-27 14:21:38 +0100 | [diff] [blame] | 426 | if (checkValid && !mProcessInfo->isPidTrusted(pid)) { |
Chong Zhang | c7303e8 | 2020-12-02 16:38:52 -0800 | [diff] [blame] | 427 | pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
| 428 | ALOGW("%s called with untrusted pid %d, using calling pid %d", __FUNCTION__, |
| 429 | pid, callingPid); |
| 430 | pid = callingPid; |
Ronghua Wu | d11c43a | 2016-01-27 16:26:12 -0800 | [diff] [blame] | 431 | } |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 432 | PidResourceInfosMap::iterator found = mMap.find(pid); |
| 433 | if (found == mMap.end()) { |
Ronghua Wu | 37c8924 | 2015-07-15 12:23:48 -0700 | [diff] [blame] | 434 | 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] | 435 | return Status::ok(); |
Ronghua Wu | 37c8924 | 2015-07-15 12:23:48 -0700 | [diff] [blame] | 436 | } |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 437 | ResourceInfos& infos = found->second; |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 438 | |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 439 | ResourceInfos::iterator foundClient = infos.find(clientId); |
| 440 | if (foundClient == infos.end()) { |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 441 | ALOGV("removeResource: didn't find clientId %lld", (long long) clientId); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 442 | return Status::ok(); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 443 | } |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 444 | |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 445 | const ResourceInfo& info = foundClient->second; |
Girish | d11a03a | 2023-11-30 21:17:51 +0000 | [diff] [blame] | 446 | for (const MediaResourceParcel& res : info.resources.getResources()) { |
| 447 | onLastRemoved(res, info.uid); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 448 | } |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 449 | |
Girish | 1f002cf | 2023-02-17 00:36:29 +0000 | [diff] [blame] | 450 | // Since this client has been removed, update the metrics collector. |
| 451 | mResourceManagerMetrics->notifyClientReleased(clientInfo); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 452 | |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 453 | if (mObserverService != nullptr && !info.resources.empty()) { |
| 454 | mObserverService->onResourceRemoved(info.uid, pid, info.resources); |
| 455 | } |
| 456 | |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 457 | infos.erase(foundClient); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 458 | return Status::ok(); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 461 | void ResourceManagerService::getClientForResource_l( |
| 462 | const ResourceRequestInfo& resourceRequestInfo, |
| 463 | std::vector<ClientInfo>& clientsInfo) { |
Girish | aff0ef2 | 2023-10-13 00:22:39 +0000 | [diff] [blame] | 464 | int callingPid = resourceRequestInfo.mCallingPid; |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 465 | const MediaResourceParcel* res = resourceRequestInfo.mResource; |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 466 | if (res == NULL) { |
| 467 | return; |
| 468 | } |
Girish | aff0ef2 | 2023-10-13 00:22:39 +0000 | [diff] [blame] | 469 | |
| 470 | // Before looking into other processes, check if we have clients marked for |
| 471 | // pending removal in the same process. |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 472 | ClientInfo clientInfo; |
| 473 | if (getBiggestClientPendingRemoval_l(callingPid, res->type, res->subType, clientInfo)) { |
| 474 | clientsInfo.emplace_back(clientInfo); |
Girish | aff0ef2 | 2023-10-13 00:22:39 +0000 | [diff] [blame] | 475 | return; |
| 476 | } |
| 477 | |
| 478 | // Now find client(s) from a lowest priority process that has needed resources. |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 479 | if (getLowestPriorityBiggestClient_l(resourceRequestInfo, clientInfo)) { |
| 480 | clientsInfo.push_back(clientInfo); |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | |
Girish | 0ac5c21 | 2023-11-23 09:14:03 +0000 | [diff] [blame] | 484 | bool ResourceManagerService::getTargetClients( |
Girish | 88a8350 | 2023-11-23 11:23:07 +0000 | [diff] [blame] | 485 | const ClientInfoParcel& clientInfo, |
Girish | 0ac5c21 | 2023-11-23 09:14:03 +0000 | [diff] [blame] | 486 | const std::vector<MediaResourceParcel>& resources, |
| 487 | std::vector<ClientInfo>& targetClients) { |
Girish | 88a8350 | 2023-11-23 11:23:07 +0000 | [diff] [blame] | 488 | int32_t callingPid = clientInfo.pid; |
Girish | 1c68240 | 2024-01-31 21:03:51 +0000 | [diff] [blame] | 489 | int64_t clientId = clientInfo.id; |
Girish | 0ac5c21 | 2023-11-23 09:14:03 +0000 | [diff] [blame] | 490 | std::scoped_lock lock{mLock}; |
| 491 | if (!mProcessInfo->isPidTrusted(callingPid)) { |
| 492 | pid_t actualCallingPid = IPCThreadState::self()->getCallingPid(); |
| 493 | ALOGW("%s called with untrusted pid %d, using actual calling pid %d", __FUNCTION__, |
| 494 | callingPid, actualCallingPid); |
| 495 | callingPid = actualCallingPid; |
| 496 | } |
| 497 | const MediaResourceParcel *secureCodec = NULL; |
| 498 | const MediaResourceParcel *nonSecureCodec = NULL; |
| 499 | const MediaResourceParcel *graphicMemory = NULL; |
| 500 | const MediaResourceParcel *drmSession = NULL; |
| 501 | for (size_t i = 0; i < resources.size(); ++i) { |
| 502 | switch (resources[i].type) { |
| 503 | case MediaResource::Type::kSecureCodec: |
| 504 | secureCodec = &resources[i]; |
| 505 | break; |
| 506 | case MediaResource::Type::kNonSecureCodec: |
| 507 | nonSecureCodec = &resources[i]; |
| 508 | break; |
| 509 | case MediaResource::Type::kGraphicMemory: |
| 510 | graphicMemory = &resources[i]; |
| 511 | break; |
| 512 | case MediaResource::Type::kDrmSession: |
| 513 | drmSession = &resources[i]; |
| 514 | break; |
| 515 | default: |
| 516 | break; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | // first pass to handle secure/non-secure codec conflict |
| 521 | if (secureCodec != NULL) { |
| 522 | MediaResourceParcel mediaResource{.type = MediaResource::Type::kSecureCodec, |
| 523 | .subType = secureCodec->subType}; |
Girish | 1c68240 | 2024-01-31 21:03:51 +0000 | [diff] [blame] | 524 | ResourceRequestInfo resourceRequestInfo{callingPid, clientId, &mediaResource}; |
Girish | 0ac5c21 | 2023-11-23 09:14:03 +0000 | [diff] [blame] | 525 | if (!mSupportsMultipleSecureCodecs) { |
| 526 | if (!getAllClients_l(resourceRequestInfo, targetClients)) { |
| 527 | return false; |
| 528 | } |
| 529 | } |
| 530 | if (!mSupportsSecureWithNonSecureCodec) { |
| 531 | mediaResource.type = MediaResource::Type::kNonSecureCodec; |
| 532 | if (!getAllClients_l(resourceRequestInfo, targetClients)) { |
| 533 | return false; |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | if (nonSecureCodec != NULL) { |
| 538 | if (!mSupportsSecureWithNonSecureCodec) { |
| 539 | MediaResourceParcel mediaResource{.type = MediaResource::Type::kSecureCodec, |
| 540 | .subType = nonSecureCodec->subType}; |
Girish | 1c68240 | 2024-01-31 21:03:51 +0000 | [diff] [blame] | 541 | ResourceRequestInfo resourceRequestInfo{callingPid, clientId, &mediaResource}; |
Girish | 0ac5c21 | 2023-11-23 09:14:03 +0000 | [diff] [blame] | 542 | if (!getAllClients_l(resourceRequestInfo, targetClients)) { |
| 543 | return false; |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | if (drmSession != NULL) { |
Girish | 1c68240 | 2024-01-31 21:03:51 +0000 | [diff] [blame] | 549 | ResourceRequestInfo resourceRequestInfo{callingPid, clientId, drmSession}; |
Girish | 0ac5c21 | 2023-11-23 09:14:03 +0000 | [diff] [blame] | 550 | getClientForResource_l(resourceRequestInfo, targetClients); |
| 551 | if (targetClients.size() == 0) { |
| 552 | return false; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | if (targetClients.size() == 0 && graphicMemory != nullptr) { |
| 557 | // if no secure/non-secure codec conflict, run second pass to handle other resources. |
Girish | 1c68240 | 2024-01-31 21:03:51 +0000 | [diff] [blame] | 558 | ResourceRequestInfo resourceRequestInfo{callingPid, clientId, graphicMemory}; |
Girish | 0ac5c21 | 2023-11-23 09:14:03 +0000 | [diff] [blame] | 559 | getClientForResource_l(resourceRequestInfo, targetClients); |
| 560 | } |
| 561 | |
| 562 | if (targetClients.size() == 0) { |
| 563 | // if we are here, run the third pass to free one codec with the same type. |
| 564 | if (secureCodec != nullptr) { |
Girish | 1c68240 | 2024-01-31 21:03:51 +0000 | [diff] [blame] | 565 | ResourceRequestInfo resourceRequestInfo{callingPid, clientId, secureCodec}; |
Girish | 0ac5c21 | 2023-11-23 09:14:03 +0000 | [diff] [blame] | 566 | getClientForResource_l(resourceRequestInfo, targetClients); |
| 567 | } |
| 568 | if (nonSecureCodec != nullptr) { |
Girish | 1c68240 | 2024-01-31 21:03:51 +0000 | [diff] [blame] | 569 | ResourceRequestInfo resourceRequestInfo{callingPid, clientId, nonSecureCodec}; |
Girish | 0ac5c21 | 2023-11-23 09:14:03 +0000 | [diff] [blame] | 570 | getClientForResource_l(resourceRequestInfo, targetClients); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | if (targetClients.size() == 0) { |
| 575 | // if we are here, run the fourth pass to free one codec with the different type. |
| 576 | if (secureCodec != nullptr) { |
| 577 | MediaResource temp(MediaResource::Type::kNonSecureCodec, secureCodec->subType, 1); |
Girish | 1c68240 | 2024-01-31 21:03:51 +0000 | [diff] [blame] | 578 | ResourceRequestInfo resourceRequestInfo{callingPid, clientId, &temp}; |
Girish | 0ac5c21 | 2023-11-23 09:14:03 +0000 | [diff] [blame] | 579 | getClientForResource_l(resourceRequestInfo, targetClients); |
| 580 | } |
| 581 | if (nonSecureCodec != nullptr) { |
| 582 | MediaResource temp(MediaResource::Type::kSecureCodec, nonSecureCodec->subType, 1); |
Girish | 1c68240 | 2024-01-31 21:03:51 +0000 | [diff] [blame] | 583 | ResourceRequestInfo resourceRequestInfo{callingPid, clientId, &temp}; |
Girish | 0ac5c21 | 2023-11-23 09:14:03 +0000 | [diff] [blame] | 584 | getClientForResource_l(resourceRequestInfo, targetClients); |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | return !targetClients.empty(); |
| 589 | } |
| 590 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 591 | Status ResourceManagerService::reclaimResource(const ClientInfoParcel& clientInfo, |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 592 | const std::vector<MediaResourceParcel>& resources, bool* _aidl_return) { |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 593 | std::string clientName = clientInfo.name; |
| 594 | String8 log = String8::format("reclaimResource(callingPid %d, uid %d resources %s)", |
Girish | 88a8350 | 2023-11-23 11:23:07 +0000 | [diff] [blame] | 595 | clientInfo.pid, clientInfo.uid, getString(resources).c_str()); |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 596 | mServiceLog->add(log); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 597 | *_aidl_return = false; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 598 | |
Girish | 0ac5c21 | 2023-11-23 09:14:03 +0000 | [diff] [blame] | 599 | // Check if there are any resources to be reclaimed before processing. |
| 600 | if (resources.empty()) { |
Girish | e7b338f | 2024-02-08 22:03:51 +0000 | [diff] [blame] | 601 | // Invalid reclaim request. So no need to log. |
Girish | 0ac5c21 | 2023-11-23 09:14:03 +0000 | [diff] [blame] | 602 | return Status::ok(); |
| 603 | } |
| 604 | |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 605 | std::vector<ClientInfo> targetClients; |
Girish | e7b338f | 2024-02-08 22:03:51 +0000 | [diff] [blame] | 606 | if (getTargetClients(clientInfo, resources, targetClients)) { |
| 607 | // Reclaim all the target clients. |
| 608 | *_aidl_return = reclaimUnconditionallyFrom(targetClients); |
| 609 | } else { |
| 610 | // No clients to reclaim from. |
Girish | 0ac5c21 | 2023-11-23 09:14:03 +0000 | [diff] [blame] | 611 | ALOGI("%s: There aren't any clients to reclaim from", __func__); |
Girish | e7b338f | 2024-02-08 22:03:51 +0000 | [diff] [blame] | 612 | // We need to log this failed reclaim as "no clients to reclaim from". |
| 613 | targetClients.clear(); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 616 | // Log Reclaim Pushed Atom to statsd |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 617 | pushReclaimAtom(clientInfo, targetClients, *_aidl_return); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 618 | |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 619 | return Status::ok(); |
| 620 | } |
| 621 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 622 | void ResourceManagerService::pushReclaimAtom(const ClientInfoParcel& clientInfo, |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 623 | const std::vector<ClientInfo>& targetClients, |
| 624 | bool reclaimed) { |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 625 | int32_t callingPid = clientInfo.pid; |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 626 | int requesterPriority = -1; |
| 627 | getPriority_l(callingPid, &requesterPriority); |
Girish | 1f002cf | 2023-02-17 00:36:29 +0000 | [diff] [blame] | 628 | std::vector<int> priorities; |
| 629 | priorities.push_back(requesterPriority); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 630 | |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 631 | for (const ClientInfo& targetClient : targetClients) { |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 632 | int targetPriority = -1; |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 633 | getPriority_l(targetClient.mPid, &targetPriority); |
Girish | 1f002cf | 2023-02-17 00:36:29 +0000 | [diff] [blame] | 634 | priorities.push_back(targetPriority); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 635 | } |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 636 | mResourceManagerMetrics->pushReclaimAtom(clientInfo, priorities, targetClients, reclaimed); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Girish | e830527 | 2023-12-18 19:17:58 +0000 | [diff] [blame] | 639 | std::shared_ptr<IResourceManagerClient> ResourceManagerService::getClient_l( |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 640 | int pid, const int64_t& clientId) const { |
| 641 | std::map<int, ResourceInfos>::const_iterator found = mMap.find(pid); |
| 642 | if (found == mMap.end()) { |
| 643 | ALOGV("%s: didn't find pid %d for clientId %lld", __func__, pid, (long long) clientId); |
| 644 | return nullptr; |
| 645 | } |
| 646 | |
| 647 | const ResourceInfos& infos = found->second; |
| 648 | ResourceInfos::const_iterator foundClient = infos.find(clientId); |
| 649 | if (foundClient == infos.end()) { |
| 650 | ALOGV("%s: didn't find clientId %lld", __func__, (long long) clientId); |
| 651 | return nullptr; |
| 652 | } |
| 653 | |
| 654 | return foundClient->second.client; |
| 655 | } |
| 656 | |
Girish | e830527 | 2023-12-18 19:17:58 +0000 | [diff] [blame] | 657 | bool ResourceManagerService::removeClient_l(int pid, const int64_t& clientId) { |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 658 | std::map<int, ResourceInfos>::iterator found = mMap.find(pid); |
| 659 | if (found == mMap.end()) { |
| 660 | ALOGV("%s: didn't find pid %d for clientId %lld", __func__, pid, (long long) clientId); |
| 661 | return false; |
| 662 | } |
| 663 | |
| 664 | ResourceInfos& infos = found->second; |
| 665 | ResourceInfos::iterator foundClient = infos.find(clientId); |
| 666 | if (foundClient == infos.end()) { |
| 667 | ALOGV("%s: didn't find clientId %lld", __func__, (long long) clientId); |
| 668 | return false; |
| 669 | } |
| 670 | |
| 671 | infos.erase(foundClient); |
| 672 | return true; |
| 673 | } |
| 674 | |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 675 | bool ResourceManagerService::reclaimUnconditionallyFrom( |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 676 | const std::vector<ClientInfo>& targetClients) { |
| 677 | if (targetClients.size() == 0) { |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 678 | return false; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 681 | int64_t failedClientId = -1; |
| 682 | int32_t failedClientPid = -1; |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 683 | for (const ClientInfo& targetClient : targetClients) { |
Girish | e830527 | 2023-12-18 19:17:58 +0000 | [diff] [blame] | 684 | std::shared_ptr<IResourceManagerClient> client = nullptr; |
| 685 | { |
| 686 | std::scoped_lock lock{mLock}; |
| 687 | client = getClient_l(targetClient.mPid, targetClient.mClientId); |
| 688 | } |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 689 | if (client == nullptr) { |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 690 | // skip already released clients. |
| 691 | continue; |
| 692 | } |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 693 | String8 log = String8::format("reclaimResource from client %p", client.get()); |
Ronghua Wu | a8ec8fc | 2015-05-07 13:58:22 -0700 | [diff] [blame] | 694 | mServiceLog->add(log); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 695 | bool success; |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 696 | Status status = client->reclaimResource(&success); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 697 | if (!status.isOk() || !success) { |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 698 | failedClientId = targetClient.mClientId; |
| 699 | failedClientPid = targetClient.mPid; |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 700 | break; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 701 | } |
| 702 | } |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 703 | |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 704 | if (failedClientId == -1) { |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 705 | return true; |
Ronghua Wu | 76d4c7f | 2015-10-23 15:01:53 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 708 | { |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 709 | std::scoped_lock lock{mLock}; |
Girish | e830527 | 2023-12-18 19:17:58 +0000 | [diff] [blame] | 710 | bool found = removeClient_l(failedClientPid, failedClientId); |
Brian Lindahl | 9f626cf | 2022-04-25 13:29:59 +0200 | [diff] [blame] | 711 | if (found) { |
| 712 | ALOGW("Failed to reclaim resources from client with pid %d", failedClientPid); |
| 713 | } else { |
| 714 | ALOGW("Failed to reclaim resources from unlocateable client"); |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 718 | return false; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 721 | bool ResourceManagerService::overridePid_l(int32_t originalPid, int32_t newPid) { |
| 722 | mOverridePidMap.erase(originalPid); |
| 723 | if (newPid != -1) { |
| 724 | mOverridePidMap.emplace(originalPid, newPid); |
| 725 | return true; |
| 726 | } |
| 727 | |
| 728 | return false; |
| 729 | } |
| 730 | |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 731 | Status ResourceManagerService::overridePid(int originalPid, int newPid) { |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 732 | String8 log = String8::format("overridePid(originalPid %d, newPid %d)", |
| 733 | originalPid, newPid); |
| 734 | mServiceLog->add(log); |
| 735 | |
| 736 | // allow if this is called from the same process or the process has |
| 737 | // permission. |
| 738 | if ((AIBinder_getCallingPid() != getpid()) && |
| 739 | (checkCallingPermission(String16( |
| 740 | "android.permission.MEDIA_RESOURCE_OVERRIDE_PID")) == false)) { |
| 741 | ALOGE( |
| 742 | "Permission Denial: can't access overridePid method from pid=%d, " |
| 743 | "self pid=%d\n", |
| 744 | AIBinder_getCallingPid(), getpid()); |
| 745 | return Status::fromServiceSpecificError(PERMISSION_DENIED); |
| 746 | } |
| 747 | |
| 748 | { |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 749 | std::scoped_lock lock{mLock}; |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 750 | if (overridePid_l(originalPid, newPid)) { |
Girish | 1f002cf | 2023-02-17 00:36:29 +0000 | [diff] [blame] | 751 | mResourceManagerMetrics->addPid(newPid); |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | |
| 755 | return Status::ok(); |
| 756 | } |
| 757 | |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 758 | bool ResourceManagerService::overrideProcessInfo_l( |
| 759 | const std::shared_ptr<IResourceManagerClient>& client, |
| 760 | int pid, |
| 761 | int procState, |
| 762 | int oomScore) { |
| 763 | removeProcessInfoOverride_l(pid); |
| 764 | |
| 765 | if (!mProcessInfo->overrideProcessInfo(pid, procState, oomScore)) { |
| 766 | // Override value is rejected by ProcessInfo. |
| 767 | return false; |
| 768 | } |
| 769 | |
| 770 | ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(pid), |
| 771 | .uid = 0, |
| 772 | .id = 0, |
| 773 | .name = "<unknown client>"}; |
| 774 | auto deathNotifier = DeathNotifier::Create( |
| 775 | client, ref<ResourceManagerService>(), clientInfo, true); |
| 776 | |
| 777 | mProcessInfoOverrideMap.emplace(pid, ProcessInfoOverride{deathNotifier, client}); |
| 778 | return true; |
| 779 | } |
| 780 | |
Chong Zhang | 97d367b | 2020-09-16 12:53:14 -0700 | [diff] [blame] | 781 | Status ResourceManagerService::overrideProcessInfo( |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 782 | const std::shared_ptr<IResourceManagerClient>& client, int pid, int procState, |
Chong Zhang | 97d367b | 2020-09-16 12:53:14 -0700 | [diff] [blame] | 783 | int oomScore) { |
| 784 | String8 log = String8::format("overrideProcessInfo(pid %d, procState %d, oomScore %d)", |
| 785 | pid, procState, oomScore); |
| 786 | mServiceLog->add(log); |
| 787 | |
| 788 | // Only allow the override if the caller already can access process state and oom scores. |
| 789 | int callingPid = AIBinder_getCallingPid(); |
| 790 | if (callingPid != getpid() && (callingPid != pid || !checkCallingPermission(String16( |
| 791 | "android.permission.GET_PROCESS_STATE_AND_OOM_SCORE")))) { |
| 792 | ALOGE("Permission Denial: overrideProcessInfo method from pid=%d", callingPid); |
| 793 | return Status::fromServiceSpecificError(PERMISSION_DENIED); |
| 794 | } |
| 795 | |
| 796 | if (client == nullptr) { |
| 797 | return Status::fromServiceSpecificError(BAD_VALUE); |
| 798 | } |
| 799 | |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 800 | std::scoped_lock lock{mLock}; |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 801 | if (!overrideProcessInfo_l(client, pid, procState, oomScore)) { |
Chong Zhang | 97d367b | 2020-09-16 12:53:14 -0700 | [diff] [blame] | 802 | // Override value is rejected by ProcessInfo. |
| 803 | return Status::fromServiceSpecificError(BAD_VALUE); |
| 804 | } |
Chong Zhang | 97d367b | 2020-09-16 12:53:14 -0700 | [diff] [blame] | 805 | return Status::ok(); |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 806 | |
Chong Zhang | 97d367b | 2020-09-16 12:53:14 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Chong Zhang | 97d367b | 2020-09-16 12:53:14 -0700 | [diff] [blame] | 809 | void ResourceManagerService::removeProcessInfoOverride(int pid) { |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 810 | std::scoped_lock lock{mLock}; |
Chong Zhang | 97d367b | 2020-09-16 12:53:14 -0700 | [diff] [blame] | 811 | |
| 812 | removeProcessInfoOverride_l(pid); |
| 813 | } |
| 814 | |
| 815 | void ResourceManagerService::removeProcessInfoOverride_l(int pid) { |
| 816 | auto it = mProcessInfoOverrideMap.find(pid); |
| 817 | if (it == mProcessInfoOverrideMap.end()) { |
| 818 | return; |
| 819 | } |
| 820 | |
| 821 | mProcessInfo->removeProcessInfoOverride(pid); |
Chong Zhang | 97d367b | 2020-09-16 12:53:14 -0700 | [diff] [blame] | 822 | mProcessInfoOverrideMap.erase(pid); |
| 823 | } |
| 824 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 825 | Status ResourceManagerService::markClientForPendingRemoval(const ClientInfoParcel& clientInfo) { |
| 826 | int32_t pid = clientInfo.pid; |
| 827 | int64_t clientId = clientInfo.id; |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 828 | String8 log = String8::format( |
| 829 | "markClientForPendingRemoval(pid %d, clientId %lld)", |
| 830 | pid, (long long) clientId); |
| 831 | mServiceLog->add(log); |
| 832 | |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 833 | std::scoped_lock lock{mLock}; |
Brian Lindahl | cf3bafb | 2022-01-27 14:21:38 +0100 | [diff] [blame] | 834 | if (!mProcessInfo->isPidTrusted(pid)) { |
Chong Zhang | c7303e8 | 2020-12-02 16:38:52 -0800 | [diff] [blame] | 835 | pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
| 836 | ALOGW("%s called with untrusted pid %d, using calling pid %d", __FUNCTION__, |
| 837 | pid, callingPid); |
| 838 | pid = callingPid; |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 839 | } |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 840 | PidResourceInfosMap::iterator found = mMap.find(pid); |
| 841 | if (found == mMap.end()) { |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 842 | ALOGV("markClientForPendingRemoval: didn't find pid %d for clientId %lld", |
| 843 | pid, (long long)clientId); |
| 844 | return Status::ok(); |
| 845 | } |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 846 | ResourceInfos& infos = found->second; |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 847 | |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 848 | ResourceInfos::iterator foundClient = infos.find(clientId); |
| 849 | if (foundClient == infos.end()) { |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 850 | ALOGV("markClientForPendingRemoval: didn't find clientId %lld", (long long) clientId); |
| 851 | return Status::ok(); |
| 852 | } |
| 853 | |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 854 | ResourceInfo& info = foundClient->second; |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 855 | info.pendingRemoval = true; |
| 856 | return Status::ok(); |
| 857 | } |
| 858 | |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 859 | Status ResourceManagerService::reclaimResourcesFromClientsPendingRemoval(int32_t pid) { |
| 860 | String8 log = String8::format("reclaimResourcesFromClientsPendingRemoval(pid %d)", pid); |
| 861 | mServiceLog->add(log); |
| 862 | |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 863 | std::vector<ClientInfo> targetClients; |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 864 | { |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 865 | std::scoped_lock lock{mLock}; |
Brian Lindahl | cf3bafb | 2022-01-27 14:21:38 +0100 | [diff] [blame] | 866 | if (!mProcessInfo->isPidTrusted(pid)) { |
Chong Zhang | c7303e8 | 2020-12-02 16:38:52 -0800 | [diff] [blame] | 867 | pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
| 868 | ALOGW("%s called with untrusted pid %d, using calling pid %d", __FUNCTION__, |
| 869 | pid, callingPid); |
| 870 | pid = callingPid; |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | for (MediaResource::Type type : {MediaResource::Type::kSecureCodec, |
| 874 | MediaResource::Type::kNonSecureCodec, |
| 875 | MediaResource::Type::kGraphicMemory, |
| 876 | MediaResource::Type::kDrmSession}) { |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 877 | switch (type) { |
| 878 | // Codec resources are segregated by audio, video and image domains. |
| 879 | case MediaResource::Type::kSecureCodec: |
| 880 | case MediaResource::Type::kNonSecureCodec: |
Girish | a5a2d67 | 2023-09-20 18:40:20 +0000 | [diff] [blame] | 881 | for (MediaResource::SubType subType : {MediaResource::SubType::kHwAudioCodec, |
| 882 | MediaResource::SubType::kSwAudioCodec, |
| 883 | MediaResource::SubType::kHwVideoCodec, |
| 884 | MediaResource::SubType::kSwVideoCodec, |
| 885 | MediaResource::SubType::kHwImageCodec, |
| 886 | MediaResource::SubType::kSwImageCodec}) { |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 887 | ClientInfo clientInfo; |
| 888 | if (getBiggestClientPendingRemoval_l(pid, type, subType, clientInfo)) { |
| 889 | targetClients.emplace_back(clientInfo); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 890 | continue; |
| 891 | } |
| 892 | } |
| 893 | break; |
| 894 | // Non-codec resources are shared by audio, video and image codecs (no subtype). |
| 895 | default: |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 896 | ClientInfo clientInfo; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 897 | if (getBiggestClientPendingRemoval_l(pid, type, |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 898 | MediaResource::SubType::kUnspecifiedSubType, clientInfo)) { |
| 899 | targetClients.emplace_back(clientInfo); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 900 | } |
| 901 | break; |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | } |
| 905 | |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 906 | if (!targetClients.empty()) { |
| 907 | reclaimUnconditionallyFrom(targetClients); |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 908 | } |
| 909 | return Status::ok(); |
| 910 | } |
| 911 | |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 912 | bool ResourceManagerService::getPriority_l(int pid, int* priority) const { |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 913 | int newPid = pid; |
| 914 | |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 915 | std::map<int, int>::const_iterator found = mOverridePidMap.find(pid); |
| 916 | if (found != mOverridePidMap.end()) { |
| 917 | newPid = found->second; |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 918 | ALOGD("getPriority_l: use override pid %d instead original pid %d", |
| 919 | newPid, pid); |
| 920 | } |
| 921 | |
| 922 | return mProcessInfo->getPriority(newPid, priority); |
| 923 | } |
| 924 | |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 925 | bool ResourceManagerService::getAllClients_l( |
| 926 | const ResourceRequestInfo& resourceRequestInfo, |
| 927 | std::vector<ClientInfo>& clientsInfo) { |
| 928 | MediaResource::Type type = resourceRequestInfo.mResource->type; |
| 929 | MediaResource::SubType subType = resourceRequestInfo.mResource->subType; |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 930 | |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 931 | for (auto& [pid, infos] : mMap) { |
| 932 | for (const auto& [id, info] : infos) { |
Girish | 1c68240 | 2024-01-31 21:03:51 +0000 | [diff] [blame] | 933 | if (pid == resourceRequestInfo.mCallingPid && id == resourceRequestInfo.mClientId) { |
| 934 | ALOGI("%s: Skip the client[%jd] for which the resource request is made", |
| 935 | __func__, id); |
| 936 | continue; |
| 937 | } |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 938 | if (hasResourceType(type, subType, info.resources)) { |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 939 | if (!isCallingPriorityHigher_l(resourceRequestInfo.mCallingPid, pid)) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 940 | // some higher/equal priority process owns the resource, |
| 941 | // this request can't be fulfilled. |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 942 | ALOGE("%s: can't reclaim resource %s from pid %d", |
| 943 | __func__, asString(type), pid); |
| 944 | clientsInfo.clear(); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 945 | return false; |
| 946 | } |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 947 | clientsInfo.emplace_back(pid, info.uid, info.clientId); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 948 | } |
| 949 | } |
| 950 | } |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 951 | if (clientsInfo.size() == 0) { |
| 952 | ALOGV("%s: didn't find any resource %s", __func__, asString(type)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 953 | } |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 954 | return true; |
| 955 | } |
| 956 | |
Girish | aff0ef2 | 2023-10-13 00:22:39 +0000 | [diff] [blame] | 957 | // Process priority (oom score) based reclaim: |
| 958 | // - Find a process with lowest priority (than that of calling process). |
| 959 | // - Find the bigegst client (with required resources) from that process. |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 960 | bool ResourceManagerService::getLowestPriorityBiggestClient_l( |
| 961 | const ResourceRequestInfo& resourceRequestInfo, |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 962 | ClientInfo& clientInfo) { |
Girish | 56fda31 | 2023-10-12 21:32:35 +0000 | [diff] [blame] | 963 | int callingPid = resourceRequestInfo.mCallingPid; |
| 964 | MediaResource::Type type = resourceRequestInfo.mResource->type; |
| 965 | MediaResource::SubType subType = resourceRequestInfo.mResource->subType; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 966 | int lowestPriorityPid; |
| 967 | int lowestPriority; |
| 968 | int callingPriority; |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 969 | |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 970 | if (!getPriority_l(callingPid, &callingPriority)) { |
Girish | aff0ef2 | 2023-10-13 00:22:39 +0000 | [diff] [blame] | 971 | ALOGE("%s: can't get process priority for pid %d", __func__, callingPid); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 972 | return false; |
| 973 | } |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 974 | if (!getLowestPriorityPid_l(type, subType, &lowestPriorityPid, &lowestPriority)) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 975 | return false; |
| 976 | } |
| 977 | if (lowestPriority <= callingPriority) { |
Girish | aff0ef2 | 2023-10-13 00:22:39 +0000 | [diff] [blame] | 978 | ALOGE("%s: lowest priority %d vs caller priority %d", |
| 979 | __func__, lowestPriority, callingPriority); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 980 | return false; |
| 981 | } |
| 982 | |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 983 | if (!getBiggestClient_l(lowestPriorityPid, type, subType, clientInfo)) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 984 | return false; |
| 985 | } |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 986 | |
Girish | aff0ef2 | 2023-10-13 00:22:39 +0000 | [diff] [blame] | 987 | ALOGI("%s: CallingProcess(%d:%d) will reclaim from the lowestPriorityProcess(%d:%d)", |
| 988 | __func__, callingPid, callingPriority, lowestPriorityPid, lowestPriority); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 989 | return true; |
| 990 | } |
| 991 | |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 992 | bool ResourceManagerService::getLowestPriorityPid_l(MediaResource::Type type, |
| 993 | MediaResource::SubType subType, int *lowestPriorityPid, int *lowestPriority) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 994 | int pid = -1; |
| 995 | int priority = -1; |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 996 | for (auto& [tempPid, infos] : mMap) { |
| 997 | if (infos.size() == 0) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 998 | // no client on this process. |
| 999 | continue; |
| 1000 | } |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 1001 | if (!hasResourceType(type, subType, infos)) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1002 | // doesn't have the requested resource type |
| 1003 | continue; |
| 1004 | } |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 1005 | int tempPriority = -1; |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 1006 | if (!getPriority_l(tempPid, &tempPriority)) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1007 | ALOGV("getLowestPriorityPid_l: can't get priority of pid %d, skipped", tempPid); |
| 1008 | // TODO: remove this pid from mMap? |
| 1009 | continue; |
| 1010 | } |
| 1011 | if (pid == -1 || tempPriority > priority) { |
| 1012 | // initial the value |
| 1013 | pid = tempPid; |
| 1014 | priority = tempPriority; |
| 1015 | } |
| 1016 | } |
| 1017 | if (pid != -1) { |
| 1018 | *lowestPriorityPid = pid; |
| 1019 | *lowestPriority = priority; |
| 1020 | } |
| 1021 | return (pid != -1); |
| 1022 | } |
| 1023 | |
| 1024 | bool ResourceManagerService::isCallingPriorityHigher_l(int callingPid, int pid) { |
| 1025 | int callingPidPriority; |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 1026 | if (!getPriority_l(callingPid, &callingPidPriority)) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1027 | return false; |
| 1028 | } |
| 1029 | |
| 1030 | int priority; |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 1031 | if (!getPriority_l(pid, &priority)) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1032 | return false; |
| 1033 | } |
| 1034 | |
| 1035 | return (callingPidPriority < priority); |
| 1036 | } |
| 1037 | |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1038 | bool ResourceManagerService::getBiggestClientPendingRemoval_l(int pid, MediaResource::Type type, |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 1039 | MediaResource::SubType subType, ClientInfo& clientInfo) { |
| 1040 | return getBiggestClient_l(pid, type, subType, clientInfo, true /* pendingRemovalOnly */); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | bool ResourceManagerService::getBiggestClient_l(int pid, MediaResource::Type type, |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 1044 | MediaResource::SubType subType, ClientInfo& clientInfo, bool pendingRemovalOnly) { |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 1045 | PidResourceInfosMap::iterator found = mMap.find(pid); |
| 1046 | if (found == mMap.end()) { |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 1047 | ALOGE_IF(!pendingRemovalOnly, |
| 1048 | "getBiggestClient_l: can't find resource info for pid %d", pid); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1049 | return false; |
| 1050 | } |
| 1051 | |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 1052 | uid_t uid = -1; |
| 1053 | int64_t clientId = -1; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1054 | uint64_t largestValue = 0; |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 1055 | const ResourceInfos& infos = found->second; |
| 1056 | for (const auto& [id, info] : infos) { |
| 1057 | const ResourceList& resources = info.resources; |
| 1058 | if (pendingRemovalOnly && !info.pendingRemoval) { |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 1059 | continue; |
| 1060 | } |
Girish | d11a03a | 2023-11-30 21:17:51 +0000 | [diff] [blame] | 1061 | for (const MediaResourceParcel& resource : resources.getResources()) { |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1062 | if (hasResourceType(type, subType, resource)) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 1063 | if (resource.value > largestValue) { |
| 1064 | largestValue = resource.value; |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 1065 | clientId = info.clientId; |
Girish | 434b4d8 | 2023-07-11 23:24:54 +0000 | [diff] [blame] | 1066 | uid = info.uid; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 1072 | if (clientId == -1) { |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 1073 | ALOGE_IF(!pendingRemovalOnly, |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1074 | "getBiggestClient_l: can't find resource type %s and subtype %s for pid %d", |
| 1075 | asString(type), asString(subType), pid); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1076 | return false; |
| 1077 | } |
| 1078 | |
Girish | ab17b0f | 2023-11-20 06:00:44 +0000 | [diff] [blame] | 1079 | clientInfo.mPid = pid; |
| 1080 | clientInfo.mUid = uid; |
| 1081 | clientInfo.mClientId = clientId; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1082 | return true; |
| 1083 | } |
| 1084 | |
Girish | 1f002cf | 2023-02-17 00:36:29 +0000 | [diff] [blame] | 1085 | Status ResourceManagerService::notifyClientCreated(const ClientInfoParcel& clientInfo) { |
| 1086 | mResourceManagerMetrics->notifyClientCreated(clientInfo); |
| 1087 | return Status::ok(); |
| 1088 | } |
| 1089 | |
| 1090 | Status ResourceManagerService::notifyClientStarted(const ClientConfigParcel& clientConfig) { |
| 1091 | mResourceManagerMetrics->notifyClientStarted(clientConfig); |
| 1092 | return Status::ok(); |
| 1093 | } |
| 1094 | |
| 1095 | Status ResourceManagerService::notifyClientStopped(const ClientConfigParcel& clientConfig) { |
| 1096 | mResourceManagerMetrics->notifyClientStopped(clientConfig); |
| 1097 | return Status::ok(); |
| 1098 | } |
| 1099 | |
Girish | de8eb59 | 2023-04-13 18:49:17 +0000 | [diff] [blame] | 1100 | Status ResourceManagerService::notifyClientConfigChanged(const ClientConfigParcel& clientConfig) { |
| 1101 | mResourceManagerMetrics->notifyClientConfigChanged(clientConfig); |
| 1102 | return Status::ok(); |
| 1103 | } |
| 1104 | |
Girish | 1f002cf | 2023-02-17 00:36:29 +0000 | [diff] [blame] | 1105 | long ResourceManagerService::getPeakConcurrentPixelCount(int pid) const { |
| 1106 | return mResourceManagerMetrics->getPeakConcurrentPixelCount(pid); |
| 1107 | } |
| 1108 | |
| 1109 | long ResourceManagerService::getCurrentConcurrentPixelCount(int pid) const { |
| 1110 | return mResourceManagerMetrics->getCurrentConcurrentPixelCount(pid); |
| 1111 | } |
| 1112 | |
Girish | 6a6044d | 2023-11-22 21:23:14 +0000 | [diff] [blame] | 1113 | void ResourceManagerService::notifyClientReleased(const ClientInfoParcel& clientInfo) { |
| 1114 | mResourceManagerMetrics->notifyClientReleased(clientInfo); |
| 1115 | } |
| 1116 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1117 | } // namespace android |