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