Merge "Add ConnectivityManager.reportNetworkConnectivity() API" into m-wireless-dev
This commit is contained in:
@@ -16980,7 +16980,8 @@ package android.net {
|
|||||||
method public void registerNetworkCallback(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback);
|
method public void registerNetworkCallback(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback);
|
||||||
method public void releaseNetworkRequest(android.app.PendingIntent);
|
method public void releaseNetworkRequest(android.app.PendingIntent);
|
||||||
method public void removeDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener);
|
method public void removeDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener);
|
||||||
method public void reportBadNetwork(android.net.Network);
|
method public deprecated void reportBadNetwork(android.net.Network);
|
||||||
|
method public void reportNetworkConnectivity(android.net.Network, boolean);
|
||||||
method public void requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback);
|
method public void requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback);
|
||||||
method public void requestNetwork(android.net.NetworkRequest, android.app.PendingIntent);
|
method public void requestNetwork(android.net.NetworkRequest, android.app.PendingIntent);
|
||||||
method public deprecated boolean requestRouteToHost(int, int);
|
method public deprecated boolean requestRouteToHost(int, int);
|
||||||
|
|||||||
@@ -18241,7 +18241,8 @@ package android.net {
|
|||||||
method public void registerNetworkCallback(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback);
|
method public void registerNetworkCallback(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback);
|
||||||
method public void releaseNetworkRequest(android.app.PendingIntent);
|
method public void releaseNetworkRequest(android.app.PendingIntent);
|
||||||
method public void removeDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener);
|
method public void removeDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener);
|
||||||
method public void reportBadNetwork(android.net.Network);
|
method public deprecated void reportBadNetwork(android.net.Network);
|
||||||
|
method public void reportNetworkConnectivity(android.net.Network, boolean);
|
||||||
method public void requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback);
|
method public void requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback);
|
||||||
method public void requestNetwork(android.net.NetworkRequest, android.app.PendingIntent);
|
method public void requestNetwork(android.net.NetworkRequest, android.app.PendingIntent);
|
||||||
method public deprecated boolean requestRouteToHost(int, int);
|
method public deprecated boolean requestRouteToHost(int, int);
|
||||||
|
|||||||
@@ -1708,10 +1708,33 @@ public class ConnectivityManager {
|
|||||||
*
|
*
|
||||||
* @param network The {@link Network} the application was attempting to use
|
* @param network The {@link Network} the application was attempting to use
|
||||||
* or {@code null} to indicate the current default network.
|
* or {@code null} to indicate the current default network.
|
||||||
|
* @deprecated Use {@link #reportNetworkConnectivity} which allows reporting both
|
||||||
|
* working and non-working connectivity.
|
||||||
*/
|
*/
|
||||||
public void reportBadNetwork(Network network) {
|
public void reportBadNetwork(Network network) {
|
||||||
try {
|
try {
|
||||||
mService.reportBadNetwork(network);
|
// One of these will be ignored because it matches system's current state.
|
||||||
|
// The other will trigger the necessary reevaluation.
|
||||||
|
mService.reportNetworkConnectivity(network, true);
|
||||||
|
mService.reportNetworkConnectivity(network, false);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report to the framework whether a network has working connectivity.
|
||||||
|
* This provides a hint to the system that a particular network is providing
|
||||||
|
* working connectivity or not. In response the framework may re-evaluate
|
||||||
|
* the network's connectivity and might take further action thereafter.
|
||||||
|
*
|
||||||
|
* @param network The {@link Network} the application was attempting to use
|
||||||
|
* or {@code null} to indicate the current default network.
|
||||||
|
* @param hasConnectivity {@code true} if the application was able to successfully access the
|
||||||
|
* Internet using {@code network} or {@code false} if not.
|
||||||
|
*/
|
||||||
|
public void reportNetworkConnectivity(Network network, boolean hasConnectivity) {
|
||||||
|
try {
|
||||||
|
mService.reportNetworkConnectivity(network, hasConnectivity);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ interface IConnectivityManager
|
|||||||
|
|
||||||
void reportInetCondition(int networkType, int percentage);
|
void reportInetCondition(int networkType, int percentage);
|
||||||
|
|
||||||
void reportBadNetwork(in Network network);
|
void reportNetworkConnectivity(in Network network, boolean hasConnectivity);
|
||||||
|
|
||||||
ProxyInfo getGlobalProxy();
|
ProxyInfo getGlobalProxy();
|
||||||
|
|
||||||
|
|||||||
@@ -2461,25 +2461,27 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
public void reportInetCondition(int networkType, int percentage) {
|
public void reportInetCondition(int networkType, int percentage) {
|
||||||
NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
|
NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
|
||||||
if (nai == null) return;
|
if (nai == null) return;
|
||||||
boolean isGood = percentage > 50;
|
reportNetworkConnectivity(nai.network, percentage > 50);
|
||||||
// Revalidate if the app report does not match our current validated state.
|
|
||||||
if (isGood != nai.lastValidated) {
|
|
||||||
// Make the message logged by reportBadNetwork below less confusing.
|
|
||||||
if (DBG && isGood) log("reportInetCondition: type=" + networkType + " ok, revalidate");
|
|
||||||
reportBadNetwork(nai.network);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportBadNetwork(Network network) {
|
public void reportNetworkConnectivity(Network network, boolean hasConnectivity) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
enforceInternetPermission();
|
enforceInternetPermission();
|
||||||
|
|
||||||
if (network == null) return;
|
NetworkAgentInfo nai;
|
||||||
|
if (network == null) {
|
||||||
final int uid = Binder.getCallingUid();
|
nai = getDefaultNetwork();
|
||||||
NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
|
} else {
|
||||||
|
nai = getNetworkAgentInfoForNetwork(network);
|
||||||
|
}
|
||||||
if (nai == null) return;
|
if (nai == null) return;
|
||||||
if (DBG) log("reportBadNetwork(" + nai.name() + ") by " + uid);
|
// Revalidate if the app report does not match our current validated state.
|
||||||
|
if (hasConnectivity == nai.lastValidated) return;
|
||||||
|
final int uid = Binder.getCallingUid();
|
||||||
|
if (DBG) {
|
||||||
|
log("reportNetworkConnectivity(" + nai.network.netId + ", " + hasConnectivity +
|
||||||
|
") by " + uid);
|
||||||
|
}
|
||||||
synchronized (nai) {
|
synchronized (nai) {
|
||||||
// Validating an uncreated network could result in a call to rematchNetworkAndRequests()
|
// Validating an uncreated network could result in a call to rematchNetworkAndRequests()
|
||||||
// which isn't meant to work on uncreated networks.
|
// which isn't meant to work on uncreated networks.
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
// If a network is not validated, make one attempt every 10 mins to see if it starts working.
|
// If a network is not validated, make one attempt every 10 mins to see if it starts working.
|
||||||
private static final int REEVALUATE_PAUSE_MS = 10*60*1000;
|
private static final int REEVALUATE_PAUSE_MS = 10*60*1000;
|
||||||
private static final int PERIODIC_ATTEMPTS = 1;
|
private static final int PERIODIC_ATTEMPTS = 1;
|
||||||
// When an application calls reportBadNetwork, only make one attempt.
|
// When an application calls reportNetworkConnectivity, only make one attempt.
|
||||||
private static final int REEVALUATE_ATTEMPTS = 1;
|
private static final int REEVALUATE_ATTEMPTS = 1;
|
||||||
private final int mReevaluateDelayMs;
|
private final int mReevaluateDelayMs;
|
||||||
private int mReevaluateToken = 0;
|
private int mReevaluateToken = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user