Add log for debugging ConnectivityManager

Add log to ConnectivityManager for better investigations of issue.
This patch adds StackTrace to the following APIs.

reportInetCondition()
reportBadNetwork()
reportNetworkConnectivity()
sendRequestForNetwork()
requestNetwork()
releaseNetworkRequest()
registerNetworkCallback()
unregisterNetworkCallback()

Bug: 116751720
Change-Id: I992292cd9d6f3d69c91ddbde5577591f9ec0f39b
This commit is contained in:
Soi, Yoshinari
2015-11-12 12:09:02 +09:00
committed by Fen Wang
parent 39a51e0191
commit b8102ef4d7

View File

@@ -84,6 +84,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
@@ -2494,6 +2495,7 @@ public class ConnectivityManager {
* {@hide}
*/
public void reportInetCondition(int networkType, int percentage) {
printStackTrace();
try {
mService.reportInetCondition(networkType, percentage);
} catch (RemoteException e) {
@@ -2514,6 +2516,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.
@@ -2536,6 +2539,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) {
@@ -3074,6 +3078,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;
@@ -3333,6 +3338,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);
@@ -3356,6 +3362,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);
@@ -3440,6 +3447,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);
@@ -3521,6 +3529,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.
@@ -3953,4 +3962,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());
}
}
}