// Path: aisen_downloader/src/main/java/org/aiwen/downloader/utils/Utils.java
// public class Utils {
// 
//     public static void close(Closeable closeable) {
//         try {
//             if (closeable != null)
//                 closeable.close();
//         } catch (Exception e) {
//             e.printStackTrace();
//         }
//     }
// 
//     public static String getDownloaderTAG(Request request) {
//         return Constants.TAG + "_Thread_" + request.key;
//     }
// 
//     public static long now() {
//         return System.currentTimeMillis();
//     }
// 
//     public static long realtime() {
//         return SystemClock.elapsedRealtime();
//     }
// 
//     public static boolean isNetworkActive() {
//         Hawk hawk = Hawk.getInstance();
//         if (hawk != null) {
//             ConnectivityManager connectivityManager = (ConnectivityManager) hawk.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
//             NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
// 
//             return networkInfo != null && networkInfo.isConnected();
//         }
// 
//         return false;
//     }
// 
//     public static boolean isWifiActive() {
//         Hawk hawk = Hawk.getInstance();
//         if (hawk != null) {
//             ConnectivityManager connectivityManager = (ConnectivityManager) hawk.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
//             NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
// 
//             return networkInfo != null &&
//                         networkInfo.getType() == ConnectivityManager.TYPE_WIFI &&
//                         networkInfo.isConnected();
//         }
// 
//         return false;
//     }
// 
// }


import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import org.aiwen.downloader.utils.Utils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
        updateNotifier(!Downloads.Status.isStatusRunning(request.downloadInfo.status));

        // 更新观察者
        final RequestSubject requestSubject = mRequestSubjects.get(request.key);
        if (requestSubject != null) {
            // 在UI线程中更新状态
            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    requestSubject.notifyStatus(request);

                    if (mConfiguration.statusCallback != null) {
                        mConfiguration.statusCallback.onStatusChanged(request);
                    }
                }

            });
        }
    }

    public void notifyAllStatus() {
        Set<String> keySet = mRequestSubjects.keySet();
        for (String key : keySet) {
            notifyStatus(mRequestMap.get(key));
        }
    }

    private long mLastNotifyTime;
    void updateNotifier(boolean force) {
// Path: aisen_downloader/src/main/java/org/aiwen/downloader/utils/Utils.java
// public class Utils {
// 
//     public static void close(Closeable closeable) {
//         try {
//             if (closeable != null)
//                 closeable.close();
//         } catch (Exception e) {
//             e.printStackTrace();
//         }
//     }
// 
//     public static String getDownloaderTAG(Request request) {
//         return Constants.TAG + "_Thread_" + request.key;
//     }
// 
//     public static long now() {
//         return System.currentTimeMillis();
//     }
// 
//     public static long realtime() {
//         return SystemClock.elapsedRealtime();
//     }
// 
//     public static boolean isNetworkActive() {
//         Hawk hawk = Hawk.getInstance();
//         if (hawk != null) {
//             ConnectivityManager connectivityManager = (ConnectivityManager) hawk.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
//             NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
// 
//             return networkInfo != null && networkInfo.isConnected();
//         }
// 
//         return false;
//     }
// 
//     public static boolean isWifiActive() {
//         Hawk hawk = Hawk.getInstance();
//         if (hawk != null) {
//             ConnectivityManager connectivityManager = (ConnectivityManager) hawk.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
//             NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
// 
//             return networkInfo != null &&
//                         networkInfo.getType() == ConnectivityManager.TYPE_WIFI &&
//                         networkInfo.isConnected();
//         }
// 
//         return false;
//     }
// 
// }


// Path: aisen_downloader/src/main/java/org/aiwen/downloader/Hawk.java
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import org.aiwen.downloader.utils.Utils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

        updateNotifier(!Downloads.Status.isStatusRunning(request.downloadInfo.status));

        // 更新观察者
        final RequestSubject requestSubject = mRequestSubjects.get(request.key);
        if (requestSubject != null) {
            // 在UI线程中更新状态
            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    requestSubject.notifyStatus(request);

                    if (mConfiguration.statusCallback != null) {
                        mConfiguration.statusCallback.onStatusChanged(request);
                    }
                }

            });
        }
    }

    public void notifyAllStatus() {
        Set<String> keySet = mRequestSubjects.keySet();
        for (String key : keySet) {
            notifyStatus(mRequestMap.get(key));
        }
    }

    private long mLastNotifyTime;
    void updateNotifier(boolean force) {
        long now = Utils.now();