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

Commit 2d661e79 authored by Andre Le's avatar Andre Le
Browse files

ComposeClock: Move shade's clock interactor and repository to common dir

Move and rename ShadeHeaderClockInteractor and
ShadeHeaderClockRepository to systemui/clock. This is part of an effort
to create a composable clock that will be used in both the status bar
and the shade.

Bug: 390204943
Flag: com.android.systemui.clock_modernization
Test: ClockInteractorTest, ClockRepositoryTest
Change-Id: I0912e07eaea753ecdce2b34c85e07ba9df81d48a
parent 679115af
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.systemui.shade.data.repository
package com.android.systemui.clock.data.repository

import android.app.AlarmManager
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -30,17 +30,16 @@ import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.times
import org.mockito.Mockito.verify

@SmallTest
@RunWith(AndroidJUnit4::class)
class ShadeHeaderClockRepositoryTest : SysuiTestCase() {
class ClockRepositoryTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val nextAlarmController = kosmos.nextAlarmController

    val underTest = kosmos.shadeHeaderClockRepository
    val underTest = kosmos.clockRepository

    @Test
    fun nextAlarmIntent_updates() =
+15 −15
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.systemui.shade.domain.interactor
package com.android.systemui.clock.domain.interactor

import android.app.AlarmManager
import android.content.Intent
@@ -27,14 +27,14 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectValues
import com.android.systemui.kosmos.testScope
import com.android.systemui.plugins.activityStarter
import com.android.systemui.statusbar.policy.NextAlarmController.NextAlarmChangeCallback
import com.android.systemui.statusbar.policy.NextAlarmController
import com.android.systemui.statusbar.policy.nextAlarmController
import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.argThat
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.withArgCaptor
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth
import java.util.Date
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
@@ -47,25 +47,25 @@ import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatcher
import org.mockito.Mockito.verify
import org.mockito.Mockito

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
class ShadeHeaderClockInteractorTest : SysuiTestCase() {
class ClockInteractorTest : SysuiTestCase() {

    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val activityStarter = kosmos.activityStarter
    private val nextAlarmController = kosmos.nextAlarmController

    private val underTest = kosmos.shadeHeaderClockInteractor
    private val underTest = kosmos.clockInteractor

    @Test
    fun launchClockActivity_default() =
        testScope.runTest {
            underTest.launchClockActivity()
            verify(activityStarter)
            Mockito.verify(activityStarter)
                .postStartActivityDismissingKeyguard(
                    argThat(IntentMatcherAction(AlarmClock.ACTION_SHOW_ALARMS)),
                    any(),
@@ -76,13 +76,13 @@ class ShadeHeaderClockInteractorTest : SysuiTestCase() {
    fun launchClockActivity_nextAlarmIntent() =
        testScope.runTest {
            val callback =
                withArgCaptor<NextAlarmChangeCallback> {
                    verify(nextAlarmController).addCallback(capture())
                withArgCaptor<NextAlarmController.NextAlarmChangeCallback> {
                    Mockito.verify(nextAlarmController).addCallback(capture())
                }
            callback.onNextAlarmChanged(AlarmManager.AlarmClockInfo(1L, mock()))

            underTest.launchClockActivity()
            verify(activityStarter).postStartActivityDismissingKeyguard(any())
            Mockito.verify(activityStarter).postStartActivityDismissingKeyguard(any())
        }

    @Test
@@ -95,20 +95,20 @@ class ShadeHeaderClockInteractorTest : SysuiTestCase() {
            sendIntentActionBroadcast(Intent.ACTION_LOCALE_CHANGED)
            sendIntentActionBroadcast(Intent.ACTION_TIMEZONE_CHANGED)

            assertThat(timeZoneOrLocaleChanges).hasSize(4)
            Truth.assertThat(timeZoneOrLocaleChanges).hasSize(4)
        }

    @Test
    fun onTimezoneOrLocaleChanged_timeChanged_doesNotEmit() =
        testScope.runTest {
            val timeZoneOrLocaleChanges by collectValues(underTest.onTimezoneOrLocaleChanged)
            assertThat(timeZoneOrLocaleChanges).hasSize(1)
            Truth.assertThat(timeZoneOrLocaleChanges).hasSize(1)

            sendIntentActionBroadcast(Intent.ACTION_TIME_CHANGED)
            sendIntentActionBroadcast(Intent.ACTION_TIME_TICK)

            // Expect only 1 event to have been emitted onStart, but no more.
            assertThat(timeZoneOrLocaleChanges).hasSize(1)
            Truth.assertThat(timeZoneOrLocaleChanges).hasSize(1)
        }

    @Test
@@ -125,7 +125,7 @@ class ShadeHeaderClockInteractorTest : SysuiTestCase() {
            sendIntentActionBroadcast(Intent.ACTION_TIME_CHANGED)
            val laterTime = checkNotNull(currentTime)

            assertThat(differenceBetween(laterTime, earlierTime)).isEqualTo(3.seconds)
            Truth.assertThat(differenceBetween(laterTime, earlierTime)).isEqualTo(3.seconds)
        }

    @Test
@@ -142,7 +142,7 @@ class ShadeHeaderClockInteractorTest : SysuiTestCase() {
            sendIntentActionBroadcast(Intent.ACTION_TIME_TICK)
            val laterTime = checkNotNull(currentTime)

            assertThat(differenceBetween(laterTime, earlierTime)).isEqualTo(7.seconds)
            Truth.assertThat(differenceBetween(laterTime, earlierTime)).isEqualTo(7.seconds)
        }

    private fun differenceBetween(date1: Date, date2: Date): Duration {
+2 −6
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.systemui.shade.data.repository
package com.android.systemui.clock.data.repository

import android.app.PendingIntent
import com.android.systemui.dagger.SysUISingleton
@@ -22,11 +22,7 @@ import com.android.systemui.statusbar.policy.NextAlarmController
import javax.inject.Inject

@SysUISingleton
class ShadeHeaderClockRepository
@Inject
constructor(
    nextAlarmController: NextAlarmController,
) {
class ClockRepository @Inject constructor(nextAlarmController: NextAlarmController) {
    private val nextAlarmCallback =
        NextAlarmController.NextAlarmChangeCallback { nextAlarm ->
            nextAlarmIntent = nextAlarm?.showIntent
+4 −4
Original line number Diff line number Diff line
@@ -14,16 +14,16 @@
 * limitations under the License.
 */

package com.android.systemui.shade.domain.interactor
package com.android.systemui.clock.domain.interactor

import android.content.Intent
import android.content.IntentFilter
import android.os.UserHandle
import android.provider.AlarmClock
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.clock.data.repository.ClockRepository
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.shade.data.repository.ShadeHeaderClockRepository
import com.android.systemui.util.kotlin.emitOnStart
import com.android.systemui.util.time.SystemClock
import java.util.Date
@@ -32,10 +32,10 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

@SysUISingleton
class ShadeHeaderClockInteractor
class ClockInteractor
@Inject
constructor(
    private val repository: ShadeHeaderClockRepository,
    private val repository: ClockRepository,
    private val activityStarter: ActivityStarter,
    private val broadcastDispatcher: BroadcastDispatcher,
    private val systemClock: SystemClock,
+2 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.unit.IntRect
import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.systemui.battery.BatteryMeterViewController
import com.android.systemui.clock.domain.interactor.ClockInteractor
import com.android.systemui.kairos.ExperimentalKairosApi
import com.android.systemui.kairos.KairosNetwork
import com.android.systemui.lifecycle.ExclusiveActivatable
@@ -44,7 +45,6 @@ import com.android.systemui.scene.shared.model.Overlays
import com.android.systemui.scene.shared.model.TransitionKeys.SlightlyFasterShadeCollapse
import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.shade.domain.interactor.PrivacyChipInteractor
import com.android.systemui.shade.domain.interactor.ShadeHeaderClockInteractor
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.shade.domain.interactor.ShadeModeInteractor
import com.android.systemui.statusbar.phone.StatusBarLocation
@@ -78,7 +78,7 @@ constructor(
    mobileIconsInteractor: MobileIconsInteractor,
    val mobileIconsViewModel: MobileIconsViewModel,
    private val privacyChipInteractor: PrivacyChipInteractor,
    private val clockInteractor: ShadeHeaderClockInteractor,
    private val clockInteractor: ClockInteractor,
    private val tintedIconManagerFactory: TintedIconManager.Factory,
    private val batteryMeterViewControllerFactory: BatteryMeterViewController.Factory,
    val statusBarIconController: StatusBarIconController,
Loading