mediaresourcemanager: add pid to removeResource method

Bug: 22496209
Change-Id: I73311573e8d1ac15fec668a9ef6e6af7a07a1d30
diff --git a/media/libmedia/IResourceManagerService.cpp b/media/libmedia/IResourceManagerService.cpp
index 6902e99..4598686 100644
--- a/media/libmedia/IResourceManagerService.cpp
+++ b/media/libmedia/IResourceManagerService.cpp
@@ -85,9 +85,10 @@
         remote()->transact(ADD_RESOURCE, data, &reply);
     }
 
-    virtual void removeResource(int64_t clientId) {
+    virtual void removeResource(int pid, int64_t clientId) {
         Parcel data, reply;
         data.writeInterfaceToken(IResourceManagerService::getInterfaceDescriptor());
+        data.writeInt32(pid);
         data.writeInt64(clientId);
 
         remote()->transact(REMOVE_RESOURCE, data, &reply);
@@ -139,8 +140,9 @@
 
         case REMOVE_RESOURCE: {
             CHECK_INTERFACE(IResourceManagerService, data, reply);
+            int pid = data.readInt32();
             int64_t clientId = data.readInt64();
-            removeResource(clientId);
+            removeResource(pid, clientId);
             return NO_ERROR;
         } break;
 
diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp
index fb32d3a..09742a4 100644
--- a/media/libstagefright/MediaCodec.cpp
+++ b/media/libstagefright/MediaCodec.cpp
@@ -54,10 +54,6 @@
 
 namespace android {
 
-static inline int getCallingPid() {
-    return IPCThreadState::self()->getCallingPid();
-}
-
 static int64_t getId(sp<IResourceManagerClient> client) {
     return (int64_t) client.get();
 }
@@ -108,7 +104,8 @@
     DISALLOW_EVIL_CONSTRUCTORS(ResourceManagerClient);
 };
 
-MediaCodec::ResourceManagerServiceProxy::ResourceManagerServiceProxy() {
+MediaCodec::ResourceManagerServiceProxy::ResourceManagerServiceProxy()
+        : mPid(IPCThreadState::self()->getCallingPid()) {
 }
 
 MediaCodec::ResourceManagerServiceProxy::~ResourceManagerServiceProxy() {
@@ -135,7 +132,6 @@
 }
 
 void MediaCodec::ResourceManagerServiceProxy::addResource(
-        int pid,
         int64_t clientId,
         const sp<IResourceManagerClient> client,
         const Vector<MediaResource> &resources) {
@@ -143,7 +139,7 @@
     if (mService == NULL) {
         return;
     }
-    mService->addResource(pid, clientId, client, resources);
+    mService->addResource(mPid, clientId, client, resources);
 }
 
 void MediaCodec::ResourceManagerServiceProxy::removeResource(int64_t clientId) {
@@ -151,16 +147,16 @@
     if (mService == NULL) {
         return;
     }
-    mService->removeResource(clientId);
+    mService->removeResource(mPid, clientId);
 }
 
 bool MediaCodec::ResourceManagerServiceProxy::reclaimResource(
-        int callingPid, const Vector<MediaResource> &resources) {
+        const Vector<MediaResource> &resources) {
     Mutex::Autolock _l(mLock);
     if (mService == NULL) {
         return false;
     }
-    return mService->reclaimResource(callingPid, resources);
+    return mService->reclaimResource(mPid, resources);
 }
 
 // static
@@ -375,7 +371,7 @@
     for (int i = 0; i <= kMaxRetry; ++i) {
         if (i > 0) {
             // Don't try to reclaim resource for the first time.
-            if (!mResourceManagerService->reclaimResource(getCallingPid(), resources)) {
+            if (!mResourceManagerService->reclaimResource(resources)) {
                 break;
             }
         }
@@ -438,7 +434,7 @@
     for (int i = 0; i <= kMaxRetry; ++i) {
         if (i > 0) {
             // Don't try to reclaim resource for the first time.
-            if (!mResourceManagerService->reclaimResource(getCallingPid(), resources)) {
+            if (!mResourceManagerService->reclaimResource(resources)) {
                 break;
             }
         }
@@ -517,7 +513,7 @@
     Vector<MediaResource> resources;
     resources.push_back(MediaResource(type, subtype, value));
     mResourceManagerService->addResource(
-            getCallingPid(), getId(mResourceManagerClient), mResourceManagerClient, resources);
+            getId(mResourceManagerClient), mResourceManagerClient, resources);
 }
 
 status_t MediaCodec::start() {
@@ -535,7 +531,7 @@
     for (int i = 0; i <= kMaxRetry; ++i) {
         if (i > 0) {
             // Don't try to reclaim resource for the first time.
-            if (!mResourceManagerService->reclaimResource(getCallingPid(), resources)) {
+            if (!mResourceManagerService->reclaimResource(resources)) {
                 break;
             }
             // Recover codec from previous error before retry start.