Merge "Implement INetworkMonitorCallbacks#notifyDataStallSuspected."
This commit is contained in:
@@ -68,6 +68,7 @@ import android.database.ContentObserver;
|
||||
import android.net.CaptivePortal;
|
||||
import android.net.ConnectionInfo;
|
||||
import android.net.ConnectivityDiagnosticsManager.ConnectivityReport;
|
||||
import android.net.ConnectivityDiagnosticsManager.DataStallReport;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.ICaptivePortal;
|
||||
import android.net.IConnectivityDiagnosticsCallback;
|
||||
@@ -3008,6 +3009,21 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
EVENT_PROVISIONING_NOTIFICATION, PROVISIONING_NOTIFICATION_HIDE, mNetId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyDataStallSuspected(
|
||||
long timestampMillis, int detectionMethod, PersistableBundle extras) {
|
||||
final Message msg =
|
||||
mConnectivityDiagnosticsHandler.obtainMessage(
|
||||
ConnectivityDiagnosticsHandler.EVENT_DATA_STALL_SUSPECTED,
|
||||
detectionMethod, mNetId, timestampMillis);
|
||||
msg.setData(new Bundle(extras));
|
||||
|
||||
// NetworkStateTrackerHandler currently doesn't take any actions based on data
|
||||
// stalls so send the message directly to ConnectivityDiagnosticsHandler and avoid
|
||||
// the cost of going through two handlers.
|
||||
mConnectivityDiagnosticsHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInterfaceVersion() {
|
||||
return this.VERSION;
|
||||
@@ -7559,6 +7575,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
*/
|
||||
private static final int EVENT_NETWORK_TESTED = ConnectivityService.EVENT_NETWORK_TESTED;
|
||||
|
||||
/**
|
||||
* Event for NetworkMonitor to inform ConnectivityService that a potential data stall has
|
||||
* been detected on the network.
|
||||
* obj = Long the timestamp (in millis) for when the suspected data stall was detected.
|
||||
* arg1 = {@link DataStallReport#DetectionMethod} indicating the detection method.
|
||||
* arg2 = NetID.
|
||||
* data = PersistableBundle of extras passed from NetworkMonitor.
|
||||
*/
|
||||
private static final int EVENT_DATA_STALL_SUSPECTED = 4;
|
||||
|
||||
private ConnectivityDiagnosticsHandler(Looper looper) {
|
||||
super(looper);
|
||||
}
|
||||
@@ -7589,6 +7615,17 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
handleNetworkTestedWithExtras(reportEvent, extras);
|
||||
break;
|
||||
}
|
||||
case EVENT_DATA_STALL_SUSPECTED: {
|
||||
final NetworkAgentInfo nai = getNetworkAgentInfoForNetId(msg.arg2);
|
||||
if (nai == null) break;
|
||||
|
||||
// This is safe because NetworkMonitorCallbacks#notifyDataStallSuspected
|
||||
// receives a PersistableBundle and converts it to the Bundle in the incoming
|
||||
// Message.
|
||||
final PersistableBundle extras = new PersistableBundle(msg.getData());
|
||||
handleDataStallSuspected(nai, (long) msg.obj, msg.arg1, extras);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7718,6 +7755,22 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDataStallSuspected(
|
||||
@NonNull NetworkAgentInfo nai, long timestampMillis, int detectionMethod,
|
||||
@NonNull PersistableBundle extras) {
|
||||
final DataStallReport report =
|
||||
new DataStallReport(nai.network, timestampMillis, detectionMethod, extras);
|
||||
final List<IConnectivityDiagnosticsCallback> results =
|
||||
getMatchingPermissionedCallbacks(nai);
|
||||
for (final IConnectivityDiagnosticsCallback cb : results) {
|
||||
try {
|
||||
cb.onDataStallSuspected(report);
|
||||
} catch (RemoteException ex) {
|
||||
loge("Error invoking onDataStallSuspected", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<IConnectivityDiagnosticsCallback> getMatchingPermissionedCallbacks(
|
||||
@NonNull NetworkAgentInfo nai) {
|
||||
final List<IConnectivityDiagnosticsCallback> results = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user