1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.statusbar.pipeline.mobile.data.repository.prod 18 19 import android.telephony.CellSignalStrengthCdma 20 import android.telephony.SignalStrength 21 import android.telephony.TelephonyCallback 22 import android.telephony.TelephonyDisplayInfo 23 import android.telephony.TelephonyManager 24 import com.android.systemui.util.mockito.any 25 import com.android.systemui.util.mockito.argumentCaptor 26 import com.android.systemui.util.mockito.mock 27 import com.android.systemui.util.mockito.whenever 28 import com.google.common.truth.Truth.assertThat 29 import org.mockito.Mockito.verify 30 31 /** Helper methods for telephony-related callbacks for mobile tests. */ 32 object MobileTelephonyHelpers { getTelephonyCallbacksnull33 fun getTelephonyCallbacks(mockTelephonyManager: TelephonyManager): List<TelephonyCallback> { 34 val callbackCaptor = argumentCaptor<TelephonyCallback>() 35 verify(mockTelephonyManager).registerTelephonyCallback(any(), callbackCaptor.capture()) 36 return callbackCaptor.allValues 37 } 38 39 /** Convenience constructor for SignalStrength */ signalStrengthnull40 fun signalStrength(gsmLevel: Int, cdmaLevel: Int, isGsm: Boolean): SignalStrength { 41 val signalStrength = mock<SignalStrength>() 42 whenever(signalStrength.isGsm).thenReturn(isGsm) 43 whenever(signalStrength.level).thenReturn(gsmLevel) 44 val cdmaStrength = 45 mock<CellSignalStrengthCdma>().also { whenever(it.level).thenReturn(cdmaLevel) } 46 whenever(signalStrength.getCellSignalStrengths(CellSignalStrengthCdma::class.java)) 47 .thenReturn(listOf(cdmaStrength)) 48 49 return signalStrength 50 } 51 telephonyDisplayInfonull52 fun telephonyDisplayInfo(networkType: Int, overrideNetworkType: Int) = 53 TelephonyDisplayInfo(networkType, overrideNetworkType) 54 55 inline fun <reified T> getTelephonyCallbackForType(mockTelephonyManager: TelephonyManager): T { 56 val cbs = getTelephonyCallbacks(mockTelephonyManager).filterIsInstance<T>() 57 assertThat(cbs.size).isEqualTo(1) 58 return cbs[0] 59 } 60 } 61