Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Is your app really connected?

Is your app really connected?

Presentation about connectivity in the Android applications shown during DroidCon Poland in Kraków on 01.12.2017.

Piotr Wittchen

December 01, 2017

More Decks by Piotr Wittchen

Other Decks in Programming


  1. What happens when the user wants to download some data?

    Scenario #1 1. User opens the app 2. Device is connected to the network 3. App downloads data from server 4. User can read data Senario #2 1. User opens the app 2. Device is not connected to the network 3. App tries to download data from server 4. ... 5. Connection timeout 6. Nothing happens or app crashes 7. User is not happy :-( Happy path :-D Unhappy path ;-(
  2. Let’s see another use case 1. User opens an app

    2. Device is disconnected from the network 3. Connectivity check fails 4. Device gets connected to the network 5. User cannot access the network with the app 6. User is unhappy :-( Unhappy path ;-( How to fix this situation?
  3. Lollipop arrives! We got a new shiny Android version! Hooray!

    But wait… Network Monitoring API has changed.
  4. Lollipop arrives! We got a new shiny Android version! Hooray!

    But wait… Network Monitoring API has changed.
  5. Marshmallow arrives! We got a new shiny Android version! Hooray!

    But wait… There’s a Doze Mode. We need yet another BroadcastReceiver notifying app that network is down when the phone sleeps.
  6. China banned the Google! China is behind the Walled Garden

    We need to ping other host than Google or verify HTTP Status 204 (No Content)
  7. ClearText Traffic Starting with Android 9.0 (API level 28), cleartext

    support is disabled by default. We need to apply additional network security configuration in such cases. • https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted • https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted/50834 600#50834600
  8. How often should we check Internet connectivity? It depends on

    our use case Continuous checking in a given interval is more reliable, but consumes more data transfer and drains the battery Sometimes one time check is enough
  9. Mixing it all together Network BroadcastReceiver for pre-Lollipop devices Managing

    different connection types Network Callback from Lollipop Checking Internet connectivity for Walled Garden Doze mode Checking Internet connectivity with Socket Frequency of checking Internet connectivity Handling connectivity check asynchronously ClearText traffic
  10. So what should I do now? You can implement all

    of that stuff by yourself or...
  11. Why would I use it? • ~3 years of development

    and maintenance • 10 developers contributed to the code-base • 41 releases so far • More than 80% of code covered by unit tests • Documentation, JavaDocs and exemplary apps • Works with RxJava1.x and RxJava2.x (on separate artifacts and git branches) • Up to date with the latest RxJava version (which is used as a dependency) • Works with Java and Kotlin • It’s free and open-source: https://github.com/pwittchen/ReactiveNetwork • Backed by Travis Continuous Integration Server • Verified by static code analysis tools (CheckStyle, PMD, FindBugs, Lint, NullAway) • Tested in production • Available on the Maven Central Repository (easy to use with Gradle)
  12. ReactiveNetwork does not force you to use any concrete solution

    or strategy Pick whatever you need from it or extend it
  13. Network observing strategies is implemented by: Correct strategy is chosen

    by the library automatically, but we can use any strategy explicitly if we want to.
  14. Customization of the Internet connectivity check We can use and

    type from RxJava2 depending on our use case We can customize: • host • port • timeout in ms • initial observing interval in ms • ping interval in ms • strategy https://github.com/pwittchen/ReactiveNetwork#observing-internet-connectivity
  15. Respecting battery state How to perform a data synchronization, while

    being connected to AC and WiFi network at the same time?
  16. Summary • We need to be aware of network and

    Internet connectivity • Apps can work off-line • Apps can be disconnected from the network anytime • WiFi network can be disconnected from the Internet anytime • Battery of the device should not be drained • Mobile data transfer should be used carefully • We should provide the best User Experience possible • Do not reinvent the wheel - we have libraries :-)