Report video battery on/off from mediaserver
We can't track video stats accurately if it's reported from
app side MediaCodec. If the app dies, video stats get stuck
in On state forever. This can be easily triggered by forcefully
kill and app that uses MediaCodec from app side (instead of
through mediaserver's Recorder or Player service), eg.
launch GoogleCamera app and switch to Video tab, and kill it
from adb shell.
In order to track MediaCodec usage from apps we need to move
the battery stats reporting from MediaCodec into ResourceManager.
bug: 138381810
test:
1. test if app uses MediaCodec directly and it dies off, the video
off is received: launch GoogleCamera app, swipe to Video tab,
"dumpsys batterystats --history" and see +video; now adb shell
kill GoogleCamera, dumpsys should show -video.
2. test app that uses MediaCodec through mediaserver: use Chrome
(which uses MediaPlayer) to play some website with video, kills
Chrome from adb shell, and check -video is received.
In anycase it shouldn't stuck in On state.
3. ResourceManagerService_test
Change-Id: I164b31681c4e72e8cce02342641dbec14b8df374
(cherry picked from commit 47db2ff19c3ceb2d3b39ff9315a463984e55dec1)
diff --git a/services/mediaresourcemanager/ResourceManagerService.cpp b/services/mediaresourcemanager/ResourceManagerService.cpp
index 28bfd3f..117a211 100644
--- a/services/mediaresourcemanager/ResourceManagerService.cpp
+++ b/services/mediaresourcemanager/ResourceManagerService.cpp
@@ -21,8 +21,11 @@
#include <binder/IMediaResourceMonitor.h>
#include <binder/IServiceManager.h>
+#include <cutils/sched_policy.h>
#include <dirent.h>
#include <media/stagefright/ProcessInfo.h>
+#include <mediautils/BatteryNotifier.h>
+#include <mediautils/SchedulingPolicyService.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -31,8 +34,7 @@
#include "ResourceManagerService.h"
#include "ServiceLog.h"
-#include "mediautils/SchedulingPolicyService.h"
-#include <cutils/sched_policy.h>
+
namespace android {
namespace {
@@ -101,6 +103,7 @@
}
static ResourceInfo& getResourceInfoForEdit(
+ uid_t uid,
int64_t clientId,
const sp<IResourceManagerClient>& client,
ResourceInfos& infos) {
@@ -110,9 +113,11 @@
}
}
ResourceInfo info;
+ info.uid = uid;
info.clientId = clientId;
info.client = client;
info.cpuBoost = false;
+ info.batteryNoted = false;
infos.push_back(info);
return infos.editItemAt(infos.size() - 1);
}
@@ -204,7 +209,9 @@
mServiceLog(new ServiceLog()),
mSupportsMultipleSecureCodecs(true),
mSupportsSecureWithNonSecureCodec(true),
- mCpuBoostCount(0) {}
+ mCpuBoostCount(0) {
+ BatteryNotifier::getInstance().noteResetVideo();
+}
ResourceManagerService::~ResourceManagerService() {}
@@ -226,6 +233,7 @@
void ResourceManagerService::addResource(
int pid,
+ int uid,
int64_t clientId,
const sp<IResourceManagerClient> client,
const Vector<MediaResource> &resources) {
@@ -239,7 +247,7 @@
return;
}
ResourceInfos& infos = getResourceInfosForEdit(pid, mMap);
- ResourceInfo& info = getResourceInfoForEdit(clientId, client, infos);
+ ResourceInfo& info = getResourceInfoForEdit(uid, clientId, client, infos);
// TODO: do the merge instead of append.
info.resources.appendVector(resources);
@@ -253,6 +261,11 @@
ALOGW("couldn't request cpuset boost");
}
mCpuBoostCount++;
+ } else if (resources[i].mType == MediaResource::kBattery
+ && resources[i].mSubType == MediaResource::kVideoCodec
+ && !info.batteryNoted) {
+ info.batteryNoted = true;
+ BatteryNotifier::getInstance().noteStartVideo(info.uid);
}
}
if (info.deathNotifier == nullptr) {
@@ -291,6 +304,9 @@
requestCpusetBoost(false, this);
}
}
+ if (infos[j].batteryNoted) {
+ BatteryNotifier::getInstance().noteStopVideo(infos[j].uid);
+ }
IInterface::asBinder(infos[j].client)->unlinkToDeath(infos[j].deathNotifier);
j = infos.removeAt(j);
found = true;