Hold a wakelock while retrieving reports

This attempts to fix an issue where the device will go to sleep while
retrieving a report. If this happens a report may contain inconsistent
timestamps.

Bug: 167329914
Test: m -j
Change-Id: Ibee08d95043759aa1114274378e4d72336174010
Merged-In: Ibee08d95043759aa1114274378e4d72336174010
(cherry picked from commit e0f4b3da97)
This commit is contained in:
Jeffrey Huang
2020-09-03 14:37:06 -07:00
parent 51571f8993
commit c6f24fa5e0

View File

@@ -27,6 +27,7 @@ import android.os.Binder;
import android.os.IPullAtomCallback;
import android.os.IStatsManagerService;
import android.os.IStatsd;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.util.ArrayMap;
@@ -412,8 +413,13 @@ public class StatsManagerService extends IStatsManagerService.Stub {
@Override
public byte[] getData(long key, String packageName) throws IllegalStateException {
enforceDumpAndUsageStatsPermission(packageName);
PowerManager powerManager = (PowerManager)
mContext.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
/*tag=*/ StatsManagerService.class.getCanonicalName());
int callingUid = Binder.getCallingUid();
final long token = Binder.clearCallingIdentity();
wl.acquire();
try {
IStatsd statsd = waitForStatsd();
if (statsd != null) {
@@ -423,6 +429,7 @@ public class StatsManagerService extends IStatsManagerService.Stub {
Log.e(TAG, "Failed to getData with statsd");
throw new IllegalStateException(e.getMessage(), e);
} finally {
wl.release();
Binder.restoreCallingIdentity(token);
}
throw new IllegalStateException("Failed to connect to statsd to getData");