Starting March 27, 2025, we recommend using android-latest-release instead of aosp-main to build and contribute to AOSP. For more information, see Changes to AOSP.
Stay organized with collections
Save and categorize content based on your preferences.
The Connectivity Diagnostics API allows apps that own or manage networks, such
as carrier apps, VPN apps, and Wi-Fi suggestion apps, to receive diagnostic
network connectivity information from the framework. These apps can register
callbacks and receive notifications with connectivity information for the
networks that they own or manage. Apps won't receive notifications for networks
that aren't owned or managed by the app.
The following are examples of apps that manage or own networks:
Carrier apps: Manage cellular networks for which their subId
has carrier privileges for
Wi-Fi suggestion apps: Own Wi-Fi networks that they suggest to the
system
VPN apps: Manage all networks that their VPN uses, but only when
they are the active VPN
Callbacks are invoked in the following cases:
Network validation: The system finished evaluating a specific network.
The
ConnectivityReport
class provides information on the current state of the network and the
results of any tests or procedures performed as part of the validation.
public class ConnectivityReport {
Network network;
long reportTimestamp;
LinkProperties linkProperties;
NetworkCapabilities networkCapabilities;
PersistableBundle additionalInfo;
}
Data stall suspected: A data stall, a condition in which IP packets
aren't properly flowing through the network, is suspected. The
DataStallReport
class provides information about suspected data stalls.
public class DataStallReport {
Network network;
long reportTimestamp;
int detectionMethod;
LinkProperties linkProperties;
NetworkCapabilities networkCapabilities;
PersistableBundle stallDetails;
}
Connectivity reported: An app has reported connectivity through
ConnectivityManager#reportNetworkConnectivity
to the system. The network and reported connectivity (whether the app
believes the network does or doesn't provide connectivity) is shared.
Implementation
To use the Connectivity Diagnostics API, an app must obtain a
ConnectivityDiagnosticsManager
instance from the platform. This instance should be used to register and
unregister
ConnectivityDiagnosticsCallback
implementations. Callback methods that aren't overridden are no-ops.
Below is an example for registering and unregistering
ConnectivityDiagnosticsCallback:
NetworkRequestrequest=newNetworkRequest.Builder().addTransportType(TRANSPORT_CELLULAR).build();// Use an Executor that is appropriate for your use caseExecutorexecutor=Executors.newSingleThreadExecutor();ConnectivityDiagnosticsManagercdm=context.getSystemService(ConnectivityDiagnosticsManager.class);ExampleCallbackcallback=newExampleCallback();cdm.registerConnectivityDiagnosticsCallback(request,executor,callback);...// Collect connectivity information on networks that match with request...cdm.unregisterConnectivityDiagnosticsCallback(callback);
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-06-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-26 UTC."],[],[],null,["# Connectivity Diagnostics API\n\nThe Connectivity Diagnostics API allows apps that own or manage networks, such\nas carrier apps, VPN apps, and Wi-Fi suggestion apps, to receive diagnostic\nnetwork connectivity information from the framework. These apps can register\ncallbacks and receive notifications with connectivity information for the\nnetworks that they own or manage. Apps won't receive notifications for networks\nthat aren't owned or managed by the app.\n\nThe following are examples of apps that manage or own networks:\n\n- **Carrier apps:** Manage cellular networks for which their `subId` has carrier privileges for\n- **Wi-Fi suggestion apps:** Own Wi-Fi networks that they suggest to the system\n- **VPN apps:** Manage all networks that their VPN uses, but only when they are the active VPN\n\nCallbacks are invoked in the following cases:\n\n- **Network validation:** The system finished evaluating a specific network.\n The\n [`ConnectivityReport`](https://developer.android.com/reference/android/net/ConnectivityDiagnosticsManager.ConnectivityReport)\n class provides information on the current state of the network and the\n results of any tests or procedures performed as part of the validation.\n\n public class ConnectivityReport {\n Network network;\n long reportTimestamp;\n LinkProperties linkProperties;\n NetworkCapabilities networkCapabilities;\n PersistableBundle additionalInfo;\n }\n\n- **Data stall suspected:** A data stall, a condition in which IP packets\n aren't properly flowing through the network, is suspected. The\n [`DataStallReport`](https://developer.android.com/reference/android/net/ConnectivityDiagnosticsManager.DataStallReport)\n class provides information about suspected data stalls.\n\n public class DataStallReport {\n Network network;\n long reportTimestamp;\n int detectionMethod;\n LinkProperties linkProperties;\n NetworkCapabilities networkCapabilities;\n PersistableBundle stallDetails;\n }\n\n- **Connectivity reported:** An app has reported connectivity through\n [`ConnectivityManager#reportNetworkConnectivity`](https://developer.android.com/reference/android/net/ConnectivityManager#reportNetworkConnectivity(android.net.Network,%20boolean))\n to the system. The network and reported connectivity (whether the app\n believes the network does or doesn't provide connectivity) is shared.\n\nImplementation\n--------------\n\n| **Note:** Apps registering callbacks must have the [`ACCESS_FINE_LOCATION`](https://developer.android.com/reference/android/Manifest.permission#ACCESS_FINE_LOCATION) permission because connecting to location-specific networks can expose the fine location of the user.\n\nTo use the Connectivity Diagnostics API, an app must obtain a\n[`ConnectivityDiagnosticsManager`](https://developer.android.com/reference/android/net/ConnectivityDiagnosticsManager)\ninstance from the platform. This instance should be used to register and\nunregister\n[`ConnectivityDiagnosticsCallback`](https://developer.android.com/reference/android/net/ConnectivityDiagnosticsManager.ConnectivityDiagnosticsCallback)\nimplementations. Callback methods that aren't overridden are no-ops.\n\nBelow is an example of a\n[`ConnectivityDiagnosticsCallback`](https://developer.android.com/reference/android/net/ConnectivityDiagnosticsManager.ConnectivityDiagnosticsCallback)\nimplementation: \n\n public class ExampleCallback extends ConnectivityDiagnosticsCallback {\n @Override\n public void onConnectivityReportAvailable(@NonNull ConnectivityReport report) {\n ... \n // Log data, take action based on report result, etc\n ... \n }\n\n @Override\n public void onDataStallSuspected(@NonNull DataStallReport report) {\n ... \n // Log data, take action based on report result, etc\n ... \n }\n\n @Override\n public void onNetworkConnectivityReported(\n @NonNull Network network, boolean hasConnectivity) {\n ... \n // Log data, take action based on report result, etc\n ... \n }\n }\n\nTo register callbacks and receive notifications, call\n[`registerConnectivityDiagnosticsCallback`](https://developer.android.com/reference/android/net/ConnectivityDiagnosticsManager#registerConnectivityDiagnosticsCallback(android.net.NetworkRequest,%20java.util.concurrent.Executor,%20android.net.ConnectivityDiagnosticsManager.ConnectivityDiagnosticsCallback)).\nTo unregister callbacks and stop receiving notifications, call\n[`unregisterConnectivityDiagnosticsCallback`](https://developer.android.com/reference/android/net/ConnectivityDiagnosticsManager#unregisterConnectivityDiagnosticsCallback(android.net.ConnectivityDiagnosticsManager.ConnectivityDiagnosticsCallback)).\n| **Note:** The callbacks must be registered and unregistered using the same [`uid`](https://developer.android.com/reference/android/content/pm/ApplicationInfo.html#uid).\n\nBelow is an example for registering and unregistering\n`ConnectivityDiagnosticsCallback`: \n\n NetworkRequest request =\n new NetworkRequest.Builder()\n .addTransportType(TRANSPORT_CELLULAR)\n .build();\n // Use an Executor that is appropriate for your use case\n Executor executor = Executors.newSingleThreadExecutor();\n\n ConnectivityDiagnosticsManager cdm =\n context.getSystemService(ConnectivityDiagnosticsManager.class);\n\n ExampleCallback callback = new ExampleCallback();\n cdm.registerConnectivityDiagnosticsCallback(\n request, executor, callback);\n\n ... \n // Collect connectivity information on networks that match with request\n ... \n\n cdm.unregisterConnectivityDiagnosticsCallback(callback);\n\nValidation\n----------\n\nThe Connectivity Diagnostics API is CTS tested by\n[`ConnectivityDiagnosticsManagerTest`](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/modules/Connectivity/tests/cts/net/src/android/net/cts/ConnectivityDiagnosticsManagerTest.java)."]]