@Implementation(minSdk = O) protected String getImei(int slotIndex) { checkReadPhoneStatePermission(); return slotIndexToImei.get(slotIndex); }
public void setAllCellInfo(List<CellInfo> allCellInfo) { this.allCellInfo = allCellInfo; if (VERSION.SDK_INT >= JELLY_BEAN_MR1) { for (PhoneStateListener listener : getListenersForFlags(LISTEN_CELL_INFO)) { listener.onCellInfoChanged(allCellInfo); } } }
@Implementation protected void listen(PhoneStateListener listener, int flags) { lastListener = listener; lastEventFlags = flags; if (flags == LISTEN_NONE) { phoneStateRegistrations.remove(listener); } else { initListener(listener, flags); phoneStateRegistrations.put(listener, flags); } }
/** Sets the current call state to the desired state and updates any listeners. */ public void setCallState(int callState) { setCallState(callState, null); }
public void setSimCountryIso(String simCountryIso) { setSimCountryIso(/* subId= */ 0, simCountryIso); }
/** Sets the sim state of slot 0. */ public void setSimState(int simState) { setSimState(/* slotIndex= */ 0, simState); }
private void setNetworkCountryIso(String countryIso) { Shadows.shadowOf(telephonyManager).setNetworkCountryIso(countryIso); } }
@Implementation protected int getSimState() { return getSimState(/* slotIndex= */ 0); }
@Test public void shouldGiveCallState() { PhoneStateListener listener = mock(PhoneStateListener.class); telephonyManager.listen(listener, LISTEN_CALL_STATE); shadowOf(telephonyManager).setCallState(CALL_STATE_RINGING, "911"); assertEquals(CALL_STATE_RINGING, telephonyManager.getCallState()); verify(listener).onCallStateChanged(CALL_STATE_RINGING, "911"); shadowOf(telephonyManager).setCallState(CALL_STATE_OFFHOOK, "911"); assertEquals(CALL_STATE_OFFHOOK, telephonyManager.getCallState()); verify(listener).onCallStateChanged(CALL_STATE_OFFHOOK, null); }
@Test @Config(minSdk = N) public void shouldGetSimIosWhenSetUsingSlotNumber() { String expectedSimIso = "usa"; int subId = 2; shadowOf(telephonyManager).setSimCountryIso(subId, expectedSimIso); assertThat(telephonyManager.getSimCountryIso(subId)).isEqualTo(expectedSimIso); }
@Test @Config(minSdk = O) public void shouldGetSimStateUsingSlotNumber() { int expectedSimState = TelephonyManager.SIM_STATE_ABSENT; int slotNumber = 3; shadowOf(telephonyManager).setSimState(slotNumber, expectedSimState); assertThat(telephonyManager.getSimState(slotNumber)).isEqualTo(expectedSimState); }
@Test public void shouldGiveNetworkCountryIso() { shadowOf(telephonyManager).setNetworkCountryIso("SomeIso"); assertEquals("SomeIso", telephonyManager.getNetworkCountryIso()); }
@Implementation protected int getSimState() { return getSimState(/* slotIndex= */ 0); }
@Implementation(minSdk = O) protected String getMeid(int slotIndex) { checkReadPhoneStatePermission(); return slotIndexToMeid.get(slotIndex); }
public void setCellLocation(CellLocation cellLocation) { this.cellLocation = cellLocation; for (PhoneStateListener listener : getListenersForFlags(LISTEN_CELL_LOCATION)) { listener.onCellLocationChanged(cellLocation); } }
@Implementation public void listen(PhoneStateListener listener, int flags) { lastListener = listener; lastEventFlags = flags; if (flags == LISTEN_NONE) { phoneStateRegistrations.remove(listener); } else { initListener(listener, flags); phoneStateRegistrations.put(listener, flags); } }
/** Sets the current call state to the desired state and updates any listeners. */ public void setCallState(int callState) { setCallState(callState, null); }
public void setSimCountryIso(String simCountryIso) { setSimCountryIso(/* subId= */ 0, simCountryIso); }
/** Sets the sim state of slot 0. */ public void setSimState(int simState) { setSimState(/* slotIndex= */ 0, simState); }
(TelephonyManager) RuntimeEnvironment.application.getSystemService(Context.TELEPHONY_SERVICE); Shadows.shadowOf(telephonyManager).setNetworkCountryIso(FAST_COUNTRY_ISO); networkInfoOffline = ShadowNetworkInfo.newInstance(