Search in sources :

Example 31 with SignalStrength

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);
}
Also used : PhoneStateListener(android.telephony.PhoneStateListener) SignalStrength(android.telephony.SignalStrength) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 32 with SignalStrength

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);
}
Also used : SignalStrength(android.telephony.SignalStrength) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 33 with SignalStrength

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);
                }
            };
        }
    }
}
Also used : ServiceState(android.telephony.ServiceState) Phone(com.android.internal.telephony.Phone) PhoneStateListener(android.telephony.PhoneStateListener) SignalStrength(android.telephony.SignalStrength)

Example 34 with SignalStrength

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;
    }
}
Also used : Method(java.lang.reflect.Method) SuppressLint(android.annotation.SuppressLint) SignalStrength(android.telephony.SignalStrength) CellSignalStrength(android.telephony.CellSignalStrength)

Example 35 with SignalStrength

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);
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager) SignalStrength(android.telephony.SignalStrength)

Aggregations

SignalStrength (android.telephony.SignalStrength)35 ServiceState (android.telephony.ServiceState)13 RemoteException (android.os.RemoteException)11 PhoneStateListener (android.telephony.PhoneStateListener)9 Phone (com.android.internal.telephony.Phone)7 Bundle (android.os.Bundle)5 VoLteServiceState (android.telephony.VoLteServiceState)5 TelephonyManager (android.telephony.TelephonyManager)3 Test (org.junit.Test)3 SuppressLint (android.annotation.SuppressLint)2 CellSignalStrength (android.telephony.CellSignalStrength)2 Method (java.lang.reflect.Method)2 Config (org.robolectric.annotation.Config)2 AsyncResult (android.os.AsyncResult)1 ServiceStateTable.getContentValuesForServiceState (android.provider.Telephony.ServiceStateTable.getContentValuesForServiceState)1 FlakyTest (android.support.test.filters.FlakyTest)1 SubscriptionInfo (android.telephony.SubscriptionInfo)1 CdmaCellLocation (android.telephony.cdma.CdmaCellLocation)1 GsmCellLocation (android.telephony.gsm.GsmCellLocation)1 MediumTest (android.test.suitebuilder.annotation.MediumTest)1