class LollipopNetworkObservingStrategy implements NetworkObservingStrategy {

  @Override public Observable<Connectivity> observeNetworkConnectivity(final Context context) {
    final String service = Context.CONNECTIVITY_SERVICE;
    final ConnectivityManager manager = (ConnectivityManager) context.getSystemService(service);

    return Observable.create(new ObservableOnSubscribe<Connectivity>() {
      @Override public void subscribe(ObservableEmitter<Connectivity> subscriber) throws Exception {
        networkCallback = createNetworkCallback(subscriber, context);
        final NetworkRequest networkRequest = new NetworkRequest.Builder().build();
        manager.registerNetworkCallback(networkRequest, networkCallback);
      }
    }).doOnDispose(new Action() {
      @Override public void run() {
        tryToUnregisterCallback(manager);
      }
    }).startWith(Connectivity.create(context)).distinctUntilChanged();
  }

}