Merge changes I3ba50cbd,I970ee365 am: 37f2408143
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1620859 Change-Id: I2cf4ea0abb1ff7bc74302cce16cbe8041b08d321
This commit is contained in:
@@ -655,14 +655,14 @@ public class NetworkStatsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify {@code NetworkStatsService} about network status changed.
|
* Notify {@code NetworkStatsService} about network status changed.
|
||||||
*
|
*
|
||||||
* Notifies NetworkStatsService of network state changes for data usage accounting purposes.
|
* Notifies NetworkStatsService of network state changes for data usage accounting purposes.
|
||||||
*
|
*
|
||||||
* To avoid races that attribute data usage to wrong network, such as new network with
|
* To avoid races that attribute data usage to wrong network, such as new network with
|
||||||
* the same interface after SIM hot-swap, this function will not return until
|
* the same interface after SIM hot-swap, this function will not return until
|
||||||
* {@code NetworkStatsService} finishes its work of retrieving traffic statistics from
|
* {@code NetworkStatsService} finishes its work of retrieving traffic statistics from
|
||||||
* all data sources.
|
* all data sources.
|
||||||
*
|
*
|
||||||
* @param defaultNetworks the list of all networks that could be used by network traffic that
|
* @param defaultNetworks the list of all networks that could be used by network traffic that
|
||||||
* does not explicitly select a network.
|
* does not explicitly select a network.
|
||||||
@@ -689,8 +689,7 @@ public class NetworkStatsManager {
|
|||||||
Objects.requireNonNull(defaultNetworks);
|
Objects.requireNonNull(defaultNetworks);
|
||||||
Objects.requireNonNull(networkStateSnapshots);
|
Objects.requireNonNull(networkStateSnapshots);
|
||||||
Objects.requireNonNull(underlyingNetworkInfos);
|
Objects.requireNonNull(underlyingNetworkInfos);
|
||||||
// TODO: Change internal namings after the name is decided.
|
mService.notifyNetworkStatus(defaultNetworks.toArray(new Network[0]),
|
||||||
mService.forceUpdateIfaces(defaultNetworks.toArray(new Network[0]),
|
|
||||||
networkStateSnapshots.toArray(new NetworkStateSnapshot[0]), activeIface,
|
networkStateSnapshots.toArray(new NetworkStateSnapshot[0]), activeIface,
|
||||||
underlyingNetworkInfos.toArray(new UnderlyingNetworkInfo[0]));
|
underlyingNetworkInfos.toArray(new UnderlyingNetworkInfo[0]));
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ interface INetworkStatsService {
|
|||||||
/** Increment data layer count of operations performed for UID and tag. */
|
/** Increment data layer count of operations performed for UID and tag. */
|
||||||
void incrementOperationCount(int uid, int tag, int operationCount);
|
void incrementOperationCount(int uid, int tag, int operationCount);
|
||||||
|
|
||||||
/** Force update of ifaces. */
|
/** Notify {@code NetworkStatsService} about network status changed. */
|
||||||
void forceUpdateIfaces(
|
void notifyNetworkStatus(
|
||||||
in Network[] defaultNetworks,
|
in Network[] defaultNetworks,
|
||||||
in NetworkStateSnapshot[] snapshots,
|
in NetworkStateSnapshot[] snapshots,
|
||||||
in String activeIface,
|
in String activeIface,
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
private static final int MSG_PERFORM_POLL = 1;
|
private static final int MSG_PERFORM_POLL = 1;
|
||||||
// Perform polling, persist network, and register the global alert again.
|
// Perform polling, persist network, and register the global alert again.
|
||||||
private static final int MSG_PERFORM_POLL_REGISTER_ALERT = 2;
|
private static final int MSG_PERFORM_POLL_REGISTER_ALERT = 2;
|
||||||
private static final int MSG_UPDATE_IFACES = 3;
|
private static final int MSG_NOTIFY_NETWORK_STATUS = 3;
|
||||||
// A message for broadcasting ACTION_NETWORK_STATS_UPDATED in handler thread to prevent
|
// A message for broadcasting ACTION_NETWORK_STATS_UPDATED in handler thread to prevent
|
||||||
// deadlock.
|
// deadlock.
|
||||||
private static final int MSG_BROADCAST_NETWORK_STATS_UPDATED = 4;
|
private static final int MSG_BROADCAST_NETWORK_STATS_UPDATED = 4;
|
||||||
@@ -379,11 +379,12 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
performPoll(FLAG_PERSIST_ALL);
|
performPoll(FLAG_PERSIST_ALL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_UPDATE_IFACES: {
|
case MSG_NOTIFY_NETWORK_STATUS: {
|
||||||
// If no cached states, ignore.
|
// If no cached states, ignore.
|
||||||
if (mLastNetworkStateSnapshots == null) break;
|
if (mLastNetworkStateSnapshots == null) break;
|
||||||
// TODO (b/181642673): Protect mDefaultNetworks from concurrent accessing.
|
// TODO (b/181642673): Protect mDefaultNetworks from concurrent accessing.
|
||||||
updateIfaces(mDefaultNetworks, mLastNetworkStateSnapshots, mActiveIface);
|
handleNotifyNetworkStatus(
|
||||||
|
mDefaultNetworks, mLastNetworkStateSnapshots, mActiveIface);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_PERFORM_POLL_REGISTER_ALERT: {
|
case MSG_PERFORM_POLL_REGISTER_ALERT: {
|
||||||
@@ -474,7 +475,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
@NonNull Looper looper, @NonNull Executor executor,
|
@NonNull Looper looper, @NonNull Executor executor,
|
||||||
@NonNull NetworkStatsService service) {
|
@NonNull NetworkStatsService service) {
|
||||||
// TODO: Update RatType passively in NSS, instead of querying into the monitor
|
// TODO: Update RatType passively in NSS, instead of querying into the monitor
|
||||||
// when forceUpdateIface.
|
// when notifyNetworkStatus.
|
||||||
return new NetworkStatsSubscriptionsMonitor(context, looper, executor,
|
return new NetworkStatsSubscriptionsMonitor(context, looper, executor,
|
||||||
(subscriberId, type) -> service.handleOnCollapsedRatTypeChanged());
|
(subscriberId, type) -> service.handleOnCollapsedRatTypeChanged());
|
||||||
}
|
}
|
||||||
@@ -971,16 +972,19 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forceUpdateIfaces(
|
/**
|
||||||
Network[] defaultNetworks,
|
* Notify {@code NetworkStatsService} about network status changed.
|
||||||
NetworkStateSnapshot[] networkStates,
|
*/
|
||||||
String activeIface,
|
public void notifyNetworkStatus(
|
||||||
UnderlyingNetworkInfo[] underlyingNetworkInfos) {
|
@NonNull Network[] defaultNetworks,
|
||||||
|
@NonNull NetworkStateSnapshot[] networkStates,
|
||||||
|
@Nullable String activeIface,
|
||||||
|
@NonNull UnderlyingNetworkInfo[] underlyingNetworkInfos) {
|
||||||
checkNetworkStackPermission(mContext);
|
checkNetworkStackPermission(mContext);
|
||||||
|
|
||||||
final long token = Binder.clearCallingIdentity();
|
final long token = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
updateIfaces(defaultNetworks, networkStates, activeIface);
|
handleNotifyNetworkStatus(defaultNetworks, networkStates, activeIface);
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(token);
|
Binder.restoreCallingIdentity(token);
|
||||||
}
|
}
|
||||||
@@ -1244,12 +1248,12 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void handleOnCollapsedRatTypeChanged() {
|
public void handleOnCollapsedRatTypeChanged() {
|
||||||
// Protect service from frequently updating. Remove pending messages if any.
|
// Protect service from frequently updating. Remove pending messages if any.
|
||||||
mHandler.removeMessages(MSG_UPDATE_IFACES);
|
mHandler.removeMessages(MSG_NOTIFY_NETWORK_STATUS);
|
||||||
mHandler.sendMessageDelayed(
|
mHandler.sendMessageDelayed(
|
||||||
mHandler.obtainMessage(MSG_UPDATE_IFACES), mSettings.getPollDelay());
|
mHandler.obtainMessage(MSG_NOTIFY_NETWORK_STATUS), mSettings.getPollDelay());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateIfaces(
|
private void handleNotifyNetworkStatus(
|
||||||
Network[] defaultNetworks,
|
Network[] defaultNetworks,
|
||||||
NetworkStateSnapshot[] snapshots,
|
NetworkStateSnapshot[] snapshots,
|
||||||
String activeIface) {
|
String activeIface) {
|
||||||
@@ -1257,7 +1261,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
mWakeLock.acquire();
|
mWakeLock.acquire();
|
||||||
try {
|
try {
|
||||||
mActiveIface = activeIface;
|
mActiveIface = activeIface;
|
||||||
updateIfacesLocked(defaultNetworks, snapshots);
|
handleNotifyNetworkStatusLocked(defaultNetworks, snapshots);
|
||||||
} finally {
|
} finally {
|
||||||
mWakeLock.release();
|
mWakeLock.release();
|
||||||
}
|
}
|
||||||
@@ -1270,10 +1274,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
* they are combined under a single {@link NetworkIdentitySet}.
|
* they are combined under a single {@link NetworkIdentitySet}.
|
||||||
*/
|
*/
|
||||||
@GuardedBy("mStatsLock")
|
@GuardedBy("mStatsLock")
|
||||||
private void updateIfacesLocked(@NonNull Network[] defaultNetworks,
|
private void handleNotifyNetworkStatusLocked(@NonNull Network[] defaultNetworks,
|
||||||
@NonNull NetworkStateSnapshot[] snapshots) {
|
@NonNull NetworkStateSnapshot[] snapshots) {
|
||||||
if (!mSystemReady) return;
|
if (!mSystemReady) return;
|
||||||
if (LOGV) Slog.v(TAG, "updateIfacesLocked()");
|
if (LOGV) Slog.v(TAG, "handleNotifyNetworkStatusLocked()");
|
||||||
|
|
||||||
// take one last stats snapshot before updating iface mapping. this
|
// take one last stats snapshot before updating iface mapping. this
|
||||||
// isn't perfect, since the kernel may already be counting traffic from
|
// isn't perfect, since the kernel may already be counting traffic from
|
||||||
|
|||||||
Reference in New Issue
Block a user