Merge "NetworkStats: Fix race condition causing system server crashes" am: 08b928e8ed
am: f37da9a879 Change-Id: I0ab308d5215ddb174ffb115e36948685d68da3ec
This commit is contained in:
@@ -380,14 +380,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void systemReady() {
|
public void systemReady() {
|
||||||
mSystemReady = true;
|
|
||||||
|
|
||||||
if (!isBandwidthControlEnabled()) {
|
|
||||||
Slog.w(TAG, "bandwidth controls disabled, unable to track stats");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (mStatsLock) {
|
synchronized (mStatsLock) {
|
||||||
|
mSystemReady = true;
|
||||||
|
|
||||||
// create data recorders along with historical rotators
|
// create data recorders along with historical rotators
|
||||||
mDevRecorder = buildRecorder(PREFIX_DEV, mSettings.getDevConfig(), false);
|
mDevRecorder = buildRecorder(PREFIX_DEV, mSettings.getDevConfig(), false);
|
||||||
mXtRecorder = buildRecorder(PREFIX_XT, mSettings.getXtConfig(), false);
|
mXtRecorder = buildRecorder(PREFIX_XT, mSettings.getXtConfig(), false);
|
||||||
@@ -433,7 +428,14 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
// ignored; service lives in system_server
|
// ignored; service lives in system_server
|
||||||
}
|
}
|
||||||
|
|
||||||
registerPollAlarmLocked();
|
// schedule periodic pall alarm based on {@link NetworkStatsSettings#getPollInterval()}.
|
||||||
|
final PendingIntent pollIntent =
|
||||||
|
PendingIntent.getBroadcast(mContext, 0, new Intent(ACTION_NETWORK_STATS_POLL), 0);
|
||||||
|
|
||||||
|
final long currentRealtime = SystemClock.elapsedRealtime();
|
||||||
|
mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, currentRealtime,
|
||||||
|
mSettings.getPollInterval(), pollIntent);
|
||||||
|
|
||||||
registerGlobalAlert();
|
registerGlobalAlert();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -493,23 +495,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear any existing {@link #ACTION_NETWORK_STATS_POLL} alarms, and
|
|
||||||
* reschedule based on current {@link NetworkStatsSettings#getPollInterval()}.
|
|
||||||
*/
|
|
||||||
private void registerPollAlarmLocked() {
|
|
||||||
if (mPollIntent != null) {
|
|
||||||
mAlarmManager.cancel(mPollIntent);
|
|
||||||
}
|
|
||||||
|
|
||||||
mPollIntent = PendingIntent.getBroadcast(
|
|
||||||
mContext, 0, new Intent(ACTION_NETWORK_STATS_POLL), 0);
|
|
||||||
|
|
||||||
final long currentRealtime = SystemClock.elapsedRealtime();
|
|
||||||
mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, currentRealtime,
|
|
||||||
mSettings.getPollInterval(), mPollIntent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register for a global alert that is delivered through
|
* Register for a global alert that is delivered through
|
||||||
* {@link INetworkManagementEventObserver} once a threshold amount of data
|
* {@link INetworkManagementEventObserver} once a threshold amount of data
|
||||||
@@ -555,8 +540,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private INetworkStatsSession openSessionInternal(final int flags, final String callingPackage) {
|
private INetworkStatsSession openSessionInternal(final int flags, final String callingPackage) {
|
||||||
assertBandwidthControlEnabled();
|
|
||||||
|
|
||||||
final int callingUid = Binder.getCallingUid();
|
final int callingUid = Binder.getCallingUid();
|
||||||
final int usedFlags = isRateLimitedForPoll(callingUid)
|
final int usedFlags = isRateLimitedForPoll(callingUid)
|
||||||
? flags & (~NetworkStatsManager.FLAG_POLL_ON_OPEN)
|
? flags & (~NetworkStatsManager.FLAG_POLL_ON_OPEN)
|
||||||
@@ -749,7 +732,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
|
|
||||||
private long getNetworkTotalBytes(NetworkTemplate template, long start, long end) {
|
private long getNetworkTotalBytes(NetworkTemplate template, long start, long end) {
|
||||||
assertSystemReady();
|
assertSystemReady();
|
||||||
assertBandwidthControlEnabled();
|
|
||||||
|
|
||||||
// NOTE: if callers want to get non-augmented data, they should go
|
// NOTE: if callers want to get non-augmented data, they should go
|
||||||
// through the public API
|
// through the public API
|
||||||
@@ -760,7 +742,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
|
|
||||||
private NetworkStats getNetworkUidBytes(NetworkTemplate template, long start, long end) {
|
private NetworkStats getNetworkUidBytes(NetworkTemplate template, long start, long end) {
|
||||||
assertSystemReady();
|
assertSystemReady();
|
||||||
assertBandwidthControlEnabled();
|
|
||||||
|
|
||||||
final NetworkStatsCollection uidComplete;
|
final NetworkStatsCollection uidComplete;
|
||||||
synchronized (mStatsLock) {
|
synchronized (mStatsLock) {
|
||||||
@@ -775,7 +756,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
if (Binder.getCallingUid() != uid) {
|
if (Binder.getCallingUid() != uid) {
|
||||||
mContext.enforceCallingOrSelfPermission(ACCESS_NETWORK_STATE, TAG);
|
mContext.enforceCallingOrSelfPermission(ACCESS_NETWORK_STATE, TAG);
|
||||||
}
|
}
|
||||||
assertBandwidthControlEnabled();
|
|
||||||
|
|
||||||
// TODO: switch to data layer stats once kernel exports
|
// TODO: switch to data layer stats once kernel exports
|
||||||
// for now, read network layer stats and flatten across all ifaces
|
// for now, read network layer stats and flatten across all ifaces
|
||||||
@@ -862,7 +842,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
NetworkState[] networkStates,
|
NetworkState[] networkStates,
|
||||||
String activeIface) {
|
String activeIface) {
|
||||||
checkNetworkStackPermission(mContext);
|
checkNetworkStackPermission(mContext);
|
||||||
assertBandwidthControlEnabled();
|
|
||||||
|
|
||||||
final long token = Binder.clearCallingIdentity();
|
final long token = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
@@ -875,7 +854,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
@Override
|
@Override
|
||||||
public void forceUpdate() {
|
public void forceUpdate() {
|
||||||
mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG);
|
mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG);
|
||||||
assertBandwidthControlEnabled();
|
|
||||||
|
|
||||||
final long token = Binder.clearCallingIdentity();
|
final long token = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
@@ -886,8 +864,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void advisePersistThreshold(long thresholdBytes) {
|
private void advisePersistThreshold(long thresholdBytes) {
|
||||||
assertBandwidthControlEnabled();
|
|
||||||
|
|
||||||
// clamp threshold into safe range
|
// clamp threshold into safe range
|
||||||
mPersistThreshold = MathUtils.constrain(thresholdBytes, 128 * KB_IN_BYTES, 2 * MB_IN_BYTES);
|
mPersistThreshold = MathUtils.constrain(thresholdBytes, 128 * KB_IN_BYTES, 2 * MB_IN_BYTES);
|
||||||
if (LOGV) {
|
if (LOGV) {
|
||||||
@@ -1746,24 +1722,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertBandwidthControlEnabled() {
|
|
||||||
if (!isBandwidthControlEnabled()) {
|
|
||||||
throw new IllegalStateException("Bandwidth module disabled");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBandwidthControlEnabled() {
|
|
||||||
final long token = Binder.clearCallingIdentity();
|
|
||||||
try {
|
|
||||||
return mNetworkManager.isBandwidthControlEnabled();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
// ignored; service lives in system_server
|
|
||||||
return false;
|
|
||||||
} finally {
|
|
||||||
Binder.restoreCallingIdentity(token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DropBoxNonMonotonicObserver implements NonMonotonicObserver<String> {
|
private class DropBoxNonMonotonicObserver implements NonMonotonicObserver<String> {
|
||||||
@Override
|
@Override
|
||||||
public void foundNonMonotonic(NetworkStats left, int leftIndex, NetworkStats right,
|
public void foundNonMonotonic(NetworkStats left, int leftIndex, NetworkStats right,
|
||||||
|
|||||||
Reference in New Issue
Block a user