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-14 20:39:34 +00:00
Родитель 733458951b
Коммит 33ffe027d9
2 изменённых файлов: 39 добавлений и 1 удалений

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

@ -66,6 +66,8 @@ import android.location.LocationListener;
import android.location.LocationManager;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
@ -1231,6 +1233,27 @@ public class GeckoAppShell {
}
}
@WrapForJNI(calledFrom = "gecko")
private static String getDNSDomains() {
if (Build.VERSION.SDK_INT < 23) {
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")
private static int[] getSystemColors() {
// attrsAppearance[] must correspond to AndroidSystemColors structure in android/AndroidBridge.h

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

@ -134,7 +134,22 @@ nsAndroidNetworkLinkService::GetNetworkID(nsACString& aNetworkID) {
NS_IMETHODIMP
nsAndroidNetworkLinkService::GetDnsSuffixList(
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() {