Bug 1588218 - Expose DNS suffix list (Android) r=michal,snorp

Differential Revision: https://phabricator.services.mozilla.com/D51561

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Valentin Gosu 2019-11-11 20:51:42 +00:00
Родитель 142c229418
Коммит f4d8a78639
2 изменённых файлов: 39 добавлений и 1 удалений

Просмотреть файл

@ -66,6 +66,8 @@ import android.location.LocationListener;
import android.location.LocationManager; import android.location.LocationManager;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -1231,6 +1233,27 @@ public class GeckoAppShell {
} }
} }
@WrapForJNI(calledFrom = "gecko")
private static String getDNSDomains() {
if (Build.VERSION.SDK_INT < 21) {
return "";
}
ConnectivityManager cm = (ConnectivityManager)
getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
Network net = cm.getActiveNetwork();
if (net == null) {
return "";
}
LinkProperties lp = cm.getLinkProperties(net);
if (lp == null) {
return "";
}
return lp.getDomains();
}
@WrapForJNI(calledFrom = "gecko") @WrapForJNI(calledFrom = "gecko")
private static int[] getSystemColors() { private static int[] getSystemColors() {
// attrsAppearance[] must correspond to AndroidSystemColors structure in android/AndroidBridge.h // attrsAppearance[] must correspond to AndroidSystemColors structure in android/AndroidBridge.h

Просмотреть файл

@ -134,7 +134,22 @@ nsAndroidNetworkLinkService::GetNetworkID(nsACString& aNetworkID) {
NS_IMETHODIMP NS_IMETHODIMP
nsAndroidNetworkLinkService::GetDnsSuffixList( nsAndroidNetworkLinkService::GetDnsSuffixList(
nsTArray<nsCString>& aDnsSuffixList) { nsTArray<nsCString>& aDnsSuffixList) {
return NS_ERROR_NOT_IMPLEMENTED; aDnsSuffixList.Clear();
if (!mozilla::AndroidBridge::Bridge()) {
NS_WARNING("GetDnsSuffixList is not supported without a bridge connection");
return NS_ERROR_NOT_AVAILABLE;
}
auto suffixList = java::GeckoAppShell::GetDNSDomains();
if (!suffixList) {
return NS_OK;
}
nsAutoCString list(suffixList->ToCString());
for (const nsACString& suffix : list.Split(',')) {
aDnsSuffixList.AppendElement(suffix);
}
return NS_OK;
} }
void nsAndroidNetworkLinkService::OnNetworkChanged() { void nsAndroidNetworkLinkService::OnNetworkChanged() {