am e149ffe2: Add network callback logging to the Connectivity app in dev tools.
* commit 'e149ffe2e90a099dd2ea1446fc756cb464bc3c60': Add network callback logging to the Connectivity app in dev tools.
This commit is contained in:
@@ -28,8 +28,12 @@ import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.ConnectivityManager.NetworkCallback;
|
||||
import android.net.LinkAddress;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkRequest;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.RouteInfo;
|
||||
import android.net.wifi.ScanResult;
|
||||
@@ -254,6 +258,34 @@ public class Connectivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
private static class DevToolsNetworkCallback extends NetworkCallback {
|
||||
private static final String TAG = "DevToolsNetworkCallback";
|
||||
|
||||
public void onPreCheck(Network network) {
|
||||
Log.d(TAG, "onPreCheck: " + network.netId);
|
||||
}
|
||||
|
||||
public void onAvailable(Network network) {
|
||||
Log.d(TAG, "onAvailable: " + network.netId);
|
||||
}
|
||||
|
||||
public void onCapabilitiesChanged(Network network, NetworkCapabilities nc) {
|
||||
Log.d(TAG, "onCapabilitiesChanged: " + network.netId + " " + nc.toString());
|
||||
}
|
||||
|
||||
public void onLinkPropertiesChanged(Network network, LinkProperties lp) {
|
||||
Log.d(TAG, "onLinkPropertiesChanged: " + network.netId + " " + lp.toString());
|
||||
}
|
||||
|
||||
public void onLosing(Network network, int maxMsToLive) {
|
||||
Log.d(TAG, "onLosing: " + network.netId + " " + maxMsToLive);
|
||||
}
|
||||
|
||||
public void onLost(Network network) {
|
||||
Log.d(TAG, "onLost: " + network.netId);
|
||||
}
|
||||
}
|
||||
private DevToolsNetworkCallback mCallback;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
@@ -325,11 +357,20 @@ public class Connectivity extends Activity {
|
||||
|
||||
mLinkStatsResults = (TextView)findViewById(R.id.stats);
|
||||
mLinkStatsResults.setVisibility(View.VISIBLE);
|
||||
|
||||
NetworkRequest.Builder builder = new NetworkRequest.Builder();
|
||||
for (int i = 0; i < 255; i++) {
|
||||
try { builder.removeCapability(i); } catch (IllegalArgumentException e) {}
|
||||
}
|
||||
NetworkRequest request = builder.build();
|
||||
mCallback = new DevToolsNetworkCallback();
|
||||
mCm.registerNetworkCallback(request, mCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mCm.unregisterNetworkCallback(mCallback);
|
||||
unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user