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
parent 142c229418
commit f4d8a78639
2 changed files with 39 additions and 1 deletions

View File

@ -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 < 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")
private static int[] getSystemColors() {
// attrsAppearance[] must correspond to AndroidSystemColors structure in android/AndroidBridge.h

View File

@ -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() {