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

Commit 42c5b81f authored by Austin Tankiang's avatar Austin Tankiang Committed by Android (Google) Code Review
Browse files

Merge "Fix system notifications when visual signals flag is on" into main

parents f0d52d9e 8d53b1e9
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import static com.android.documentsui.services.FileOperationService.EXTRA_OPERAT
import static com.android.documentsui.services.FileOperationService.MESSAGE_FINISH;
import static com.android.documentsui.services.FileOperationService.MESSAGE_PROGRESS;
import static com.android.documentsui.services.FileOperationService.OPERATION_COPY;
import static com.android.documentsui.util.FlagUtils.isVisualSignalsFlagEnabled;
import static com.android.documentsui.util.Material3Config.getRes;

import android.app.Notification;
@@ -1054,7 +1055,11 @@ class CopyJob extends ResolvedResourcesJob {
        }

        protected void update(Builder builder, Function<Long, String> messageFormatter) {
            // When the flag is enabled, updateEstimatedRemainingTime() is already called
            // elsewhere at the same time, so only call it when the flag is disabled.
            if (!isVisualSignalsFlagEnabled()) {
                updateEstimateRemainingTime();
            }
            final double completed = getProgress();

            builder.setProgress(100, (int) (completed * 100), false);
+10 −1
Original line number Diff line number Diff line
@@ -614,7 +614,16 @@ public class FileOperationService extends Service implements Job.Listener {
            var progress = new ArrayList<JobProgress>();
            synchronized (mJobs) {
                for (JobRecord rec : mJobs.values()) {
                    progress.add(rec.job.getJobProgress());
                    var job = rec.job;
                    progress.add(job.getJobProgress());

                    // Only job in set up state has progress bar
                    if (job.getState() == Job.STATE_SET_UP) {
                        notificationManager.notify(
                                mForegroundJob == job ? null : job.id,
                                NOTIFICATION_ID_PROGRESS,
                                job.getProgressNotification());
                    }
                }
            }
            Intent intent = new Intent();
+1 −2
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.documentsui.services;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;

import android.app.Notification;
@@ -74,7 +73,7 @@ class TestNotificationManager {
        return null;
    }

    private boolean hasNotification(int id, String jobId) {
    boolean hasNotification(int id, String jobId) {
        if (mNotifications.get(id) == null) {
            return false;
        }
+14 −5
Original line number Diff line number Diff line
@@ -109,8 +109,6 @@ public class FileOperationServiceTest extends ServiceTestCase<FileOperationServi

        assertNull(mService.features);
        mService.features = features;

        mService.mVisualSignalsEnabled = false;
    }

    @Override
@@ -265,26 +263,37 @@ public class FileOperationServiceTest extends ServiceTestCase<FileOperationServi
    public void testRunsInForeground_MultipleJobs() throws Exception {
        startService(createCopyIntent(Arrays.asList(ALPHA_DOC), BETA_DOC));
        startService(createCopyIntent(Arrays.asList(GAMMA_DOC), DELTA_DOC));
        Job job2 = mCopyJobs.get(1);

        mExecutor.run(0);
        mForegroundManager.assertInForeground();

        mHandler.dispatchAllMessages();
        while (mTestNotificationManager.hasNotification(
                FileOperationService.NOTIFICATION_ID_PROGRESS, job2.id)) {
            mHandler.dispatchNextMessage();
        }
        mForegroundManager.assertInForeground();
    }

    public void testFinishesInBackground_MultipleJobs() throws Exception {
        startService(createCopyIntent(Arrays.asList(ALPHA_DOC), BETA_DOC));
        startService(createCopyIntent(Arrays.asList(GAMMA_DOC), DELTA_DOC));
        Job job2 = mCopyJobs.get(1);

        mExecutor.run(0);
        mForegroundManager.assertInForeground();

        mHandler.dispatchAllMessages();
        while (mTestNotificationManager.hasNotification(
                FileOperationService.NOTIFICATION_ID_PROGRESS, job2.id)) {
            mHandler.dispatchNextMessage();
        }
        mForegroundManager.assertInForeground();

        mExecutor.run(0);
        mHandler.dispatchAllMessages();
        while (mTestNotificationManager.hasNotification(
                FileOperationService.NOTIFICATION_ID_PROGRESS, null)) {
            mHandler.dispatchNextMessage();
        }
        mForegroundManager.assertInBackground();
    }