Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 62a7e015 authored by Chong Zhang's avatar Chong Zhang
Browse files

Only allow mediaserver to report video battery stats

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.

(This reverts commit 0fc2da03,
since neither video nor audio reports battery from client side.)

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.

Change-Id: I17ce96715f20e9d29e4f429995e48294d5fd5cb7
parent f165a18a
Loading
Loading
Loading
Loading
+4 −11
Original line number Diff line number Diff line
@@ -756,7 +756,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
    }

    public void noteStartAudio(int uid) {
        enforceSelfOrCallingPermission(uid);
        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteAudioOnLocked(uid);
            StatsLog.write_non_chained(StatsLog.AUDIO_STATE_CHANGED, uid, null,
@@ -765,7 +765,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
    }

    public void noteStopAudio(int uid) {
        enforceSelfOrCallingPermission(uid);
        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteAudioOffLocked(uid);
            StatsLog.write_non_chained(StatsLog.AUDIO_STATE_CHANGED, uid, null,
@@ -774,7 +774,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
    }

    public void noteStartVideo(int uid) {
        enforceSelfOrCallingPermission(uid);
        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteVideoOnLocked(uid);
            StatsLog.write_non_chained(StatsLog.MEDIA_CODEC_STATE_CHANGED, uid, null,
@@ -783,7 +783,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
    }

    public void noteStopVideo(int uid) {
        enforceSelfOrCallingPermission(uid);
        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteVideoOffLocked(uid);
            StatsLog.write_non_chained(StatsLog.MEDIA_CODEC_STATE_CHANGED, uid,
@@ -1184,13 +1184,6 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                Binder.getCallingPid(), Binder.getCallingUid(), null);
    }

    private void enforceSelfOrCallingPermission(int uid) {
        if (Binder.getCallingUid() == uid) {
            return;
        }
        enforceCallingPermission();
    }

    final class WakeupReasonThread extends Thread {
        private static final int MAX_REASON_SIZE = 512;
        private CharsetDecoder mDecoder;