media: changed resource type from String8 to enum.
Bug: 27338692
Change-Id: I0161de084682e2317cba81dc5f55c17d5d478570
diff --git a/services/mediaresourcemanager/ResourceManagerService.cpp b/services/mediaresourcemanager/ResourceManagerService.cpp
index 3d4e0b5..e1235b8 100644
--- a/services/mediaresourcemanager/ResourceManagerService.cpp
+++ b/services/mediaresourcemanager/ResourceManagerService.cpp
@@ -43,7 +43,7 @@
return itemsStr;
}
-static bool hasResourceType(String8 type, Vector<MediaResource> resources) {
+static bool hasResourceType(MediaResource::Type type, Vector<MediaResource> resources) {
for (size_t i = 0; i < resources.size(); ++i) {
if (resources[i].mType == type) {
return true;
@@ -52,7 +52,7 @@
return false;
}
-static bool hasResourceType(String8 type, ResourceInfos infos) {
+static bool hasResourceType(MediaResource::Type type, ResourceInfos infos) {
for (size_t i = 0; i < infos.size(); ++i) {
if (hasResourceType(type, infos[i].resources)) {
return true;
@@ -96,8 +96,8 @@
if (binder != NULL) {
sp<IMediaResourceMonitor> service = interface_cast<IMediaResourceMonitor>(binder);
for (size_t i = 0; i < resources.size(); ++i) {
- service->notifyResourceGranted(pid, String16(resources[i].mType),
- String16(resources[i].mSubType), resources[i].mValue);
+ service->notifyResourceGranted(pid, String16(asString(resources[i].mType)),
+ String16(asString(resources[i].mSubType)), resources[i].mValue);
}
}
}
@@ -275,12 +275,12 @@
const MediaResource *nonSecureCodec = NULL;
const MediaResource *graphicMemory = NULL;
for (size_t i = 0; i < resources.size(); ++i) {
- String8 type = resources[i].mType;
- if (resources[i].mType == kResourceSecureCodec) {
+ MediaResource::Type type = resources[i].mType;
+ if (resources[i].mType == MediaResource::kSecureCodec) {
secureCodec = &resources[i];
- } else if (type == kResourceNonSecureCodec) {
+ } else if (type == MediaResource::kNonSecureCodec) {
nonSecureCodec = &resources[i];
- } else if (type == kResourceGraphicMemory) {
+ } else if (type == MediaResource::kGraphicMemory) {
graphicMemory = &resources[i];
}
}
@@ -288,19 +288,19 @@
// first pass to handle secure/non-secure codec conflict
if (secureCodec != NULL) {
if (!mSupportsMultipleSecureCodecs) {
- if (!getAllClients_l(callingPid, String8(kResourceSecureCodec), &clients)) {
+ if (!getAllClients_l(callingPid, MediaResource::kSecureCodec, &clients)) {
return false;
}
}
if (!mSupportsSecureWithNonSecureCodec) {
- if (!getAllClients_l(callingPid, String8(kResourceNonSecureCodec), &clients)) {
+ if (!getAllClients_l(callingPid, MediaResource::kNonSecureCodec, &clients)) {
return false;
}
}
}
if (nonSecureCodec != NULL) {
if (!mSupportsSecureWithNonSecureCodec) {
- if (!getAllClients_l(callingPid, String8(kResourceSecureCodec), &clients)) {
+ if (!getAllClients_l(callingPid, MediaResource::kSecureCodec, &clients)) {
return false;
}
}
@@ -320,11 +320,11 @@
if (clients.size() == 0) {
// if we are here, run the fourth pass to free one codec with the different type.
if (secureCodec != NULL) {
- MediaResource temp(String8(kResourceNonSecureCodec), 1);
+ MediaResource temp(MediaResource::kNonSecureCodec, 1);
getClientForResource_l(callingPid, &temp, &clients);
}
if (nonSecureCodec != NULL) {
- MediaResource temp(String8(kResourceSecureCodec), 1);
+ MediaResource temp(MediaResource::kSecureCodec, 1);
getClientForResource_l(callingPid, &temp, &clients);
}
}
@@ -374,7 +374,7 @@
}
bool ResourceManagerService::getAllClients_l(
- int callingPid, const String8 &type, Vector<sp<IResourceManagerClient>> *clients) {
+ int callingPid, MediaResource::Type type, Vector<sp<IResourceManagerClient>> *clients) {
Vector<sp<IResourceManagerClient>> temp;
for (size_t i = 0; i < mMap.size(); ++i) {
ResourceInfos &infos = mMap.editValueAt(i);
@@ -384,7 +384,7 @@
// some higher/equal priority process owns the resource,
// this request can't be fulfilled.
ALOGE("getAllClients_l: can't reclaim resource %s from pid %d",
- type.string(), mMap.keyAt(i));
+ asString(type), mMap.keyAt(i));
return false;
}
temp.push_back(infos[j].client);
@@ -392,7 +392,7 @@
}
}
if (temp.size() == 0) {
- ALOGV("getAllClients_l: didn't find any resource %s", type.string());
+ ALOGV("getAllClients_l: didn't find any resource %s", asString(type));
return true;
}
clients->appendVector(temp);
@@ -400,7 +400,7 @@
}
bool ResourceManagerService::getLowestPriorityBiggestClient_l(
- int callingPid, const String8 &type, sp<IResourceManagerClient> *client) {
+ int callingPid, MediaResource::Type type, sp<IResourceManagerClient> *client) {
int lowestPriorityPid;
int lowestPriority;
int callingPriority;
@@ -425,7 +425,7 @@
}
bool ResourceManagerService::getLowestPriorityPid_l(
- const String8 &type, int *lowestPriorityPid, int *lowestPriority) {
+ MediaResource::Type type, int *lowestPriorityPid, int *lowestPriority) {
int pid = -1;
int priority = -1;
for (size_t i = 0; i < mMap.size(); ++i) {
@@ -472,7 +472,7 @@
}
bool ResourceManagerService::getBiggestClient_l(
- int pid, const String8 &type, sp<IResourceManagerClient> *client) {
+ int pid, MediaResource::Type type, sp<IResourceManagerClient> *client) {
ssize_t index = mMap.indexOfKey(pid);
if (index < 0) {
ALOGE("getBiggestClient_l: can't find resource info for pid %d", pid);
@@ -495,7 +495,7 @@
}
if (clientTemp == NULL) {
- ALOGE("getBiggestClient_l: can't find resource type %s for pid %d", type.string(), pid);
+ ALOGE("getBiggestClient_l: can't find resource type %s for pid %d", asString(type), pid);
return false;
}
diff --git a/services/mediaresourcemanager/ResourceManagerService.h b/services/mediaresourcemanager/ResourceManagerService.h
index 4769373..8f6fe9a 100644
--- a/services/mediaresourcemanager/ResourceManagerService.h
+++ b/services/mediaresourcemanager/ResourceManagerService.h
@@ -79,22 +79,22 @@
// Gets the list of all the clients who own the specified resource type.
// Returns false if any client belongs to a process with higher priority than the
// calling process. The clients will remain unchanged if returns false.
- bool getAllClients_l(int callingPid, const String8 &type,
+ bool getAllClients_l(int callingPid, MediaResource::Type type,
Vector<sp<IResourceManagerClient>> *clients);
// Gets the client who owns specified resource type from lowest possible priority process.
// Returns false if the calling process priority is not higher than the lowest process
// priority. The client will remain unchanged if returns false.
- bool getLowestPriorityBiggestClient_l(int callingPid, const String8 &type,
+ bool getLowestPriorityBiggestClient_l(int callingPid, MediaResource::Type type,
sp<IResourceManagerClient> *client);
// Gets lowest priority process that has the specified resource type.
// Returns false if failed. The output parameters will remain unchanged if failed.
- bool getLowestPriorityPid_l(const String8 &type, int *pid, int *priority);
+ bool getLowestPriorityPid_l(MediaResource::Type type, int *pid, int *priority);
// Gets the client who owns biggest piece of specified resource type from pid.
// Returns false if failed. The client will remain unchanged if failed.
- bool getBiggestClient_l(int pid, const String8 &type, sp<IResourceManagerClient> *client);
+ bool getBiggestClient_l(int pid, MediaResource::Type type, sp<IResourceManagerClient> *client);
bool isCallingPriorityHigher_l(int callingPid, int pid);
diff --git a/services/mediaresourcemanager/test/ResourceManagerService_test.cpp b/services/mediaresourcemanager/test/ResourceManagerService_test.cpp
index cffedc6..62b7711 100644
--- a/services/mediaresourcemanager/test/ResourceManagerService_test.cpp
+++ b/services/mediaresourcemanager/test/ResourceManagerService_test.cpp
@@ -152,24 +152,24 @@
void addResource() {
// kTestPid1 mTestClient1
Vector<MediaResource> resources1;
- resources1.push_back(MediaResource(String8(kResourceSecureCodec), 1));
+ resources1.push_back(MediaResource(MediaResource::kSecureCodec, 1));
mService->addResource(kTestPid1, getId(mTestClient1), mTestClient1, resources1);
- resources1.push_back(MediaResource(String8(kResourceGraphicMemory), 200));
+ resources1.push_back(MediaResource(MediaResource::kGraphicMemory, 200));
Vector<MediaResource> resources11;
- resources11.push_back(MediaResource(String8(kResourceGraphicMemory), 200));
+ resources11.push_back(MediaResource(MediaResource::kGraphicMemory, 200));
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));
+ resources2.push_back(MediaResource(MediaResource::kNonSecureCodec, 1));
+ resources2.push_back(MediaResource(MediaResource::kGraphicMemory, 300));
mService->addResource(kTestPid2, getId(mTestClient2), mTestClient2, resources2);
// kTestPid2 mTestClient3
Vector<MediaResource> resources3;
mService->addResource(kTestPid2, getId(mTestClient3), mTestClient3, resources3);
- resources3.push_back(MediaResource(String8(kResourceSecureCodec), 1));
- resources3.push_back(MediaResource(String8(kResourceGraphicMemory), 100));
+ resources3.push_back(MediaResource(MediaResource::kSecureCodec, 1));
+ resources3.push_back(MediaResource(MediaResource::kGraphicMemory, 100));
mService->addResource(kTestPid2, getId(mTestClient3), mTestClient3, resources3);
const PidResourceInfosMap &map = mService->mMap;
@@ -237,14 +237,12 @@
void testGetAllClients() {
addResource();
- String8 type = String8(kResourceSecureCodec);
- String8 unknowType = String8("unknowType");
+ MediaResource::Type type = MediaResource::kSecureCodec;
Vector<sp<IResourceManagerClient> > clients;
EXPECT_FALSE(mService->getAllClients_l(kLowPriorityPid, type, &clients));
// some higher priority process (e.g. kTestPid2) owns the resource, so getAllClients_l
// will fail.
EXPECT_FALSE(mService->getAllClients_l(kMidPriorityPid, type, &clients));
- EXPECT_TRUE(mService->getAllClients_l(kHighPriorityPid, unknowType, &clients));
EXPECT_TRUE(mService->getAllClients_l(kHighPriorityPid, type, &clients));
EXPECT_EQ(2u, clients.size());
@@ -254,8 +252,8 @@
void testReclaimResourceSecure() {
Vector<MediaResource> resources;
- resources.push_back(MediaResource(String8(kResourceSecureCodec), 1));
- resources.push_back(MediaResource(String8(kResourceGraphicMemory), 150));
+ resources.push_back(MediaResource(MediaResource::kSecureCodec, 1));
+ resources.push_back(MediaResource(MediaResource::kGraphicMemory, 150));
// ### secure codec can't coexist and secure codec can coexist with non-secure codec ###
{
@@ -356,7 +354,7 @@
mService->mSupportsSecureWithNonSecureCodec = true;
Vector<MediaResource> resources;
- resources.push_back(MediaResource(String8(kResourceSecureCodec), 1));
+ resources.push_back(MediaResource(MediaResource::kSecureCodec, 1));
EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
// secure codec from lowest process got reclaimed
@@ -374,8 +372,8 @@
void testReclaimResourceNonSecure() {
Vector<MediaResource> resources;
- resources.push_back(MediaResource(String8(kResourceNonSecureCodec), 1));
- resources.push_back(MediaResource(String8(kResourceGraphicMemory), 150));
+ resources.push_back(MediaResource(MediaResource::kNonSecureCodec, 1));
+ resources.push_back(MediaResource(MediaResource::kGraphicMemory, 150));
// ### secure codec can't coexist with non-secure codec ###
{
@@ -429,7 +427,7 @@
mService->mSupportsSecureWithNonSecureCodec = true;
Vector<MediaResource> resources;
- resources.push_back(MediaResource(String8(kResourceNonSecureCodec), 1));
+ resources.push_back(MediaResource(MediaResource::kNonSecureCodec, 1));
EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
// one non secure codec from lowest process got reclaimed
@@ -445,7 +443,7 @@
}
void testGetLowestPriorityBiggestClient() {
- String8 type = String8(kResourceGraphicMemory);
+ MediaResource::Type type = MediaResource::kGraphicMemory;
sp<IResourceManagerClient> client;
EXPECT_FALSE(mService->getLowestPriorityBiggestClient_l(kHighPriorityPid, type, &client));
@@ -454,8 +452,8 @@
EXPECT_FALSE(mService->getLowestPriorityBiggestClient_l(kLowPriorityPid, type, &client));
EXPECT_TRUE(mService->getLowestPriorityBiggestClient_l(kHighPriorityPid, type, &client));
- // kTestPid1 is the lowest priority process with kResourceGraphicMemory.
- // mTestClient1 has the largest kResourceGraphicMemory within kTestPid1.
+ // kTestPid1 is the lowest priority process with MediaResource::kGraphicMemory.
+ // mTestClient1 has the largest MediaResource::kGraphicMemory within kTestPid1.
EXPECT_EQ(mTestClient1, client);
}
@@ -464,7 +462,7 @@
int priority;
TestProcessInfo processInfo;
- String8 type = String8(kResourceGraphicMemory);
+ MediaResource::Type type = MediaResource::kGraphicMemory;
EXPECT_FALSE(mService->getLowestPriorityPid_l(type, &pid, &priority));
addResource();
@@ -475,7 +473,7 @@
processInfo.getPriority(kTestPid1, &priority1);
EXPECT_EQ(priority1, priority);
- type = String8(kResourceNonSecureCodec);
+ type = MediaResource::kNonSecureCodec;
EXPECT_TRUE(mService->getLowestPriorityPid_l(type, &pid, &priority));
EXPECT_EQ(kTestPid2, pid);
int priority2;
@@ -484,7 +482,7 @@
}
void testGetBiggestClient() {
- String8 type = String8(kResourceGraphicMemory);
+ MediaResource::Type type = MediaResource::kGraphicMemory;
sp<IResourceManagerClient> client;
EXPECT_FALSE(mService->getBiggestClient_l(kTestPid2, type, &client));