Invoke onConnectivityReport on registering ConnectivityDiagnostics.
This change updates the behavior for registering ConnectivityDiagnosticsCallbacks. Now, after a successful register() call, callbacks will receive cached ConnectivityReports for all matching, permissioned networks. This allows registrants to be updated with the network state for their networks without having to wait for the next network validation. Bug: 147849853 Test: atest FrameworksNetTests Change-Id: I924ba8fdcc847f453557021591bde38602fe089c Merged-In: I924ba8fdcc847f453557021591bde38602fe089c (cherry picked from commit 95ec0b206b759e1d26bc1dbb2255a515bb24358a)
This commit is contained in:
@@ -7855,6 +7855,34 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
cb.asBinder().linkToDeath(cbInfo, 0);
|
||||
} catch (RemoteException e) {
|
||||
cbInfo.binderDied();
|
||||
return;
|
||||
}
|
||||
|
||||
// Once registered, provide ConnectivityReports for matching Networks
|
||||
final List<NetworkAgentInfo> matchingNetworks = new ArrayList<>();
|
||||
synchronized (mNetworkForNetId) {
|
||||
for (int i = 0; i < mNetworkForNetId.size(); i++) {
|
||||
final NetworkAgentInfo nai = mNetworkForNetId.valueAt(i);
|
||||
if (nai.satisfies(nri.request)) {
|
||||
matchingNetworks.add(nai);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final NetworkAgentInfo nai : matchingNetworks) {
|
||||
final ConnectivityReport report = nai.getConnectivityReport();
|
||||
if (report == null) {
|
||||
continue;
|
||||
}
|
||||
if (!checkConnectivityDiagnosticsPermissions(
|
||||
nri.mPid, nri.mUid, nai, cbInfo.mCallingPackageName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
cb.onConnectivityReportAvailable(report);
|
||||
} catch (RemoteException e) {
|
||||
// Exception while sending the ConnectivityReport. Move on to the next network.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7890,6 +7918,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
nai.linkProperties,
|
||||
networkCapabilities,
|
||||
extras);
|
||||
nai.setConnectivityReport(report);
|
||||
final List<IConnectivityDiagnosticsCallback> results =
|
||||
getMatchingPermissionedCallbacks(nai);
|
||||
for (final IConnectivityDiagnosticsCallback cb : results) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.server.connectivity;
|
||||
|
||||
import static android.net.ConnectivityDiagnosticsManager.ConnectivityReport;
|
||||
import static android.net.NetworkCapabilities.transportNamesOf;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
@@ -243,6 +244,9 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
||||
// How many of the satisfied requests are of type BACKGROUND_REQUEST.
|
||||
private int mNumBackgroundNetworkRequests = 0;
|
||||
|
||||
// The last ConnectivityReport made available for this network.
|
||||
private ConnectivityReport mConnectivityReport;
|
||||
|
||||
public final Messenger messenger;
|
||||
public final AsyncChannel asyncChannel;
|
||||
|
||||
@@ -621,6 +625,30 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
||||
for (LingerTimer timer : mLingerTimers) { pw.println(timer); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the most recent ConnectivityReport for this network.
|
||||
*
|
||||
* <p>This should only be called from the ConnectivityService thread.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public void setConnectivityReport(@NonNull ConnectivityReport connectivityReport) {
|
||||
mConnectivityReport = connectivityReport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the most recent ConnectivityReport for this network, or null if none have been
|
||||
* reported yet.
|
||||
*
|
||||
* <p>This should only be called from the ConnectivityService thread.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@Nullable
|
||||
public ConnectivityReport getConnectivityReport() {
|
||||
return mConnectivityReport;
|
||||
}
|
||||
|
||||
// TODO: Print shorter members first and only print the boolean variable which value is true
|
||||
// to improve readability.
|
||||
public String toString() {
|
||||
|
||||
Reference in New Issue
Block a user