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

Commit d6581965 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[Status Bar][Wifi] Add carrier merged sub ID to TrackerLibRepo.

Bug: 292534484
Test: atest WifiRepositoryViaTrackerLibTest
Change-Id: Idb0fc71f82eb0bbe0309f86dd78d46efe862e46a
parent 1a3a5b53
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -49,6 +49,9 @@ interface WifiRepository {
        const val COL_NAME_IS_ENABLED = "isEnabled"
        const val COL_NAME_IS_ENABLED = "isEnabled"
        /** Column name to use for [isWifiDefault] for table logging. */
        /** Column name to use for [isWifiDefault] for table logging. */
        const val COL_NAME_IS_DEFAULT = "isDefault"
        const val COL_NAME_IS_DEFAULT = "isDefault"

        const val CARRIER_MERGED_INVALID_SUB_ID_REASON =
            "Wifi network was carrier merged but had invalid sub ID"
    }
    }
}
}


+1 −3
Original line number Original line Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityMod
import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepository
import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepository
import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepositoryImpl.Companion.getMainOrUnderlyingWifiInfo
import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepositoryImpl.Companion.getMainOrUnderlyingWifiInfo
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.CARRIER_MERGED_INVALID_SUB_ID_REASON
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.COL_NAME_IS_DEFAULT
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.COL_NAME_IS_DEFAULT
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.COL_NAME_IS_ENABLED
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.COL_NAME_IS_ENABLED
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepositoryDagger
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepositoryDagger
@@ -277,9 +278,6 @@ constructor(
                .addTransportType(TRANSPORT_WIFI)
                .addTransportType(TRANSPORT_WIFI)
                .addTransportType(TRANSPORT_CELLULAR)
                .addTransportType(TRANSPORT_CELLULAR)
                .build()
                .build()

        private const val CARRIER_MERGED_INVALID_SUB_ID_REASON =
            "Wifi network was carrier merged but had invalid sub ID"
    }
    }


    @SysUISingleton
    @SysUISingleton
+38 −33
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.pipeline.wifi.data.repository.prod
package com.android.systemui.statusbar.pipeline.wifi.data.repository.prod


import android.net.wifi.WifiManager
import android.net.wifi.WifiManager
import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.lifecycle.LifecycleRegistry
@@ -33,6 +34,7 @@ import com.android.systemui.statusbar.connectivity.WifiPickerTrackerFactory
import com.android.systemui.statusbar.pipeline.dagger.WifiTrackerLibInputLog
import com.android.systemui.statusbar.pipeline.dagger.WifiTrackerLibInputLog
import com.android.systemui.statusbar.pipeline.dagger.WifiTrackerLibTableLog
import com.android.systemui.statusbar.pipeline.dagger.WifiTrackerLibTableLog
import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityModel
import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityModel
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.CARRIER_MERGED_INVALID_SUB_ID_REASON
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.COL_NAME_IS_DEFAULT
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.COL_NAME_IS_DEFAULT
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.COL_NAME_IS_ENABLED
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.COL_NAME_IS_ENABLED
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepositoryViaTrackerLibDagger
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepositoryViaTrackerLibDagger
@@ -178,16 +180,28 @@ constructor(
            return WIFI_NETWORK_DEFAULT
            return WIFI_NETWORK_DEFAULT
        }
        }
        return if (this is MergedCarrierEntry) {
        return if (this is MergedCarrierEntry) {
            this.convertCarrierMergedToModel()
        } else {
            this.convertNormalToModel()
        }
    }

    private fun MergedCarrierEntry.convertCarrierMergedToModel(): WifiNetworkModel {
        return if (this.subscriptionId == INVALID_SUBSCRIPTION_ID) {
            WifiNetworkModel.Invalid(CARRIER_MERGED_INVALID_SUB_ID_REASON)
        } else {
            WifiNetworkModel.CarrierMerged(
            WifiNetworkModel.CarrierMerged(
                networkId = NETWORK_ID,
                networkId = NETWORK_ID,
                // TODO(b/292534484): Fetch the real subscription ID from [MergedCarrierEntry].
                subscriptionId = this.subscriptionId,
                subscriptionId = TEMP_SUB_ID,
                level = this.level,
                level = this.level,
                // WifiManager APIs to calculate the signal level start from 0, so
                // WifiManager APIs to calculate the signal level start from 0, so
                // maxSignalLevel + 1 represents the total level buckets count.
                // maxSignalLevel + 1 represents the total level buckets count.
                numberOfLevels = wifiManager.maxSignalLevel + 1,
                numberOfLevels = wifiManager.maxSignalLevel + 1,
            )
            )
        } else {
        }
    }

    private fun WifiEntry.convertNormalToModel(): WifiNetworkModel {
        val hotspotDeviceType =
        val hotspotDeviceType =
            if (isInstantTetherEnabled && this is HotspotNetworkEntry) {
            if (isInstantTetherEnabled && this is HotspotNetworkEntry) {
                this.deviceType.toHotspotDeviceType()
                this.deviceType.toHotspotDeviceType()
@@ -195,7 +209,7 @@ constructor(
                WifiNetworkModel.HotspotDeviceType.NONE
                WifiNetworkModel.HotspotDeviceType.NONE
            }
            }


            WifiNetworkModel.Active(
        return WifiNetworkModel.Active(
            networkId = NETWORK_ID,
            networkId = NETWORK_ID,
            isValidated = this.hasInternetAccess(),
            isValidated = this.hasInternetAccess(),
            level = this.level,
            level = this.level,
@@ -211,7 +225,6 @@ constructor(
            passpointProviderFriendlyName = null,
            passpointProviderFriendlyName = null,
        )
        )
    }
    }
    }


    override val isWifiDefault: StateFlow<Boolean> =
    override val isWifiDefault: StateFlow<Boolean> =
        wifiPickerTrackerInfo
        wifiPickerTrackerInfo
@@ -310,13 +323,5 @@ constructor(
         * to [WifiRepositoryViaTrackerLib].
         * to [WifiRepositoryViaTrackerLib].
         */
         */
        private const val NETWORK_ID = -1
        private const val NETWORK_ID = -1

        /**
         * A temporary subscription ID until WifiTrackerLib exposes a method to fetch the
         * subscription ID.
         *
         * Use -2 because [SubscriptionManager.INVALID_SUBSCRIPTION_ID] is -1.
         */
        private const val TEMP_SUB_ID = -2
    }
    }
}
}
+22 −35
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.pipeline.wifi.data.repository.prod
import android.net.wifi.WifiManager
import android.net.wifi.WifiManager
import android.net.wifi.WifiManager.UNKNOWN_SSID
import android.net.wifi.WifiManager.UNKNOWN_SSID
import android.net.wifi.sharedconnectivity.app.NetworkProviderInfo
import android.net.wifi.sharedconnectivity.app.NetworkProviderInfo
import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
import android.testing.TestableLooper
import android.testing.TestableLooper
import androidx.test.filters.SmallTest
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.SysuiTestCase
@@ -431,6 +432,7 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
                mock<MergedCarrierEntry>().apply {
                mock<MergedCarrierEntry>().apply {
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.level).thenReturn(3)
                    whenever(this.level).thenReturn(3)
                    whenever(this.subscriptionId).thenReturn(567)
                }
                }
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            getCallback().onWifiEntriesChanged()
            getCallback().onWifiEntriesChanged()
@@ -438,7 +440,7 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
            assertThat(latest is WifiNetworkModel.CarrierMerged).isTrue()
            assertThat(latest is WifiNetworkModel.CarrierMerged).isTrue()
            val latestMerged = latest as WifiNetworkModel.CarrierMerged
            val latestMerged = latest as WifiNetworkModel.CarrierMerged
            assertThat(latestMerged.level).isEqualTo(3)
            assertThat(latestMerged.level).isEqualTo(3)
            // numberOfLevels = maxSignalLevel + 1
            assertThat(latestMerged.subscriptionId).isEqualTo(567)
        }
        }


    @Test
    @Test
@@ -461,30 +463,23 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
            assertThat(latestMerged.numberOfLevels).isEqualTo(6)
            assertThat(latestMerged.numberOfLevels).isEqualTo(6)
        }
        }


    /* TODO(b/292534484): Re-enable this test once WifiTrackerLib gives us the subscription ID.
    @Test
    @Test
    fun wifiNetwork_carrierMergedButInvalidSubId_flowHasInvalid() =
    fun wifiNetwork_carrierMergedButInvalidSubId_flowHasInvalid() =
        testScope.runTest {
        testScope.runTest {
            val latest by collectLastValue(underTest.wifiNetwork)
            val latest by collectLastValue(underTest.wifiNetwork)


            val wifiInfo =
            val wifiEntry =
                mock<WifiInfo>().apply {
                mock<MergedCarrierEntry>().apply {
                    whenever(this.isPrimary).thenReturn(true)
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.isCarrierMerged).thenReturn(true)
                    whenever(this.subscriptionId).thenReturn(INVALID_SUBSCRIPTION_ID)
                    whenever(this.subscriptionId).thenReturn(INVALID_SUBSCRIPTION_ID)
                }
                }
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)


            getNetworkCallback()
            getCallback().onWifiEntriesChanged()
                .onCapabilitiesChanged(
                    NETWORK,
                    createWifiNetworkCapabilities(wifiInfo),
                )


            assertThat(latest).isInstanceOf(WifiNetworkModel.Invalid::class.java)
            assertThat(latest).isInstanceOf(WifiNetworkModel.Invalid::class.java)
        }
        }


     */

    @Test
    @Test
    fun wifiNetwork_notValidated_networkNotValidated() =
    fun wifiNetwork_notValidated_networkNotValidated() =
        testScope.runTest {
        testScope.runTest {
@@ -714,31 +709,23 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
            assertThat(underTest.isWifiConnectedWithValidSsid()).isFalse()
            assertThat(underTest.isWifiConnectedWithValidSsid()).isFalse()
        }
        }


    /* TODO(b/292534484): Re-enable this test once WifiTrackerLib gives us the subscription ID.
    @Test
    @Test
    fun isWifiConnectedWithValidSsid_invalidNetwork_false() =
    fun isWifiConnectedWithValidSsid_invalidNetwork_false() =
        testScope.runTest {
        testScope.runTest {
            collectLastValue(underTest.wifiNetwork)
            collectLastValue(underTest.wifiNetwork)


           val wifiInfo =
            val wifiEntry =
               mock<WifiInfo>().apply {
                mock<MergedCarrierEntry>().apply {
                   whenever(this.isPrimary).thenReturn(true)
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                   whenever(this.isCarrierMerged).thenReturn(true)
                    whenever(this.subscriptionId).thenReturn(INVALID_SUBSCRIPTION_ID)
                    whenever(this.subscriptionId).thenReturn(INVALID_SUBSCRIPTION_ID)
                }
                }

            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
           getNetworkCallback()
            getCallback().onWifiEntriesChanged()
               .onCapabilitiesChanged(
                   NETWORK,
                   createWifiNetworkCapabilities(wifiInfo),
               )
            testScope.runCurrent()
            testScope.runCurrent()


            assertThat(underTest.isWifiConnectedWithValidSsid()).isFalse()
            assertThat(underTest.isWifiConnectedWithValidSsid()).isFalse()
        }
        }


    */

    @Test
    @Test
    fun isWifiConnectedWithValidSsid_activeNetwork_nullTitle_false() =
    fun isWifiConnectedWithValidSsid_activeNetwork_nullTitle_false() =
        testScope.runTest {
        testScope.runTest {