Add more testing for ResourceManagerService

Refactor the calls to other system services to an interface
to allow more testing.

Add test for callbacks to BatteryStatsService and
SchedulingPolicyService.

bug: 138381810
bug: 139440234
test: presubmit
Change-Id: I04408ad5a126e9f4083b5806b228449cb432acf6
diff --git a/services/mediaresourcemanager/ResourceManagerService.cpp b/services/mediaresourcemanager/ResourceManagerService.cpp
index 5a52b3d..bdcd5e4 100644
--- a/services/mediaresourcemanager/ResourceManagerService.cpp
+++ b/services/mediaresourcemanager/ResourceManagerService.cpp
@@ -200,16 +200,44 @@
     return OK;
 }
 
-ResourceManagerService::ResourceManagerService()
-    : ResourceManagerService(new ProcessInfo()) {}
+struct SystemCallbackImpl :
+        public ResourceManagerService::SystemCallbackInterface {
+    SystemCallbackImpl() {}
 
-ResourceManagerService::ResourceManagerService(sp<ProcessInfoInterface> processInfo)
+    virtual void noteStartVideo(int uid) override {
+        BatteryNotifier::getInstance().noteStartVideo(uid);
+    }
+    virtual void noteStopVideo(int uid) override {
+        BatteryNotifier::getInstance().noteStopVideo(uid);
+    }
+    virtual void noteResetVideo() override {
+        BatteryNotifier::getInstance().noteResetVideo();
+    }
+    virtual bool requestCpusetBoost(
+            bool enable, const sp<IInterface> &client) override {
+        return android::requestCpusetBoost(enable, client);
+    }
+
+protected:
+    virtual ~SystemCallbackImpl() {}
+
+private:
+    DISALLOW_EVIL_CONSTRUCTORS(SystemCallbackImpl);
+};
+
+ResourceManagerService::ResourceManagerService()
+    : ResourceManagerService(new ProcessInfo(), new SystemCallbackImpl()) {}
+
+ResourceManagerService::ResourceManagerService(
+        const sp<ProcessInfoInterface> &processInfo,
+        const sp<SystemCallbackInterface> &systemResource)
     : mProcessInfo(processInfo),
+      mSystemCB(systemResource),
       mServiceLog(new ServiceLog()),
       mSupportsMultipleSecureCodecs(true),
       mSupportsSecureWithNonSecureCodec(true),
       mCpuBoostCount(0) {
-    BatteryNotifier::getInstance().noteResetVideo();
+    mSystemCB->noteResetVideo();
 }
 
 ResourceManagerService::~ResourceManagerService() {}
@@ -238,13 +266,13 @@
         // Request it on every new instance of kCpuBoost, as the media.codec
         // could have died, if we only do it the first time subsequent instances
         // never gets the boost.
-        if (requestCpusetBoost(true, this) != OK) {
+        if (mSystemCB->requestCpusetBoost(true, this) != OK) {
             ALOGW("couldn't request cpuset boost");
         }
         mCpuBoostCount++;
     } else if (resource.mType == MediaResource::kBattery
             && resource.mSubType == MediaResource::kVideoCodec) {
-        BatteryNotifier::getInstance().noteStartVideo(clientInfo.uid);
+        mSystemCB->noteStartVideo(clientInfo.uid);
     }
 }
 
@@ -254,11 +282,11 @@
             && resource.mSubType == MediaResource::kUnspecifiedSubType
             && mCpuBoostCount > 0) {
         if (--mCpuBoostCount == 0) {
-            requestCpusetBoost(false, this);
+            mSystemCB->requestCpusetBoost(false, this);
         }
     } else if (resource.mType == MediaResource::kBattery
             && resource.mSubType == MediaResource::kVideoCodec) {
-        BatteryNotifier::getInstance().noteStopVideo(clientInfo.uid);
+        mSystemCB->noteStopVideo(clientInfo.uid);
     }
 }