admin
2023-11-21 2eec3de87b6b616a69a46c1f97c2397159031d2f
library-DownloadProvider/src/com/mozillaonline/providers/downloads/DownloadReceiver.java
@@ -30,6 +30,7 @@
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
/**
@@ -46,7 +47,8 @@
        String action = intent.getAction();
        /*if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
            startService(context);
        } else */if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
        } else */
        if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
            NetworkInfo info = (NetworkInfo)
                    intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
            if (info != null && info.isConnected()) {
@@ -101,7 +103,8 @@
    /**
     * Hide a system notification for a download.
     * @param uri URI to update the download
     *
     * @param uri    URI to update the download
     * @param cursor Cursor for reading the download's fields
     */
    private void hideNotification(Context context, Uri uri, Cursor cursor) {
@@ -128,7 +131,7 @@
    private void openDownload(Context context, Cursor cursor) {
        String filename = cursor.getString(cursor.getColumnIndexOrThrow(Downloads._DATA));
        String mimetype =
            cursor.getString(cursor.getColumnIndexOrThrow(Downloads.COLUMN_MIME_TYPE));
                cursor.getString(cursor.getColumnIndexOrThrow(Downloads.COLUMN_MIME_TYPE));
        Uri path = Uri.parse(filename);
        // If there is no scheme, then it must be a file
        if (path.getScheme() == null) {
@@ -147,6 +150,7 @@
    /**
     * Notify the owner of a running download that its notification was clicked.
     *
     * @param intent the broadcast intent sent by the notification manager
     * @param cursor Cursor for reading the download's fields
     */
@@ -185,6 +189,11 @@
    }
    private void startService(Context context) {
        context.startService(new Intent(context, DownloadService.class));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            context.startForegroundService(new Intent(context, DownloadService.class));
        } else {
            context.startService(new Intent(context, DownloadService.class));
        }
    }
}