diff options
author | Ronghua Wu <ronghuawu@google.com> | 2015-07-15 12:23:48 -0700 |
---|---|---|
committer | Ronghua Wu <ronghuawu@google.com> | 2015-07-17 10:19:21 -0700 |
commit | 37c8924c508a7c9b8bd3c8ce80fc005070531902 (patch) | |
tree | 0ed47e0ceb97bcdf6169e1189f0f555b6c2bd89c /services/mediaresourcemanager | |
parent | 495151d3f4c5f92f1d162efb32b636521c105df5 (diff) | |
download | frameworks_av-37c8924c508a7c9b8bd3c8ce80fc005070531902.zip frameworks_av-37c8924c508a7c9b8bd3c8ce80fc005070531902.tar.gz frameworks_av-37c8924c508a7c9b8bd3c8ce80fc005070531902.tar.bz2 |
mediaresourcemanager: add pid to removeResource method
Bug: 22496209
Change-Id: I73311573e8d1ac15fec668a9ef6e6af7a07a1d30
Diffstat (limited to 'services/mediaresourcemanager')
3 files changed, 33 insertions, 27 deletions
diff --git a/services/mediaresourcemanager/ResourceManagerService.cpp b/services/mediaresourcemanager/ResourceManagerService.cpp index 61147ff..e54cc5a 100644 --- a/services/mediaresourcemanager/ResourceManagerService.cpp +++ b/services/mediaresourcemanager/ResourceManagerService.cpp @@ -179,23 +179,24 @@ void ResourceManagerService::addResource( info.resources.appendVector(resources); } -void ResourceManagerService::removeResource(int64_t clientId) { - String8 log = String8::format("removeResource(%lld)", (long long) clientId); +void ResourceManagerService::removeResource(int pid, int64_t clientId) { + String8 log = String8::format( + "removeResource(pid %d, clientId %lld)", + pid, (long long) clientId); mServiceLog->add(log); Mutex::Autolock lock(mLock); + ssize_t index = mMap.indexOfKey(pid); + if (index < 0) { + ALOGV("removeResource: didn't find pid %d for clientId %lld", pid, (long long) clientId); + return; + } bool found = false; - for (size_t i = 0; i < mMap.size(); ++i) { - ResourceInfos &infos = mMap.editValueAt(i); - for (size_t j = 0; j < infos.size();) { - if (infos[j].clientId == clientId) { - j = infos.removeAt(j); - found = true; - } else { - ++j; - } - } - if (found) { + ResourceInfos &infos = mMap.editValueAt(index); + for (size_t j = 0; j < infos.size(); ++j) { + if (infos[j].clientId == clientId) { + j = infos.removeAt(j); + found = true; break; } } diff --git a/services/mediaresourcemanager/ResourceManagerService.h b/services/mediaresourcemanager/ResourceManagerService.h index ca218fc..4769373 100644 --- a/services/mediaresourcemanager/ResourceManagerService.h +++ b/services/mediaresourcemanager/ResourceManagerService.h @@ -63,7 +63,7 @@ public: const sp<IResourceManagerClient> client, const Vector<MediaResource> &resources); - virtual void removeResource(int64_t clientId); + virtual void removeResource(int pid, int64_t clientId); // Tries to reclaim resource from processes with lower priority than the calling process // according to the requested resources. diff --git a/services/mediaresourcemanager/test/ResourceManagerService_test.cpp b/services/mediaresourcemanager/test/ResourceManagerService_test.cpp index 8ae6a55..df49ddc 100644 --- a/services/mediaresourcemanager/test/ResourceManagerService_test.cpp +++ b/services/mediaresourcemanager/test/ResourceManagerService_test.cpp @@ -29,6 +29,10 @@ namespace android { +static int64_t getId(sp<IResourceManagerClient> client) { + return (int64_t) client.get(); +} + struct TestProcessInfo : public ProcessInfoInterface { TestProcessInfo() {} virtual ~TestProcessInfo() {} @@ -45,12 +49,12 @@ private: }; struct TestClient : public BnResourceManagerClient { - TestClient(sp<ResourceManagerService> service) - : mReclaimed(false), mService(service) {} + TestClient(int pid, sp<ResourceManagerService> service) + : mReclaimed(false), mPid(pid), mService(service) {} virtual bool reclaimResource() { sp<IResourceManagerClient> client(this); - mService->removeResource((int64_t) client.get()); + mService->removeResource(mPid, (int64_t) client.get()); mReclaimed = true; return true; } @@ -72,6 +76,7 @@ protected: private: bool mReclaimed; + int mPid; sp<ResourceManagerService> mService; DISALLOW_EVIL_CONSTRUCTORS(TestClient); }; @@ -87,9 +92,9 @@ class ResourceManagerServiceTest : public ::testing::Test { public: ResourceManagerServiceTest() : mService(new ResourceManagerService(new TestProcessInfo)), - mTestClient1(new TestClient(mService)), - mTestClient2(new TestClient(mService)), - mTestClient3(new TestClient(mService)) { + mTestClient1(new TestClient(kTestPid1, mService)), + mTestClient2(new TestClient(kTestPid2, mService)), + mTestClient3(new TestClient(kTestPid2, mService)) { } protected: @@ -144,24 +149,24 @@ protected: // kTestPid1 mTestClient1 Vector<MediaResource> resources1; resources1.push_back(MediaResource(String8(kResourceSecureCodec), 1)); - mService->addResource(kTestPid1, (int64_t) mTestClient1.get(), mTestClient1, resources1); + mService->addResource(kTestPid1, getId(mTestClient1), mTestClient1, resources1); resources1.push_back(MediaResource(String8(kResourceGraphicMemory), 200)); Vector<MediaResource> resources11; resources11.push_back(MediaResource(String8(kResourceGraphicMemory), 200)); - mService->addResource(kTestPid1, (int64_t) mTestClient1.get(), mTestClient1, resources11); + mService->addResource(kTestPid1, getId(mTestClient1), mTestClient1, resources11); // kTestPid2 mTestClient2 Vector<MediaResource> resources2; resources2.push_back(MediaResource(String8(kResourceNonSecureCodec), 1)); resources2.push_back(MediaResource(String8(kResourceGraphicMemory), 300)); - mService->addResource(kTestPid2, (int64_t) mTestClient2.get(), mTestClient2, resources2); + mService->addResource(kTestPid2, getId(mTestClient2), mTestClient2, resources2); // kTestPid2 mTestClient3 Vector<MediaResource> resources3; - mService->addResource(kTestPid2, (int64_t) mTestClient3.get(), mTestClient3, resources3); + mService->addResource(kTestPid2, getId(mTestClient3), mTestClient3, resources3); resources3.push_back(MediaResource(String8(kResourceSecureCodec), 1)); resources3.push_back(MediaResource(String8(kResourceGraphicMemory), 100)); - mService->addResource(kTestPid2, (int64_t) mTestClient3.get(), mTestClient3, resources3); + mService->addResource(kTestPid2, getId(mTestClient3), mTestClient3, resources3); const PidResourceInfosMap &map = mService->mMap; EXPECT_EQ(2u, map.size()); @@ -213,7 +218,7 @@ protected: void testRemoveResource() { addResource(); - mService->removeResource((int64_t) mTestClient2.get()); + mService->removeResource(kTestPid2, getId(mTestClient2)); const PidResourceInfosMap &map = mService->mMap; EXPECT_EQ(2u, map.size()); @@ -431,7 +436,7 @@ protected: verifyClients(true /* c1 */, false /* c2 */, false /* c3 */); // clean up client 3 which still left - mService->removeResource((int64_t) mTestClient3.get()); + mService->removeResource(kTestPid2, getId(mTestClient3)); } } |