/** * Sets the current call state with the option to specify an incoming phone number for the * CALL_STATE_RINGING state. The incoming phone number will be ignored for all other cases. */ public void setCallState(int callState, String incomingPhoneNumber) { if (callState != CALL_STATE_RINGING) { incomingPhoneNumber = null; } this.callState = callState; this.incomingPhoneNumber = incomingPhoneNumber; for (PhoneStateListener listener : getListenersForFlags(LISTEN_CALL_STATE)) { listener.onCallStateChanged(callState, incomingPhoneNumber); } }
private void initListener(PhoneStateListener listener, int flags) { if ((flags & LISTEN_CALL_STATE) != 0) { listener.onCallStateChanged(callState, incomingPhoneNumber); } if ((flags & LISTEN_CELL_INFO) != 0) { if (VERSION.SDK_INT >= JELLY_BEAN_MR1) { listener.onCellInfoChanged(allCellInfo); } } if ((flags & LISTEN_CELL_LOCATION) != 0) { listener.onCellLocationChanged(cellLocation); } }
/** Sets the value to be returned by {@link #getSignalStrength()} */ public void setSignalStrength(SignalStrength signalStrength) { this.signalStrength = signalStrength; for (PhoneStateListener listener : getListenersForFlags(PhoneStateListener.LISTEN_SIGNAL_STRENGTHS)) { listener.onSignalStrengthsChanged(signalStrength); } }
public void setCellLocation(CellLocation cellLocation) { this.cellLocation = cellLocation; for (PhoneStateListener listener : getListenersForFlags(LISTEN_CELL_LOCATION)) { listener.onCellLocationChanged(cellLocation); } }
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); } } }
@Override public void onServiceStateChanged(ServiceState serviceState) { super.onServiceStateChanged(serviceState); updateNetworkStatus(); } }, PhoneStateListener.LISTEN_SERVICE_STATE);
@Test public void shouldGiveCellLocation() { PhoneStateListener listener = mock(PhoneStateListener.class); telephonyManager.listen(listener, LISTEN_CELL_LOCATION); CellLocation mockCellLocation = mock(CellLocation.class); shadowOf(telephonyManager).setCellLocation(mockCellLocation); assertEquals(mockCellLocation, telephonyManager.getCellLocation()); verify(listener).onCellLocationChanged(mockCellLocation); }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void shouldGiveAllCellInfo() { PhoneStateListener listener = mock(PhoneStateListener.class); telephonyManager.listen(listener, LISTEN_CELL_INFO); List<CellInfo> allCellInfo = Collections.singletonList(mock(CellInfo.class)); shadowOf(telephonyManager).setAllCellInfo(allCellInfo); assertEquals(allCellInfo, telephonyManager.getAllCellInfo()); verify(listener).onCellInfoChanged(allCellInfo); }
@Override public void onServiceStateChanged(ServiceState serviceState) { super.onServiceStateChanged(serviceState); final int state = serviceState.getState(); if (state == ServiceState.STATE_IN_SERVICE || state == ServiceState.STATE_POWER_OFF) { final boolean roamingState = serviceState .getRoaming(); if (roamingState != isRoamingOn()) { setRoamingOn(roamingState); } } } };
@Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_IDLE: Log.d(TAG, "PhoneStateListener: CALL_STATE_IDLE"); if (mMediaPlayer != null) { mMediaPlayer.start(); } break; case TelephonyManager.CALL_STATE_OFFHOOK: Log.d(TAG, "PhoneStateListener: CALL_STATE_OFFHOOK"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } break; case TelephonyManager.CALL_STATE_RINGING: Log.d(TAG, "PhoneStateListener: CALL_STATE_RINGING: " + incomingNumber); break; } } };
@Test public void testListenInit() { PhoneStateListener listener = mock(PhoneStateListener.class); telephonyManager.listen(listener, LISTEN_CALL_STATE | LISTEN_CELL_INFO | LISTEN_CELL_LOCATION); verify(listener).onCallStateChanged(CALL_STATE_IDLE, null); verify(listener).onCellLocationChanged(null); if (VERSION.SDK_INT >= JELLY_BEAN_MR1) { verify(listener).onCellInfoChanged(Collections.emptyList()); } }
@Override synchronized public void onCellLocationChanged(CellLocation location) { super.onCellLocationChanged(location); newSatisfiedState(match(location)); } }
@Test @Config(minSdk = P) public void shouldGiveSignalStrength() { PhoneStateListener listener = mock(PhoneStateListener.class); telephonyManager.listen(listener, LISTEN_SIGNAL_STRENGTHS); SignalStrength ss = Shadow.newInstanceOf(SignalStrength.class); shadowOf(telephonyManager).setSignalStrength(ss); verify(listener).onSignalStrengthsChanged(ss); } }
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); } } }
@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); }
private void initListener(PhoneStateListener listener, int flags) { if ((flags & LISTEN_CALL_STATE) != 0) { listener.onCallStateChanged(callState, incomingPhoneNumber); } if ((flags & LISTEN_CELL_INFO) != 0) { if (VERSION.SDK_INT >= JELLY_BEAN_MR1) { listener.onCellInfoChanged(allCellInfo); } } if ((flags & LISTEN_CELL_LOCATION) != 0) { listener.onCellLocationChanged(cellLocation); } }
public void setCellLocation(CellLocation cellLocation) { this.cellLocation = cellLocation; for (PhoneStateListener listener : getListenersForFlags(LISTEN_CELL_LOCATION)) { listener.onCellLocationChanged(cellLocation); } }
public void onSignalStrengthsChanged(SignalStrength signalStrength) { super.onSignalStrengthsChanged(signalStrength); ConnectivityListener listener = (ConnectivityListener) this.mListener.get(); if (listener != null) { listener.mConnectivityStatus.mMobileSignalStrength = ConnectivityListener.getLevel(signalStrength); } } }
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); } } }
@Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); if (state == TelephonyManager.CALL_STATE_RINGING) { String phoneNumber = incomingNumber; } } }