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

Commit 5ced75e6 authored by Austin Tankiang's avatar Austin Tankiang
Browse files

Disable auto-dismiss of visual signals

The current auto-dismiss timing is too short and makes it difficult to
interact with the signals. Disable it for now so we can see how
intrusive the signals are and as a stopgap measure for now.

Bug: 439695733
Test: atest 'DocumentsUIGoogleTests:com.android.documentsui.JobPanelViewModelTest'
Test: atest 'DocumentsUIGoogleTests:com.android.documentsui.JobPanelUiTest'
Flag: com.android.documentsui.flags.visual_signals_ro
Change-Id: I96400e386b29acbd504382e4a49e3d4d7b454a47
parent 574829ca
Loading
Loading
Loading
Loading
+0 −18
Original line number Diff line number Diff line
@@ -17,19 +17,16 @@ package com.android.documentsui

import android.os.Parcelable
import android.util.Log
import androidx.annotation.VisibleForTesting
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.android.documentsui.base.SharedMinimal.DEBUG
import com.android.documentsui.services.JobProgress
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch

/**
 * Manages the UI state for the [JobPanelController].
@@ -40,10 +37,6 @@ import kotlinx.coroutines.launch
class JobPanelViewModel(scopeOverride: CoroutineScope? = null) : ViewModel() {
    companion object {
        private const val TAG = "JobPanelViewModel"
        private const val AUTO_DISMISS_DELAY = 3000L

        @VisibleForTesting
        var disableAutoDismiss = false
    }

    /**
@@ -129,17 +122,6 @@ class JobPanelViewModel(scopeOverride: CoroutineScope? = null) : ViewModel() {
            _currentJobs.merge(jobProgress.id, ProgressViewModel(jobProgress)) { old, new ->
                ProgressViewModel(new.jobProgress, old.expanded)
            }

            if (jobProgress.isFinal && !jobProgress.hasFailures &&
                !pendingRemoves.contains(jobProgress.id)) {
                if (!disableAutoDismiss) {
                    scope.launch {
                        delay(AUTO_DISMISS_DELAY)
                        dismissProgress(jobProgress.id)
                        pendingRemoves.remove(jobProgress.id)
                    }
                }
            }
        }
        _currentJobs.entries.removeAll { (id, model) -> !model.jobProgress.isFinal && id !in seen }

+0 −14
Original line number Diff line number Diff line
@@ -52,10 +52,8 @@ import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.not
import org.junit.After
import org.junit.Assert.assertTrue
import org.junit.Assume.assumeTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -110,18 +108,6 @@ class JobPanelUiTest : ActivityTestJunit4<FilesActivity>() {
        onView(withId(R.id.job_progress_panel_title)).check(matches(isDisplayed()))
    }

    @Before
    fun disableAutoDismiss() {
        // The auto dismiss behaviour will cause some tests to flake depending on how fast the test
        // is run, so just disable it.
        JobPanelViewModel.disableAutoDismiss = true
    }

    @After
    fun reenableAutoDismiss() {
        JobPanelViewModel.disableAutoDismiss = false
    }

    @Test
    fun testInProgressItems() {
        onView(withId(R.id.job_progress_toolbar_indicator)).check(doesNotExist())
+0 −61
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import com.android.documentsui.rules.OverrideFlagsRule
import com.android.documentsui.services.FileOperationService
import com.android.documentsui.services.Job
import com.android.documentsui.testing.MutableJobProgress
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.UnconfinedTestDispatcher
@@ -241,66 +240,6 @@ class JobPanelViewModelTest {
        )
    }

    @Test
    fun testAutoDismiss() = runTest {
        val viewModel = JobPanelViewModel(this)

        val inProgress = MutableJobProgress(
            id = "in_progress_job",
            operationType = FileOperationService.OPERATION_COPY,
            state = Job.STATE_SET_UP,
            msg = "Job in progress",
            hasFailures = false,
            currentBytes = 40,
            requiredBytes = 100,
        )

        val succeeded = MutableJobProgress(
            id = "succeeded_job",
            operationType = FileOperationService.OPERATION_COPY,
            state = Job.STATE_COMPLETED,
            msg = "Job succeeded",
            hasFailures = false,
        )

        val failed = MutableJobProgress(
            id = "failed_job",
            operationType = FileOperationService.OPERATION_COPY,
            state = Job.STATE_COMPLETED,
            msg = "Job failed",
            hasFailures = true,
        )

        val start = testScheduler.timeSource.markNow()
        viewModel.updateProgress(listOf(inProgress, succeeded, failed).toJobProgressList())
        testScheduler.advanceTimeBy(2.seconds)
        assertEquals(
            listOf(inProgress, succeeded, failed)
                .withExpandStates(false, false, false),
            ArrayList(viewModel.currentJobs.values)
        )

        inProgress.state = Job.STATE_CANCELED
        viewModel.updateProgress(listOf(inProgress).toJobProgressList())

        // After three seconds from first update, the succeeded job should auto dismiss.
        testScheduler.advanceTimeBy(1.seconds)
        testScheduler.runCurrent()
        assertEquals(
            listOf(inProgress, failed)
                .withExpandStates(false, false),
            ArrayList(viewModel.currentJobs.values)
        )

        // The previously in progress job should auto dismiss at five seconds.
        testScheduler.advanceUntilIdle()
        assertEquals(5.seconds, start.elapsedNow())
        assertEquals(
            listOf(failed).withExpandStates(false),
            ArrayList(viewModel.currentJobs.values)
        )
    }

    @OptIn(ExperimentalCoroutinesApi::class)
    @Test
    fun testDismissCompleted() = runTest {