Eliminate race conditions in UID-based network filtering.
The previous code retrieved information from the legacy tracker multiple times for each user query, leading to race conditions where the info could've changed between the calls. Refactors the handling of legacy data types in ConnectivityService and unifies call paths so that APIs that deal with legacy data types (NetworkInfo and int/networkType) and newer types (such as Network) go through common code paths, using NetworkState to hold all the necessary data pieces. This enables follow-on bug fixes to getActiveNetworkInfo(). The changes are limited to public "query" APIs (those that retrieve some network information or the other). More details about the specific changes and their rationale can be found in the code review thread. Bug: 17460017 Change-Id: I656ee7eddf2b8cace5627036452bb5748043406c
This commit is contained in:
@@ -29,20 +29,23 @@ public class NetworkState implements Parcelable {
|
|||||||
public final NetworkInfo networkInfo;
|
public final NetworkInfo networkInfo;
|
||||||
public final LinkProperties linkProperties;
|
public final LinkProperties linkProperties;
|
||||||
public final NetworkCapabilities networkCapabilities;
|
public final NetworkCapabilities networkCapabilities;
|
||||||
|
public final Network network;
|
||||||
/** Currently only used by testing. */
|
/** Currently only used by testing. */
|
||||||
public final String subscriberId;
|
public final String subscriberId;
|
||||||
public final String networkId;
|
public final String networkId;
|
||||||
|
|
||||||
public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties,
|
public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties,
|
||||||
NetworkCapabilities networkCapabilities) {
|
NetworkCapabilities networkCapabilities, Network network) {
|
||||||
this(networkInfo, linkProperties, networkCapabilities, null, null);
|
this(networkInfo, linkProperties, networkCapabilities, network, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties,
|
public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties,
|
||||||
NetworkCapabilities networkCapabilities, String subscriberId, String networkId) {
|
NetworkCapabilities networkCapabilities, Network network, String subscriberId,
|
||||||
|
String networkId) {
|
||||||
this.networkInfo = networkInfo;
|
this.networkInfo = networkInfo;
|
||||||
this.linkProperties = linkProperties;
|
this.linkProperties = linkProperties;
|
||||||
this.networkCapabilities = networkCapabilities;
|
this.networkCapabilities = networkCapabilities;
|
||||||
|
this.network = network;
|
||||||
this.subscriberId = subscriberId;
|
this.subscriberId = subscriberId;
|
||||||
this.networkId = networkId;
|
this.networkId = networkId;
|
||||||
}
|
}
|
||||||
@@ -51,6 +54,7 @@ public class NetworkState implements Parcelable {
|
|||||||
networkInfo = in.readParcelable(null);
|
networkInfo = in.readParcelable(null);
|
||||||
linkProperties = in.readParcelable(null);
|
linkProperties = in.readParcelable(null);
|
||||||
networkCapabilities = in.readParcelable(null);
|
networkCapabilities = in.readParcelable(null);
|
||||||
|
network = in.readParcelable(null);
|
||||||
subscriberId = in.readString();
|
subscriberId = in.readString();
|
||||||
networkId = in.readString();
|
networkId = in.readString();
|
||||||
}
|
}
|
||||||
@@ -65,6 +69,7 @@ public class NetworkState implements Parcelable {
|
|||||||
out.writeParcelable(networkInfo, flags);
|
out.writeParcelable(networkInfo, flags);
|
||||||
out.writeParcelable(linkProperties, flags);
|
out.writeParcelable(linkProperties, flags);
|
||||||
out.writeParcelable(networkCapabilities, flags);
|
out.writeParcelable(networkCapabilities, flags);
|
||||||
|
out.writeParcelable(network, flags);
|
||||||
out.writeString(subscriberId);
|
out.writeString(subscriberId);
|
||||||
out.writeString(networkId);
|
out.writeString(networkId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -819,20 +819,62 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private NetworkState getFilteredNetworkState(int networkType, int uid) {
|
||||||
* Check if UID should be blocked from using the network represented by the given networkType.
|
NetworkInfo info = null;
|
||||||
* @deprecated Uses mLegacyTypeTracker; cannot deal with multiple Networks of the same type.
|
LinkProperties lp = null;
|
||||||
*/
|
NetworkCapabilities nc = null;
|
||||||
private boolean isNetworkBlocked(int networkType, int uid) {
|
Network network = null;
|
||||||
return isNetworkWithLinkPropertiesBlocked(getLinkPropertiesForType(networkType), uid);
|
|
||||||
|
if (mLegacyTypeTracker.isTypeSupported(networkType)) {
|
||||||
|
NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
|
||||||
|
if (nai != null) {
|
||||||
|
synchronized (nai) {
|
||||||
|
info = new NetworkInfo(nai.networkInfo);
|
||||||
|
lp = new LinkProperties(nai.linkProperties);
|
||||||
|
nc = new NetworkCapabilities(nai.networkCapabilities);
|
||||||
|
network = new Network(nai.network);
|
||||||
|
}
|
||||||
|
info.setType(networkType);
|
||||||
|
} else {
|
||||||
|
info = new NetworkInfo(networkType, 0, getNetworkTypeName(networkType), "");
|
||||||
|
info.setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, null, null);
|
||||||
|
info.setIsAvailable(true);
|
||||||
|
lp = new LinkProperties();
|
||||||
|
nc = new NetworkCapabilities();
|
||||||
|
network = null;
|
||||||
|
}
|
||||||
|
info = getFilteredNetworkInfo(info, lp, uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new NetworkState(info, lp, nc, network);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private NetworkAgentInfo getNetworkAgentInfoForNetwork(Network network) {
|
||||||
* Check if UID should be blocked from using the network represented by the given
|
if (network == null) {
|
||||||
* NetworkAgentInfo.
|
return null;
|
||||||
*/
|
}
|
||||||
private boolean isNetworkBlocked(NetworkAgentInfo nai, int uid) {
|
synchronized (mNetworkForNetId) {
|
||||||
return isNetworkWithLinkPropertiesBlocked(nai.linkProperties, uid);
|
return mNetworkForNetId.get(network.netId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private NetworkState getUnfilteredActiveNetworkState(int uid) {
|
||||||
|
NetworkInfo info = null;
|
||||||
|
LinkProperties lp = null;
|
||||||
|
NetworkCapabilities nc = null;
|
||||||
|
Network network = null;
|
||||||
|
|
||||||
|
NetworkAgentInfo nai = mNetworkForRequestId.get(mDefaultRequest.requestId);
|
||||||
|
if (nai != null) {
|
||||||
|
synchronized (nai) {
|
||||||
|
info = new NetworkInfo(nai.networkInfo);
|
||||||
|
lp = new LinkProperties(nai.linkProperties);
|
||||||
|
nc = new NetworkCapabilities(nai.networkCapabilities);
|
||||||
|
network = new Network(nai.network);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new NetworkState(info, lp, nc, network);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -859,40 +901,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
/**
|
/**
|
||||||
* Return a filtered {@link NetworkInfo}, potentially marked
|
* Return a filtered {@link NetworkInfo}, potentially marked
|
||||||
* {@link DetailedState#BLOCKED} based on
|
* {@link DetailedState#BLOCKED} based on
|
||||||
* {@link #isNetworkBlocked}.
|
* {@link #isNetworkWithLinkPropertiesBlocked}.
|
||||||
* @deprecated Uses mLegacyTypeTracker; cannot deal with multiple Networks of the same type.
|
|
||||||
*/
|
*/
|
||||||
private NetworkInfo getFilteredNetworkInfo(int networkType, int uid) {
|
private NetworkInfo getFilteredNetworkInfo(NetworkInfo info, LinkProperties lp, int uid) {
|
||||||
NetworkInfo info = getNetworkInfoForType(networkType);
|
if (info != null && isNetworkWithLinkPropertiesBlocked(lp, uid)) {
|
||||||
return getFilteredNetworkInfo(info, networkType, uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @deprecated Uses mLegacyTypeTracker; cannot deal with multiple Networks of the same type.
|
|
||||||
*/
|
|
||||||
private NetworkInfo getFilteredNetworkInfo(NetworkInfo info, int networkType, int uid) {
|
|
||||||
if (isNetworkBlocked(networkType, uid)) {
|
|
||||||
// network is blocked; clone and override state
|
|
||||||
info = new NetworkInfo(info);
|
|
||||||
info.setDetailedState(DetailedState.BLOCKED, null, null);
|
|
||||||
if (VDBG) log("returning Blocked NetworkInfo");
|
|
||||||
}
|
|
||||||
if (mLockdownTracker != null) {
|
|
||||||
info = mLockdownTracker.augmentNetworkInfo(info);
|
|
||||||
if (VDBG) log("returning Locked NetworkInfo");
|
|
||||||
}
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
private NetworkInfo getFilteredNetworkInfo(NetworkAgentInfo nai, int uid) {
|
|
||||||
NetworkInfo info = nai.networkInfo;
|
|
||||||
if (isNetworkBlocked(nai, uid)) {
|
|
||||||
// network is blocked; clone and override state
|
// network is blocked; clone and override state
|
||||||
info = new NetworkInfo(info);
|
info = new NetworkInfo(info);
|
||||||
info.setDetailedState(DetailedState.BLOCKED, null, null);
|
info.setDetailedState(DetailedState.BLOCKED, null, null);
|
||||||
if (DBG) log("returning Blocked NetworkInfo");
|
if (DBG) log("returning Blocked NetworkInfo");
|
||||||
}
|
}
|
||||||
if (mLockdownTracker != null) {
|
if (info != null && mLockdownTracker != null) {
|
||||||
info = mLockdownTracker.augmentNetworkInfo(info);
|
info = mLockdownTracker.augmentNetworkInfo(info);
|
||||||
if (DBG) log("returning Locked NetworkInfo");
|
if (DBG) log("returning Locked NetworkInfo");
|
||||||
}
|
}
|
||||||
@@ -910,7 +928,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
public NetworkInfo getActiveNetworkInfo() {
|
public NetworkInfo getActiveNetworkInfo() {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
final int uid = Binder.getCallingUid();
|
final int uid = Binder.getCallingUid();
|
||||||
return getNetworkInfo(mActiveDefaultNetwork, uid);
|
NetworkState state = getUnfilteredActiveNetworkState(uid);
|
||||||
|
return getFilteredNetworkInfo(state.networkInfo, state.linkProperties, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -945,8 +964,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
NetworkInfo provNi = getProvisioningNetworkInfo();
|
NetworkInfo provNi = getProvisioningNetworkInfo();
|
||||||
if (provNi == null) {
|
if (provNi == null) {
|
||||||
final int uid = Binder.getCallingUid();
|
provNi = getActiveNetworkInfo();
|
||||||
provNi = getNetworkInfo(mActiveDefaultNetwork, uid);
|
|
||||||
}
|
}
|
||||||
if (DBG) log("getProvisioningOrActiveNetworkInfo: X provNi=" + provNi);
|
if (DBG) log("getProvisioningOrActiveNetworkInfo: X provNi=" + provNi);
|
||||||
return provNi;
|
return provNi;
|
||||||
@@ -954,62 +972,50 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
public NetworkInfo getActiveNetworkInfoUnfiltered() {
|
public NetworkInfo getActiveNetworkInfoUnfiltered() {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
if (isNetworkTypeValid(mActiveDefaultNetwork)) {
|
final int uid = Binder.getCallingUid();
|
||||||
return getNetworkInfoForType(mActiveDefaultNetwork);
|
NetworkState state = getUnfilteredActiveNetworkState(uid);
|
||||||
}
|
return state.networkInfo;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkInfo getActiveNetworkInfoForUid(int uid) {
|
public NetworkInfo getActiveNetworkInfoForUid(int uid) {
|
||||||
enforceConnectivityInternalPermission();
|
enforceConnectivityInternalPermission();
|
||||||
return getNetworkInfo(mActiveDefaultNetwork, uid);
|
NetworkState state = getUnfilteredActiveNetworkState(uid);
|
||||||
|
return getFilteredNetworkInfo(state.networkInfo, state.linkProperties, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkInfo getNetworkInfo(int networkType) {
|
public NetworkInfo getNetworkInfo(int networkType) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
final int uid = Binder.getCallingUid();
|
final int uid = Binder.getCallingUid();
|
||||||
return getNetworkInfo(networkType, uid);
|
NetworkState state = getFilteredNetworkState(networkType, uid);
|
||||||
|
return state.networkInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private NetworkInfo getNetworkInfo(int networkType, int uid) {
|
@Override
|
||||||
|
public NetworkInfo getNetworkInfoForNetwork(Network network) {
|
||||||
|
enforceAccessPermission();
|
||||||
|
final int uid = Binder.getCallingUid();
|
||||||
NetworkInfo info = null;
|
NetworkInfo info = null;
|
||||||
if (isNetworkTypeValid(networkType)) {
|
NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
|
||||||
if (getNetworkInfoForType(networkType) != null) {
|
if (nai != null) {
|
||||||
info = getFilteredNetworkInfo(networkType, uid);
|
synchronized (nai) {
|
||||||
|
info = new NetworkInfo(nai.networkInfo);
|
||||||
|
info = getFilteredNetworkInfo(info, nai.linkProperties, uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public NetworkInfo getNetworkInfoForNetwork(Network network) {
|
|
||||||
enforceAccessPermission();
|
|
||||||
if (network == null) return null;
|
|
||||||
|
|
||||||
final int uid = Binder.getCallingUid();
|
|
||||||
NetworkAgentInfo nai = null;
|
|
||||||
synchronized (mNetworkForNetId) {
|
|
||||||
nai = mNetworkForNetId.get(network.netId);
|
|
||||||
}
|
|
||||||
if (nai == null) return null;
|
|
||||||
synchronized (nai) {
|
|
||||||
if (nai.networkInfo == null) return null;
|
|
||||||
|
|
||||||
return getFilteredNetworkInfo(nai, uid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkInfo[] getAllNetworkInfo() {
|
public NetworkInfo[] getAllNetworkInfo() {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
final int uid = Binder.getCallingUid();
|
|
||||||
final ArrayList<NetworkInfo> result = Lists.newArrayList();
|
final ArrayList<NetworkInfo> result = Lists.newArrayList();
|
||||||
for (int networkType = 0; networkType <= ConnectivityManager.MAX_NETWORK_TYPE;
|
for (int networkType = 0; networkType <= ConnectivityManager.MAX_NETWORK_TYPE;
|
||||||
networkType++) {
|
networkType++) {
|
||||||
if (getNetworkInfoForType(networkType) != null) {
|
NetworkInfo info = getNetworkInfo(networkType);
|
||||||
result.add(getFilteredNetworkInfo(networkType, uid));
|
if (info != null) {
|
||||||
|
result.add(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.toArray(new NetworkInfo[result.size()]);
|
return result.toArray(new NetworkInfo[result.size()]);
|
||||||
@@ -1019,11 +1025,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
public Network getNetworkForType(int networkType) {
|
public Network getNetworkForType(int networkType) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
final int uid = Binder.getCallingUid();
|
final int uid = Binder.getCallingUid();
|
||||||
if (isNetworkBlocked(networkType, uid)) {
|
NetworkState state = getFilteredNetworkState(networkType, uid);
|
||||||
return null;
|
if (!isNetworkWithLinkPropertiesBlocked(state.linkProperties, uid)) {
|
||||||
|
return state.network;
|
||||||
}
|
}
|
||||||
NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
|
return null;
|
||||||
return (nai == null) ? null : nai.network;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1041,7 +1047,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
@Override
|
@Override
|
||||||
public boolean isNetworkSupported(int networkType) {
|
public boolean isNetworkSupported(int networkType) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
return (isNetworkTypeValid(networkType) && (getNetworkInfoForType(networkType) != null));
|
return mLegacyTypeTracker.isTypeSupported(networkType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1054,14 +1060,20 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public LinkProperties getActiveLinkProperties() {
|
public LinkProperties getActiveLinkProperties() {
|
||||||
return getLinkPropertiesForType(mActiveDefaultNetwork);
|
enforceAccessPermission();
|
||||||
|
final int uid = Binder.getCallingUid();
|
||||||
|
NetworkState state = getUnfilteredActiveNetworkState(uid);
|
||||||
|
return state.linkProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LinkProperties getLinkPropertiesForType(int networkType) {
|
public LinkProperties getLinkPropertiesForType(int networkType) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
if (isNetworkTypeValid(networkType)) {
|
NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
|
||||||
return getLinkPropertiesForTypeInternal(networkType);
|
if (nai != null) {
|
||||||
|
synchronized (nai) {
|
||||||
|
return new LinkProperties(nai.linkProperties);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -1070,11 +1082,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
@Override
|
@Override
|
||||||
public LinkProperties getLinkProperties(Network network) {
|
public LinkProperties getLinkProperties(Network network) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
NetworkAgentInfo nai = null;
|
NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
|
||||||
synchronized (mNetworkForNetId) {
|
|
||||||
nai = mNetworkForNetId.get(network.netId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nai != null) {
|
if (nai != null) {
|
||||||
synchronized (nai) {
|
synchronized (nai) {
|
||||||
return new LinkProperties(nai.linkProperties);
|
return new LinkProperties(nai.linkProperties);
|
||||||
@@ -1086,10 +1094,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
@Override
|
@Override
|
||||||
public NetworkCapabilities getNetworkCapabilities(Network network) {
|
public NetworkCapabilities getNetworkCapabilities(Network network) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
NetworkAgentInfo nai = null;
|
NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
|
||||||
synchronized (mNetworkForNetId) {
|
|
||||||
nai = mNetworkForNetId.get(network.netId);
|
|
||||||
}
|
|
||||||
if (nai != null) {
|
if (nai != null) {
|
||||||
synchronized (nai) {
|
synchronized (nai) {
|
||||||
return new NetworkCapabilities(nai.networkCapabilities);
|
return new NetworkCapabilities(nai.networkCapabilities);
|
||||||
@@ -1105,36 +1110,22 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
final ArrayList<NetworkState> result = Lists.newArrayList();
|
final ArrayList<NetworkState> result = Lists.newArrayList();
|
||||||
for (int networkType = 0; networkType <= ConnectivityManager.MAX_NETWORK_TYPE;
|
for (int networkType = 0; networkType <= ConnectivityManager.MAX_NETWORK_TYPE;
|
||||||
networkType++) {
|
networkType++) {
|
||||||
if (getNetworkInfoForType(networkType) != null) {
|
NetworkState state = getFilteredNetworkState(networkType, uid);
|
||||||
final NetworkInfo info = getFilteredNetworkInfo(networkType, uid);
|
if (state.networkInfo != null) {
|
||||||
final LinkProperties lp = getLinkPropertiesForTypeInternal(networkType);
|
result.add(state);
|
||||||
final NetworkCapabilities netcap = getNetworkCapabilitiesForType(networkType);
|
|
||||||
result.add(new NetworkState(info, lp, netcap));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.toArray(new NetworkState[result.size()]);
|
return result.toArray(new NetworkState[result.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private NetworkState getNetworkStateUnchecked(int networkType) {
|
|
||||||
if (isNetworkTypeValid(networkType)) {
|
|
||||||
NetworkInfo info = getNetworkInfoForType(networkType);
|
|
||||||
if (info != null) {
|
|
||||||
return new NetworkState(info,
|
|
||||||
getLinkPropertiesForTypeInternal(networkType),
|
|
||||||
getNetworkCapabilitiesForType(networkType));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
|
public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
|
final int uid = Binder.getCallingUid();
|
||||||
final long token = Binder.clearCallingIdentity();
|
final long token = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
final NetworkState state = getNetworkStateUnchecked(mActiveDefaultNetwork);
|
final NetworkState state = getUnfilteredActiveNetworkState(uid);
|
||||||
if (state != null) {
|
if (state.networkInfo != null) {
|
||||||
try {
|
try {
|
||||||
return mPolicyManager.getNetworkQuotaInfo(state);
|
return mPolicyManager.getNetworkQuotaInfo(state);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
@@ -1149,17 +1140,18 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
@Override
|
@Override
|
||||||
public boolean isActiveNetworkMetered() {
|
public boolean isActiveNetworkMetered() {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
|
final int uid = Binder.getCallingUid();
|
||||||
final long token = Binder.clearCallingIdentity();
|
final long token = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
return isNetworkMeteredUnchecked(mActiveDefaultNetwork);
|
return isActiveNetworkMeteredUnchecked(uid);
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(token);
|
Binder.restoreCallingIdentity(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNetworkMeteredUnchecked(int networkType) {
|
private boolean isActiveNetworkMeteredUnchecked(int uid) {
|
||||||
final NetworkState state = getNetworkStateUnchecked(networkType);
|
final NetworkState state = getUnfilteredActiveNetworkState(uid);
|
||||||
if (state != null) {
|
if (state.networkInfo != null) {
|
||||||
try {
|
try {
|
||||||
return mPolicyManager.isNetworkMetered(state);
|
return mPolicyManager.isNetworkMetered(state);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
@@ -1330,16 +1322,18 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
// kick off connectivity change broadcast for active network, since
|
// kick off connectivity change broadcast for active network, since
|
||||||
// global background policy change is radical.
|
// global background policy change is radical.
|
||||||
final int networkType = mActiveDefaultNetwork;
|
// TODO: Dead code; remove.
|
||||||
if (isNetworkTypeValid(networkType)) {
|
//
|
||||||
final NetworkStateTracker tracker = mNetTrackers[networkType];
|
// final int networkType = mActiveDefaultNetwork;
|
||||||
if (tracker != null) {
|
// if (isNetworkTypeValid(networkType)) {
|
||||||
final NetworkInfo info = tracker.getNetworkInfo();
|
// final NetworkStateTracker tracker = mNetTrackers[networkType];
|
||||||
if (info != null && info.isConnected()) {
|
// if (tracker != null) {
|
||||||
sendConnectedBroadcast(info);
|
// final NetworkInfo info = tracker.getNetworkInfo();
|
||||||
}
|
// if (info != null && info.isConnected()) {
|
||||||
}
|
// sendConnectedBroadcast(info);
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1804,10 +1798,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
private boolean isLiveNetworkAgent(NetworkAgentInfo nai, String msg) {
|
private boolean isLiveNetworkAgent(NetworkAgentInfo nai, String msg) {
|
||||||
if (nai.network == null) return false;
|
if (nai.network == null) return false;
|
||||||
final NetworkAgentInfo officialNai;
|
final NetworkAgentInfo officialNai = getNetworkAgentInfoForNetwork(nai.network);
|
||||||
synchronized (mNetworkForNetId) {
|
|
||||||
officialNai = mNetworkForNetId.get(nai.network.netId);
|
|
||||||
}
|
|
||||||
if (officialNai != null && officialNai.equals(nai)) return true;
|
if (officialNai != null && officialNai.equals(nai)) return true;
|
||||||
if (officialNai != null || VDBG) {
|
if (officialNai != null || VDBG) {
|
||||||
loge(msg + " - isLiveNetworkAgent found mismatched netId: " + officialNai +
|
loge(msg + " - isLiveNetworkAgent found mismatched netId: " + officialNai +
|
||||||
@@ -2003,7 +1994,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
* to the link that may have incorrectly setup by the lower
|
* to the link that may have incorrectly setup by the lower
|
||||||
* levels.
|
* levels.
|
||||||
*/
|
*/
|
||||||
LinkProperties lp = getLinkPropertiesForTypeInternal(info.getType());
|
LinkProperties lp = getLinkPropertiesForType(info.getType());
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
log("EVENT_STATE_CHANGED: connected to provisioning network, lp=" + lp);
|
log("EVENT_STATE_CHANGED: connected to provisioning network, lp=" + lp);
|
||||||
}
|
}
|
||||||
@@ -2556,10 +2547,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (network == null) return;
|
if (network == null) return;
|
||||||
|
|
||||||
final int uid = Binder.getCallingUid();
|
final int uid = Binder.getCallingUid();
|
||||||
NetworkAgentInfo nai = null;
|
NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
|
||||||
synchronized (mNetworkForNetId) {
|
|
||||||
nai = mNetworkForNetId.get(network.netId);
|
|
||||||
}
|
|
||||||
if (nai == null) return;
|
if (nai == null) return;
|
||||||
if (DBG) log("reportBadNetwork(" + nai.name() + ") by " + uid);
|
if (DBG) log("reportBadNetwork(" + nai.name() + ") by " + uid);
|
||||||
synchronized (nai) {
|
synchronized (nai) {
|
||||||
@@ -2567,7 +2555,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// which isn't meant to work on uncreated networks.
|
// which isn't meant to work on uncreated networks.
|
||||||
if (!nai.created) return;
|
if (!nai.created) return;
|
||||||
|
|
||||||
if (isNetworkBlocked(nai, uid)) return;
|
if (isNetworkWithLinkPropertiesBlocked(nai.linkProperties, uid)) return;
|
||||||
|
|
||||||
nai.networkMonitor.sendMessage(NetworkMonitor.CMD_FORCE_REEVALUATION, uid);
|
nai.networkMonitor.sendMessage(NetworkMonitor.CMD_FORCE_REEVALUATION, uid);
|
||||||
}
|
}
|
||||||
@@ -4371,44 +4359,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
|
|
||||||
private LinkProperties getLinkPropertiesForTypeInternal(int networkType) {
|
|
||||||
NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
|
|
||||||
if (nai != null) {
|
|
||||||
synchronized (nai) {
|
|
||||||
return new LinkProperties(nai.linkProperties);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new LinkProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
private NetworkInfo getNetworkInfoForType(int networkType) {
|
|
||||||
if (!mLegacyTypeTracker.isTypeSupported(networkType))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
|
|
||||||
if (nai != null) {
|
|
||||||
NetworkInfo result = new NetworkInfo(nai.networkInfo);
|
|
||||||
result.setType(networkType);
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
NetworkInfo result = new NetworkInfo(
|
|
||||||
networkType, 0, ConnectivityManager.getNetworkTypeName(networkType), "");
|
|
||||||
result.setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, null, null);
|
|
||||||
result.setIsAvailable(true);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private NetworkCapabilities getNetworkCapabilitiesForType(int networkType) {
|
|
||||||
NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
|
|
||||||
if (nai != null) {
|
|
||||||
synchronized (nai) {
|
|
||||||
return new NetworkCapabilities(nai.networkCapabilities);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new NetworkCapabilities();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addVpnAddress(String address, int prefixLength) {
|
public boolean addVpnAddress(String address, int prefixLength) {
|
||||||
throwIfLockdownEnabled();
|
throwIfLockdownEnabled();
|
||||||
|
|||||||
@@ -1006,7 +1006,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
|
|||||||
info.setDetailedState(DetailedState.CONNECTED, null, null);
|
info.setDetailedState(DetailedState.CONNECTED, null, null);
|
||||||
final LinkProperties prop = new LinkProperties();
|
final LinkProperties prop = new LinkProperties();
|
||||||
prop.setInterfaceName(TEST_IFACE);
|
prop.setInterfaceName(TEST_IFACE);
|
||||||
return new NetworkState(info, prop, null, null, TEST_SSID);
|
return new NetworkState(info, prop, null, null, null, TEST_SSID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NetworkState buildMobile3gState(String subscriberId) {
|
private static NetworkState buildMobile3gState(String subscriberId) {
|
||||||
@@ -1015,7 +1015,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
|
|||||||
info.setDetailedState(DetailedState.CONNECTED, null, null);
|
info.setDetailedState(DetailedState.CONNECTED, null, null);
|
||||||
final LinkProperties prop = new LinkProperties();
|
final LinkProperties prop = new LinkProperties();
|
||||||
prop.setInterfaceName(TEST_IFACE);
|
prop.setInterfaceName(TEST_IFACE);
|
||||||
return new NetworkState(info, prop, null, subscriberId, null);
|
return new NetworkState(info, prop, null, null, subscriberId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NetworkState buildMobile4gState(String iface) {
|
private static NetworkState buildMobile4gState(String iface) {
|
||||||
@@ -1023,7 +1023,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
|
|||||||
info.setDetailedState(DetailedState.CONNECTED, null, null);
|
info.setDetailedState(DetailedState.CONNECTED, null, null);
|
||||||
final LinkProperties prop = new LinkProperties();
|
final LinkProperties prop = new LinkProperties();
|
||||||
prop.setInterfaceName(iface);
|
prop.setInterfaceName(iface);
|
||||||
return new NetworkState(info, prop, null);
|
return new NetworkState(info, prop, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private NetworkStats buildEmptyStats() {
|
private NetworkStats buildEmptyStats() {
|
||||||
|
|||||||
Reference in New Issue
Block a user