Print human-readable OEM managed states
For NetworkTemplate and NetworkIdentity, print human-readable representations of the OEM managed state in the classes' respective toString() functions. Bug: 180557699 Test: Manual - run atest NetworkTemplateTest NetworkIdentityTest and verify that the logcat output shows the String representation of the OEM managed state correctly. Change-Id: Ia180b911f91f41937ac713e6b3691d82f682e146
This commit is contained in:
@@ -26,8 +26,10 @@ import android.service.NetworkIdentityProto;
|
||||
import android.telephony.Annotation.NetworkType;
|
||||
import android.util.proto.ProtoOutputStream;
|
||||
|
||||
import com.android.net.module.util.NetworkCapabilitiesUtils;
|
||||
import com.android.net.module.util.NetworkIdentityUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -121,11 +123,37 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
}
|
||||
builder.append(", metered=").append(mMetered);
|
||||
builder.append(", defaultNetwork=").append(mDefaultNetwork);
|
||||
// TODO(180557699): Print a human readable string for OEM managed state.
|
||||
builder.append(", oemManaged=").append(mOemManaged);
|
||||
builder.append(", oemManaged=").append(getOemManagedNames(mOemManaged));
|
||||
return builder.append("}").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the human readable representation of a bitfield representing the OEM managed state of a
|
||||
* network.
|
||||
*/
|
||||
static String getOemManagedNames(int oemManaged) {
|
||||
if (oemManaged == OEM_NONE) {
|
||||
return "OEM_NONE";
|
||||
}
|
||||
final int[] bitPositions = NetworkCapabilitiesUtils.unpackBits(oemManaged);
|
||||
final ArrayList<String> oemManagedNames = new ArrayList<String>();
|
||||
for (int position : bitPositions) {
|
||||
oemManagedNames.add(nameOfOemManaged(1 << position));
|
||||
}
|
||||
return String.join(",", oemManagedNames);
|
||||
}
|
||||
|
||||
private static String nameOfOemManaged(int oemManagedBit) {
|
||||
switch (oemManagedBit) {
|
||||
case OEM_PAID:
|
||||
return "OEM_PAID";
|
||||
case OEM_PRIVATE:
|
||||
return "OEM_PRIVATE";
|
||||
default:
|
||||
return "Invalid(" + oemManagedBit + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public void dumpDebug(ProtoOutputStream proto, long tag) {
|
||||
final long start = proto.start(tag);
|
||||
|
||||
|
||||
@@ -344,7 +344,7 @@ public class NetworkTemplate implements Parcelable {
|
||||
builder.append(", subType=").append(mSubType);
|
||||
}
|
||||
if (mOemManaged != OEM_MANAGED_ALL) {
|
||||
builder.append(", oemManaged=").append(mOemManaged);
|
||||
builder.append(", oemManaged=").append(getOemManagedNames(mOemManaged));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
@@ -640,6 +640,19 @@ public class NetworkTemplate implements Parcelable {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getOemManagedNames(int oemManaged) {
|
||||
switch (oemManaged) {
|
||||
case OEM_MANAGED_ALL:
|
||||
return "OEM_MANAGED_ALL";
|
||||
case OEM_MANAGED_NO:
|
||||
return "OEM_MANAGED_NO";
|
||||
case OEM_MANAGED_YES:
|
||||
return "OEM_MANAGED_YES";
|
||||
default:
|
||||
return NetworkIdentity.getOemManagedNames(oemManaged);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Examine the given template and normalize if it refers to a "merged"
|
||||
* mobile subscriber. We pick the "lowest" merged subscriber as the primary
|
||||
|
||||
Reference in New Issue
Block a user