44 lines
1.8 KiB
Diff
44 lines
1.8 KiB
Diff
![]() |
From 2f262ed47122e57283ee85c2cca138728559ef35 Mon Sep 17 00:00:00 2001
|
||
|
From: Dmitry Muhomor <muhomor.dmitry@gmail.com>
|
||
|
Date: Mon, 10 Jan 2022 15:50:33 +0200
|
||
|
Subject: [PATCH] make DownloadManager.enqueue() a no-op when INTERNET
|
||
|
permission is revoked
|
||
|
|
||
|
---
|
||
|
core/java/android/app/DownloadManager.java | 8 ++++++++
|
||
|
1 file changed, 8 insertions(+)
|
||
|
|
||
|
diff --git a/core/java/android/app/DownloadManager.java b/core/java/android/app/DownloadManager.java
|
||
|
index 355092378279..cb4a16641953 100644
|
||
|
--- a/core/java/android/app/DownloadManager.java
|
||
|
+++ b/core/java/android/app/DownloadManager.java
|
||
|
@@ -16,6 +16,7 @@
|
||
|
|
||
|
package android.app;
|
||
|
|
||
|
+import android.Manifest;
|
||
|
import android.annotation.NonNull;
|
||
|
import android.annotation.Nullable;
|
||
|
import android.annotation.RequiresPermission;
|
||
|
@@ -31,6 +32,7 @@
|
||
|
import android.content.ContentUris;
|
||
|
import android.content.ContentValues;
|
||
|
import android.content.Context;
|
||
|
+import android.content.pm.PackageManager;
|
||
|
import android.database.Cursor;
|
||
|
import android.database.CursorWrapper;
|
||
|
import android.database.DatabaseUtils;
|
||
|
@@ -1115,6 +1117,12 @@ public void onMediaStoreDownloadsDeleted(@NonNull LongSparseArray<String> idToMi
|
||
|
* calls related to this download.
|
||
|
*/
|
||
|
public long enqueue(Request request) {
|
||
|
+ // don't crash apps that expect INTERNET permission to be always granted
|
||
|
+ Context ctx = ActivityThread.currentApplication();
|
||
|
+ if (ctx != null && ctx.checkSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) {
|
||
|
+ // invalid id (DownloadProvider uses SQLite and returns a row id)
|
||
|
+ return -1;
|
||
|
+ }
|
||
|
ContentValues values = request.toContentValues(mPackageName);
|
||
|
Uri downloadUri = mResolver.insert(Downloads.Impl.CONTENT_URI, values);
|
||
|
long id = Long.parseLong(downloadUri.getLastPathSegment());
|