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

Commit 759afa52 authored by junyulai's avatar junyulai Committed by Junyu Lai
Browse files

[SP21.2] Address comments for API council review about aosp/1172143

This is modified since the shape of API is changed in the
counter-part CL.

Test: atest FrameworksNetTests FrameworksTelephonyTests
Test: atest TetheringTests NetworkStackTests
Fix: 148552904
Change-Id: Idaeb921f6f87c507766566e145838647d47284bd
Merged-In: I1d377ee277e9c21e398d7446b1db28c877cbe6b2
(cherry picked from aosp/1253986)
parent 97397fad
Loading
Loading
Loading
Loading
+15 −15
Original line number Diff line number Diff line
@@ -24,35 +24,35 @@ private const val DEFAULT_TIMEOUT_MS = 200L

open class TestableNetworkStatsProvider : INetworkStatsProvider.Stub() {
    sealed class CallbackType {
        data class RequestUpdate(val token: Int) : CallbackType()
        data class SetLimit(val iface: String?, val quotaBytes: Long) : CallbackType()
        data class SetAlert(val quotaBytes: Long) : CallbackType()
        data class OnRequestStatsUpdate(val token: Int) : CallbackType()
        data class OnSetLimit(val iface: String?, val quotaBytes: Long) : CallbackType()
        data class OnSetAlert(val quotaBytes: Long) : CallbackType()
    }

    private val history = ArrayTrackRecord<CallbackType>().ReadHead()

    override fun requestStatsUpdate(token: Int) {
        history.add(CallbackType.RequestUpdate(token))
    override fun onRequestStatsUpdate(token: Int) {
        history.add(CallbackType.OnRequestStatsUpdate(token))
    }

    override fun setLimit(iface: String?, quotaBytes: Long) {
        history.add(CallbackType.SetLimit(iface, quotaBytes))
    override fun onSetLimit(iface: String?, quotaBytes: Long) {
        history.add(CallbackType.OnSetLimit(iface, quotaBytes))
    }

    override fun setAlert(quotaBytes: Long) {
        history.add(CallbackType.SetAlert(quotaBytes))
    override fun onSetAlert(quotaBytes: Long) {
        history.add(CallbackType.OnSetAlert(quotaBytes))
    }

    fun expectStatsUpdate(token: Int) {
        assertEquals(CallbackType.RequestUpdate(token), history.poll(DEFAULT_TIMEOUT_MS))
    fun expectOnRequestStatsUpdate(token: Int) {
        assertEquals(CallbackType.OnRequestStatsUpdate(token), history.poll(DEFAULT_TIMEOUT_MS))
    }

    fun expectSetLimit(iface: String?, quotaBytes: Long) {
        assertEquals(CallbackType.SetLimit(iface, quotaBytes), history.poll(DEFAULT_TIMEOUT_MS))
    fun expectOnSetLimit(iface: String?, quotaBytes: Long) {
        assertEquals(CallbackType.OnSetLimit(iface, quotaBytes), history.poll(DEFAULT_TIMEOUT_MS))
    }

    fun expectSetAlert(quotaBytes: Long) {
        assertEquals(CallbackType.SetAlert(quotaBytes), history.poll(DEFAULT_TIMEOUT_MS))
    fun expectOnSetAlert(quotaBytes: Long) {
        assertEquals(CallbackType.OnSetAlert(quotaBytes), history.poll(DEFAULT_TIMEOUT_MS))
    }

    @JvmOverloads