Show "0 B used" when no data usage this cycle
When the latest cycle has no data usage, currently it shows all time usage without cycle info, which could confuse user. Change to "0 B used used xxx - xxx" to fix this issue. Fix: 292346951 Test: manual - on Mobile Settings Test: unit tests Change-Id: Ic06fd63a3bc049d70538d0a3cd1fa3d62dbd71d7
This commit is contained in:
@@ -107,7 +107,7 @@ class DataUsagePreferenceController(context: Context, key: String) :
|
|||||||
|
|
||||||
private fun getDataUsageSummary(): String? {
|
private fun getDataUsageSummary(): String? {
|
||||||
val repository = createNetworkCycleDataRepository() ?: return null
|
val repository = createNetworkCycleDataRepository() ?: return null
|
||||||
repository.loadFirstCycle()?.takeIf { it.usage > 0 }?.let { usageData ->
|
repository.loadFirstCycle()?.let { usageData ->
|
||||||
return mContext.getString(
|
return mContext.getString(
|
||||||
R.string.data_usage_template,
|
R.string.data_usage_template,
|
||||||
usageData.formatUsage(mContext),
|
usageData.formatUsage(mContext),
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import android.net.NetworkTemplate
|
|||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.telephony.SubscriptionManager
|
import android.telephony.SubscriptionManager
|
||||||
import android.util.DataUnit
|
import android.util.DataUnit
|
||||||
import androidx.lifecycle.Lifecycle
|
|
||||||
import androidx.lifecycle.testing.TestLifecycleOwner
|
import androidx.lifecycle.testing.TestLifecycleOwner
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
@@ -78,13 +77,11 @@ class DataUsagePreferenceControllerTest {
|
|||||||
fun setUp() {
|
fun setUp() {
|
||||||
mockSession = ExtendedMockito.mockitoSession()
|
mockSession = ExtendedMockito.mockitoSession()
|
||||||
.initMocks(this)
|
.initMocks(this)
|
||||||
.mockStatic(SubscriptionManager::class.java)
|
|
||||||
.spyStatic(DataUsageUtils::class.java)
|
.spyStatic(DataUsageUtils::class.java)
|
||||||
.spyStatic(DataUsageLib::class.java)
|
.spyStatic(DataUsageLib::class.java)
|
||||||
.strictness(Strictness.LENIENT)
|
.strictness(Strictness.LENIENT)
|
||||||
.startMocking()
|
.startMocking()
|
||||||
|
|
||||||
whenever(SubscriptionManager.isValidSubscriptionId(SUB_ID)).thenReturn(true)
|
|
||||||
ExtendedMockito.doReturn(true).`when` { DataUsageUtils.hasMobileData(context) }
|
ExtendedMockito.doReturn(true).`when` { DataUsageUtils.hasMobileData(context) }
|
||||||
ExtendedMockito.doReturn(networkTemplate).`when` {
|
ExtendedMockito.doReturn(networkTemplate).`when` {
|
||||||
DataUsageLib.getMobileTemplate(context, SUB_ID)
|
DataUsageLib.getMobileTemplate(context, SUB_ID)
|
||||||
@@ -109,9 +106,10 @@ class DataUsagePreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getAvailabilityStatus_invalidSubId_returnUnsearchable() {
|
fun getAvailabilityStatus_invalidSubId_returnUnsearchable() {
|
||||||
controller.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID)
|
val availabilityStatus =
|
||||||
|
controller.getAvailabilityStatus(SubscriptionManager.INVALID_SUBSCRIPTION_ID)
|
||||||
|
|
||||||
assertThat(controller.availabilityStatus).isEqualTo(AVAILABLE_UNSEARCHABLE)
|
assertThat(availabilityStatus).isEqualTo(AVAILABLE_UNSEARCHABLE)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -120,7 +118,7 @@ class DataUsagePreferenceControllerTest {
|
|||||||
repository.stub {
|
repository.stub {
|
||||||
on { loadFirstCycle() } doReturn usageData
|
on { loadFirstCycle() } doReturn usageData
|
||||||
}
|
}
|
||||||
controller.onViewCreated(TestLifecycleOwner(initialState = Lifecycle.State.STARTED))
|
controller.onViewCreated(TestLifecycleOwner())
|
||||||
waitUntil { preference.summary != null }
|
waitUntil { preference.summary != null }
|
||||||
|
|
||||||
controller.handlePreferenceTreeClick(preference)
|
controller.handlePreferenceTreeClick(preference)
|
||||||
@@ -136,21 +134,22 @@ class DataUsagePreferenceControllerTest {
|
|||||||
fun updateState_invalidSubId_disabled() = runBlocking {
|
fun updateState_invalidSubId_disabled() = runBlocking {
|
||||||
controller.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID)
|
controller.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID)
|
||||||
|
|
||||||
controller.onViewCreated(TestLifecycleOwner(initialState = Lifecycle.State.STARTED))
|
controller.onViewCreated(TestLifecycleOwner())
|
||||||
|
|
||||||
waitUntil { !preference.isEnabled }
|
waitUntil { !preference.isEnabled }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun updateState_noUsageData_shouldDisablePreference() = runBlocking {
|
fun updateState_noUsageData_shouldEnablePreference() = runBlocking {
|
||||||
val usageData = NetworkUsageData(START_TIME, END_TIME, 0L)
|
val usageData = NetworkUsageData(START_TIME, END_TIME, 0L)
|
||||||
repository.stub {
|
repository.stub {
|
||||||
on { loadFirstCycle() } doReturn usageData
|
on { loadFirstCycle() } doReturn usageData
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.onViewCreated(TestLifecycleOwner(initialState = Lifecycle.State.STARTED))
|
controller.onViewCreated(TestLifecycleOwner())
|
||||||
|
|
||||||
waitUntil { !preference.isEnabled }
|
waitUntil { preference.isEnabled }
|
||||||
|
waitUntil { preference.summary?.contains("0 B used") == true }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -160,9 +159,9 @@ class DataUsagePreferenceControllerTest {
|
|||||||
on { loadFirstCycle() } doReturn usageData
|
on { loadFirstCycle() } doReturn usageData
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.onViewCreated(TestLifecycleOwner(initialState = Lifecycle.State.STARTED))
|
controller.onViewCreated(TestLifecycleOwner())
|
||||||
|
|
||||||
waitUntil { preference.summary?.contains("1.00 MB") == true }
|
waitUntil { preference.summary?.contains("1.00 MB used") == true }
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
|
|||||||
Reference in New Issue
Block a user