Minor fixes to NetworkCapabilities#toString.

1. The current code only prints the array of administrator UIDs
   if it's empty. This is clearly an oversight. Print it only if
   it's non-empty.
2. Only print requestor UID and package name if they are set.
   This makes output shorter in the common case that they are
   unset.
3. Reorder the output at the end: group all UIDs together, and
   place SSID and private DNS broken bit after that.
4. Make the private DNS broken indication a single word instead
   of a sentence. This saves space and makes it easier to write
   regexps.

New format:
... SignalStrength: -72 OwnerUid: 1000 AdminUids: [1000] SSID: ...
... Uid: 1000 RequestorUid: 1000 RequestorPkg: android ...

Test: manual
Change-Id: I2f5ccc1d9e4af6ddacc4d193185a17723822972b
This commit is contained in:
Lorenzo Colitti
2020-11-16 09:34:52 +09:00
parent 459ad2aa4b
commit 1ea1cda675

View File

@@ -1802,20 +1802,26 @@ public final class NetworkCapabilities implements Parcelable {
sb.append(" OwnerUid: ").append(mOwnerUid);
}
if (mAdministratorUids.length == 0) {
sb.append(" AdministratorUids: ").append(Arrays.toString(mAdministratorUids));
if (!ArrayUtils.isEmpty(mAdministratorUids)) {
sb.append(" AdminUids: ").append(Arrays.toString(mAdministratorUids));
}
if (mRequestorUid != Process.INVALID_UID) {
sb.append(" RequestorUid: ").append(mRequestorUid);
}
if (mRequestorPackageName != null) {
sb.append(" RequestorPkg: ").append(mRequestorPackageName);
}
if (null != mSSID) {
sb.append(" SSID: ").append(mSSID);
}
if (mPrivateDnsBroken) {
sb.append(" Private DNS is broken");
}
sb.append(" RequestorUid: ").append(mRequestorUid);
sb.append(" RequestorPackageName: ").append(mRequestorPackageName);
if (mPrivateDnsBroken) {
sb.append(" PrivateDnsBroken");
}
sb.append("]");
return sb.toString();