Search in sources :

Example 16 with SignalStrength

use of android.telephony.SignalStrength in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SubscriptionsPreferenceController method setIcon.

@VisibleForTesting
void setIcon(Preference pref, int subId, boolean isDefaultForData) {
    final TelephonyManager mgr = mContext.getSystemService(TelephonyManager.class).createForSubscriptionId(subId);
    final SignalStrength strength = mgr.getSignalStrength();
    int level = (strength == null) ? 0 : strength.getLevel();
    int numLevels = SignalStrength.NUM_SIGNAL_STRENGTH_BINS;
    if (shouldInflateSignalStrength(subId)) {
        level += 1;
        numLevels += 1;
    }
    final boolean showCutOut = !isDefaultForData || !mgr.isDataEnabled();
    pref.setIcon(getIcon(level, numLevels, showCutOut));
}
Also used : TelephonyManager(android.telephony.TelephonyManager) SignalStrength(android.telephony.SignalStrength) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 17 with SignalStrength

use of android.telephony.SignalStrength in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SignalStrengthListener method updateSubscriptionIds.

/**
 * Updates the set of ids we want to be listening for, beginning to listen for any new ids and
 * stopping listening for any ids not contained in the new set
 */
public void updateSubscriptionIds(Set<Integer> ids) {
    Set<Integer> currentIds = new ArraySet<>(mListeners.keySet());
    for (int idToRemove : Sets.difference(currentIds, ids)) {
        stopListening(idToRemove);
        mListeners.remove(idToRemove);
    }
    for (int idToAdd : Sets.difference(ids, currentIds)) {
        PhoneStateListener listener = new PhoneStateListener() {

            @Override
            public void onSignalStrengthsChanged(SignalStrength signalStrength) {
                mCallback.onSignalStrengthChanged();
            }
        };
        mListeners.put(idToAdd, listener);
        startListening(idToAdd);
    }
}
Also used : ArraySet(android.util.ArraySet) PhoneStateListener(android.telephony.PhoneStateListener) SignalStrength(android.telephony.SignalStrength)

Example 18 with SignalStrength

use of android.telephony.SignalStrength in project android_frameworks_base by ParanoidAndroid.

the class TelephonyRegistry method notifySignalStrength.

public void notifySignalStrength(SignalStrength signalStrength) {
    if (!checkNotifyPermission("notifySignalStrength()")) {
        return;
    }
    synchronized (mRecords) {
        mSignalStrength = signalStrength;
        for (Record r : mRecords) {
            if ((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
                try {
                    r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
                } catch (RemoteException ex) {
                    mRemoveList.add(r.binder);
                }
            }
            if ((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
                try {
                    int gsmSignalStrength = signalStrength.getGsmSignalStrength();
                    r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1 : gsmSignalStrength));
                } catch (RemoteException ex) {
                    mRemoveList.add(r.binder);
                }
            }
        }
        handleRemoveListLocked();
    }
    broadcastSignalStrengthChanged(signalStrength);
}
Also used : RemoteException(android.os.RemoteException) SignalStrength(android.telephony.SignalStrength)

Example 19 with SignalStrength

use of android.telephony.SignalStrength in project android_frameworks_base by DirtyUnicorns.

the class TelephonyRegistry method notifySignalStrengthForPhoneId.

public void notifySignalStrengthForPhoneId(int phoneId, int subId, SignalStrength signalStrength) {
    if (!checkNotifyPermission("notifySignalStrength()")) {
        return;
    }
    if (VDBG) {
        log("notifySignalStrengthForPhoneId: subId=" + subId + " phoneId=" + phoneId + " signalStrength=" + signalStrength);
        toStringLogSSC("notifySignalStrengthForPhoneId");
    }
    synchronized (mRecords) {
        if (validatePhoneId(phoneId)) {
            if (VDBG)
                log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
            mSignalStrength[phoneId] = signalStrength;
            for (Record r : mRecords) {
                if (VDBG) {
                    log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId + " phoneId=" + phoneId + " ss=" + signalStrength);
                }
                if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) && idMatch(r.subId, subId, phoneId)) {
                    try {
                        if (DBG) {
                            log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r + " subId=" + subId + " phoneId=" + phoneId + " ss=" + signalStrength);
                        }
                        r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
                if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) && idMatch(r.subId, subId, phoneId)) {
                    try {
                        int gsmSignalStrength = signalStrength.getGsmSignalStrength();
                        int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
                        if (DBG) {
                            log("notifySignalStrengthForPhoneId: callback.onSS r=" + r + " subId=" + subId + " phoneId=" + phoneId + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
                        }
                        r.callback.onSignalStrengthChanged(ss);
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
        } else {
            log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
        }
        handleRemoveListLocked();
    }
    broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
}
Also used : RemoteException(android.os.RemoteException) SignalStrength(android.telephony.SignalStrength)

Example 20 with SignalStrength

use of android.telephony.SignalStrength in project XobotOS by xamarin.

the class CdmaServiceStateTracker method onSignalStrengthResult.

/**
     *  send signal-strength-changed notification if changed
     *  Called both for solicited and unsolicited signal strength updates
     */
protected void onSignalStrengthResult(AsyncResult ar) {
    SignalStrength oldSignalStrength = mSignalStrength;
    if (ar.exception != null) {
        // Most likely radio is resetting/disconnected change to default values.
        setSignalStrengthDefaultValues();
    } else {
        int[] ints = (int[]) ar.result;
        int offset = 2;
        int cdmaDbm = (ints[offset] > 0) ? -ints[offset] : -120;
        int cdmaEcio = (ints[offset + 1] > 0) ? -ints[offset + 1] : -160;
        int evdoRssi = (ints[offset + 2] > 0) ? -ints[offset + 2] : -120;
        int evdoEcio = (ints[offset + 3] > 0) ? -ints[offset + 3] : -1;
        int evdoSnr = ((ints[offset + 4] > 0) && (ints[offset + 4] <= 8)) ? ints[offset + 4] : -1;
        //log(String.format("onSignalStrengthResult cdmaDbm=%d cdmaEcio=%d evdoRssi=%d evdoEcio=%d evdoSnr=%d",
        //        cdmaDbm, cdmaEcio, evdoRssi, evdoEcio, evdoSnr));
        mSignalStrength = new SignalStrength(99, -1, cdmaDbm, cdmaEcio, evdoRssi, evdoEcio, evdoSnr, false);
    }
    try {
        phone.notifySignalStrength();
    } catch (NullPointerException ex) {
        loge("onSignalStrengthResult() Phone already destroyed: " + ex + "SignalStrength not notified");
    }
}
Also used : 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