Acquire wakelock during network stats collection.
Bug: 4517275 Change-Id: I01dfe3b13d7aca84605446e9e9927d0648623552
This commit is contained in:
@@ -60,6 +60,7 @@ import android.os.Environment;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.os.INetworkManagementService;
|
import android.os.INetworkManagementService;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -112,6 +113,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
private final TrustedTime mTime;
|
private final TrustedTime mTime;
|
||||||
private final NetworkStatsSettings mSettings;
|
private final NetworkStatsSettings mSettings;
|
||||||
|
|
||||||
|
private final PowerManager.WakeLock mWakeLock;
|
||||||
|
|
||||||
private IConnectivityManager mConnManager;
|
private IConnectivityManager mConnManager;
|
||||||
|
|
||||||
// @VisibleForTesting
|
// @VisibleForTesting
|
||||||
@@ -191,6 +194,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
mTime = checkNotNull(time, "missing TrustedTime");
|
mTime = checkNotNull(time, "missing TrustedTime");
|
||||||
mSettings = checkNotNull(settings, "missing NetworkStatsSettings");
|
mSettings = checkNotNull(settings, "missing NetworkStatsSettings");
|
||||||
|
|
||||||
|
final PowerManager powerManager = (PowerManager) context.getSystemService(
|
||||||
|
Context.POWER_SERVICE);
|
||||||
|
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
|
||||||
|
|
||||||
mHandlerThread = new HandlerThread(TAG);
|
mHandlerThread = new HandlerThread(TAG);
|
||||||
mHandlerThread.start();
|
mHandlerThread.start();
|
||||||
mHandler = new Handler(mHandlerThread.getLooper());
|
mHandler = new Handler(mHandlerThread.getLooper());
|
||||||
@@ -408,7 +415,12 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
// on background handler thread, and verified CONNECTIVITY_INTERNAL
|
// on background handler thread, and verified CONNECTIVITY_INTERNAL
|
||||||
// permission above.
|
// permission above.
|
||||||
synchronized (mStatsLock) {
|
synchronized (mStatsLock) {
|
||||||
|
mWakeLock.acquire();
|
||||||
|
try {
|
||||||
updateIfacesLocked();
|
updateIfacesLocked();
|
||||||
|
} finally {
|
||||||
|
mWakeLock.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -419,8 +431,12 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
// on background handler thread, and verified UPDATE_DEVICE_STATS
|
// on background handler thread, and verified UPDATE_DEVICE_STATS
|
||||||
// permission above.
|
// permission above.
|
||||||
synchronized (mStatsLock) {
|
synchronized (mStatsLock) {
|
||||||
// TODO: acquire wakelock while performing poll
|
mWakeLock.acquire();
|
||||||
|
try {
|
||||||
performPollLocked(true, false);
|
performPollLocked(true, false);
|
||||||
|
} finally {
|
||||||
|
mWakeLock.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -433,7 +449,12 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
final int uid = intent.getIntExtra(EXTRA_UID, 0);
|
final int uid = intent.getIntExtra(EXTRA_UID, 0);
|
||||||
synchronized (mStatsLock) {
|
synchronized (mStatsLock) {
|
||||||
// TODO: perform one last stats poll for UID
|
// TODO: perform one last stats poll for UID
|
||||||
|
mWakeLock.acquire();
|
||||||
|
try {
|
||||||
removeUidLocked(uid);
|
removeUidLocked(uid);
|
||||||
|
} finally {
|
||||||
|
mWakeLock.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user