Merge changes I09167532,I7df77a99,I67797b3f,Ic27e706f
am: 796c9446f7
Change-Id: Ib54334f0147616e604d8852b368aaefb44df88ca
This commit is contained in:
@@ -28,6 +28,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* A POD object to represent attributes of a single L2 network entry.
|
||||
@@ -207,4 +208,52 @@ public class NetworkAttributes {
|
||||
public int hashCode() {
|
||||
return Objects.hash(assignedV4Address, groupHint, dnsAddresses, mtu);
|
||||
}
|
||||
|
||||
/** Pretty print */
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringJoiner resultJoiner = new StringJoiner(" ", "{", "}");
|
||||
final ArrayList<String> nullFields = new ArrayList<>();
|
||||
|
||||
if (null != assignedV4Address) {
|
||||
resultJoiner.add("assignedV4Addr :");
|
||||
resultJoiner.add(assignedV4Address.toString());
|
||||
} else {
|
||||
nullFields.add("assignedV4Addr");
|
||||
}
|
||||
|
||||
if (null != groupHint) {
|
||||
resultJoiner.add("groupHint :");
|
||||
resultJoiner.add(groupHint);
|
||||
} else {
|
||||
nullFields.add("groupHint");
|
||||
}
|
||||
|
||||
if (null != dnsAddresses) {
|
||||
resultJoiner.add("dnsAddr : [");
|
||||
for (final InetAddress addr : dnsAddresses) {
|
||||
resultJoiner.add(addr.getHostAddress());
|
||||
}
|
||||
resultJoiner.add("]");
|
||||
} else {
|
||||
nullFields.add("dnsAddr");
|
||||
}
|
||||
|
||||
if (null != mtu) {
|
||||
resultJoiner.add("mtu :");
|
||||
resultJoiner.add(mtu.toString());
|
||||
} else {
|
||||
nullFields.add("mtu");
|
||||
}
|
||||
|
||||
if (!nullFields.isEmpty()) {
|
||||
resultJoiner.add("; Null fields : [");
|
||||
for (final String field : nullFields) {
|
||||
resultJoiner.add(field);
|
||||
}
|
||||
resultJoiner.add("]");
|
||||
}
|
||||
|
||||
return resultJoiner.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,4 +128,19 @@ public class SameL3NetworkResponse {
|
||||
public int hashCode() {
|
||||
return Objects.hash(l2Key1, l2Key2, confidence);
|
||||
}
|
||||
|
||||
@Override
|
||||
/** Pretty print */
|
||||
public String toString() {
|
||||
switch (getNetworkSameness()) {
|
||||
case NETWORK_SAME:
|
||||
return "\"" + l2Key1 + "\" same L3 network as \"" + l2Key2 + "\"";
|
||||
case NETWORK_DIFFERENT:
|
||||
return "\"" + l2Key1 + "\" different L3 network from \"" + l2Key2 + "\"";
|
||||
case NETWORK_NEVER_CONNECTED:
|
||||
return "\"" + l2Key1 + "\" can't be tested against \"" + l2Key2 + "\"";
|
||||
default:
|
||||
return "Buggy sameness value ? \"" + l2Key1 + "\", \"" + l2Key2 + "\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ import android.annotation.NonNull;
|
||||
public class Status {
|
||||
public static final int SUCCESS = 0;
|
||||
|
||||
public static final int ERROR_DATABASE_CANNOT_BE_OPENED = -1;
|
||||
|
||||
public final int resultCode;
|
||||
|
||||
public Status(final int resultCode) {
|
||||
@@ -47,4 +49,14 @@ public class Status {
|
||||
public boolean isSuccess() {
|
||||
return SUCCESS == resultCode;
|
||||
}
|
||||
|
||||
/** Pretty print */
|
||||
@Override
|
||||
public String toString() {
|
||||
switch (resultCode) {
|
||||
case SUCCESS: return "SUCCESS";
|
||||
case ERROR_DATABASE_CANNOT_BE_OPENED: return "DATABASE CANNOT BE OPENED";
|
||||
default: return "Unknown value ?!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
44
core/java/android/net/ipmemorystore/Utils.java
Normal file
44
core/java/android/net/ipmemorystore/Utils.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.ipmemorystore;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
|
||||
/** {@hide} */
|
||||
public class Utils {
|
||||
/** Pretty print */
|
||||
public static String blobToString(final Blob blob) {
|
||||
final StringBuilder sb = new StringBuilder("Blob : [");
|
||||
if (blob.data.length <= 24) {
|
||||
appendByteArray(sb, blob.data, 0, blob.data.length);
|
||||
} else {
|
||||
appendByteArray(sb, blob.data, 0, 16);
|
||||
sb.append("...");
|
||||
appendByteArray(sb, blob.data, blob.data.length - 8, blob.data.length);
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// Adds the hex representation of the array between the specified indices (inclusive, exclusive)
|
||||
private static void appendByteArray(@NonNull final StringBuilder sb, @NonNull final byte[] ar,
|
||||
final int from, final int to) {
|
||||
for (int i = from; i < to; ++i) {
|
||||
sb.append(String.format("%02X", ar[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user