ABS 2013: Dive into Android Networking - Adding Ethernet Connectivity

Benjamin Zores
Benjamin ZoresSoftware Architect at Benjamin Zores
Dive Into Android Networking:
Adding Ethernet Connectivity
Benjamin Zores
ABS 2013 – 19th February 2013 – San Francisco, CA

                                                               1

                                      COPYRIGHT © 2012 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
About Me

               ANDROID PLATFORM ARCHITECT

   ALCATEL     • Expert and Evangelist on Open Source Software.
   LUCENT      • 9y experience on various multimedia/network embedded devices design.
               • From low-level BSP integration to global applicative software architecture.


               PROJECT FOUNDER, LEADER AND/OR CONTRIBUTOR FOR:

               • OpenBricks                     Embedded Linux cross-build framework.
    OPEN
               • GeeXboX                        Embedded multimedia HTPC distribution.
   SOURCE      • uShare                         UPnP A/V and DLNA Media Server.
               • MPlayer                        Linux media player application.



               FORMER LINUX FOUNDATION’S EVENTS SPEAKER

    LINUX      • ELC     2010                   GeeXboX Enna: Embedded Media Center
 FOUNDATION    • ELC-E   2010                   State of Multimedia in 2010 Embedded Linux Devices
 CONFERENCES   • ELC-E   2011                   Linux Optimization Techniques: How Not to Be Slow ?
               • ABS     2012                   Android Device Porting Walkthrough
               • ELC-E   2012                   Dive Into Android Networking: Adding Ethernet Connectivity

                                                          2

                                COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Bibliographical References


                                                                                 My Android bibles,
                                                                             from my Android mentors:

                                                                                   Karim Yaghmour
                                                                                   Marko Gargenta




   Followed by my own publications:
       « Discovering Android »

     Series of articles published in
    GNU/Linux Magazine France


                                                     3

                           COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Android Supported Connectivity Means


• Mobile (i.e. GSM / EDGE / HSDPA / LTE) ans its siblings:
  - Mobile MMS (Multimedia Messaging Service)
  - Mobile SUPL (Secure User Plan Location)
  - Mobile DUN (Dial Up Networking [bridge])
  - Mobile HIPRI (High Priority)
• Wi-Fi
• WiMax
• Bluetooth
• Ethernet (really ??)



                                                       4

                             COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Android Networking Architecture


• Kernel Drivers (Ethernet, Wi-Fi, Bluetooth, WiMax …)
• Kernel TCP/IP layer with POSIX user-space API support.
• Android Hardware Abstraction Layer (HAL)
• Android Bionic C library (not 100% POSIX …)
• Android libnetutils (Network Utilities)
• Android Netd (Network Daemon)
• Android ConnectivityManager and ConnectivityService
  (part of the Java Framework).
• Android Java Apps



                                                      5

                            COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Bionic C Library


• No /etc/network/interfaces support.
• No /etc/nsswitch.conf support.
• No /etc/resolv.conf support.
• Everything (IP, DNS, router, proxy …) is property-based
  - Available through getprop/setprop commands




                                                      6

                            COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Netd and libnetutils


• Netd
 - Mostly provides tethering capabilities.
 - Accepts commands through UNIX socket.
 - Can be controlled by apps or ndc command.
 - Features bandwidth control, IP forwarding, NAT/PAN for SoftAP …


• Libnetutils
 - Low-level interface control interface
 - Provides API to ifconfig / netcfg / route / dhcpcd
 - Used by HAL and system framework to control network interfaces.



                                                         7

                               COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
ConnectivityManager and ConnectivityService


• Orchestrate and manage global networking at Java framework level.
• Rely on underlying libnetutils and netd services to control hardware.
• Interact with interface-specific managers (WifiManager …).


• Role and Duties:
  - Track and monitor various network connectivity interfaces
    (Mobile, Bluetooth, Wi-Fi …)
  - Notify registered apps (through Intent broadcasting)
    of a system connectivity state change.
  - Switch from one network type to another when connection is lost.
  - Provide an interface for apps to retrieve all possible connections’ states.

                                                          8

                                COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Radio Layer Interface


• Communicates with
  broadband processor for
  both voice and data.

• Uses RIL and proprietary
  rild to interface with
  system.

• Data connection
  is exported by
  Connectivity Manager
  through TYPE_MOBILE_*


                                                       9

                             COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Bluetooth Interface

• Communicates with BT
  chipset through BlueZ
  and libbluedroid.

• Provides both audio
  and data management.

• Data connection
  is exported by
  Connectivity Manager
  through
  TYPE_BLUETOOTH.

• Interface with netd
  for tethering.


                                                   10

                          COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
NFC Interface




• Introduced with Ice Cream Sandwich for Near Field Communication.
• Rely on NFC HAL.
• Currently only support chips from NXP (PN544).
• Uses Android Beam for P2P data exchange.
• Doesn’t interface with Connectivity Service/Manager.

                                                     11

                            COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
WiFi Station/AP/P2P Interface




• Rely on HAL for specific driver interface with JNI binding.
• Data connection is exported by Connectivity Manager through TYPE_WIFI.
• WiFi configuration is stored in file system and SQLite database.

                                                        12

                               COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity




       So what about Ethernet ??




                                                13

                       COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Work Context


• Designing an Enterprise Desktop IP Phone.

• Differs heavily from usual Android devices:
  - Always connected, no battery
  - No Radio (GSM/CDMA).
  - No WiFi Station mode, AP only.
  - LAN through Ethernet PHY/Switch.
  - Always docked, no screen rotation.
  - No accelerometer, no GPS …
  - => Not a Smartphone



                                                       14

                              COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Give Unto Caesar What is Caesar's …




     Most of the work
    presented hereafter
       is courtesy of

      Fabien Brisset




                                                15

                       COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Android Ethernet Upstream Status

• Ethernet is supported through native Linux kernel drivers.

• ifconfig / netcfg / ping commands work but remain at platform level.

• Regular /etc/resolv.conf DNS is not supported due to Bionic host resolution.

• Native system daemons (C/C++) support regular Linux networking API.

• Java framework services and apps rely on Connectivity Manager
  and have no clue what Ethernet route/connection actually means.
  - Except for some apps (e.g. Browser, which relies on native implementation).

• Barely no Android device features Ethernet
  - Except from some obscure Chinese tablets.

• Ethernet connection type exists in ICS API.
  - But with no Connectivity Manager or Connectivity Service implementation.


                                                            16

                                   COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Enterprise Requirements & ECM Status



• Enterprise Requirements:
 - Reliability: Ensuring data connection works in 100% cases
   for all possible applications.
 - HTTP(S) seamless proxy support for all applications.
 - Corporate firewalls prevents some services behavior (e.g. NTP).
   - Need to ensure everything stays behind the walls.
 - Ethernet 802.1x authentication.


• Ethernet Connectivity Manager (ECM) Status
 - ECM patch has been done by Android-x86 team for netbooks.
   - Not 100% accurate or sufficient.


                                                          17

                                 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Ethernet Interface – ECM Patch Status




• Mismatch in implementation towards WiFi.
• Rely on DHCPCd dhcp implementation instead of libnetutils.
• Not completely bind on Connectivity Manager and Service.
                                                          18

                                 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Am I Connected or What ?


• Changes in Android framework, Settings app and System UI.
• Supports DHCP (ECM patch default) and Static IP (added) addressing.
• Connection status is available in notification bar.




                                                       19

                              COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
ECM Patch Additions

• Register Ethernet Service
  - In framework's core/java/android/app/ContextImpl.java:


    registerService(ETHERNET_SERVICE, new ServiceFetcher() {
       public Object createService(ContextImpl ctx) {
         IBinder b = ServiceManager.getService(ETHERNET_SERVICE);
         IEthernetManager srv = IEthernetManager.Stub.asInterface(b);
         return new EthernetManager(srv, ctx.mMainThread.getHandler());
    }});


• Letting Connectivity Service know about Ethernet:
  - In framework's services/java/com/android/server/ConnectivityService.java:


   [...] else if (networkType == ConnectivityManager.TYPE_ETHERNET)
                    usedNetworkType = ConnectivityManager.TYPE_ETHERNET;




                                                            20

                                   COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
ECM Patch Additions

• Forcing default network preferences:
    - In framework's core/java/android/net/ConnectivityManager.java:


-      public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;
+      public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_ETHERNET;


Issue: Android public API is being modified and make update-api is required.


    - In framework's packages/SettingsProvider/res/values/defaults.xml:


-      <integer name="def_network_preference">1</integer>
+      <integer name="def_network_preference">9</integer>


    - In framework's services/java/com/android/server/EthernetService.java:

-      Settings.Secure.putString(cr, Settings.Secure.ETHERNET_IFNAME, DevName[0]);
+      Settings.Secure.putString(cr, Settings.Secure.ETHERNET_IFNAME, "eth0");


                                                               21

                                      COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity




       And now, bugs and workarounds
            for various use cases:

      Making Ethernet 100% functional.




                                                22

                       COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Connection Information




                                   Symptom:

   What is my Ethernet IP configuration or MAC address info ?
                                                  23

                         COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Connection Information – IP Address

• In Settings's res/xml/device_info_status.xml:
    <Preference android:key="ethernet_ip_address"
        style="?android:attr/preferenceInformationStyle"
        android:title="@string/ethernet_advanced_ip_address_title"
        android:summary="@string/device_info_not_available"
        android:persistent="false" />

• In src/com/android/settings/deviceinfo/Status.java:
    private void setEthernetIpAddressStatus() {
         EthernetManager mgr = getSystemService(ETHERNET_SERVICE);
         EthernetDevInfo info = mgr.getSavedConfig();
         Preference ip = findPreference("ethernet_ip_address");
         String addr = null;
         if (info != null) {
             if (info.getIpAddress() != null)
                 addr = info.getIpAddress();
             else
                 addr = SystemProperties.get("dhcp.eth0.ipaddress");
         }
         ip.setSummary(!TextUtils.isEmpty(addr) ? Addr :
             getString(R.string.status_unavailable));
    }

                                                           24

                                  COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Connection Information – MAC Address

• In framework's JNI code core/jni/android_net_ethernet.cpp:

   {"getInterfaceMacAddress", "()Ljava/lang/String;",
          (void *)android_net_ethernet_getInterfaceMacAddress},
   [...]
   static jstring android_net_ethernet_getInterfaceMacAddress(JNIEnv *env, jobject clazz) {
       struct ifreq ifr;
       strcpy (ifr.ifr_name, "eth0");
       strcpy (ifr.ifr_hwaddr.sa_data, "");
       sock = socket (AF_INET, SOCK_STREAM, 0);
       ioctl (sock, SIOCGIFHWADDR, &ifr);
       ptr = (unsigned char *) ifr.ifr_hwaddr.sa_data;
       snprintf (buf, 64, "%02x:%02x:%02x:%02x:%02x:%02x",
            (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
            (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377));
       return env->NewStringUTF(buf);
   }




                                                           25

                                  COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Connection Information – MAC Address

• In Settings' res/xml/device_info_status.xml:
    <Preference android:key="ethernet_mac_address"
        style="?android:attr/preferenceInformationStyle"
        android:title="@string/status_ethernet_mac_address"
        android:summary="@string/device_info_not_available"
        android:persistent="false" />



• In Settings’ src/com/android/settings/deviceinfo/Status.java:
   private void setEthernetMacAddress() {
       EthernetManager mgr = getSystemService(ETHERNET_SERVICE);
       EthernetDevInfo info = mgr.getSavedConfig();
       Preference mac = findPreference("ethernet_mac_address");
       String addr = info == null ? null : info.getMacAddress();
       mac.setSummary(!TextUtils.isEmpty(addr) ? addr
               : getString(R.string.status_unavailable));
   }




                                                          26

                                 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Android DNS Entry Management

                                                        Symptom:
              DHCP can't seem to provide me with valid DNS entries.

•   Match Android process (AID) authorizations to update system properties in init's init/property_service.c:

     { "rw.",                  AID_SYSTEM,       0 },
     { "net.",                 AID_DHCP,         0 },


•   In DHCPCD's dhcpcd-hooks/20-dns.conf:

      for dnsaddr in ${new_domain_name_servers}; do
          setprop dhcp.${interface}.dns${count} ${dnsaddr}
+         setprop net.dns${count} ${dnsaddr}
+         setprop net.${interface}.dns${count} ${dnsaddr}
          count=$(($count + 1))
      done


• In framework's ethernet/java/android/net/ethernet/EthernetStateTracker.java:

    SystemProperties.set("net.dns1", mDhcpInfo.dns1);
    SystemProperties.set("net." + mInterfaceName + ".dns1", mDhcpInfo.dns1);




                                                                      27

                                             COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
HTTP(S) Proxy




                                 Symptom:

                   I'm behind HTTP(S) proxy.
         I need my apps to seamlessly know about that !

                                                28

                       COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
HTTP(S) Proxy

• Overlay frameworks/base/core/res/res/values/config.xml:


   <string name="config_default_proxy_host" translatable="false">a.b.c.d</string>
   <integer name="config_default_proxy_port" translatable="false">8080</integer>




• In framework’s services/java/com/android/server/ConnectivityService.java:
   String proxyHost = context.getResources().getString(
              com.android.internal.R.string.config_default_proxy_host);
   int proxyPort = context.getResources().getInteger(
              com.android.internal.R.integer.config_default_proxy_port);
   mGlobalProxy = new ProxyProperties(proxyHost, proxyPort, null);
   SystemProperties.set("net.http.proxy", proxyHost + ":" + proxyPort);




                                                          29

                                 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Custom NTP Server




                                  Symptom:

     I'm behind corporate firewall and can't do NTP request.
          My company provides its internal NTP server.

                                                 30

                        COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Custom NTP Server

• Overlay frameworks/base/core/res/res/values/config.xml:
      <!-- Remote server that can provide NTP responses. -->
      <string translatable="false" name="config_ntpServer">a.b.c.d</string>
      <!-- Timeout to wait for NTP server response. -->
      <integer name="config_ntpTimeout">20000</integer>


• In framework's core/java/android/util/NtpTrustedTime.java:
-      final String defaultServer =
            res.getString(com.android.internal.R.string.config_ntpServer);
+      String defaultServer = Settings.System.getString(resolver, Settings.System.NTP_SERVER);


• In framework's services/java/com/android/server/NetworkTimeUpdateService.java:
    - Force NTP update on Ethernet state change:
      if (netInfo.getState() == NetworkInfo.State.CONNECTED &&
            netInfo.getType() == ConnectivityManager.TYPE_ETHERNET)
          mHandler.obtainMessage(EVENT_ETHERNET_CONNECTED).sendToTarget();
      [...]
      case EVENT_WIFI_CONNECTED:
      case EVENT_ETHERNET_CONNECTED:
         onPollNetworkTime(msg.what);

                                                                            31

                                                   COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Custom NTP Server

• In Settings's res/xml/date_time_prefs.xml:


   <EditTextPreference
       android:title="@string/ntp_server_time"
       android:key="ntp_server"
       android:singleLine="true"
       android:summary="192.168.1.1"
       android:inputType="textUri"/>




• In Settings' src/com/android/settings/DateTimeSettings.java:
   EditTextPreference pref = findPreference("ntp_server");
   String server =
         Settings.System.getString(getContentResolver(), Settings.System.NTP_SERVER);
   pref.setText(server);
   pref.setSummary(server);




                                                           32

                                  COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Email

                                           Symptom:

                    I can't download email attachments.



• In src/com/android/email/AttachmentInfo.java:
- if (networkType != ConnectivityManager.TYPE_WIFI) {
+ if ((networkType != ConnectivityManager.TYPE_WIFI) &&
         (networkType != ConnectivityManager.TYPE_ETHERNET)) {




• In src/com/android/email/service/AttachmentDownloadService.java:
- if (ecm.getActiveNetworkType() != ConnectivityManager.TYPE_WIFI) {
+ if ((ecm.getActiveNetworkType() != ConnectivityManager.TYPE_WIFI) &&
      (ecm.getActiveNetworkType() != ConnectivityManager.TYPE_ETHERNET)) {




                                                          33

                                 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Connectivity Route




                                  Symptom:

               I can't access to Google Play Store.
                   The application just crash !
                                                 34

                        COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Connectivity Route


Reverse engineering
apps may help:

• Dex2jar
 - Extracts usable classes.jar
   from APK archives.
 - See http://code.google.com/p/dex2jar/



• Java Decompiler (jd-gui)
 - See http://java.decompiler.free.fr/?q=jdgui




                                                               35

                                      COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Connectivity Route

• Many (certified?) apps assume that WiFi or mobile connection is always present.
    - We need to trick the system for Ethernet.

    - But this is truly an ugly hack.


• In framework's services/java/com/android/server/ConnectivityService.java:
      public NetworkInfo getNetworkInfo(int networkType, int uid) {
-         return getNetworkInfo(networkType, uid);
+         switch (networkType) {
+             case ConnectivityManager.TYPE_MOBILE:
+             case ConnectivityManager.TYPE_WIFI:
+             case ConnectivityManager.TYPE_WIMAX:
+                 networkType = ConnectivityManager.TYPE_ETHERNET;
+                 break;
+             default:
+                 break;
+         }
+        return getNetworkInfo(networkType, uid);
      }

• Android shouldn't expose WiFi Manager API !
    - Apps should always go through Connectivity Manager for all network information.


• Limitations:
    - Connectivity Manager API can't configure default connection type (currently hardcoded).

    - Too few information on existing devices' connectivity states.


                                                                               36

                                                      COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Download Provider

                                                  Symptom:

          My browser works fine but I just can't download files.



• In DownloadProvider's src/com/android/providers/downloads/DownloadInfo.java:
  - Add Ethernet connectivity support


  case ConnectivityManager.TYPE_ETHERNET:
     return DownloadManager.Request.NETWORK_ETHERNET;
  [...]
  if (networkType == ConnectivityManager.TYPE_ETHERNET) {
     return NETWORK_OK; // anything goes over ethernet
  }




                                                                 37

                                        COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Multimedia Streaming

                                                                             Symptom:

                              My browser works fine but I can't play multimedia contents.


• Force Chrome HTTP stack instead of Android HTTP stack.
    -   By default, Stagefright can't bypass proxy (see frameworks/base/media/libstagefright/Android.mk)

    -   Overlay in your device's device.mk file:        HTTP := chrome


•   In framework's media/libstagefright/chromium_http/support.cpp:
    char value[PROPERTY_VALUE_MAX];
    property_get("net.http.proxy", value, "Unknown");

    net::ProxyConfigServiceAndroid cfg = new net::ProxyConfigServiceAndroid();
    if (strcmp(value_proxy,"Unknown") != 0) {
       std::string proxy = value;
       cfg->UpdateProxySettings(proxy, "");
    }

    set_proxy_service(net::ProxyService::CreateWithoutProxyResolver(cfg, net_log()));

•   In framework's services/java/com/android/server/ConnectivityService.java:
    -   Optionally force proxy detection in proprietary OMX Codecs:

    SystemProperties.set("net.proxy", host + ":" + port);
    SystemProperties.set("rw.HTTP_PROXY", "http://" + host + ":" + port);



                                                                                       38

                                                              COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Phone / SIP VoIP

                                                           Symptom:

                        I can do VoIP SIP calls over WiFi but not over Ethernet.

• Overlay frameworks/base/core/res/res/values/config.xml:
  <bool name="config_sip_ethernet">true</bool>


• In framework's voip/java/android/net/sip/SipManager.java:
  public static boolean isSipEthernet(Context context) {
      return context.getResources().getBoolean(com.android.internal.R.bool.config_sip_ethernet);
  }


• In framework's voip/java/com/android/server/sip/SipService.java:
  boolean mSipOnWifiOnly = SipManager.isSipWifiOnly(context);
  boolean mSipEthernet = SipManager.isSipEthernet(context);

  boolean connected = (info != null && info.isConnected() &&
            ((!mSipOnWifiOnly || info.getType() == ConnectivityManager.TYPE_WIFI) ||
              ( mSipEthernet   && info.getType() == ConnectivityManager.TYPE_ETHERNET));


• In Phone's src/com/android/phone/SipCallOptionHandler.java:
  return ((ni.getType() == ConnectivityManager.TYPE_WIFI) || !SipManager.isSipWifiOnly(this)) ||
         ((ni.getType() == ConnectivityManager.TYPE_ETHERNET) && SipManager.isSipEthernet(this));



                                                                     39

                                            COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Network Statistics




                                   Symptom:
                   How much data did I use ?
                 Where are my network statistics ?
                                                 40

                        COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Network Statistics

• Overlay frameworks/base/core/res/res/values/config.xml:


   <!-- Set of NetworkInfo.getType() that reflect data usage. -->
   <integer-array translatable="false" name="config_data_usage_network_types">
       <item>9</item> <!-- TYPE_MOBILE_ETHERNET -->
   </integer-array>
   <!-- The default iface on which to monitor data use -->
   <string name="config_datause_iface">eth0</string>


• Update Logtags samples in framework's
  services/java/com/android/server/EventLogTags.logtags:
51102 netstats_ethernet_sample
(dev_rx_bytes|2|2),(dev_tx_bytes|2|2),(dev_rx_pkts|2|1),(dev_tx_pkts|2|1),(xt_rx_bytes|2|2),
(xt_tx_bytes|2|2),(xt_rx_pkts|2|1),(xt_tx_pkts|2|1),(uid_rx_bytes|2|2),(uid_tx_bytes|2|2),(u
id_rx_pkts|2|1),(uid_tx_pkts|2|1),(trusted_time|2|3),(dev_history_start|2|3)


• In framework's ethernet/java/android/net/ethernet/EthernetStateTracker.java:
  - One need to add support for LinkProperties
   LinkProperties mLinkProperties = mDhcpInfo.makeLinkProperties();
   mLinkProperties.setInterfaceName("eth0");


                                                                      41

                                             COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Network Statistics

• In framework's services/java/com/android/server/net/NetworkStatsService.java:
  - Need to collect Ethernet samples.
   import static android.net.NetworkTemplate.buildTemplateEthernet;
   NetworkTemplate template = buildTemplateEthernet();
   devTotal = getSummaryForNetworkDev(template, start, end).getTotal(devTotal);
   devHistoryStart = getHistoryStartLocked(template, mNetworkDevStats);
   xtTotal = getSummaryForNetworkXt(template, start, end).getTotal(xtTotal);
   uidTotal = getSummaryForAllUid(template, start, end, false).getTotal(uidTotal);
   EventLogTags.writeNetstatsEthernetSample(
         devTotal.rxBytes, devTotal.rxPackets, devTotal.txBytes, devTotal.txPackets,
         xtTotal.rxBytes, xtTotal.rxPackets, xtTotal.txBytes, xtTotal.txPackets,
         uidTotal.rxBytes, uidTotal.rxPackets, uidTotal.txBytes, uidTotal.txPackets,
         trustedTime, devHistoryStart);




• Adding ConnectivityManager.TYPE_ETHERNET support to Monkey's NetworkMonitor
  - Used to display time spent proceeding data from Ethernet interface.




                                                                     42

                                            COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Next Steps ?

• Patchset is available on GitHub:
 • Current changeset with extra features is 504 kB big.
 • https://github.com/gxben/aosp-ethernet


• Properly redesign the ECM patch to match Wi-Fi architecture.

• Port from Ice Cream Sandwich to Jelly Bean (ongoing work)

• Design Ethernet HAL for 802.1x / WPA support.

• Contribute / upstream to Linaro ?

• And then to Google ?
                                                            43

                                   COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
Dive Into Android Networking: Adding Ethernet Connectivity
Thanks




             Thank You


                                                44

                       COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
ABS 2013: Dive into Android Networking - Adding Ethernet Connectivity
ABS 2013: Dive into Android Networking - Adding Ethernet Connectivity
1 of 46

Recommended

ELCE 2012 - Dive into Android Networking: Adding Ethernet Connectivity by
ELCE 2012 - Dive into Android Networking: Adding Ethernet ConnectivityELCE 2012 - Dive into Android Networking: Adding Ethernet Connectivity
ELCE 2012 - Dive into Android Networking: Adding Ethernet ConnectivityBenjamin Zores
8.7K views40 slides
Android Booting Sequence by
Android Booting SequenceAndroid Booting Sequence
Android Booting SequenceJayanta Ghoshal
4.4K views11 slides
Android Boot Time Optimization by
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time OptimizationKan-Ru Chen
13.1K views59 slides
Android Binder IPC for Linux by
Android Binder IPC for LinuxAndroid Binder IPC for Linux
Android Binder IPC for LinuxYu-Hsin Hung
2.5K views30 slides
Embedded Android Workshop with Pie by
Embedded Android Workshop with PieEmbedded Android Workshop with Pie
Embedded Android Workshop with PieOpersys inc.
2K views251 slides
Android Automotive by
Android AutomotiveAndroid Automotive
Android AutomotiveOpersys inc.
5.5K views44 slides

More Related Content

What's hot

Low Level View of Android System Architecture by
Low Level View of Android System ArchitectureLow Level View of Android System Architecture
Low Level View of Android System ArchitectureNational Cheng Kung University
12.2K views102 slides
Deep Dive Into Android Security by
Deep Dive Into Android SecurityDeep Dive Into Android Security
Deep Dive Into Android SecurityMarakana Inc.
9.3K views42 slides
Android Security by
Android SecurityAndroid Security
Android SecuritySuminda Gunawardhana
1.7K views62 slides
Android graphic system (SurfaceFlinger) : Design Pattern's perspective by
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveBin Chen
94.4K views53 slides
Design and Concepts of Android Graphics by
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android GraphicsNational Cheng Kung University
62.7K views58 slides
RedHat Linux by
RedHat LinuxRedHat Linux
RedHat LinuxApo
31.7K views18 slides

What's hot(20)

Deep Dive Into Android Security by Marakana Inc.
Deep Dive Into Android SecurityDeep Dive Into Android Security
Deep Dive Into Android Security
Marakana Inc.9.3K views
Android graphic system (SurfaceFlinger) : Design Pattern's perspective by Bin Chen
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Bin Chen94.4K views
RedHat Linux by Apo
RedHat LinuxRedHat Linux
RedHat Linux
Apo31.7K views
Android device driver structure introduction by William Liang
Android device driver structure introductionAndroid device driver structure introduction
Android device driver structure introduction
William Liang5.5K views
Android booting sequece and setup and debugging by Utkarsh Mankad
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
Utkarsh Mankad11.6K views
Android ppt by Ansh Singh
Android pptAndroid ppt
Android ppt
Ansh Singh63.5K views
Embedded Linux Quick Start Guide v1.5 by Chris Simmonds
Embedded Linux Quick Start Guide v1.5Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5
Chris Simmonds1.2K views
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo... by The Linux Foundation
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...
Booting Android: bootloaders, fastboot and boot images by Chris Simmonds
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
Chris Simmonds120.9K views
Android Internals by Opersys inc.
Android InternalsAndroid Internals
Android Internals
Opersys inc.14.1K views
Q4.11: Porting Android to new Platforms by Linaro
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
Linaro4.4K views

Viewers also liked

망고100 보드로 놀아보자 19 by
망고100 보드로 놀아보자 19망고100 보드로 놀아보자 19
망고100 보드로 놀아보자 19종인 전
2.6K views26 slides
Quick start guide-mango-am335x by
Quick start guide-mango-am335xQuick start guide-mango-am335x
Quick start guide-mango-am335x종인 전
1.2K views8 slides
Understanding the Android System Server by
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System ServerOpersys inc.
53.5K views25 slides
Investigation report on 64 bit support and some of new features in aosp master by
Investigation report on 64 bit support and some of new features in aosp masterInvestigation report on 64 bit support and some of new features in aosp master
Investigation report on 64 bit support and some of new features in aosp masterhidenorly
2.3K views44 slides
Android Networking by
Android NetworkingAndroid Networking
Android NetworkingMatteo Bonifazi
1.1K views25 slides
Solaiemes explaining RCS by
Solaiemes explaining RCSSolaiemes explaining RCS
Solaiemes explaining RCSSolaiemes
624 views128 slides

Viewers also liked(11)

망고100 보드로 놀아보자 19 by 종인 전
망고100 보드로 놀아보자 19망고100 보드로 놀아보자 19
망고100 보드로 놀아보자 19
종인 전2.6K views
Quick start guide-mango-am335x by 종인 전
Quick start guide-mango-am335xQuick start guide-mango-am335x
Quick start guide-mango-am335x
종인 전1.2K views
Understanding the Android System Server by Opersys inc.
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
Opersys inc.53.5K views
Investigation report on 64 bit support and some of new features in aosp master by hidenorly
Investigation report on 64 bit support and some of new features in aosp masterInvestigation report on 64 bit support and some of new features in aosp master
Investigation report on 64 bit support and some of new features in aosp master
hidenorly2.3K views
Solaiemes explaining RCS by Solaiemes
Solaiemes explaining RCSSolaiemes explaining RCS
Solaiemes explaining RCS
Solaiemes624 views
Best practices for mobile app development android march 15 2013 ts by Tasneem Sayeed
Best practices for mobile app development   android march 15 2013 tsBest practices for mobile app development   android march 15 2013 ts
Best practices for mobile app development android march 15 2013 ts
Tasneem Sayeed9.9K views
Android crash debugging by Ashish Agrawal
Android crash debuggingAndroid crash debugging
Android crash debugging
Ashish Agrawal49.3K views
Ubuntu Cloud Juju by eNovance
Ubuntu Cloud JujuUbuntu Cloud Juju
Ubuntu Cloud Juju
eNovance6.8K views
Android Internals by Opersys inc.
Android InternalsAndroid Internals
Android Internals
Opersys inc.7.8K views

Similar to ABS 2013: Dive into Android Networking - Adding Ethernet Connectivity

OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na... by
OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...
OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...Pôle Systematic Paris-Region
686 views39 slides
Developers’ mDay u Banjoj Luci - Janko Isidorović, Mainflux – Unified IoT Pl... by
Developers’ mDay u Banjoj Luci - Janko Isidorović, Mainflux –  Unified IoT Pl...Developers’ mDay u Banjoj Luci - Janko Isidorović, Mainflux –  Unified IoT Pl...
Developers’ mDay u Banjoj Luci - Janko Isidorović, Mainflux – Unified IoT Pl...mCloud
326 views67 slides
Mainflux - Hyperscalable Unified IoT Platform by
Mainflux - Hyperscalable Unified IoT PlatformMainflux - Hyperscalable Unified IoT Platform
Mainflux - Hyperscalable Unified IoT PlatformSasa Klopanovic
323 views68 slides
Mainflux - Hyperscalable Unified IoT Platform by
Mainflux - Hyperscalable Unified IoT PlatformMainflux - Hyperscalable Unified IoT Platform
Mainflux - Hyperscalable Unified IoT PlatformSasa Klopanovic
190 views68 slides
ch5-Fog Networks and Cloud Computing by
ch5-Fog Networks and Cloud Computingch5-Fog Networks and Cloud Computing
ch5-Fog Networks and Cloud Computingssuser06ea42
21 views50 slides
A SOFTWARE DEFINED RADIO BASED by
A SOFTWARE DEFINED RADIO BASEDA SOFTWARE DEFINED RADIO BASED
A SOFTWARE DEFINED RADIO BASEDANGELIN JOHN
482 views26 slides

Similar to ABS 2013: Dive into Android Networking - Adding Ethernet Connectivity(20)

Developers’ mDay u Banjoj Luci - Janko Isidorović, Mainflux – Unified IoT Pl... by mCloud
Developers’ mDay u Banjoj Luci - Janko Isidorović, Mainflux –  Unified IoT Pl...Developers’ mDay u Banjoj Luci - Janko Isidorović, Mainflux –  Unified IoT Pl...
Developers’ mDay u Banjoj Luci - Janko Isidorović, Mainflux – Unified IoT Pl...
mCloud326 views
Mainflux - Hyperscalable Unified IoT Platform by Sasa Klopanovic
Mainflux - Hyperscalable Unified IoT PlatformMainflux - Hyperscalable Unified IoT Platform
Mainflux - Hyperscalable Unified IoT Platform
Sasa Klopanovic323 views
Mainflux - Hyperscalable Unified IoT Platform by Sasa Klopanovic
Mainflux - Hyperscalable Unified IoT PlatformMainflux - Hyperscalable Unified IoT Platform
Mainflux - Hyperscalable Unified IoT Platform
Sasa Klopanovic190 views
ch5-Fog Networks and Cloud Computing by ssuser06ea42
ch5-Fog Networks and Cloud Computingch5-Fog Networks and Cloud Computing
ch5-Fog Networks and Cloud Computing
ssuser06ea4221 views
A SOFTWARE DEFINED RADIO BASED by ANGELIN JOHN
A SOFTWARE DEFINED RADIO BASEDA SOFTWARE DEFINED RADIO BASED
A SOFTWARE DEFINED RADIO BASED
ANGELIN JOHN482 views
Droidcon 2013 france - The Growth of Android in Embedded Systems by Benjamin Zores
Droidcon 2013 france - The Growth of Android in Embedded SystemsDroidcon 2013 france - The Growth of Android in Embedded Systems
Droidcon 2013 france - The Growth of Android in Embedded Systems
Benjamin Zores3K views
PLNOG14: The benefits of "OPEN" in networking for operators - Joerg Ammon, Br... by PROIDEA
PLNOG14: The benefits of "OPEN" in networking for operators - Joerg Ammon, Br...PLNOG14: The benefits of "OPEN" in networking for operators - Joerg Ammon, Br...
PLNOG14: The benefits of "OPEN" in networking for operators - Joerg Ammon, Br...
PROIDEA474 views
Open Source & The Internet of Things by All Things Open
Open Source & The Internet of ThingsOpen Source & The Internet of Things
Open Source & The Internet of Things
All Things Open639 views
Software Defined Networking/Openflow: A path to Programmable Networks by MyNOG
Software Defined Networking/Openflow: A path to Programmable NetworksSoftware Defined Networking/Openflow: A path to Programmable Networks
Software Defined Networking/Openflow: A path to Programmable Networks
MyNOG3.2K views
Rapid industrial grade IoT prototyping with sierra wireless by sierradeveloper
Rapid industrial grade IoT prototyping with sierra wirelessRapid industrial grade IoT prototyping with sierra wireless
Rapid industrial grade IoT prototyping with sierra wireless
sierradeveloper936 views
Designing For Interoperability in Mobile by AllSeen Alliance
Designing For Interoperability in MobileDesigning For Interoperability in Mobile
Designing For Interoperability in Mobile
AllSeen Alliance1K views
Are you ready to be edgy? Bringing applications to the edge of the network by Megan O'Keefe
Are you ready to be edgy? Bringing applications to the edge of the networkAre you ready to be edgy? Bringing applications to the edge of the network
Are you ready to be edgy? Bringing applications to the edge of the network
Megan O'Keefe1.6K views
Connecting_Things_2.01_Instructor Supplemental Materials_Chapter4.pptx by ssuser52b751
Connecting_Things_2.01_Instructor Supplemental Materials_Chapter4.pptxConnecting_Things_2.01_Instructor Supplemental Materials_Chapter4.pptx
Connecting_Things_2.01_Instructor Supplemental Materials_Chapter4.pptx
ssuser52b7512 views
Dynamic Software Defined Network Infrastructure Test Bed at Marist College by ADVA
Dynamic Software Defined Network Infrastructure Test Bed at Marist CollegeDynamic Software Defined Network Infrastructure Test Bed at Marist College
Dynamic Software Defined Network Infrastructure Test Bed at Marist College
ADVA1.6K views
08 sdn system intelligence short public beijing sdn conference - 130828 by Mason Mei
08 sdn system intelligence   short public beijing sdn conference - 13082808 sdn system intelligence   short public beijing sdn conference - 130828
08 sdn system intelligence short public beijing sdn conference - 130828
Mason Mei230 views
Brocade Ethernet Fabrics and the ODDC by EMC Nederland
Brocade Ethernet Fabrics and the ODDCBrocade Ethernet Fabrics and the ODDC
Brocade Ethernet Fabrics and the ODDC
EMC Nederland2.9K views

More from Benjamin Zores

CloudOpen 2014 - Extending Cloud Automation, When OpenStack Meets Ansible by
CloudOpen 2014 - Extending Cloud Automation, When OpenStack Meets AnsibleCloudOpen 2014 - Extending Cloud Automation, When OpenStack Meets Ansible
CloudOpen 2014 - Extending Cloud Automation, When OpenStack Meets AnsibleBenjamin Zores
1.2K views43 slides
ABS 2014 - The Growth of Android in Embedded Systems by
ABS 2014 - The Growth of Android in Embedded SystemsABS 2014 - The Growth of Android in Embedded Systems
ABS 2014 - The Growth of Android in Embedded SystemsBenjamin Zores
1.6K views37 slides
ABS 2014 - Android Kit Kat Internals by
ABS 2014 - Android Kit Kat InternalsABS 2014 - Android Kit Kat Internals
ABS 2014 - Android Kit Kat InternalsBenjamin Zores
6.8K views66 slides
Droidcon 2013 France - Android Platform Anatomy by
Droidcon 2013 France - Android Platform AnatomyDroidcon 2013 France - Android Platform Anatomy
Droidcon 2013 France - Android Platform AnatomyBenjamin Zores
3.3K views59 slides
ABS 2013: Android Jelly Bean Device Porting Walkthrough by
ABS 2013: Android Jelly Bean Device Porting WalkthroughABS 2013: Android Jelly Bean Device Porting Walkthrough
ABS 2013: Android Jelly Bean Device Porting WalkthroughBenjamin Zores
10.9K views127 slides
ABS 2012 - Android Device Porting Walkthrough by
ABS 2012 - Android Device Porting WalkthroughABS 2012 - Android Device Porting Walkthrough
ABS 2012 - Android Device Porting WalkthroughBenjamin Zores
10.4K views52 slides

More from Benjamin Zores(11)

CloudOpen 2014 - Extending Cloud Automation, When OpenStack Meets Ansible by Benjamin Zores
CloudOpen 2014 - Extending Cloud Automation, When OpenStack Meets AnsibleCloudOpen 2014 - Extending Cloud Automation, When OpenStack Meets Ansible
CloudOpen 2014 - Extending Cloud Automation, When OpenStack Meets Ansible
Benjamin Zores1.2K views
ABS 2014 - The Growth of Android in Embedded Systems by Benjamin Zores
ABS 2014 - The Growth of Android in Embedded SystemsABS 2014 - The Growth of Android in Embedded Systems
ABS 2014 - The Growth of Android in Embedded Systems
Benjamin Zores1.6K views
ABS 2014 - Android Kit Kat Internals by Benjamin Zores
ABS 2014 - Android Kit Kat InternalsABS 2014 - Android Kit Kat Internals
ABS 2014 - Android Kit Kat Internals
Benjamin Zores6.8K views
Droidcon 2013 France - Android Platform Anatomy by Benjamin Zores
Droidcon 2013 France - Android Platform AnatomyDroidcon 2013 France - Android Platform Anatomy
Droidcon 2013 France - Android Platform Anatomy
Benjamin Zores3.3K views
ABS 2013: Android Jelly Bean Device Porting Walkthrough by Benjamin Zores
ABS 2013: Android Jelly Bean Device Porting WalkthroughABS 2013: Android Jelly Bean Device Porting Walkthrough
ABS 2013: Android Jelly Bean Device Porting Walkthrough
Benjamin Zores10.9K views
ABS 2012 - Android Device Porting Walkthrough by Benjamin Zores
ABS 2012 - Android Device Porting WalkthroughABS 2012 - Android Device Porting Walkthrough
ABS 2012 - Android Device Porting Walkthrough
Benjamin Zores10.4K views
ELCE 2011 - BZ - Embedded Linux Optimization Techniques - How Not To Be Slow by Benjamin Zores
ELCE 2011 - BZ - Embedded Linux Optimization Techniques - How Not To Be SlowELCE 2011 - BZ - Embedded Linux Optimization Techniques - How Not To Be Slow
ELCE 2011 - BZ - Embedded Linux Optimization Techniques - How Not To Be Slow
Benjamin Zores997 views
Introduction to OpenBricks: an Embedded Linux Framework by Benjamin Zores
Introduction to OpenBricks: an Embedded Linux FrameworkIntroduction to OpenBricks: an Embedded Linux Framework
Introduction to OpenBricks: an Embedded Linux Framework
Benjamin Zores1.8K views
ELCE 2010 - State Of Multimedia In 2010 Embedded Linux Devices by Benjamin Zores
ELCE 2010 - State Of Multimedia In 2010 Embedded Linux DevicesELCE 2010 - State Of Multimedia In 2010 Embedded Linux Devices
ELCE 2010 - State Of Multimedia In 2010 Embedded Linux Devices
Benjamin Zores511 views
ELC 2010 - GeeXboX Enna: Embedded Media Center by Benjamin Zores
ELC 2010 - GeeXboX Enna: Embedded Media CenterELC 2010 - GeeXboX Enna: Embedded Media Center
ELC 2010 - GeeXboX Enna: Embedded Media Center
Benjamin Zores960 views
Fosdem 2010 - An Introduction to Enna Media Center by Benjamin Zores
Fosdem 2010 - An Introduction to Enna Media CenterFosdem 2010 - An Introduction to Enna Media Center
Fosdem 2010 - An Introduction to Enna Media Center
Benjamin Zores558 views

Recently uploaded

Data-centric AI and the convergence of data and model engineering: opportunit... by
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...Paolo Missier
29 views40 slides
"How we switched to Kanban and how it integrates with product planning", Vady... by
"How we switched to Kanban and how it integrates with product planning", Vady..."How we switched to Kanban and how it integrates with product planning", Vady...
"How we switched to Kanban and how it integrates with product planning", Vady...Fwdays
61 views24 slides
"Thriving Culture in a Product Company — Practical Story", Volodymyr Tsukur by
"Thriving Culture in a Product Company — Practical Story", Volodymyr Tsukur"Thriving Culture in a Product Company — Practical Story", Volodymyr Tsukur
"Thriving Culture in a Product Company — Practical Story", Volodymyr TsukurFwdays
40 views31 slides
MemVerge: Past Present and Future of CXL by
MemVerge: Past Present and Future of CXLMemVerge: Past Present and Future of CXL
MemVerge: Past Present and Future of CXLCXL Forum
110 views26 slides
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... by
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...NUS-ISS
23 views70 slides
The Research Portal of Catalonia: Growing more (information) & more (services) by
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
66 views25 slides

Recently uploaded(20)

Data-centric AI and the convergence of data and model engineering: opportunit... by Paolo Missier
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier29 views
"How we switched to Kanban and how it integrates with product planning", Vady... by Fwdays
"How we switched to Kanban and how it integrates with product planning", Vady..."How we switched to Kanban and how it integrates with product planning", Vady...
"How we switched to Kanban and how it integrates with product planning", Vady...
Fwdays61 views
"Thriving Culture in a Product Company — Practical Story", Volodymyr Tsukur by Fwdays
"Thriving Culture in a Product Company — Practical Story", Volodymyr Tsukur"Thriving Culture in a Product Company — Practical Story", Volodymyr Tsukur
"Thriving Culture in a Product Company — Practical Story", Volodymyr Tsukur
Fwdays40 views
MemVerge: Past Present and Future of CXL by CXL Forum
MemVerge: Past Present and Future of CXLMemVerge: Past Present and Future of CXL
MemVerge: Past Present and Future of CXL
CXL Forum110 views
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... by NUS-ISS
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
NUS-ISS23 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10165 views
"Ukrainian Mobile Banking Scaling in Practice. From 0 to 100 and beyond", Vad... by Fwdays
"Ukrainian Mobile Banking Scaling in Practice. From 0 to 100 and beyond", Vad..."Ukrainian Mobile Banking Scaling in Practice. From 0 to 100 and beyond", Vad...
"Ukrainian Mobile Banking Scaling in Practice. From 0 to 100 and beyond", Vad...
Fwdays40 views
AMD: 4th Generation EPYC CXL Demo by CXL Forum
AMD: 4th Generation EPYC CXL DemoAMD: 4th Generation EPYC CXL Demo
AMD: 4th Generation EPYC CXL Demo
CXL Forum126 views
TE Connectivity: Card Edge Interconnects by CXL Forum
TE Connectivity: Card Edge InterconnectsTE Connectivity: Card Edge Interconnects
TE Connectivity: Card Edge Interconnects
CXL Forum96 views
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada110 views
Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada119 views
MemVerge: Memory Viewer Software by CXL Forum
MemVerge: Memory Viewer SoftwareMemVerge: Memory Viewer Software
MemVerge: Memory Viewer Software
CXL Forum118 views
Samsung: CMM-H Tiered Memory Solution with Built-in DRAM by CXL Forum
Samsung: CMM-H Tiered Memory Solution with Built-in DRAMSamsung: CMM-H Tiered Memory Solution with Built-in DRAM
Samsung: CMM-H Tiered Memory Solution with Built-in DRAM
CXL Forum105 views
Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst449 views
The Importance of Cybersecurity for Digital Transformation by NUS-ISS
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital Transformation
NUS-ISS25 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman25 views

ABS 2013: Dive into Android Networking - Adding Ethernet Connectivity

  • 1. Dive Into Android Networking: Adding Ethernet Connectivity Benjamin Zores ABS 2013 – 19th February 2013 – San Francisco, CA 1 COPYRIGHT © 2012 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 2. Dive Into Android Networking: Adding Ethernet Connectivity About Me ANDROID PLATFORM ARCHITECT ALCATEL • Expert and Evangelist on Open Source Software. LUCENT • 9y experience on various multimedia/network embedded devices design. • From low-level BSP integration to global applicative software architecture. PROJECT FOUNDER, LEADER AND/OR CONTRIBUTOR FOR: • OpenBricks Embedded Linux cross-build framework. OPEN • GeeXboX Embedded multimedia HTPC distribution. SOURCE • uShare UPnP A/V and DLNA Media Server. • MPlayer Linux media player application. FORMER LINUX FOUNDATION’S EVENTS SPEAKER LINUX • ELC 2010 GeeXboX Enna: Embedded Media Center FOUNDATION • ELC-E 2010 State of Multimedia in 2010 Embedded Linux Devices CONFERENCES • ELC-E 2011 Linux Optimization Techniques: How Not to Be Slow ? • ABS 2012 Android Device Porting Walkthrough • ELC-E 2012 Dive Into Android Networking: Adding Ethernet Connectivity 2 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 3. Dive Into Android Networking: Adding Ethernet Connectivity Bibliographical References My Android bibles, from my Android mentors: Karim Yaghmour Marko Gargenta Followed by my own publications: « Discovering Android » Series of articles published in GNU/Linux Magazine France 3 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 4. Dive Into Android Networking: Adding Ethernet Connectivity Android Supported Connectivity Means • Mobile (i.e. GSM / EDGE / HSDPA / LTE) ans its siblings: - Mobile MMS (Multimedia Messaging Service) - Mobile SUPL (Secure User Plan Location) - Mobile DUN (Dial Up Networking [bridge]) - Mobile HIPRI (High Priority) • Wi-Fi • WiMax • Bluetooth • Ethernet (really ??) 4 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 5. Dive Into Android Networking: Adding Ethernet Connectivity Android Networking Architecture • Kernel Drivers (Ethernet, Wi-Fi, Bluetooth, WiMax …) • Kernel TCP/IP layer with POSIX user-space API support. • Android Hardware Abstraction Layer (HAL) • Android Bionic C library (not 100% POSIX …) • Android libnetutils (Network Utilities) • Android Netd (Network Daemon) • Android ConnectivityManager and ConnectivityService (part of the Java Framework). • Android Java Apps 5 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 6. Dive Into Android Networking: Adding Ethernet Connectivity Bionic C Library • No /etc/network/interfaces support. • No /etc/nsswitch.conf support. • No /etc/resolv.conf support. • Everything (IP, DNS, router, proxy …) is property-based - Available through getprop/setprop commands 6 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 7. Dive Into Android Networking: Adding Ethernet Connectivity Netd and libnetutils • Netd - Mostly provides tethering capabilities. - Accepts commands through UNIX socket. - Can be controlled by apps or ndc command. - Features bandwidth control, IP forwarding, NAT/PAN for SoftAP … • Libnetutils - Low-level interface control interface - Provides API to ifconfig / netcfg / route / dhcpcd - Used by HAL and system framework to control network interfaces. 7 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 8. Dive Into Android Networking: Adding Ethernet Connectivity ConnectivityManager and ConnectivityService • Orchestrate and manage global networking at Java framework level. • Rely on underlying libnetutils and netd services to control hardware. • Interact with interface-specific managers (WifiManager …). • Role and Duties: - Track and monitor various network connectivity interfaces (Mobile, Bluetooth, Wi-Fi …) - Notify registered apps (through Intent broadcasting) of a system connectivity state change. - Switch from one network type to another when connection is lost. - Provide an interface for apps to retrieve all possible connections’ states. 8 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 9. Dive Into Android Networking: Adding Ethernet Connectivity Radio Layer Interface • Communicates with broadband processor for both voice and data. • Uses RIL and proprietary rild to interface with system. • Data connection is exported by Connectivity Manager through TYPE_MOBILE_* 9 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 10. Dive Into Android Networking: Adding Ethernet Connectivity Bluetooth Interface • Communicates with BT chipset through BlueZ and libbluedroid. • Provides both audio and data management. • Data connection is exported by Connectivity Manager through TYPE_BLUETOOTH. • Interface with netd for tethering. 10 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 11. Dive Into Android Networking: Adding Ethernet Connectivity NFC Interface • Introduced with Ice Cream Sandwich for Near Field Communication. • Rely on NFC HAL. • Currently only support chips from NXP (PN544). • Uses Android Beam for P2P data exchange. • Doesn’t interface with Connectivity Service/Manager. 11 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 12. Dive Into Android Networking: Adding Ethernet Connectivity WiFi Station/AP/P2P Interface • Rely on HAL for specific driver interface with JNI binding. • Data connection is exported by Connectivity Manager through TYPE_WIFI. • WiFi configuration is stored in file system and SQLite database. 12 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 13. Dive Into Android Networking: Adding Ethernet Connectivity So what about Ethernet ?? 13 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 14. Dive Into Android Networking: Adding Ethernet Connectivity Work Context • Designing an Enterprise Desktop IP Phone. • Differs heavily from usual Android devices: - Always connected, no battery - No Radio (GSM/CDMA). - No WiFi Station mode, AP only. - LAN through Ethernet PHY/Switch. - Always docked, no screen rotation. - No accelerometer, no GPS … - => Not a Smartphone 14 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 15. Dive Into Android Networking: Adding Ethernet Connectivity Give Unto Caesar What is Caesar's … Most of the work presented hereafter is courtesy of Fabien Brisset 15 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 16. Dive Into Android Networking: Adding Ethernet Connectivity Android Ethernet Upstream Status • Ethernet is supported through native Linux kernel drivers. • ifconfig / netcfg / ping commands work but remain at platform level. • Regular /etc/resolv.conf DNS is not supported due to Bionic host resolution. • Native system daemons (C/C++) support regular Linux networking API. • Java framework services and apps rely on Connectivity Manager and have no clue what Ethernet route/connection actually means. - Except for some apps (e.g. Browser, which relies on native implementation). • Barely no Android device features Ethernet - Except from some obscure Chinese tablets. • Ethernet connection type exists in ICS API. - But with no Connectivity Manager or Connectivity Service implementation. 16 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 17. Dive Into Android Networking: Adding Ethernet Connectivity Enterprise Requirements & ECM Status • Enterprise Requirements: - Reliability: Ensuring data connection works in 100% cases for all possible applications. - HTTP(S) seamless proxy support for all applications. - Corporate firewalls prevents some services behavior (e.g. NTP). - Need to ensure everything stays behind the walls. - Ethernet 802.1x authentication. • Ethernet Connectivity Manager (ECM) Status - ECM patch has been done by Android-x86 team for netbooks. - Not 100% accurate or sufficient. 17 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 18. Dive Into Android Networking: Adding Ethernet Connectivity Ethernet Interface – ECM Patch Status • Mismatch in implementation towards WiFi. • Rely on DHCPCd dhcp implementation instead of libnetutils. • Not completely bind on Connectivity Manager and Service. 18 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 19. Dive Into Android Networking: Adding Ethernet Connectivity Am I Connected or What ? • Changes in Android framework, Settings app and System UI. • Supports DHCP (ECM patch default) and Static IP (added) addressing. • Connection status is available in notification bar. 19 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 20. Dive Into Android Networking: Adding Ethernet Connectivity ECM Patch Additions • Register Ethernet Service - In framework's core/java/android/app/ContextImpl.java: registerService(ETHERNET_SERVICE, new ServiceFetcher() { public Object createService(ContextImpl ctx) { IBinder b = ServiceManager.getService(ETHERNET_SERVICE); IEthernetManager srv = IEthernetManager.Stub.asInterface(b); return new EthernetManager(srv, ctx.mMainThread.getHandler()); }}); • Letting Connectivity Service know about Ethernet: - In framework's services/java/com/android/server/ConnectivityService.java: [...] else if (networkType == ConnectivityManager.TYPE_ETHERNET) usedNetworkType = ConnectivityManager.TYPE_ETHERNET; 20 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 21. Dive Into Android Networking: Adding Ethernet Connectivity ECM Patch Additions • Forcing default network preferences: - In framework's core/java/android/net/ConnectivityManager.java: - public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI; + public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_ETHERNET; Issue: Android public API is being modified and make update-api is required. - In framework's packages/SettingsProvider/res/values/defaults.xml: - <integer name="def_network_preference">1</integer> + <integer name="def_network_preference">9</integer> - In framework's services/java/com/android/server/EthernetService.java: - Settings.Secure.putString(cr, Settings.Secure.ETHERNET_IFNAME, DevName[0]); + Settings.Secure.putString(cr, Settings.Secure.ETHERNET_IFNAME, "eth0"); 21 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 22. Dive Into Android Networking: Adding Ethernet Connectivity And now, bugs and workarounds for various use cases: Making Ethernet 100% functional. 22 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 23. Dive Into Android Networking: Adding Ethernet Connectivity Connection Information Symptom: What is my Ethernet IP configuration or MAC address info ? 23 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 24. Dive Into Android Networking: Adding Ethernet Connectivity Connection Information – IP Address • In Settings's res/xml/device_info_status.xml: <Preference android:key="ethernet_ip_address" style="?android:attr/preferenceInformationStyle" android:title="@string/ethernet_advanced_ip_address_title" android:summary="@string/device_info_not_available" android:persistent="false" /> • In src/com/android/settings/deviceinfo/Status.java: private void setEthernetIpAddressStatus() { EthernetManager mgr = getSystemService(ETHERNET_SERVICE); EthernetDevInfo info = mgr.getSavedConfig(); Preference ip = findPreference("ethernet_ip_address"); String addr = null; if (info != null) { if (info.getIpAddress() != null) addr = info.getIpAddress(); else addr = SystemProperties.get("dhcp.eth0.ipaddress"); } ip.setSummary(!TextUtils.isEmpty(addr) ? Addr : getString(R.string.status_unavailable)); } 24 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 25. Dive Into Android Networking: Adding Ethernet Connectivity Connection Information – MAC Address • In framework's JNI code core/jni/android_net_ethernet.cpp: {"getInterfaceMacAddress", "()Ljava/lang/String;", (void *)android_net_ethernet_getInterfaceMacAddress}, [...] static jstring android_net_ethernet_getInterfaceMacAddress(JNIEnv *env, jobject clazz) { struct ifreq ifr; strcpy (ifr.ifr_name, "eth0"); strcpy (ifr.ifr_hwaddr.sa_data, ""); sock = socket (AF_INET, SOCK_STREAM, 0); ioctl (sock, SIOCGIFHWADDR, &ifr); ptr = (unsigned char *) ifr.ifr_hwaddr.sa_data; snprintf (buf, 64, "%02x:%02x:%02x:%02x:%02x:%02x", (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)); return env->NewStringUTF(buf); } 25 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 26. Dive Into Android Networking: Adding Ethernet Connectivity Connection Information – MAC Address • In Settings' res/xml/device_info_status.xml: <Preference android:key="ethernet_mac_address" style="?android:attr/preferenceInformationStyle" android:title="@string/status_ethernet_mac_address" android:summary="@string/device_info_not_available" android:persistent="false" /> • In Settings’ src/com/android/settings/deviceinfo/Status.java: private void setEthernetMacAddress() { EthernetManager mgr = getSystemService(ETHERNET_SERVICE); EthernetDevInfo info = mgr.getSavedConfig(); Preference mac = findPreference("ethernet_mac_address"); String addr = info == null ? null : info.getMacAddress(); mac.setSummary(!TextUtils.isEmpty(addr) ? addr : getString(R.string.status_unavailable)); } 26 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 27. Dive Into Android Networking: Adding Ethernet Connectivity Android DNS Entry Management Symptom: DHCP can't seem to provide me with valid DNS entries. • Match Android process (AID) authorizations to update system properties in init's init/property_service.c: { "rw.", AID_SYSTEM, 0 }, { "net.", AID_DHCP, 0 }, • In DHCPCD's dhcpcd-hooks/20-dns.conf: for dnsaddr in ${new_domain_name_servers}; do setprop dhcp.${interface}.dns${count} ${dnsaddr} + setprop net.dns${count} ${dnsaddr} + setprop net.${interface}.dns${count} ${dnsaddr} count=$(($count + 1)) done • In framework's ethernet/java/android/net/ethernet/EthernetStateTracker.java: SystemProperties.set("net.dns1", mDhcpInfo.dns1); SystemProperties.set("net." + mInterfaceName + ".dns1", mDhcpInfo.dns1); 27 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 28. Dive Into Android Networking: Adding Ethernet Connectivity HTTP(S) Proxy Symptom: I'm behind HTTP(S) proxy. I need my apps to seamlessly know about that ! 28 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 29. Dive Into Android Networking: Adding Ethernet Connectivity HTTP(S) Proxy • Overlay frameworks/base/core/res/res/values/config.xml: <string name="config_default_proxy_host" translatable="false">a.b.c.d</string> <integer name="config_default_proxy_port" translatable="false">8080</integer> • In framework’s services/java/com/android/server/ConnectivityService.java: String proxyHost = context.getResources().getString( com.android.internal.R.string.config_default_proxy_host); int proxyPort = context.getResources().getInteger( com.android.internal.R.integer.config_default_proxy_port); mGlobalProxy = new ProxyProperties(proxyHost, proxyPort, null); SystemProperties.set("net.http.proxy", proxyHost + ":" + proxyPort); 29 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 30. Dive Into Android Networking: Adding Ethernet Connectivity Custom NTP Server Symptom: I'm behind corporate firewall and can't do NTP request. My company provides its internal NTP server. 30 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 31. Dive Into Android Networking: Adding Ethernet Connectivity Custom NTP Server • Overlay frameworks/base/core/res/res/values/config.xml: <!-- Remote server that can provide NTP responses. --> <string translatable="false" name="config_ntpServer">a.b.c.d</string> <!-- Timeout to wait for NTP server response. --> <integer name="config_ntpTimeout">20000</integer> • In framework's core/java/android/util/NtpTrustedTime.java: - final String defaultServer = res.getString(com.android.internal.R.string.config_ntpServer); + String defaultServer = Settings.System.getString(resolver, Settings.System.NTP_SERVER); • In framework's services/java/com/android/server/NetworkTimeUpdateService.java: - Force NTP update on Ethernet state change: if (netInfo.getState() == NetworkInfo.State.CONNECTED && netInfo.getType() == ConnectivityManager.TYPE_ETHERNET) mHandler.obtainMessage(EVENT_ETHERNET_CONNECTED).sendToTarget(); [...] case EVENT_WIFI_CONNECTED: case EVENT_ETHERNET_CONNECTED: onPollNetworkTime(msg.what); 31 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 32. Dive Into Android Networking: Adding Ethernet Connectivity Custom NTP Server • In Settings's res/xml/date_time_prefs.xml: <EditTextPreference android:title="@string/ntp_server_time" android:key="ntp_server" android:singleLine="true" android:summary="192.168.1.1" android:inputType="textUri"/> • In Settings' src/com/android/settings/DateTimeSettings.java: EditTextPreference pref = findPreference("ntp_server"); String server = Settings.System.getString(getContentResolver(), Settings.System.NTP_SERVER); pref.setText(server); pref.setSummary(server); 32 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 33. Dive Into Android Networking: Adding Ethernet Connectivity Email Symptom: I can't download email attachments. • In src/com/android/email/AttachmentInfo.java: - if (networkType != ConnectivityManager.TYPE_WIFI) { + if ((networkType != ConnectivityManager.TYPE_WIFI) && (networkType != ConnectivityManager.TYPE_ETHERNET)) { • In src/com/android/email/service/AttachmentDownloadService.java: - if (ecm.getActiveNetworkType() != ConnectivityManager.TYPE_WIFI) { + if ((ecm.getActiveNetworkType() != ConnectivityManager.TYPE_WIFI) && (ecm.getActiveNetworkType() != ConnectivityManager.TYPE_ETHERNET)) { 33 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 34. Dive Into Android Networking: Adding Ethernet Connectivity Connectivity Route Symptom: I can't access to Google Play Store. The application just crash ! 34 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 35. Dive Into Android Networking: Adding Ethernet Connectivity Connectivity Route Reverse engineering apps may help: • Dex2jar - Extracts usable classes.jar from APK archives. - See http://code.google.com/p/dex2jar/ • Java Decompiler (jd-gui) - See http://java.decompiler.free.fr/?q=jdgui 35 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 36. Dive Into Android Networking: Adding Ethernet Connectivity Connectivity Route • Many (certified?) apps assume that WiFi or mobile connection is always present. - We need to trick the system for Ethernet. - But this is truly an ugly hack. • In framework's services/java/com/android/server/ConnectivityService.java: public NetworkInfo getNetworkInfo(int networkType, int uid) { - return getNetworkInfo(networkType, uid); + switch (networkType) { + case ConnectivityManager.TYPE_MOBILE: + case ConnectivityManager.TYPE_WIFI: + case ConnectivityManager.TYPE_WIMAX: + networkType = ConnectivityManager.TYPE_ETHERNET; + break; + default: + break; + } + return getNetworkInfo(networkType, uid); } • Android shouldn't expose WiFi Manager API ! - Apps should always go through Connectivity Manager for all network information. • Limitations: - Connectivity Manager API can't configure default connection type (currently hardcoded). - Too few information on existing devices' connectivity states. 36 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 37. Dive Into Android Networking: Adding Ethernet Connectivity Download Provider Symptom: My browser works fine but I just can't download files. • In DownloadProvider's src/com/android/providers/downloads/DownloadInfo.java: - Add Ethernet connectivity support case ConnectivityManager.TYPE_ETHERNET: return DownloadManager.Request.NETWORK_ETHERNET; [...] if (networkType == ConnectivityManager.TYPE_ETHERNET) { return NETWORK_OK; // anything goes over ethernet } 37 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 38. Dive Into Android Networking: Adding Ethernet Connectivity Multimedia Streaming Symptom: My browser works fine but I can't play multimedia contents. • Force Chrome HTTP stack instead of Android HTTP stack. - By default, Stagefright can't bypass proxy (see frameworks/base/media/libstagefright/Android.mk) - Overlay in your device's device.mk file: HTTP := chrome • In framework's media/libstagefright/chromium_http/support.cpp: char value[PROPERTY_VALUE_MAX]; property_get("net.http.proxy", value, "Unknown"); net::ProxyConfigServiceAndroid cfg = new net::ProxyConfigServiceAndroid(); if (strcmp(value_proxy,"Unknown") != 0) { std::string proxy = value; cfg->UpdateProxySettings(proxy, ""); } set_proxy_service(net::ProxyService::CreateWithoutProxyResolver(cfg, net_log())); • In framework's services/java/com/android/server/ConnectivityService.java: - Optionally force proxy detection in proprietary OMX Codecs: SystemProperties.set("net.proxy", host + ":" + port); SystemProperties.set("rw.HTTP_PROXY", "http://" + host + ":" + port); 38 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 39. Dive Into Android Networking: Adding Ethernet Connectivity Phone / SIP VoIP Symptom: I can do VoIP SIP calls over WiFi but not over Ethernet. • Overlay frameworks/base/core/res/res/values/config.xml: <bool name="config_sip_ethernet">true</bool> • In framework's voip/java/android/net/sip/SipManager.java: public static boolean isSipEthernet(Context context) { return context.getResources().getBoolean(com.android.internal.R.bool.config_sip_ethernet); } • In framework's voip/java/com/android/server/sip/SipService.java: boolean mSipOnWifiOnly = SipManager.isSipWifiOnly(context); boolean mSipEthernet = SipManager.isSipEthernet(context); boolean connected = (info != null && info.isConnected() && ((!mSipOnWifiOnly || info.getType() == ConnectivityManager.TYPE_WIFI) || ( mSipEthernet && info.getType() == ConnectivityManager.TYPE_ETHERNET)); • In Phone's src/com/android/phone/SipCallOptionHandler.java: return ((ni.getType() == ConnectivityManager.TYPE_WIFI) || !SipManager.isSipWifiOnly(this)) || ((ni.getType() == ConnectivityManager.TYPE_ETHERNET) && SipManager.isSipEthernet(this)); 39 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 40. Dive Into Android Networking: Adding Ethernet Connectivity Network Statistics Symptom: How much data did I use ? Where are my network statistics ? 40 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 41. Dive Into Android Networking: Adding Ethernet Connectivity Network Statistics • Overlay frameworks/base/core/res/res/values/config.xml: <!-- Set of NetworkInfo.getType() that reflect data usage. --> <integer-array translatable="false" name="config_data_usage_network_types"> <item>9</item> <!-- TYPE_MOBILE_ETHERNET --> </integer-array> <!-- The default iface on which to monitor data use --> <string name="config_datause_iface">eth0</string> • Update Logtags samples in framework's services/java/com/android/server/EventLogTags.logtags: 51102 netstats_ethernet_sample (dev_rx_bytes|2|2),(dev_tx_bytes|2|2),(dev_rx_pkts|2|1),(dev_tx_pkts|2|1),(xt_rx_bytes|2|2), (xt_tx_bytes|2|2),(xt_rx_pkts|2|1),(xt_tx_pkts|2|1),(uid_rx_bytes|2|2),(uid_tx_bytes|2|2),(u id_rx_pkts|2|1),(uid_tx_pkts|2|1),(trusted_time|2|3),(dev_history_start|2|3) • In framework's ethernet/java/android/net/ethernet/EthernetStateTracker.java: - One need to add support for LinkProperties LinkProperties mLinkProperties = mDhcpInfo.makeLinkProperties(); mLinkProperties.setInterfaceName("eth0"); 41 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 42. Dive Into Android Networking: Adding Ethernet Connectivity Network Statistics • In framework's services/java/com/android/server/net/NetworkStatsService.java: - Need to collect Ethernet samples. import static android.net.NetworkTemplate.buildTemplateEthernet; NetworkTemplate template = buildTemplateEthernet(); devTotal = getSummaryForNetworkDev(template, start, end).getTotal(devTotal); devHistoryStart = getHistoryStartLocked(template, mNetworkDevStats); xtTotal = getSummaryForNetworkXt(template, start, end).getTotal(xtTotal); uidTotal = getSummaryForAllUid(template, start, end, false).getTotal(uidTotal); EventLogTags.writeNetstatsEthernetSample( devTotal.rxBytes, devTotal.rxPackets, devTotal.txBytes, devTotal.txPackets, xtTotal.rxBytes, xtTotal.rxPackets, xtTotal.txBytes, xtTotal.txPackets, uidTotal.rxBytes, uidTotal.rxPackets, uidTotal.txBytes, uidTotal.txPackets, trustedTime, devHistoryStart); • Adding ConnectivityManager.TYPE_ETHERNET support to Monkey's NetworkMonitor - Used to display time spent proceeding data from Ethernet interface. 42 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 43. Dive Into Android Networking: Adding Ethernet Connectivity Next Steps ? • Patchset is available on GitHub: • Current changeset with extra features is 504 kB big. • https://github.com/gxben/aosp-ethernet • Properly redesign the ECM patch to match Wi-Fi architecture. • Port from Ice Cream Sandwich to Jelly Bean (ongoing work) • Design Ethernet HAL for 802.1x / WPA support. • Contribute / upstream to Linaro ? • And then to Google ? 43 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.
  • 44. Dive Into Android Networking: Adding Ethernet Connectivity Thanks Thank You 44 COPYRIGHT © 2013 ALCATEL-LUCENT. ALL RIGHTS RESERVED.