Class AndroidCAresInitializer
This class is responsible for providing Android's ConnectivityManager
to the native c-ares initialization code. On Android, c-ares needs access to
ConnectivityManager in order to resolve DNS servers correctly.
The actual CAresInitializer instance is owned and stored on the C++ side
as a process-wide global object. This Java class does not own a native handle and
does not manage native object lifetime directly.
Typical usage:
AndroidCAresInitializer.initialize(context);
The initialization should be performed once, early in the application or test process lifecycle, before any network or DNS requests are started.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidinitialize(android.content.Context context) Initializes native c-ares support for Android.
-
Method Details
-
initialize
public static void initialize(@NonNull android.content.Context context) Initializes native c-ares support for Android.This method obtains
ConnectivityManagerfrom the provided AndroidContextand passes it to the native c-ares initialization code.If c-ares has already been initialized on the native side, this method is expected to be a no-op.
- Parameters:
context- Android context used to accessConnectivityManager. The application context is preferred, but any valid context with access toContext.CONNECTIVITY_SERVICEcan be used.- Throws:
IllegalStateException- ifConnectivityManagercannot be obtained from the provided context.RuntimeException- if native c-ares initialization fails.
-