Bug 1588218 - Expose DNS suffix list (Android) r=michal,snorp
authorValentin Gosu <valentin.gosu@gmail.com>
Thu, 14 Nov 2019 20:39:34 +0000
changeset 502048 2d2a7cb4d6ffcfd51552d08b1aff7fb1b04e3430
parent 502047 0a08184c5efec65571ba403e03bc9b983a436caf
child 502049 7a519aeac6438c53c2eec583b75a25f12dbf695c
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal, snorp
bugs1588218
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1588218 - Expose DNS suffix list (Android) r=michal,snorp Differential Revision: https://phabricator.services.mozilla.com/D51561
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
netwerk/system/android/nsAndroidNetworkLinkService.cpp
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -61,16 +61,18 @@ import android.hardware.SensorEvent;
 import android.hardware.SensorEventListener;
 import android.hardware.SensorManager;
 import android.location.Criteria;
 import android.location.Location;
 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;
 import android.os.LocaleList;
 import android.os.Looper;
 import android.os.PowerManager;
 import android.os.Vibrator;
 import android.provider.Settings;
@@ -1227,16 +1229,37 @@ public class GeckoAppShell {
             case TelephonyManager.NETWORK_TYPE_UNKNOWN:
             default:
                 Log.w(LOGTAG, "Connected to an unknown mobile network!");
                 return LINK_TYPE_UNKNOWN;
         }
     }
 
     @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
         final int[] attrsAppearance = {
             android.R.attr.textColor,
             android.R.attr.textColorPrimary,
             android.R.attr.textColorPrimaryInverse,
             android.R.attr.textColorSecondary,
             android.R.attr.textColorSecondaryInverse,
--- a/netwerk/system/android/nsAndroidNetworkLinkService.cpp
+++ b/netwerk/system/android/nsAndroidNetworkLinkService.cpp
@@ -129,17 +129,32 @@ nsAndroidNetworkLinkService::GetNetworkI
 
   mNetlinkSvc->GetNetworkID(aNetworkID);
   return NS_OK;
 }
 
 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() {
   if (mozilla::StaticPrefs::network_notify_changed()) {
     if (!mNetworkChangeTime.IsNull()) {
       mozilla::Telemetry::AccumulateTimeDelta(
           mozilla::Telemetry::NETWORK_TIME_BETWEEN_NETWORK_CHANGE_EVENTS,
           mNetworkChangeTime);