Skip to content

Proposed fix for issue 5593 #5597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion firebase-ml-modeldownloader/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

* [fixed] Fixed `SecurityException` where the `RECEIVER_EXPORTED` or `RECEIVER_NOT_EXPORTED` flag should be
specified when registerReceiver is being used. [#5597](https://github.com/firebase/firebase-android-sdk/pull/5597)

# 24.2.1
* [changed] Internal infrastructure improvements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.firebase.ml.modeldownloader.internal;

import android.annotation.SuppressLint;
import android.app.DownloadManager;
import android.app.DownloadManager.Query;
import android.app.DownloadManager.Request;
Expand All @@ -23,6 +24,7 @@
import android.content.IntentFilter;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.ParcelFileDescriptor;
Expand Down Expand Up @@ -207,12 +209,20 @@ private synchronized void removeDownloadTaskInstance(long downloadId) {
this.receiverMaps.remove(downloadId);
}

@SuppressLint("WrongConstant")
private Task<Void> registerReceiverForDownloadId(long downloadId, String modelName) {
BroadcastReceiver broadcastReceiver = getReceiverInstance(downloadId, modelName);
// It is okay to always register here. Since the broadcast receiver is the same via the lookup
// for the same download id, the same broadcast receiver will be notified only once.
context.registerReceiver(
broadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.registerReceiver(
broadcastReceiver,
new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE),
Context.RECEIVER_EXPORTED);
} else {
context.registerReceiver(
broadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

return getTaskCompletionSourceInstance(downloadId).getTask();
}
Expand Down