Search in sources :

Example 1 with ServiceState

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

the class TelephonyRegistry method listen.

@Override
public void listen(String pkgForDebug, IPhoneStateListener callback, int events, boolean notifyNow) {
    int callerUid = UserHandle.getCallingUserId();
    int myUid = UserHandle.myUserId();
    if (DBG) {
        Slog.d(TAG, "listen: E pkg=" + pkgForDebug + " events=0x" + Integer.toHexString(events) + " myUid=" + myUid + " callerUid=" + callerUid);
    }
    if (events != 0) {
        /* Checks permission and throws Security exception */
        checkListenerPermission(events);
        synchronized (mRecords) {
            // register
            Record r = null;
            find_and_add: {
                IBinder b = callback.asBinder();
                final int N = mRecords.size();
                for (int i = 0; i < N; i++) {
                    r = mRecords.get(i);
                    if (b == r.binder) {
                        break find_and_add;
                    }
                }
                r = new Record();
                r.binder = b;
                r.callback = callback;
                r.pkgForDebug = pkgForDebug;
                r.callerUid = callerUid;
                mRecords.add(r);
                if (DBG)
                    Slog.i(TAG, "listen: add new record=" + r);
            }
            int send = events & (events ^ r.events);
            r.events = events;
            if (notifyNow) {
                if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
                    try {
                        r.callback.onServiceStateChanged(new ServiceState(mServiceState));
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
                    try {
                        int gsmSignalStrength = mSignalStrength.getGsmSignalStrength();
                        r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1 : gsmSignalStrength));
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
                    try {
                        r.callback.onMessageWaitingIndicatorChanged(mMessageWaiting);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
                    try {
                        r.callback.onCallForwardingIndicatorChanged(mCallForwarding);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
                    try {
                        if (DBG_LOC)
                            Slog.d(TAG, "listen: mCellLocation=" + mCellLocation);
                        r.callback.onCellLocationChanged(new Bundle(mCellLocation));
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
                    try {
                        r.callback.onCallStateChanged(mCallState, mCallIncomingNumber);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
                    try {
                        r.callback.onDataConnectionStateChanged(mDataConnectionState, mDataConnectionNetworkType);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
                    try {
                        r.callback.onDataActivity(mDataActivity);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
                    try {
                        r.callback.onSignalStrengthsChanged(mSignalStrength);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
                    try {
                        r.callback.onOtaspChanged(mOtaspMode);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
                    try {
                        if (DBG_LOC)
                            Slog.d(TAG, "listen: mCellInfo=" + mCellInfo);
                        r.callback.onCellInfoChanged(mCellInfo);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
            }
        }
    } else {
        remove(callback.asBinder());
    }
}
Also used : IBinder(android.os.IBinder) ServiceState(android.telephony.ServiceState) Bundle(android.os.Bundle) RemoteException(android.os.RemoteException)

Example 2 with ServiceState

use of android.telephony.ServiceState in project platform_frameworks_base by android.

the class NetworkControllerSignalTest method testEmergencyOnlyNoSubscriptions.

public void testEmergencyOnlyNoSubscriptions() {
    setupDefaultSignal();
    setSubscriptions();
    mNetworkController.mLastServiceState = new ServiceState();
    mNetworkController.mLastServiceState.setEmergencyOnly(true);
    mNetworkController.recalculateEmergency();
    verifyEmergencyOnly(true);
}
Also used : ServiceState(android.telephony.ServiceState)

Example 3 with ServiceState

use of android.telephony.ServiceState in project platform_frameworks_base by android.

the class TelephonyRegistry method listen.

private void listen(String callingPackage, IPhoneStateListener callback, int events, boolean notifyNow, int subId) {
    int callerUserId = UserHandle.getCallingUserId();
    if (VDBG) {
        log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events) + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId=" + UserHandle.myUserId() + " callerUserId=" + callerUserId);
    }
    if (events != PhoneStateListener.LISTEN_NONE) {
        /* Checks permission and throws Security exception */
        checkListenerPermission(events);
        if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
            try {
                mContext.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
            // SKIP checking for run-time permission since caller or self has PRIVILEGED
            // permission
            } catch (SecurityException e) {
                if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(), callingPackage) != AppOpsManager.MODE_ALLOWED) {
                    return;
                }
            }
        }
        synchronized (mRecords) {
            // register
            Record r;
            find_and_add: {
                IBinder b = callback.asBinder();
                final int N = mRecords.size();
                for (int i = 0; i < N; i++) {
                    r = mRecords.get(i);
                    if (b == r.binder) {
                        break find_and_add;
                    }
                }
                r = new Record();
                r.binder = b;
                mRecords.add(r);
                if (DBG)
                    log("listen: add new record");
            }
            r.callback = callback;
            r.callingPackage = callingPackage;
            r.callerUserId = callerUserId;
            boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
            r.canReadPhoneState = isPhoneStateEvent && canReadPhoneState(callingPackage);
            // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
            if (!SubscriptionManager.isValidSubscriptionId(subId)) {
                r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
            } else {
                //APP specify subID
                r.subId = subId;
            }
            r.phoneId = SubscriptionManager.getPhoneId(r.subId);
            int phoneId = r.phoneId;
            r.events = events;
            if (DBG) {
                log("listen:  Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
            }
            if (VDBG)
                toStringLogSSC("listen");
            if (notifyNow && validatePhoneId(phoneId)) {
                if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
                    try {
                        if (VDBG)
                            log("listen: call onSSC state=" + mServiceState[phoneId]);
                        r.callback.onServiceStateChanged(new ServiceState(mServiceState[phoneId]));
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
                    try {
                        int gsmSignalStrength = mSignalStrength[phoneId].getGsmSignalStrength();
                        r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1 : gsmSignalStrength));
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
                    try {
                        r.callback.onMessageWaitingIndicatorChanged(mMessageWaiting[phoneId]);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
                    try {
                        r.callback.onCallForwardingIndicatorChanged(mCallForwarding[phoneId]);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
                    try {
                        if (DBG_LOC)
                            log("listen: mCellLocation = " + mCellLocation[phoneId]);
                        r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
                    try {
                        r.callback.onCallStateChanged(mCallState[phoneId], getCallIncomingNumber(r, phoneId));
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
                    try {
                        r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId], mDataConnectionNetworkType[phoneId]);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
                    try {
                        r.callback.onDataActivity(mDataActivity[phoneId]);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
                    try {
                        r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
                    try {
                        r.callback.onOtaspChanged(mOtaspMode);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
                    try {
                        if (DBG_LOC)
                            log("listen: mCellInfo[" + phoneId + "] = " + mCellInfo.get(phoneId));
                        r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
                    try {
                        r.callback.onPreciseCallStateChanged(mPreciseCallState);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
                    try {
                        r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
                    try {
                        r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) {
                    try {
                        r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
                if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) != 0) {
                    try {
                        r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
                }
            }
        }
    } else {
        if (DBG)
            log("listen: Unregister");
        remove(callback.asBinder());
    }
}
Also used : IBinder(android.os.IBinder) VoLteServiceState(android.telephony.VoLteServiceState) ServiceState(android.telephony.ServiceState) Bundle(android.os.Bundle) RemoteException(android.os.RemoteException)

Example 4 with ServiceState

use of android.telephony.ServiceState in project platform_frameworks_base by android.

the class TelephonyRegistry method checkPossibleMissNotify.

private void checkPossibleMissNotify(Record r, int phoneId) {
    int events = r.events;
    if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
        try {
            if (VDBG)
                log("checkPossibleMissNotify: onServiceStateChanged state=" + mServiceState[phoneId]);
            r.callback.onServiceStateChanged(new ServiceState(mServiceState[phoneId]));
        } catch (RemoteException ex) {
            mRemoveList.add(r.binder);
        }
    }
    if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
        try {
            SignalStrength signalStrength = mSignalStrength[phoneId];
            if (DBG) {
                log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
            }
            r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
        } catch (RemoteException ex) {
            mRemoveList.add(r.binder);
        }
    }
    if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
        try {
            int gsmSignalStrength = mSignalStrength[phoneId].getGsmSignalStrength();
            if (DBG) {
                log("checkPossibleMissNotify: onSignalStrengthChanged SS=" + gsmSignalStrength);
            }
            r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1 : gsmSignalStrength));
        } catch (RemoteException ex) {
            mRemoveList.add(r.binder);
        }
    }
    if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
        try {
            if (DBG_LOC) {
                log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = " + mCellInfo.get(phoneId));
            }
            r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
        } catch (RemoteException ex) {
            mRemoveList.add(r.binder);
        }
    }
    if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
        try {
            if (VDBG) {
                log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId=" + phoneId + " mwi=" + mMessageWaiting[phoneId]);
            }
            r.callback.onMessageWaitingIndicatorChanged(mMessageWaiting[phoneId]);
        } catch (RemoteException ex) {
            mRemoveList.add(r.binder);
        }
    }
    if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
        try {
            if (VDBG) {
                log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId=" + phoneId + " cfi=" + mCallForwarding[phoneId]);
            }
            r.callback.onCallForwardingIndicatorChanged(mCallForwarding[phoneId]);
        } catch (RemoteException ex) {
            mRemoveList.add(r.binder);
        }
    }
    if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
        try {
            if (DBG_LOC)
                log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = " + mCellLocation[phoneId]);
            r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
        } catch (RemoteException ex) {
            mRemoveList.add(r.binder);
        }
    }
    if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
        try {
            if (DBG) {
                log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState" + "=" + mDataConnectionState[phoneId] + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId] + ")");
            }
            r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId], mDataConnectionNetworkType[phoneId]);
        } catch (RemoteException ex) {
            mRemoveList.add(r.binder);
        }
    }
}
Also used : VoLteServiceState(android.telephony.VoLteServiceState) ServiceState(android.telephony.ServiceState) Bundle(android.os.Bundle) RemoteException(android.os.RemoteException) SignalStrength(android.telephony.SignalStrength)

Example 5 with ServiceState

use of android.telephony.ServiceState in project platform_frameworks_base by android.

the class TelephonyRegistry method notifyServiceStateForPhoneId.

public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
    if (!checkNotifyPermission("notifyServiceState()")) {
        return;
    }
    synchronized (mRecords) {
        if (VDBG) {
            log("notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId + " state=" + state);
        }
        if (validatePhoneId(phoneId)) {
            mServiceState[phoneId] = state;
            logServiceStateChanged("notifyServiceStateForSubscriber", subId, phoneId, state);
            if (VDBG)
                toStringLogSSC("notifyServiceStateForSubscriber");
            for (Record r : mRecords) {
                if (VDBG) {
                    log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId + " phoneId=" + phoneId + " state=" + state);
                }
                if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) && idMatch(r.subId, subId, phoneId)) {
                    try {
                        if (DBG) {
                            log("notifyServiceStateForSubscriber: callback.onSSC r=" + r + " subId=" + subId + " phoneId=" + phoneId + " state=" + state);
                        }
                        r.callback.onServiceStateChanged(new ServiceState(state));
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
        } else {
            log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
        }
        handleRemoveListLocked();
    }
    broadcastServiceStateChanged(state, phoneId, subId);
}
Also used : VoLteServiceState(android.telephony.VoLteServiceState) ServiceState(android.telephony.ServiceState) RemoteException(android.os.RemoteException)

Aggregations

ServiceState (android.telephony.ServiceState)55 RemoteException (android.os.RemoteException)19 VoLteServiceState (android.telephony.VoLteServiceState)15 Bundle (android.os.Bundle)11 PhoneStateListener (android.telephony.PhoneStateListener)10 SubscriptionInfo (android.telephony.SubscriptionInfo)7 IBinder (android.os.IBinder)6 SignalStrength (android.telephony.SignalStrength)6 Intent (android.content.Intent)5 IntentFilter (android.content.IntentFilter)5 State (com.android.internal.telephony.IccCardConstants.State)5 TelephonyManager (android.telephony.TelephonyManager)3 Paint (android.graphics.Paint)2 Fingerprint (android.hardware.fingerprint.Fingerprint)2 CdmaCellLocation (android.telephony.cdma.CdmaCellLocation)2 BitSet (java.util.BitSet)2 LinkCapabilities (android.net.LinkCapabilities)1 LinkProperties (android.net.LinkProperties)1 GsmCellLocation (android.telephony.gsm.GsmCellLocation)1 Phone (com.android.internal.telephony.Phone)1