Skip to content

Commit

Permalink
Add @RequiresPermission to NotificationTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
TWiStErRob committed Jul 26, 2023
1 parent fd96de2 commit 9f70abb
Showing 1 changed file with 24 additions and 0 deletions.
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")
// 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

0 comments on commit 9f70abb

Please sign in to comment.