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

Commit 03aa08c4 authored by Stefan Andonian's avatar Stefan Andonian
Browse files

Maintain correct Record Issue QS tile active state.

This change moves the state tracking to a shared preference value, and
then adds a listener in RecordIssueTile so that when that shared
preference value changes, the tile is refreshed.

Bug: 305049544
Flag: ACONFIG record_issue_qs_tile DEVELOPMENT
Test: Manually tested that everything works on device.
Change-Id: Ia8d188e4b16d2b789aaf1cd0d2db96bc589e77da
parent 5f9c22a9
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import com.android.systemui.qs.logging.QSLogger
import com.android.systemui.qs.pipeline.domain.interactor.PanelInteractor
import com.android.systemui.qs.tileimpl.QSTileImpl
import com.android.systemui.recordissue.IssueRecordingService
import com.android.systemui.recordissue.IssueRecordingState
import com.android.systemui.recordissue.RecordIssueDialogDelegate
import com.android.systemui.res.R
import com.android.systemui.screenrecord.RecordingService
@@ -69,6 +70,7 @@ constructor(
    private val dialogTransitionAnimator: DialogTransitionAnimator,
    private val panelInteractor: PanelInteractor,
    private val userContextProvider: UserContextProvider,
    private val issueRecordingState: IssueRecordingState,
    private val delegateFactory: RecordIssueDialogDelegate.Factory,
) :
    QSTileImpl<QSTile.BooleanState>(
@@ -83,7 +85,16 @@ constructor(
        qsLogger
    ) {

    @VisibleForTesting var isRecording: Boolean = false
    private val onRecordingChangeListener = Runnable { refreshState() }

    override fun handleSetListening(listening: Boolean) {
        super.handleSetListening(listening)
        if (listening) {
            issueRecordingState.addListener(onRecordingChangeListener)
        } else {
            issueRecordingState.removeListener(onRecordingChangeListener)
        }
    }

    override fun getTileLabel(): CharSequence = mContext.getString(R.string.qs_record_issue_label)

@@ -103,13 +114,11 @@ constructor(

    @VisibleForTesting
    public override fun handleClick(view: View?) {
        if (isRecording) {
            isRecording = false
        if (issueRecordingState.isRecording) {
            stopIssueRecordingService()
        } else {
            mUiHandler.post { showPrompt(view) }
        }
        refreshState()
    }

    private fun startIssueRecordingService(screenRecord: Boolean, winscopeTracing: Boolean) =
@@ -138,11 +147,9 @@ constructor(
        val dialog: AlertDialog =
            delegateFactory
                .create {
                    isRecording = true
                    startIssueRecordingService(it.screenRecord, it.winscopeTracing)
                    dialogTransitionAnimator.disableAllCurrentDialogsExitAnimations()
                    panelInteractor.collapsePanels()
                    refreshState()
                }
                .createDialog()
        val dismissAction =
@@ -168,7 +175,7 @@ constructor(
    @VisibleForTesting
    public override fun handleUpdateState(qsTileState: QSTile.BooleanState, arg: Any?) {
        qsTileState.apply {
            if (isRecording) {
            if (issueRecordingState.isRecording) {
                value = true
                state = Tile.STATE_ACTIVE
                forceExpandIcon = false
+3 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ constructor(
    keyguardDismissUtil: KeyguardDismissUtil,
    private val dialogTransitionAnimator: DialogTransitionAnimator,
    private val panelInteractor: PanelInteractor,
    private val issueRecordingState: IssueRecordingState,
) :
    RecordingService(
        controller,
@@ -90,6 +91,7 @@ constructor(
                    DEFAULT_MAX_TRACE_SIZE,
                    DEFAULT_MAX_TRACE_DURATION_IN_MINUTES
                )
                issueRecordingState.isRecording = true
                if (!intent.getBooleanExtra(EXTRA_SCREEN_RECORD, false)) {
                    // If we don't want to record the screen, the ACTION_SHOW_START_NOTIF action
                    // will circumvent the RecordingService's screen recording start code.
@@ -103,6 +105,7 @@ constructor(
                // this line should be removed.
                getSystemService(LauncherApps::class.java)?.saveViewCaptureData()
                TraceUtils.traceStop(contentResolver)
                issueRecordingState.isRecording = false
            }
            ACTION_SHARE -> {
                shareRecording(intent)
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.recordissue

import com.android.systemui.dagger.SysUISingleton
import java.util.concurrent.CopyOnWriteArrayList
import javax.inject.Inject

@SysUISingleton
class IssueRecordingState @Inject constructor() {

    private val listeners = CopyOnWriteArrayList<Runnable>()

    var isRecording = false
        set(value) {
            field = value
            listeners.forEach(Runnable::run)
        }

    fun addListener(listener: Runnable) {
        listeners.add(listener)
    }

    fun removeListener(listener: Runnable) {
        listeners.remove(listener)
    }
}
+9 −6
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.systemui.qs.QSHost
import com.android.systemui.qs.QsEventLogger
import com.android.systemui.qs.logging.QSLogger
import com.android.systemui.qs.pipeline.domain.interactor.PanelInteractor
import com.android.systemui.recordissue.IssueRecordingState
import com.android.systemui.recordissue.RecordIssueDialogDelegate
import com.android.systemui.res.R
import com.android.systemui.settings.UserContextProvider
@@ -74,6 +75,7 @@ class RecordIssueTileTest : SysuiTestCase() {
    @Mock private lateinit var dialog: SystemUIDialog

    private lateinit var testableLooper: TestableLooper
    private val issueRecordingState = IssueRecordingState()
    private lateinit var tile: RecordIssueTile

    @Before
@@ -100,13 +102,14 @@ class RecordIssueTileTest : SysuiTestCase() {
                dialogLauncherAnimator,
                panelInteractor,
                userContextProvider,
                issueRecordingState,
                delegateFactory,
            )
    }

    @Test
    fun qsTileUi_shouldLookCorrect_whenInactive() {
        tile.isRecording = false
        issueRecordingState.isRecording = false

        val testState = tile.newTileState()
        tile.handleUpdateState(testState, null)
@@ -118,8 +121,7 @@ class RecordIssueTileTest : SysuiTestCase() {

    @Test
    fun qsTileUi_shouldLookCorrect_whenRecording() {
        tile.isRecording = true

        issueRecordingState.isRecording = true
        val testState = tile.newTileState()
        tile.handleUpdateState(testState, null)

@@ -130,7 +132,7 @@ class RecordIssueTileTest : SysuiTestCase() {

    @Test
    fun inActiveQsTile_switchesToActive_whenClicked() {
        tile.isRecording = false
        issueRecordingState.isRecording = false

        val testState = tile.newTileState()
        tile.handleUpdateState(testState, null)
@@ -140,7 +142,7 @@ class RecordIssueTileTest : SysuiTestCase() {

    @Test
    fun activeQsTile_switchesToInActive_whenClicked() {
        tile.isRecording = true
        issueRecordingState.isRecording = true

        val testState = tile.newTileState()
        tile.handleUpdateState(testState, null)
@@ -150,7 +152,8 @@ class RecordIssueTileTest : SysuiTestCase() {

    @Test
    fun showPrompt_shouldUseKeyguardDismissUtil_ToShowDialog() {
        tile.isRecording = false
        issueRecordingState.isRecording = false

        tile.handleClick(null)
        testableLooper.processAllMessages()