Merge "Include NetworkCapabilities and LinkProperties in DataStallReport."

This commit is contained in:
Cody Kesting
2020-02-12 16:38:38 +00:00
committed by Gerrit Code Review
3 changed files with 141 additions and 28 deletions

View File

@@ -252,8 +252,8 @@ public class ConnectivityDiagnosticsManager {
@NonNull PersistableBundle additionalInfo) { @NonNull PersistableBundle additionalInfo) {
mNetwork = network; mNetwork = network;
mReportTimestamp = reportTimestamp; mReportTimestamp = reportTimestamp;
mLinkProperties = linkProperties; mLinkProperties = new LinkProperties(linkProperties);
mNetworkCapabilities = networkCapabilities; mNetworkCapabilities = new NetworkCapabilities(networkCapabilities);
mAdditionalInfo = additionalInfo; mAdditionalInfo = additionalInfo;
} }
@@ -433,6 +433,12 @@ public class ConnectivityDiagnosticsManager {
/** The detection method used to identify the suspected data stall */ /** The detection method used to identify the suspected data stall */
@DetectionMethod private final int mDetectionMethod; @DetectionMethod private final int mDetectionMethod;
/** LinkProperties available on the Network at the reported timestamp */
@NonNull private final LinkProperties mLinkProperties;
/** NetworkCapabilities available on the Network at the reported timestamp */
@NonNull private final NetworkCapabilities mNetworkCapabilities;
/** PersistableBundle that may contain additional information on the suspected data stall */ /** PersistableBundle that may contain additional information on the suspected data stall */
@NonNull private final PersistableBundle mStallDetails; @NonNull private final PersistableBundle mStallDetails;
@@ -446,16 +452,23 @@ public class ConnectivityDiagnosticsManager {
* @param network The Network for which this DataStallReport applies * @param network The Network for which this DataStallReport applies
* @param reportTimestamp The timestamp for the report * @param reportTimestamp The timestamp for the report
* @param detectionMethod The detection method used to identify this data stall * @param detectionMethod The detection method used to identify this data stall
* @param linkProperties The LinkProperties available on network at reportTimestamp
* @param networkCapabilities The NetworkCapabilities available on network at
* reportTimestamp
* @param stallDetails A PersistableBundle that may contain additional info about the report * @param stallDetails A PersistableBundle that may contain additional info about the report
*/ */
public DataStallReport( public DataStallReport(
@NonNull Network network, @NonNull Network network,
long reportTimestamp, long reportTimestamp,
@DetectionMethod int detectionMethod, @DetectionMethod int detectionMethod,
@NonNull LinkProperties linkProperties,
@NonNull NetworkCapabilities networkCapabilities,
@NonNull PersistableBundle stallDetails) { @NonNull PersistableBundle stallDetails) {
mNetwork = network; mNetwork = network;
mReportTimestamp = reportTimestamp; mReportTimestamp = reportTimestamp;
mDetectionMethod = detectionMethod; mDetectionMethod = detectionMethod;
mLinkProperties = new LinkProperties(linkProperties);
mNetworkCapabilities = new NetworkCapabilities(networkCapabilities);
mStallDetails = stallDetails; mStallDetails = stallDetails;
} }
@@ -487,6 +500,26 @@ public class ConnectivityDiagnosticsManager {
return mDetectionMethod; return mDetectionMethod;
} }
/**
* Returns the LinkProperties available when this report was taken.
*
* @return LinkProperties available on the Network at the reported timestamp
*/
@NonNull
public LinkProperties getLinkProperties() {
return new LinkProperties(mLinkProperties);
}
/**
* Returns the NetworkCapabilities when this report was taken.
*
* @return NetworkCapabilities available on the Network at the reported timestamp
*/
@NonNull
public NetworkCapabilities getNetworkCapabilities() {
return new NetworkCapabilities(mNetworkCapabilities);
}
/** /**
* Returns a PersistableBundle with additional info for this report. * Returns a PersistableBundle with additional info for this report.
* *
@@ -513,12 +546,20 @@ public class ConnectivityDiagnosticsManager {
return mReportTimestamp == that.mReportTimestamp return mReportTimestamp == that.mReportTimestamp
&& mDetectionMethod == that.mDetectionMethod && mDetectionMethod == that.mDetectionMethod
&& mNetwork.equals(that.mNetwork) && mNetwork.equals(that.mNetwork)
&& mLinkProperties.equals(that.mLinkProperties)
&& mNetworkCapabilities.equals(that.mNetworkCapabilities)
&& persistableBundleEquals(mStallDetails, that.mStallDetails); && persistableBundleEquals(mStallDetails, that.mStallDetails);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(mNetwork, mReportTimestamp, mDetectionMethod, mStallDetails); return Objects.hash(
mNetwork,
mReportTimestamp,
mDetectionMethod,
mLinkProperties,
mNetworkCapabilities,
mStallDetails);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@@ -533,6 +574,8 @@ public class ConnectivityDiagnosticsManager {
dest.writeParcelable(mNetwork, flags); dest.writeParcelable(mNetwork, flags);
dest.writeLong(mReportTimestamp); dest.writeLong(mReportTimestamp);
dest.writeInt(mDetectionMethod); dest.writeInt(mDetectionMethod);
dest.writeParcelable(mLinkProperties, flags);
dest.writeParcelable(mNetworkCapabilities, flags);
dest.writeParcelable(mStallDetails, flags); dest.writeParcelable(mStallDetails, flags);
} }
@@ -544,6 +587,8 @@ public class ConnectivityDiagnosticsManager {
in.readParcelable(null), in.readParcelable(null),
in.readLong(), in.readLong(),
in.readInt(), in.readInt(),
in.readParcelable(null),
in.readParcelable(null),
in.readParcelable(null)); in.readParcelable(null));
} }

View File

@@ -7764,7 +7764,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
@NonNull NetworkAgentInfo nai, long timestampMillis, int detectionMethod, @NonNull NetworkAgentInfo nai, long timestampMillis, int detectionMethod,
@NonNull PersistableBundle extras) { @NonNull PersistableBundle extras) {
final DataStallReport report = final DataStallReport report =
new DataStallReport(nai.network, timestampMillis, detectionMethod, extras); new DataStallReport(
nai.network,
timestampMillis,
detectionMethod,
nai.linkProperties,
nai.networkCapabilities,
extras);
final List<IConnectivityDiagnosticsCallback> results = final List<IConnectivityDiagnosticsCallback> results =
getMatchingPermissionedCallbacks(nai); getMatchingPermissionedCallbacks(nai);
for (final IConnectivityDiagnosticsCallback cb : results) { for (final IConnectivityDiagnosticsCallback cb : results) {

View File

@@ -146,17 +146,14 @@ public class ConnectivityDiagnosticsManagerTest {
@Test @Test
public void testConnectivityReportEquals() { public void testConnectivityReportEquals() {
assertEquals(createSampleConnectivityReport(), createSampleConnectivityReport()); final ConnectivityReport defaultReport = createDefaultConnectivityReport();
assertEquals(createDefaultConnectivityReport(), createDefaultConnectivityReport()); final ConnectivityReport sampleReport = createSampleConnectivityReport();
assertEquals(sampleReport, createSampleConnectivityReport());
assertEquals(defaultReport, createDefaultConnectivityReport());
final LinkProperties linkProperties = new LinkProperties(); final LinkProperties linkProperties = sampleReport.getLinkProperties();
linkProperties.setInterfaceName(INTERFACE_NAME); final NetworkCapabilities networkCapabilities = sampleReport.getNetworkCapabilities();
final PersistableBundle bundle = sampleReport.getAdditionalInfo();
final NetworkCapabilities networkCapabilities = new NetworkCapabilities();
networkCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_IMS);
final PersistableBundle bundle = new PersistableBundle();
bundle.putString(BUNDLE_KEY, BUNDLE_VALUE);
assertNotEquals( assertNotEquals(
createDefaultConnectivityReport(), createDefaultConnectivityReport(),
@@ -206,39 +203,104 @@ public class ConnectivityDiagnosticsManagerTest {
} }
private DataStallReport createSampleDataStallReport() { private DataStallReport createSampleDataStallReport() {
final LinkProperties linkProperties = new LinkProperties();
linkProperties.setInterfaceName(INTERFACE_NAME);
final PersistableBundle bundle = new PersistableBundle(); final PersistableBundle bundle = new PersistableBundle();
bundle.putString(BUNDLE_KEY, BUNDLE_VALUE); bundle.putString(BUNDLE_KEY, BUNDLE_VALUE);
return new DataStallReport(new Network(NET_ID), TIMESTAMP, DETECTION_METHOD, bundle);
final NetworkCapabilities networkCapabilities = new NetworkCapabilities();
networkCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_IMS);
return new DataStallReport(
new Network(NET_ID),
TIMESTAMP,
DETECTION_METHOD,
linkProperties,
networkCapabilities,
bundle);
} }
private DataStallReport createDefaultDataStallReport() { private DataStallReport createDefaultDataStallReport() {
return new DataStallReport(new Network(0), 0L, 0, PersistableBundle.EMPTY); return new DataStallReport(
new Network(0),
0L,
0,
new LinkProperties(),
new NetworkCapabilities(),
PersistableBundle.EMPTY);
} }
@Test @Test
public void testDataStallReportEquals() { public void testDataStallReportEquals() {
assertEquals(createSampleDataStallReport(), createSampleDataStallReport()); final DataStallReport defaultReport = createDefaultDataStallReport();
assertEquals(createDefaultDataStallReport(), createDefaultDataStallReport()); final DataStallReport sampleReport = createSampleDataStallReport();
assertEquals(sampleReport, createSampleDataStallReport());
assertEquals(defaultReport, createDefaultDataStallReport());
final PersistableBundle bundle = new PersistableBundle(); final LinkProperties linkProperties = sampleReport.getLinkProperties();
bundle.putString(BUNDLE_KEY, BUNDLE_VALUE); final NetworkCapabilities networkCapabilities = sampleReport.getNetworkCapabilities();
final PersistableBundle bundle = sampleReport.getStallDetails();
assertNotEquals( assertNotEquals(
createDefaultDataStallReport(), defaultReport,
new DataStallReport(new Network(NET_ID), 0L, 0, PersistableBundle.EMPTY)); new DataStallReport(
new Network(NET_ID),
0L,
0,
new LinkProperties(),
new NetworkCapabilities(),
PersistableBundle.EMPTY));
assertNotEquals( assertNotEquals(
createDefaultDataStallReport(), defaultReport,
new DataStallReport(new Network(0), TIMESTAMP, 0, PersistableBundle.EMPTY)); new DataStallReport(
new Network(0),
TIMESTAMP,
0,
new LinkProperties(),
new NetworkCapabilities(),
PersistableBundle.EMPTY));
assertNotEquals( assertNotEquals(
createDefaultDataStallReport(), defaultReport,
new DataStallReport(new Network(0), 0L, DETECTION_METHOD, PersistableBundle.EMPTY)); new DataStallReport(
new Network(0),
0L,
DETECTION_METHOD,
new LinkProperties(),
new NetworkCapabilities(),
PersistableBundle.EMPTY));
assertNotEquals( assertNotEquals(
createDefaultDataStallReport(), new DataStallReport(new Network(0), 0L, 0, bundle)); defaultReport,
new DataStallReport(
new Network(0),
0L,
0,
linkProperties,
new NetworkCapabilities(),
PersistableBundle.EMPTY));
assertNotEquals(
defaultReport,
new DataStallReport(
new Network(0),
0L,
0,
new LinkProperties(),
networkCapabilities,
PersistableBundle.EMPTY));
assertNotEquals(
defaultReport,
new DataStallReport(
new Network(0),
0L,
0,
new LinkProperties(),
new NetworkCapabilities(),
bundle));
} }
@Test @Test
public void testDataStallReportParcelUnparcel() { public void testDataStallReportParcelUnparcel() {
assertParcelSane(createSampleDataStallReport(), 4); assertParcelSane(createSampleDataStallReport(), 6);
} }
@Test @Test