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

Commit fceba8d0 authored by Zhe Song's avatar Zhe Song Committed by Android (Google) Code Review
Browse files

Merge "Introduce GlobalActionsRepository,Interactor to model the state." into main

parents ee646bd8 56e6428f
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -122,6 +122,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.globalactions.domain.interactor.GlobalActionsInteractor;
import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
import com.android.systemui.plugins.GlobalActionsPanelPlugin;
import com.android.systemui.scrim.ScrimDrawable;
@@ -257,6 +258,7 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
    private final ShadeController mShadeController;
    private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
    private final DialogTransitionAnimator mDialogTransitionAnimator;
    private final GlobalActionsInteractor mInteractor;

    @VisibleForTesting
    public enum GlobalActionsEvent implements UiEventLogger.UiEventEnum {
@@ -368,7 +370,8 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
            ShadeController shadeController,
            KeyguardUpdateMonitor keyguardUpdateMonitor,
            DialogTransitionAnimator dialogTransitionAnimator,
            SelectedUserInteractor selectedUserInteractor) {
            SelectedUserInteractor selectedUserInteractor,
            GlobalActionsInteractor interactor) {
        mContext = context;
        mWindowManagerFuncs = windowManagerFuncs;
        mAudioManager = audioManager;
@@ -404,6 +407,7 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
        mKeyguardUpdateMonitor = keyguardUpdateMonitor;
        mDialogTransitionAnimator = dialogTransitionAnimator;
        mSelectedUserInteractor = selectedUserInteractor;
        mInteractor = interactor;

        // receive broadcasts
        IntentFilter filter = new IntentFilter();
@@ -1333,6 +1337,7 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
        mUiEventLogger.log(GlobalActionsEvent.GA_POWER_MENU_CLOSE);
        mWindowManagerFuncs.onGlobalActionsHidden();
        mLifecycle.setCurrentState(Lifecycle.State.CREATED);
        mInteractor.onDismissed();
    }

    /**
@@ -1342,6 +1347,7 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
    public void onShow(DialogInterface dialog) {
        mMetricsLogger.visible(MetricsEvent.POWER_MENU);
        mUiEventLogger.log(GlobalActionsEvent.GA_POWER_MENU_OPEN);
        mInteractor.onShown();
    }

    /**
+35 −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.globalactions.data.repository

import com.android.systemui.dagger.SysUISingleton
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow

/** Encapsulates application state for global actions. */
@SysUISingleton
class GlobalActionsRepository @Inject constructor() {
    private val _isVisible: MutableStateFlow<Boolean> = MutableStateFlow(false)
    /** Is the global actions dialog visible. */
    val isVisible = _isVisible.asStateFlow()

    /** Sets whether the global actions dialog is visible. */
    fun setVisible(isVisible: Boolean) {
        _isVisible.value = isVisible
    }
}
+42 −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.globalactions.domain.interactor

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.globalactions.data.repository.GlobalActionsRepository
import javax.inject.Inject
import kotlinx.coroutines.flow.StateFlow

@SysUISingleton
class GlobalActionsInteractor
@Inject
constructor(
    private val repository: GlobalActionsRepository,
) {
    /** Is the global actions dialog visible. */
    val isVisible: StateFlow<Boolean> = repository.isVisible

    /** Notifies that the global actions dialog is shown. */
    fun onShown() {
        repository.setVisible(true)
    }

    /** Notifies that the global actions dialog has been dismissed. */
    fun onDismissed() {
        repository.setVisible(false)
    }
}
+19 −1
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ import com.android.systemui.SysuiTestCase;
import com.android.systemui.animation.DialogTransitionAnimator;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.globalactions.domain.interactor.GlobalActionsInteractor;
import com.android.systemui.kosmos.KosmosJavaAdapter;
import com.android.systemui.plugins.GlobalActions;
import com.android.systemui.settings.UserContextProvider;
import com.android.systemui.settings.UserTracker;
@@ -140,6 +142,8 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
    @Captor private ArgumentCaptor<OnBackInvokedCallback> mOnBackInvokedCallback;

    private TestableLooper mTestableLooper;
    private KosmosJavaAdapter mKosmos = new KosmosJavaAdapter(this);
    private GlobalActionsInteractor mInteractor;

    @Before
    public void setUp() throws Exception {
@@ -154,6 +158,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {

        mGlobalSettings = new FakeGlobalSettings();
        mSecureSettings = new FakeSettings();
        mInteractor = mKosmos.getGlobalActionsInteractor();

        mGlobalActionsDialogLite = new GlobalActionsDialogLite(mContext,
                mWindowManagerFuncs,
@@ -189,7 +194,8 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
                mShadeController,
                mKeyguardUpdateMonitor,
                mDialogTransitionAnimator,
                mSelectedUserInteractor);
                mSelectedUserInteractor,
                mInteractor);
        mGlobalActionsDialogLite.setZeroDialogPressDelayForTesting();

        ColorExtractor.GradientColors backdropColors = new ColorExtractor.GradientColors();
@@ -623,6 +629,18 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
        assertThat(bugReportAction.showBeforeProvisioning()).isFalse();
    }

    @Test
    public void testInteractor_onShow() {
        mGlobalActionsDialogLite.onShow(null);
        assertThat(mInteractor.isVisible().getValue()).isTrue();
    }

    @Test
    public void testInteractor_onDismiss() {
        mGlobalActionsDialogLite.onDismiss(mGlobalActionsDialogLite.mDialog);
        assertThat(mInteractor.isVisible().getValue()).isFalse();
    }

    private UserInfo mockCurrentUser(int flags) {
        return new UserInfo(10, "A User", flags);

+69 −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.globalactions.data.repository

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
class GlobalActionsRepositoryTest : SysuiTestCase() {
    private lateinit var underTest: GlobalActionsRepository
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope

    @Before
    fun setUp() {
        underTest = kosmos.globalActionsRepository
    }

    @Test
    fun isVisible_initialValueFalse() {
        testScope.runTest {
            val isVisible by collectLastValue(underTest.isVisible)
            runCurrent()

            assertThat(isVisible).isFalse()
        }
    }

    @Test
    fun isVisible_onChange() {
        testScope.runTest {
            val isVisible by collectLastValue(underTest.isVisible)
            runCurrent()

            underTest.setVisible(true)
            assertThat(isVisible).isTrue()

            underTest.setVisible(false)
            assertThat(isVisible).isFalse()
        }
    }
}
Loading