use of android.telephony.SignalStrength in project robolectric by robolectric.
the class ShadowTelephonyManagerTest method shouldGiveSignalStrength.
@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);
}
use of android.telephony.SignalStrength in project robolectric by robolectric.
the class ShadowTelephonyManagerTest method canSetAndGetSignalStrength.
@Test
@Config(minSdk = P)
public void canSetAndGetSignalStrength() {
SignalStrength ss = Shadow.newInstanceOf(SignalStrength.class);
shadowOf(telephonyManager).setSignalStrength(ss);
assertThat(telephonyManager.getSignalStrength()).isEqualTo(ss);
}
use of android.telephony.SignalStrength in project android_packages_apps_Settings by SudaMod.
the class SimStatus method updatePhoneInfos.
private void updatePhoneInfos() {
if (mSir != null) {
// TODO: http://b/23763013
final Phone phone = PhoneFactory.getPhone(SubscriptionManager.getPhoneId(mSir.getSubscriptionId()));
if (UserManager.get(getContext()).isAdminUser() && SubscriptionManager.isValidSubscriptionId(mSir.getSubscriptionId())) {
if (phone == null) {
Log.e(TAG, "Unable to locate a phone object for the given Subscription ID.");
return;
}
mPhone = phone;
// To avoid register multiple listeners when user changes the tab.
if (mPhoneStateListener != null && mTelephonyManager != null) {
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
mPhoneStateListener = null;
}
mPhoneStateListener = new PhoneStateListener(mSir.getSubscriptionId()) {
@Override
public void onDataConnectionStateChanged(int state) {
updateDataState();
updateNetworkType();
}
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
updateSignalStrength(signalStrength);
}
@Override
public void onServiceStateChanged(ServiceState serviceState) {
updateServiceState(serviceState);
}
};
}
}
}
use of android.telephony.SignalStrength in project network-monitor by caarmen.
the class NetMonSignalStrength method getGSMSignalStrength.
/**
* Get signal level as an int from 0..4
*/
private int getGSMSignalStrength(SignalStrength signalStrength) {
Log.v(TAG, "getGSMSignalStrength " + signalStrength);
// ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
// asu = 0 (-113dB or less) is very weak
// signal, its better to show 0 bars to the user in such cases.
// asu = 99 is a special case, where the signal strength is unknown.
int asu = signalStrength.getGsmSignalStrength();
if (asu > 0) {
if (asu <= 2 || asu == 99)
return SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
else if (asu >= GSM_SIGNAL_STRENGTH_GREAT)
return SIGNAL_STRENGTH_GREAT;
else if (asu >= GSM_SIGNAL_STRENGTH_GOOD)
return SIGNAL_STRENGTH_GOOD;
else if (asu >= GSM_SIGNAL_STRENGTH_MODERATE)
return SIGNAL_STRENGTH_MODERATE;
else
return SIGNAL_STRENGTH_POOR;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// apis getGsmLevel() and getLteLevel() don't. Let's try them.
try {
if (mTelephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_LTE) {
Method methodGetLteLevel = SignalStrength.class.getMethod("getLteLevel");
return (Integer) methodGetLteLevel.invoke(signalStrength);
} else {
Method methodGetGsmLevel = SignalStrength.class.getMethod("getGsmLevel");
return (Integer) methodGetGsmLevel.invoke(signalStrength);
}
} catch (Throwable t) {
Log.v(TAG, "getGsmLevel or getLteLevel failed: " + t.getMessage(), t);
return SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
}
} else {
return SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
}
}
use of android.telephony.SignalStrength in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SubscriptionsPreferenceControllerTest method setMockSubSignalStrength.
/**
* Helper method to set the signal strength returned for a mock subscription
* @param subs The list of subscriptions
* @param index The index in of the subscription in |subs| to change
* @param level The signal strength level to return for the subscription. Pass -1 to force
* return of a null SignalStrength object for the subscription.
*/
private void setMockSubSignalStrength(List<SubscriptionInfo> subs, int index, int level) {
final TelephonyManager mgrForSub = mTelephonyManager.createForSubscriptionId(subs.get(index).getSubscriptionId());
if (level == -1) {
when(mgrForSub.getSignalStrength()).thenReturn(null);
} else {
final SignalStrength signalStrength = mgrForSub.getSignalStrength();
when(signalStrength.getLevel()).thenReturn(level);
}
}
Aggregations