Skip to content
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

Add @RequiresPermission to NotificationTarget #5220

Merged
merged 1 commit into from
Aug 3, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.bumptech.glide.request.target;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
Expand All @@ -8,6 +10,7 @@
import android.widget.RemoteViews;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresPermission;
import com.bumptech.glide.request.transition.Transition;
import com.bumptech.glide.util.Preconditions;

Expand Down Expand Up @@ -39,6 +42,9 @@ public class NotificationTarget extends CustomTarget<Bitmap> {
* @param notification The Notification object that we want to update.
* @param notificationId The notificationId of the Notification that we want to load the Bitmap.
*/
@SuppressLint("InlinedApi")
// Alert users of Glide to have this permission.
@RequiresPermission(Manifest.permission.POST_NOTIFICATIONS)
public NotificationTarget(
Context context,
int viewId,
Expand All @@ -61,6 +67,9 @@ public NotificationTarget(
* @param notificationTag The notificationTag of the Notification that we want to load the Bitmap.
* May be {@code null}.
*/
@SuppressLint("InlinedApi")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to suppress inlined API?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See PR OP.

// Alert users of Glide to have this permission.
@RequiresPermission(Manifest.permission.POST_NOTIFICATIONS)
public NotificationTarget(
Context context,
int viewId,
Expand Down Expand Up @@ -95,6 +104,9 @@ public NotificationTarget(
* @param notificationTag The notificationTag of the Notification that we want to load the Bitmap.
* May be {@code null}.
*/
@SuppressLint("InlinedApi")
// Alert users of Glide to have this permission.
@RequiresPermission(Manifest.permission.POST_NOTIFICATIONS)
public NotificationTarget(
Context context,
int width,
Expand All @@ -116,24 +128,36 @@ public NotificationTarget(
}

/** Updates the Notification after the Bitmap resource is loaded. */
@SuppressLint("InlinedApi")
// Help tools to recognize that this method requires a permission, because it posts a notification.
@RequiresPermission(Manifest.permission.POST_NOTIFICATIONS)
private void update() {
NotificationManager manager =
(NotificationManager) this.context.getSystemService(Context.NOTIFICATION_SERVICE);
Preconditions.checkNotNull(manager)
.notify(this.notificationTag, this.notificationId, this.notification);
}

@SuppressLint("InlinedApi")
// Help tools to recognize that this method requires a permission, because it calls setBitmap().
@RequiresPermission(Manifest.permission.POST_NOTIFICATIONS)
@Override
public void onResourceReady(
@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
setBitmap(resource);
}

@SuppressLint("InlinedApi")
// Help tools to recognize that this method requires a permission, because it calls setBitmap().
@RequiresPermission(Manifest.permission.POST_NOTIFICATIONS)
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
setBitmap(null);
}

@SuppressLint("InlinedApi")
// Help tools to recognize that this method requires a permission, because it calls update().
@RequiresPermission(Manifest.permission.POST_NOTIFICATIONS)
private void setBitmap(@Nullable Bitmap bitmap) {
this.remoteViews.setImageViewBitmap(this.viewId, bitmap);
this.update();
Expand Down