Home | History | Annotate | Download | only in manager
      1 package com.bumptech.glide.manager;
      2 
      3 import android.content.Context;
      4 import android.content.pm.PackageManager;
      5 
      6 /**
      7  * A factory class that produces a functional {@link com.bumptech.glide.manager.ConnectivityMonitor} if the application
      8  * has the {@code android.permission.ACCESS_NETWORK_STATE} permission and a no-op non functional
      9  * {@link com.bumptech.glide.manager.ConnectivityMonitor} if the app does not have the required permission.
     10  */
     11 public class ConnectivityMonitorFactory {
     12     public ConnectivityMonitor build(Context context, ConnectivityMonitor.ConnectivityListener listener) {
     13         final int res = context.checkCallingOrSelfPermission("android.permission.ACCESS_NETWORK_STATE");
     14         final boolean hasPermission = res == PackageManager.PERMISSION_GRANTED;
     15         if (hasPermission) {
     16             return new DefaultConnectivityMonitor(context, listener);
     17         } else {
     18             return new NullConnectivityMonitor();
     19         }
     20     }
     21 }
     22