Skip to content

Commit

Permalink
VideoStoreImportService: avoid ForegroundServiceStartNotAllowedException
Browse files Browse the repository at this point in the history
Always start notification even if appstate changed from foreground to background.

Fixes nova-video-player/aos-AVP#1127

See https://nova-video-player.sentry.io/issues/4479407625
  • Loading branch information
courville committed Feb 15, 2024
1 parent 53efa94 commit 73f8a99
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/com/archos/mediaprovider/video/VideoStoreImportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private Notification createNotification() {
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel nc = new NotificationChannel(notifChannelId, notifChannelName,
nm.IMPORTANCE_LOW);
NotificationManager.IMPORTANCE_LOW);
nc.setDescription(notifChannelDescr);
if (nm != null)
nm.createNotificationChannel(nc);
Expand All @@ -162,17 +162,10 @@ private Notification createNotification() {
@Override
public void onCreate() {
// executed on each startService
if (AppState.isForeGround()) {
if (nm == null && n == null) {
n = createNotification();
}
startForeground(NOTIFICATION_ID, n);
log.debug("onCreate: app in foreground created notification + startForeground " + NOTIFICATION_ID + " notification null? " + (n == null));
ArchosUtils.addBreadcrumb(SentryLevel.INFO, "VideoStoreImportService.onCreate", "created notification + startForeground " + NOTIFICATION_ID + " notification null? " + (n == null) + " isForeground=" + AppState.isForeGround());
} else {
log.debug("onCreate: app in background stopSelf!");
stopSelf();
}
n = createNotification();
log.debug("onCreate: create notification + startForeground " + NOTIFICATION_ID);
ArchosUtils.addBreadcrumb(SentryLevel.INFO, "VideoStoreImportService.onCreate", "created notification + startForeground " + NOTIFICATION_ID + " notification null? " + (n == null) + " isForeground=" + AppState.isForeGround());
startForeground(NOTIFICATION_ID, n);
// importer logic
mImporter = new VideoStoreImportImpl(this);
// setup background worker thread
Expand Down

0 comments on commit 73f8a99

Please sign in to comment.