Skip to content

Commit

Permalink
Merge pull request #183 from jasper-apps:bugfix/make-download-notific…
Browse files Browse the repository at this point in the history
…ation-appear-immediately

PiperOrigin-RevId: 482165983
  • Loading branch information
rohitjoins committed Oct 24, 2022
2 parents a5b09b8 + ed55d0b commit 1565a2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Expand Up @@ -30,6 +30,8 @@
* Fix potential infinite loop in `ProgressiveDownloader` caused by
simultaneous download and playback with the same `PriorityTaskManager`
([#10570](https://github.com/google/ExoPlayer/pull/10570)).
* Make download notification appear immediately
([#183](https://github.com/androidx/media/pull/183))
* Audio:
* Adds `AudioOffloadListener.onExperimentalOffloadedPlayback` for the
AudioTrack offload state.
Expand Down
Expand Up @@ -15,15 +15,21 @@
*/
package androidx.media3.exoplayer.offline;

import static androidx.core.app.NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE;

import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import androidx.annotation.DoNotInline;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.StringRes;
import androidx.core.app.NotificationCompat;
import androidx.media3.common.C;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import androidx.media3.exoplayer.R;
import androidx.media3.exoplayer.scheduler.Requirements;
import java.util.List;
Expand Down Expand Up @@ -237,6 +243,19 @@ private Notification buildNotification(
notificationBuilder.setProgress(maxProgress, currentProgress, indeterminateProgress);
notificationBuilder.setOngoing(ongoing);
notificationBuilder.setShowWhen(showWhen);
if (Util.SDK_INT >= 31) {
Api31.setForegroundServiceBehavior(notificationBuilder);
}
return notificationBuilder.build();
}

@RequiresApi(31)
private static final class Api31 {
@SuppressLint("WrongConstant") // TODO(b/254277605): remove lint suppression
@DoNotInline
public static void setForegroundServiceBehavior(
NotificationCompat.Builder notificationBuilder) {
notificationBuilder.setForegroundServiceBehavior(FOREGROUND_SERVICE_IMMEDIATE);
}
}
}

0 comments on commit 1565a2d

Please sign in to comment.