Search in sources :

Example 1 with TelephonyDisplayInfo

use of android.telephony.TelephonyDisplayInfo in project robolectric by robolectric.

the class ShadowTelephonyManagerTest method setTelephonyDisplayInfo_notifiesListeners.

@Test
@Config(minSdk = R)
public void setTelephonyDisplayInfo_notifiesListeners() {
    PhoneStateListener listener = mock(PhoneStateListener.class);
    TelephonyDisplayInfo displayInfo = (TelephonyDisplayInfo) createTelephonyDisplayInfo(NETWORK_TYPE_LTE, OVERRIDE_NETWORK_TYPE_NR_NSA);
    telephonyManager.listen(listener, LISTEN_DISPLAY_INFO_CHANGED);
    shadowTelephonyManager.setTelephonyDisplayInfo(displayInfo);
    verify(listener, times(1)).onDisplayInfoChanged(displayInfo);
}
Also used : ShadowTelephonyManager.createTelephonyDisplayInfo(org.robolectric.shadows.ShadowTelephonyManager.createTelephonyDisplayInfo) TelephonyDisplayInfo(android.telephony.TelephonyDisplayInfo) PhoneStateListener(android.telephony.PhoneStateListener) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 2 with TelephonyDisplayInfo

use of android.telephony.TelephonyDisplayInfo in project robolectric by robolectric.

the class ShadowTelephonyManagerTest method createTelephonyDisplayInfo_correctlyCreatesDisplayInfo.

@Test
@Config(minSdk = R)
public void createTelephonyDisplayInfo_correctlyCreatesDisplayInfo() {
    TelephonyDisplayInfo displayInfo = (TelephonyDisplayInfo) createTelephonyDisplayInfo(NETWORK_TYPE_LTE, OVERRIDE_NETWORK_TYPE_LTE_CA);
    assertThat(displayInfo.getNetworkType()).isEqualTo(NETWORK_TYPE_LTE);
    assertThat(displayInfo.getOverrideNetworkType()).isEqualTo(OVERRIDE_NETWORK_TYPE_LTE_CA);
}
Also used : ShadowTelephonyManager.createTelephonyDisplayInfo(org.robolectric.shadows.ShadowTelephonyManager.createTelephonyDisplayInfo) TelephonyDisplayInfo(android.telephony.TelephonyDisplayInfo) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 3 with TelephonyDisplayInfo

use of android.telephony.TelephonyDisplayInfo in project robolectric by robolectric.

the class ShadowTelephonyManagerTest method listen_notifiesListenerOfCurrentTelephonyDisplayInfoIfInitialized.

@Test
@Config(minSdk = R)
public void listen_notifiesListenerOfCurrentTelephonyDisplayInfoIfInitialized() {
    PhoneStateListener listener = mock(PhoneStateListener.class);
    TelephonyDisplayInfo displayInfo = (TelephonyDisplayInfo) createTelephonyDisplayInfo(NETWORK_TYPE_EVDO_0, OVERRIDE_NETWORK_TYPE_NONE);
    shadowTelephonyManager.setTelephonyDisplayInfo(displayInfo);
    telephonyManager.listen(listener, LISTEN_DISPLAY_INFO_CHANGED);
    verify(listener, times(1)).onDisplayInfoChanged(displayInfo);
}
Also used : ShadowTelephonyManager.createTelephonyDisplayInfo(org.robolectric.shadows.ShadowTelephonyManager.createTelephonyDisplayInfo) TelephonyDisplayInfo(android.telephony.TelephonyDisplayInfo) PhoneStateListener(android.telephony.PhoneStateListener) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 4 with TelephonyDisplayInfo

use of android.telephony.TelephonyDisplayInfo in project android_frameworks_opt_telephony by LineageOS.

the class DcTrackerTest method testIsNrUnmeteredSubscriptionPlans.

@Test
public void testIsNrUnmeteredSubscriptionPlans() throws Exception {
    initApns(PhoneConstants.APN_TYPE_DEFAULT, new String[] { PhoneConstants.APN_TYPE_ALL });
    int id = setUpDataConnection();
    setUpSubscriptionPlans(false);
    setUpWatchdogTimer();
    doReturn(new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA)).when(mDisplayInfoController).getTelephonyDisplayInfo();
    setUpTempNotMetered();
    // NetCapability should be metered when connected to 5G with no unmetered plan or frequency
    mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TELEPHONY_DISPLAY_INFO_CHANGED));
    waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
    verify(mDataConnection, times(1)).onMeterednessChanged(false);
    // Set SubscriptionPlans unmetered
    setUpSubscriptionPlans(true);
    // NetCapability should switch to unmetered with an unmetered plan
    mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TELEPHONY_DISPLAY_INFO_CHANGED));
    waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
    verify(mDataConnection, times(1)).onMeterednessChanged(true);
    // Set MMWAVE frequency to unmetered
    mBundle.putBoolean(CarrierConfigManager.KEY_UNMETERED_NR_NSA_MMWAVE_BOOL, true);
    Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
    intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, mPhone.getPhoneId());
    intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, mPhone.getSubId());
    mContext.sendBroadcast(intent);
    waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
    // NetCapability should switch to metered without fr=MMWAVE
    mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TELEPHONY_DISPLAY_INFO_CHANGED));
    waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
    verify(mDataConnection, times(2)).onMeterednessChanged(false);
    // NetCapability should switch to unmetered with fr=MMWAVE
    doReturn(new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE)).when(mDisplayInfoController).getTelephonyDisplayInfo();
    mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TELEPHONY_DISPLAY_INFO_CHANGED));
    waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
    verify(mDataConnection, times(2)).onMeterednessChanged(true);
    resetDataConnection(id);
    resetSubscriptionPlans();
}
Also used : TelephonyDisplayInfo(android.telephony.TelephonyDisplayInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) FlakyTest(androidx.test.filters.FlakyTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) MediumTest(android.test.suitebuilder.annotation.MediumTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 5 with TelephonyDisplayInfo

use of android.telephony.TelephonyDisplayInfo in project android_frameworks_opt_telephony by LineageOS.

the class DcTrackerTest method testReevaluateUnmeteredConnectionsOnNetworkChange.

@Test
public void testReevaluateUnmeteredConnectionsOnNetworkChange() throws Exception {
    initApns(PhoneConstants.APN_TYPE_DEFAULT, new String[] { PhoneConstants.APN_TYPE_ALL });
    int id = setUpDataConnection();
    setUpSubscriptionPlans(true);
    setUpWatchdogTimer();
    setUpTempNotMetered();
    // NetCapability should be unmetered when connected to 5G
    doReturn(new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA)).when(mDisplayInfoController).getTelephonyDisplayInfo();
    mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TELEPHONY_DISPLAY_INFO_CHANGED));
    waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
    verify(mDataConnection, times(1)).onMeterednessChanged(true);
    // NetCapability should be metered when disconnected from 5G
    doReturn(new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE)).when(mDisplayInfoController).getTelephonyDisplayInfo();
    mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TELEPHONY_DISPLAY_INFO_CHANGED));
    waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
    // Data connection is running on a different thread. Have to wait.
    waitForMs(200);
    verify(mDataConnection, times(1)).onMeterednessChanged(false);
    resetDataConnection(id);
    resetSubscriptionPlans();
}
Also used : TelephonyDisplayInfo(android.telephony.TelephonyDisplayInfo) FlakyTest(androidx.test.filters.FlakyTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) MediumTest(android.test.suitebuilder.annotation.MediumTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Aggregations

TelephonyDisplayInfo (android.telephony.TelephonyDisplayInfo)15 Test (org.junit.Test)12 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 MediumTest (android.test.suitebuilder.annotation.MediumTest)4 UiThreadTest (androidx.test.annotation.UiThreadTest)4 FlakyTest (androidx.test.filters.FlakyTest)4 TelephonyTest (com.android.internal.telephony.TelephonyTest)4 Intent (android.content.Intent)3 PhoneStateListener (android.telephony.PhoneStateListener)3 SubscriptionInfo (android.telephony.SubscriptionInfo)3 Config (org.robolectric.annotation.Config)3 ShadowTelephonyManager.createTelephonyDisplayInfo (org.robolectric.shadows.ShadowTelephonyManager.createTelephonyDisplayInfo)3 PendingIntent (android.app.PendingIntent)2 NetworkRegistrationInfo (android.telephony.NetworkRegistrationInfo)1 ArraySet (android.util.ArraySet)1