Bug 1272101 - Fix nsINetworkInfoService implementation on Android to use Linux C APIs instead of Android Java APIs. r=snorp
authorKannan Vijayan <kvijayan@mozilla.com>
Thu, 02 Jun 2016 16:42:36 -0400
changeset 339265 ddb08c99af9a3909c97a7f0ba8924477c20434b1
parent 339264 a2f23b6058a275e8239a5edeeda56830afdb584f
child 339266 b1647e5d98a4e470949361f8e0211c496c68a358
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1272101
milestone49.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 1272101 - Fix nsINetworkInfoService implementation on Android to use Linux C APIs instead of Android Java APIs. r=snorp
mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
mobile/android/base/java/org/mozilla/gecko/NetworkInfoService.java
mobile/android/base/moz.build
mobile/android/installer/package-manifest.in
netwerk/base/NetworkInfoServiceAndroid.jsm
netwerk/base/moz.build
netwerk/base/nsNetworkInfoService.js
netwerk/base/nsNetworkInfoService.manifest
netwerk/build/nsNetModule.cpp
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -150,17 +150,16 @@ public class GeckoApplication extends Ap
         FilePicker.init(context);
         DownloadsIntegration.init();
         HomePanelsManager.getInstance().init(context);
 
         // This getInstance call will force initialization of the NotificationHelper, but does nothing with the result
         NotificationHelper.getInstance(context).init();
 
         MulticastDNSManager.getInstance(context).init();
-        NetworkInfoService.getInstance(context).init();
 
         // Make sure that all browser-ish applications default to the real LocalBrowserDB.
         // GeckoView consumers use their own Application class, so this doesn't affect them.
         //
         // We need to do this before any access to the profile; it controls
         // which database class is used.
         //
         // As such, this needs to occur before the GeckoView in GeckoApp is inflated -- i.e., in the
deleted file mode 100644
--- a/mobile/android/base/java/org/mozilla/gecko/NetworkInfoService.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko;
-
-import org.mozilla.gecko.EventDispatcher;
-import org.mozilla.gecko.util.EventCallback;
-import org.mozilla.gecko.util.NativeEventListener;
-import org.mozilla.gecko.util.NativeJSObject;
-import org.mozilla.gecko.util.ThreadUtils;
-
-import org.json.JSONArray;
-
-import android.content.Context;
-import android.os.Build;
-import android.support.annotation.UiThread;
-import android.util.Log;
-
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Set;
-
-public class NetworkInfoService implements NativeEventListener {
-    static final String LOGTAG = "NetworkInfoService";
-    static NetworkInfoService instance = null;
-
-    static final String MSG_LIST_NETWORK_ADDRESSES = "NetworkInfoService:ListNetworkAddresses";
-    static final String MSG_GET_HOSTNAME = "NetworkInfoService:GetHostname";
-
-    public static NetworkInfoService getInstance(final Context context) {
-        if (instance == null) {
-            instance = new NetworkInfoService(context);
-        }
-        return instance;
-    }
-
-    NetworkInfoService(final Context context) {
-    }
-
-    @UiThread
-    public void init() {
-        ThreadUtils.assertOnUiThread();
-        EventDispatcher.getInstance().registerGeckoThreadListener(this,
-                MSG_LIST_NETWORK_ADDRESSES,
-                MSG_GET_HOSTNAME);
-    }
-
-    @UiThread
-    public void tearDown() {
-        ThreadUtils.assertOnUiThread();
-        EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
-                MSG_LIST_NETWORK_ADDRESSES,
-                MSG_GET_HOSTNAME);
-    }
-
-    @Override
-    public void handleMessage(final String event, final NativeJSObject message,
-                              final EventCallback callback)
-    {
-        Log.v(LOGTAG, "handleMessage: " + event);
-
-        switch (event) {
-            case MSG_LIST_NETWORK_ADDRESSES: {
-                handleListNetworkAddresses(callback);
-                break;
-            }
-            case MSG_GET_HOSTNAME: {
-                handleGetHostname(callback);
-                break;
-            }
-        }
-    }
-
-    void handleListNetworkAddresses(final EventCallback callback) {
-        Set<String> addresses = new HashSet<String>();
-        try {
-            Enumeration<NetworkInterface> ifaceEnum = NetworkInterface.getNetworkInterfaces();
-            if (ifaceEnum != null) {
-                while (ifaceEnum.hasMoreElements()) {
-                    NetworkInterface iface = ifaceEnum.nextElement();
-                    Enumeration<InetAddress> addrList = iface.getInetAddresses();
-                    while (addrList.hasMoreElements()) {
-                        InetAddress addr = addrList.nextElement();
-                        addresses.add(addr.getHostAddress());
-                    }
-                }
-            }
-        } catch (SocketException exc) {
-            callback.sendError(-1);
-            return;
-        }
-
-        JSONArray array = new JSONArray();
-        for (String addr : addresses) {
-            array.put(addr);
-        }
-        callback.sendSuccess(array);
-    }
-
-    void handleGetHostname(final EventCallback callback) {
-        // callback.sendError(-1);
-        callback.sendSuccess(getDeviceName());
-    }
-
-    private static String getDeviceName() {
-        String manufacturer = Build.MANUFACTURER;
-        String model = Build.MODEL;
-        if (model.startsWith(manufacturer)) {
-            return capitalize(model);
-        }
-        return capitalize(manufacturer) + " " + model;
-    }
-
-    private static String capitalize(String str) {
-        if (str.length() <= 1)
-            return str;
-
-        // Capitalize the manufacturer's first letter.
-        char ch0 = str.charAt(0);
-        if (Character.isLetter(ch0) && Character.isLowerCase(ch0)) {
-            boolean upcase = true;
-            // But don't capitalize the first letter if it's an 'i' followed
-            // by a non-lowercase letter.  Sheesh.
-            if (ch0 == 'i') {
-                if (str.length() >= 2) {
-                    char ch1 = str.charAt(1);
-                    if (!Character.isLetter(ch1) || !Character.isLowerCase(ch1)) {
-                        upcase = false;
-                    }
-                }
-            }
-            if (upcase) {
-                return Character.toUpperCase(ch0) + str.substring(1);
-            }
-        }
-        return str;
-    }
-
-}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -464,17 +464,16 @@ gbjar.sources += ['java/org/mozilla/geck
     'menu/GeckoMenuItem.java',
     'menu/GeckoSubMenu.java',
     'menu/MenuItemActionBar.java',
     'menu/MenuItemDefault.java',
     'menu/MenuItemSwitcherLayout.java',
     'menu/MenuPanel.java',
     'menu/MenuPopup.java',
     'MotionEventInterceptor.java',
-    'NetworkInfoService.java',
     'NotificationClient.java',
     'NotificationHandler.java',
     'NotificationHelper.java',
     'notifications/WhatsNewReceiver.java',
     'NotificationService.java',
     'NSSBridge.java',
     'OrderedBroadcastHelper.java',
     'overlays/OverlayConstants.java',
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -257,18 +257,16 @@
 @BINPATH@/components/xpcom_xpti.xpt
 @BINPATH@/components/xpconnect.xpt
 @BINPATH@/components/xulapp.xpt
 @BINPATH@/components/xul.xpt
 @BINPATH@/components/xultmpl.xpt
 @BINPATH@/components/zipwriter.xpt
 
 ; JavaScript components
-@BINPATH@/components/nsNetworkInfoService.manifest
-@BINPATH@/components/nsNetworkInfoService.js
 @BINPATH@/components/ChromeNotifications.js
 @BINPATH@/components/ChromeNotifications.manifest
 @BINPATH@/components/ConsoleAPI.manifest
 @BINPATH@/components/ConsoleAPIStorage.js
 @BINPATH@/components/ContactManager.js
 @BINPATH@/components/ContactManager.manifest
 @BINPATH@/components/PhoneNumberService.js
 @BINPATH@/components/PhoneNumberService.manifest
deleted file mode 100644
--- a/netwerk/base/NetworkInfoServiceAndroid.jsm
+++ /dev/null
@@ -1,67 +0,0 @@
-// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-"use strict";
-
-this.EXPORTED_SYMBOLS = ["NetworkInfoServiceAndroid"];
-
-const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
-
-Cu.import("resource://gre/modules/Messaging.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/AndroidLog.jsm");
-
-var log = AndroidLog.d.bind(null, "NetworkInfoServiceAndroid");
-
-const FAILURE_INTERNAL_ERROR = -65537;
-const MSG_TAG = 'NetworkInfoService';
-
-// Helper function for sending commands to Java.
-function send(type, data, callback) {
-  if (type[0] == ":") {
-    type = MSG_TAG + type;
-  }
-  let msg = { type };
-
-  for (let i in data) {
-    try {
-      msg[i] = data[i];
-    } catch (e) {
-    }
-  }
-
-  Messaging.sendRequestForResult(msg)
-    .then(result => callback(result, null),
-          err => callback(null, typeof err === "number" ? err : FAILURE_INTERNAL_ERROR));
-}
-
-class NetworkInfoServiceAndroid {
-  constructor() {
-  }
-
-  listNetworkAddresses(aListener) {
-    send(":ListNetworkAddresses", {}, (result, err) => {
-      if (err) {
-        log("ListNetworkAddresses Failed: (" + err + ")");
-        aListener.onListNetworkAddressesFailed();
-      } else {
-        log("ListNetworkAddresses Succeeded: (" + JSON.stringify(result) + ")");
-        aListener.onListedNetworkAddresses(result);
-      }
-    });
-  }
-
-  getHostname(aListener) {
-    send(":GetHostname", {}, (result, err) => {
-      if (err) {
-        log("GetHostname Failed: (" + err + ")");
-        aListener.onGetHostnameFailed();
-      } else {
-        log("GetHostname Succeeded: (" + JSON.stringify(result) + ")");
-        aListener.onGotHostname(result);
-      }
-    });
-  }
-}
--- a/netwerk/base/moz.build
+++ b/netwerk/base/moz.build
@@ -289,22 +289,19 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'co
         'nsNetworkInfoService.cpp',
     ]
 elif CONFIG['OS_TARGET'] == 'Linux':
     SOURCES += [
         'NetworkInfoServiceLinux.cpp',
         'nsNetworkInfoService.cpp',
     ]
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
-    EXTRA_COMPONENTS += [
-        'nsNetworkInfoService.js',
-        'nsNetworkInfoService.manifest'
-    ]
-    EXTRA_JS_MODULES += [
-        'NetworkInfoServiceAndroid.jsm',
+    SOURCES += [
+        'NetworkInfoServiceLinux.cpp',
+        'nsNetworkInfoService.cpp',
     ]
 
 if CONFIG['MOZ_ENABLE_QTNETWORK']:
     SOURCES += [
     ]
 
 EXTRA_COMPONENTS += [
     'PACGenerator.js',
deleted file mode 100644
--- a/netwerk/base/nsNetworkInfoService.js
+++ /dev/null
@@ -1,56 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-"use strict";
-
-const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
-
-Cu.import('resource://gre/modules/Services.jsm');
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-
-Cu.import("resource://gre/modules/NetworkInfoServiceAndroid.jsm");
-
-const NETWORKINFOSERVICE_CID = Components.ID("{0d8245af-d5d3-4100-a6b5-1cc026aa19f2}");
-const NETWORKINFOSERVICE_CONTRACT_ID = "@mozilla.org/network-info-service;1";
-
-function log(aMsg) {
-  dump("-*- nsNetworkInfoService.js : " + aMsg + "\n");
-}
-
-function setQueryInterface(cls, ...aQIList) {
-  cls.prototype.QueryInterface = XPCOMUtils.generateQI(aQIList);
-}
-
-class nsNetworkInfoService {
-  constructor() {
-    this.impl = new NetworkInfoServiceAndroid();
-    log("nsNetworkInfoService");
-  }
-
-  listNetworkAddresses(aListener) {
-    this.impl.listNetworkAddresses({
-        onListNetworkAddressesFailed(err) {
-            aListener.onListNetworkAddressesFailed();
-        },
-        onListedNetworkAddresses(addresses) {
-            aListener.onListedNetworkAddresses(addresses, addresses.length);
-        }
-    });
-  }
-
-  getHostname(aListener) {
-    this.impl.getHostname({
-        onGetHostnameFailed(err) {
-            aListener.onGetHostnameFailed();
-        },
-        onGotHostname(hostname) {
-            aListener.onGotHostname(hostname);
-        }
-    });
-  }
-}
-setQueryInterface(nsNetworkInfoService, Ci.nsISupportsWeakReference,
-                  Ci.nsINetworkInfoService);
-nsNetworkInfoService.prototype.classID = NETWORKINFOSERVICE_CID;
-
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsNetworkInfoService]);
deleted file mode 100644
--- a/netwerk/base/nsNetworkInfoService.manifest
+++ /dev/null
@@ -1,4 +0,0 @@
-# nsNetworkInfoService.js
-
-component {0d8245af-d5d3-4100-a6b5-1cc026aa19f2} nsNetworkInfoService.js
-contract @mozilla.org/network-info-service;1 {0d8245af-d5d3-4100-a6b5-1cc026aa19f2}
--- a/netwerk/build/nsNetModule.cpp
+++ b/netwerk/build/nsNetModule.cpp
@@ -42,18 +42,17 @@
 #include "mozilla/net/NeckoChild.h"
 
 #include "nsNetCID.h"
 
 #ifndef XP_MACOSX
 #define BUILD_BINHEX_DECODER 1
 #endif
 
-#if defined(XP_MACOSX) || defined(XP_WIN) || \
-    (defined(XP_LINUX) && !defined(MOZ_WIDGET_ANDROID))
+#if defined(XP_MACOSX) || defined(XP_WIN) || defined(XP_LINUX)
 #define BUILD_NETWORK_INFO_SERVICE 1
 #endif
 
 typedef nsCategoryCache<nsIContentSniffer> ContentSnifferCache;
 ContentSnifferCache* gNetSniffers = nullptr;
 ContentSnifferCache* gDataSniffers = nullptr;
 
 ///////////////////////////////////////////////////////////////////////////////