Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2bbdd651 authored by Geoffrey Pitsch's avatar Geoffrey Pitsch Committed by Android (Google) Code Review
Browse files

Merge "Fix potential race bug where notification may persist after job finish."

parents 39092e79 d5706f0f
Loading
Loading
Loading
Loading
+19 −14
Original line number Diff line number Diff line
@@ -354,7 +354,7 @@ public class FileOperationService extends Service implements Job.Listener {
                job.id, NOTIFICATION_ID_PROGRESS, notification);

        // Set up related monitor
        JobMonitor monitor = new JobMonitor(job, notificationManager, handler);
        JobMonitor monitor = new JobMonitor(job, notificationManager, handler, mJobs);
        monitor.start();
    }

@@ -458,11 +458,14 @@ public class FileOperationService extends Service implements Job.Listener {
        private final Job mJob;
        private final NotificationManager mNotificationManager;
        private final Handler mHandler;
        private final Object mJobsLock;

        private JobMonitor(Job job, NotificationManager notificationManager, Handler handler) {
        private JobMonitor(Job job, NotificationManager notificationManager, Handler handler,
                Object jobsLock) {
            mJob = job;
            mNotificationManager = notificationManager;
            mHandler = handler;
            mJobsLock = jobsLock;
        }

        private void start() {
@@ -471,6 +474,7 @@ public class FileOperationService extends Service implements Job.Listener {

        @Override
        public void run() {
            synchronized (mJobsLock) {
                if (mJob.isFinished()) {
                    // Finish notification is already shown. Progress notification is removed.
                    // Just finish itself.
@@ -486,6 +490,7 @@ public class FileOperationService extends Service implements Job.Listener {
                mHandler.postDelayed(this, PROGRESS_INTERVAL_MILLIS);
            }
        }
    }

    @Override
    public IBinder onBind(Intent intent) {