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 d6d1308
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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 +64,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 +101,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 +125,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 d6d1308

Please sign in to comment.