연결 진단 API를 사용하면 이동통신사 앱, VPN 앱 및 Wi-Fi 추천 앱과 같은 네트워크를 소유하거나 관리하는 앱이 프레임워크에서 네트워크 연결 진단 정보를 수신할 수 있습니다. 이러한 앱은 소유하거나 관리하는 네트워크의 연결 정보로 콜백을 등록하고 알림을 수신할 수 있습니다. 앱은 소유하거나 관리하지 않는 네트워크의 알림을 수신하지 않습니다.
다음은 네트워크를 관리하거나 소유하는 앱의 예입니다.
이동통신사 앱:subId가 이동통신사 권한을 갖는 모바일 네트워크를 관리합니다.
Wi-Fi 추천 앱: 시스템에 추천되는 Wi-Fi 네트워크를 소유합니다.
VPN 앱: 활성 VPN에서만 사용하는 모든 네트워크를 관리합니다.
콜백은 다음과 같은 경우에 호출됩니다.
네트워크 유효성 검사: 시스템에서 특정 네트워크 평가를 완료했습니다.
ConnectivityReport 클래스는 네트워크의 현재 상태와 유효성 검사의 일부로 실행된 테스트 또는 절차의 결과에 관한 정보를 제공합니다.
public class ConnectivityReport {
Network network;
long reportTimestamp;
LinkProperties linkProperties;
NetworkCapabilities networkCapabilities;
PersistableBundle additionalInfo;
}
데이터 스톨이 의심됨: IP 패킷이 네트워크에서 제대로 흐르지 않는 상태인 데이터 스톨이 의심됩니다. DataStallReport 클래스는 의심되는 데이터 스톨에 관한 정보를 제공합니다.
public class DataStallReport {
Network network;
long reportTimestamp;
int detectionMethod;
LinkProperties linkProperties;
NetworkCapabilities networkCapabilities;
PersistableBundle stallDetails;
}
다음은 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);
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-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)."]]