summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/battery/domain/interactor/BatteryInteractor.kt6
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/battery/domain/interactor/BatteryInteractorTest.kt53
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/battery/ui/viewmodel/BatteryViewModelTest.kt35
3 files changed, 90 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/battery/domain/interactor/BatteryInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/battery/domain/interactor/BatteryInteractor.kt
index d53cbabb1d19..342adc6af003 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/battery/domain/interactor/BatteryInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/battery/domain/interactor/BatteryInteractor.kt
@@ -65,12 +65,12 @@ class BatteryInteractor @Inject constructor(repo: BatteryRepository) {
*/
val batteryAttributionType =
combine(isCharging, powerSave, isBatteryDefenderEnabled) { charging, powerSave, defend ->
- if (charging) {
- BatteryAttributionModel.Charging
- } else if (powerSave) {
+ if (powerSave) {
BatteryAttributionModel.PowerSave
} else if (defend) {
BatteryAttributionModel.Defend
+ } else if (charging) {
+ BatteryAttributionModel.Charging
} else {
null
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/battery/domain/interactor/BatteryInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/battery/domain/interactor/BatteryInteractorTest.kt
index df45e2e21052..7946a68a6980 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/battery/domain/interactor/BatteryInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/battery/domain/interactor/BatteryInteractorTest.kt
@@ -22,6 +22,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runTest
+import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.statusbar.policy.batteryController
import com.android.systemui.statusbar.policy.fake
import com.android.systemui.testKosmos
@@ -32,7 +33,7 @@ import org.junit.runner.RunWith
@SmallTest
@RunWith(AndroidJUnit4::class)
class BatteryInteractorTest : SysuiTestCase() {
- val kosmos = testKosmos()
+ val kosmos = testKosmos().useUnconfinedTestDispatcher()
val Kosmos.underTest by Kosmos.Fixture { batteryInteractor }
@Test
@@ -50,11 +51,61 @@ class BatteryInteractorTest : SysuiTestCase() {
assertThat(latest).isEqualTo(BatteryAttributionModel.Defend)
+ batteryController.fake._isDefender = false
+ batteryController.fake._isPowerSave = true
+
+ assertThat(latest).isEqualTo(BatteryAttributionModel.PowerSave)
+
+ batteryController.fake._isPowerSave = false
+ batteryController.fake._isPluggedIn = true
+
+ assertThat(latest).isEqualTo(BatteryAttributionModel.Charging)
+ }
+
+ @Test
+ fun attributionType_prioritizesPowerSaveOverCharging() =
+ kosmos.runTest {
+ val latest by collectLastValue(underTest.batteryAttributionType)
+
+ batteryController.fake._isPluggedIn = true
+ batteryController.fake._isDefender = true
+ batteryController.fake._isPowerSave = true
+
+ assertThat(latest).isEqualTo(BatteryAttributionModel.PowerSave)
+ }
+
+ @Test
+ fun attributionType_prioritizesPowerSaveOverDefender() =
+ kosmos.runTest {
+ val latest by collectLastValue(underTest.batteryAttributionType)
+
+ batteryController.fake._isPluggedIn = true
batteryController.fake._isPowerSave = true
+ batteryController.fake._isDefender = false
assertThat(latest).isEqualTo(BatteryAttributionModel.PowerSave)
+ }
+
+ @Test
+ fun attributionType_prioritizesDefenderOverCharging() =
+ kosmos.runTest {
+ val latest by collectLastValue(underTest.batteryAttributionType)
batteryController.fake._isPluggedIn = true
+ batteryController.fake._isPowerSave = false
+ batteryController.fake._isDefender = true
+
+ assertThat(latest).isEqualTo(BatteryAttributionModel.Defend)
+ }
+
+ @Test
+ fun attributionType_prioritizesChargingOnly() =
+ kosmos.runTest {
+ val latest by collectLastValue(underTest.batteryAttributionType)
+
+ batteryController.fake._isPluggedIn = true
+ batteryController.fake._isDefender = false
+ batteryController.fake._isPowerSave = false
assertThat(latest).isEqualTo(BatteryAttributionModel.Charging)
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/battery/ui/viewmodel/BatteryViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/battery/ui/viewmodel/BatteryViewModelTest.kt
index 6f4c745e8e7e..d8173486c8a8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/battery/ui/viewmodel/BatteryViewModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/battery/ui/viewmodel/BatteryViewModelTest.kt
@@ -97,4 +97,39 @@ class BatteryViewModelTest : SysuiTestCase() {
assertThat(underTest.glyphList).isEqualTo(listOf(BatteryGlyph.BoltLarge))
}
+
+ @Test
+ fun glyphList_attributionOrdering_prioritizesDefendOverCharging() =
+ kosmos.runTest {
+ fakeSystemSettingsRepository.setInt(Settings.System.SHOW_BATTERY_PERCENT, 0)
+ batteryController.fake._level = 39
+ batteryController.fake._isPluggedIn = true
+ batteryController.fake._isDefender = true
+
+ assertThat(underTest.glyphList).isEqualTo(listOf(BatteryGlyph.DefendLarge))
+ }
+
+ @Test
+ fun glyphList_attributionOrdering_prioritizesPowerSaveOverDefend() =
+ kosmos.runTest {
+ fakeSystemSettingsRepository.setInt(Settings.System.SHOW_BATTERY_PERCENT, 0)
+ batteryController.fake._level = 39
+ batteryController.fake._isPluggedIn = true
+ batteryController.fake._isDefender = true
+ batteryController.fake._isPowerSave = true
+
+ assertThat(underTest.glyphList).isEqualTo(listOf(BatteryGlyph.PlusLarge))
+ }
+
+ @Test
+ fun glyphList_attributionOrdering_prioritizesPowerSaveOverCharging() =
+ kosmos.runTest {
+ fakeSystemSettingsRepository.setInt(Settings.System.SHOW_BATTERY_PERCENT, 0)
+ batteryController.fake._level = 39
+ batteryController.fake._isPluggedIn = true
+ batteryController.fake._isDefender = false
+ batteryController.fake._isPowerSave = true
+
+ assertThat(underTest.glyphList).isEqualTo(listOf(BatteryGlyph.PlusLarge))
+ }
}