Merge "Add log for debugging ConnectivityManager"
This commit is contained in:
@@ -83,6 +83,7 @@ import java.util.Map;
|
||||
@SystemService(Context.CONNECTIVITY_SERVICE)
|
||||
public class ConnectivityManager {
|
||||
private static final String TAG = "ConnectivityManager";
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
/**
|
||||
* A change in network connectivity has occurred. A default connection has either
|
||||
@@ -2493,6 +2494,7 @@ public class ConnectivityManager {
|
||||
* {@hide}
|
||||
*/
|
||||
public void reportInetCondition(int networkType, int percentage) {
|
||||
printStackTrace();
|
||||
try {
|
||||
mService.reportInetCondition(networkType, percentage);
|
||||
} catch (RemoteException e) {
|
||||
@@ -2513,6 +2515,7 @@ public class ConnectivityManager {
|
||||
*/
|
||||
@Deprecated
|
||||
public void reportBadNetwork(Network network) {
|
||||
printStackTrace();
|
||||
try {
|
||||
// One of these will be ignored because it matches system's current state.
|
||||
// The other will trigger the necessary reevaluation.
|
||||
@@ -2535,6 +2538,7 @@ public class ConnectivityManager {
|
||||
* Internet using {@code network} or {@code false} if not.
|
||||
*/
|
||||
public void reportNetworkConnectivity(Network network, boolean hasConnectivity) {
|
||||
printStackTrace();
|
||||
try {
|
||||
mService.reportNetworkConnectivity(network, hasConnectivity);
|
||||
} catch (RemoteException e) {
|
||||
@@ -3073,6 +3077,7 @@ public class ConnectivityManager {
|
||||
|
||||
private NetworkRequest sendRequestForNetwork(NetworkCapabilities need, NetworkCallback callback,
|
||||
int timeoutMs, int action, int legacyType, CallbackHandler handler) {
|
||||
printStackTrace();
|
||||
checkCallbackNotNull(callback);
|
||||
Preconditions.checkArgument(action == REQUEST || need != null, "null NetworkCapabilities");
|
||||
final NetworkRequest request;
|
||||
@@ -3332,6 +3337,7 @@ public class ConnectivityManager {
|
||||
* {@link NetworkCapabilities#NET_CAPABILITY_CAPTIVE_PORTAL}.
|
||||
*/
|
||||
public void requestNetwork(NetworkRequest request, PendingIntent operation) {
|
||||
printStackTrace();
|
||||
checkPendingIntentNotNull(operation);
|
||||
try {
|
||||
mService.pendingRequestForNetwork(request.networkCapabilities, operation);
|
||||
@@ -3355,6 +3361,7 @@ public class ConnectivityManager {
|
||||
* corresponding NetworkRequest you'd like to remove. Cannot be null.
|
||||
*/
|
||||
public void releaseNetworkRequest(PendingIntent operation) {
|
||||
printStackTrace();
|
||||
checkPendingIntentNotNull(operation);
|
||||
try {
|
||||
mService.releasePendingNetworkRequest(operation);
|
||||
@@ -3439,6 +3446,7 @@ public class ConnectivityManager {
|
||||
*/
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
||||
public void registerNetworkCallback(NetworkRequest request, PendingIntent operation) {
|
||||
printStackTrace();
|
||||
checkPendingIntentNotNull(operation);
|
||||
try {
|
||||
mService.pendingListenForNetwork(request.networkCapabilities, operation);
|
||||
@@ -3520,6 +3528,7 @@ public class ConnectivityManager {
|
||||
* @param networkCallback The {@link NetworkCallback} used when making the request.
|
||||
*/
|
||||
public void unregisterNetworkCallback(NetworkCallback networkCallback) {
|
||||
printStackTrace();
|
||||
checkCallbackNotNull(networkCallback);
|
||||
final List<NetworkRequest> reqs = new ArrayList<>();
|
||||
// Find all requests associated to this callback and stop callback triggers immediately.
|
||||
@@ -3948,4 +3957,19 @@ public class ConnectivityManager {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
private void printStackTrace() {
|
||||
if (DEBUG) {
|
||||
final StackTraceElement[] callStack = Thread.currentThread().getStackTrace();
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
for (int i = 3; i < callStack.length; i++) {
|
||||
final String stackTrace = callStack[i].toString();
|
||||
if (stackTrace == null || stackTrace.contains("android.os")) {
|
||||
break;
|
||||
}
|
||||
sb.append(" [").append(stackTrace).append("]");
|
||||
}
|
||||
Log.d(TAG, "StackLog:" + sb.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user