Merge "Shorten the output of NetworkAgentInfo#toString()."
diff --git a/core/java/android/net/NetworkInfo.java b/core/java/android/net/NetworkInfo.java
index 08fe159..d752901 100644
--- a/core/java/android/net/NetworkInfo.java
+++ b/core/java/android/net/NetworkInfo.java
@@ -22,6 +22,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.telephony.Annotation.NetworkType;
+import android.text.TextUtils;
import com.android.internal.annotations.VisibleForTesting;
@@ -538,7 +539,7 @@
@Override
public String toString() {
synchronized (this) {
- StringBuilder builder = new StringBuilder("[");
+ final StringBuilder builder = new StringBuilder("[");
builder.append("type: ").append(getTypeName()).append("[").append(getSubtypeName()).
append("], state: ").append(mState).append("/").append(mDetailedState).
append(", reason: ").append(mReason == null ? "(unspecified)" : mReason).
@@ -551,6 +552,32 @@
}
}
+ /**
+ * Returns a brief summary string suitable for debugging.
+ * @hide
+ */
+ public String toShortString() {
+ synchronized (this) {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(getTypeName());
+
+ final String subtype = getSubtypeName();
+ if (!TextUtils.isEmpty(subtype)) {
+ builder.append("[").append(subtype).append("]");
+ }
+
+ builder.append(" ");
+ builder.append(mDetailedState);
+ if (mIsRoaming) {
+ builder.append(" ROAMING");
+ }
+ if (mExtraInfo != null) {
+ builder.append(" extra: ").append(mExtraInfo);
+ }
+ return builder.toString();
+ }
+ }
+
@Override
public int describeContents() {
return 0;
diff --git a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
index 2f04715..f844844 100644
--- a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
+++ b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
@@ -621,22 +621,23 @@
for (LingerTimer timer : mLingerTimers) { pw.println(timer); }
}
- // TODO: Print shorter members first and only print the boolean variable which value is true
- // to improve readability.
public String toString() {
- return "NetworkAgentInfo{ ni{" + networkInfo + "} "
- + "network{" + network + "} nethandle{" + network.getNetworkHandle() + "} "
- + "lp{" + linkProperties + "} "
- + "nc{" + networkCapabilities + "} Score{" + getCurrentScore() + "} "
- + "everValidated{" + everValidated + "} lastValidated{" + lastValidated + "} "
- + "created{" + created + "} lingering{" + isLingering() + "} "
- + "explicitlySelected{" + networkAgentConfig.explicitlySelected + "} "
- + "acceptUnvalidated{" + networkAgentConfig.acceptUnvalidated + "} "
- + "everCaptivePortalDetected{" + everCaptivePortalDetected + "} "
- + "lastCaptivePortalDetected{" + lastCaptivePortalDetected + "} "
- + "partialConnectivity{" + partialConnectivity + "} "
- + "acceptPartialConnectivity{" + networkAgentConfig.acceptPartialConnectivity + "} "
- + "clat{" + clatd + "} "
+ return "NetworkAgentInfo{"
+ + "network{" + network + "} handle{" + network.getNetworkHandle() + "} ni{"
+ + networkInfo.toShortString() + "} "
+ + " Score{" + getCurrentScore() + "} "
+ + (isLingering() ? " lingering" : "")
+ + (everValidated ? " everValidated" : "")
+ + (lastValidated ? " lastValidated" : "")
+ + (partialConnectivity ? " partialConnectivity" : "")
+ + (everCaptivePortalDetected ? " everCaptivePortal" : "")
+ + (lastCaptivePortalDetected ? " isCaptivePortal" : "")
+ + (networkAgentConfig.explicitlySelected ? " explicitlySelected" : "")
+ + (networkAgentConfig.acceptUnvalidated ? " acceptUnvalidated" : "")
+ + (networkAgentConfig.acceptPartialConnectivity ? " acceptPartialConnectivity" : "")
+ + (clatd.isStarted() ? " clat{" + clatd + "} " : "")
+ + " lp{" + linkProperties + "}"
+ + " nc{" + networkCapabilities + "}"
+ "}";
}