Skip to content
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
Expand Up @@ -255,7 +255,7 @@ public void onCreate() {
*/
private void resurrection() {
// remove stucked notification
mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker);
mNotificationManager.cancel(FOREGROUND_SERVICE_ID);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This does not seem to be necessary anymore as we now cancel the notification when the service is destroyed.

Was this maybe a relic from before using a foreground service or did you still see that the service was killed without calling onDestroy()?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is to prevent edge cases like

  • upload ongoing, notification is shown
  • app is killed
  • notification is still shown

At least I remember something like that. Maybe it is already better handled by newer Android versions…

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Probably safer to leave it in then. I re-added it back.

/**
Expand All @@ -269,6 +269,9 @@ public void onDestroy() {
mServiceHandler = null;
mServiceLooper.quit();
mServiceLooper = null;
if (mNotificationManager != null) {
mNotificationManager.cancel(FOREGROUND_SERVICE_ID);
}
mNotificationManager = null;

// remove AccountsUpdatedListener
Expand Down Expand Up @@ -705,7 +708,7 @@ private void notifyUploadStart(UploadFileOperation upload) {
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}

mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotificationBuilder.build());
mNotificationManager.notify(FOREGROUND_SERVICE_ID, mNotificationBuilder.build());
} // else wait until the upload really start (onTransferProgress is called), so that if it's discarded
// due to lack of Wifi, no notification is shown
// TODO generalize for automated uploads
Expand All @@ -730,7 +733,7 @@ public void onTransferProgress(
if (mNotificationManager == null) {
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotificationBuilder.build());
mNotificationManager.notify(FOREGROUND_SERVICE_ID, mNotificationBuilder.build());
}
mLastPercent = percent;
}
Expand All @@ -748,8 +751,6 @@ private void notifyUploadResult(UploadFileOperation upload, RemoteOperationResul
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}

mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

First, I was replacing the progress notification with the general foreground service notification here (mNotification), but that doesn't seem to be necessary as we either cancel it when the service gets destroyed or replace it with a new notification when starting the next upload.

// Only notify if the upload fails
if (!uploadResult.isCancelled() &&
!uploadResult.isSuccess() &&
Expand Down