FileDocCategorySizeDatePackage
PhoneStateIntentReceiver.javaAPI DocAndroid 5.1 API6684Thu Mar 12 22:22:54 GMT 2015com.android.internal.telephony

PhoneStateIntentReceiver

public final class PhoneStateIntentReceiver extends android.content.BroadcastReceiver
DO NOT USE THIS CLASS: Use android.telephony.TelephonyManager and PhoneStateListener instead.

Fields Summary
private static final String
LOG_TAG
private static final boolean
DBG
private static final int
NOTIF_PHONE
private static final int
NOTIF_SERVICE
private static final int
NOTIF_SIGNAL
PhoneConstants.State
mPhoneState
android.telephony.ServiceState
mServiceState
android.telephony.SignalStrength
mSignalStrength
private android.content.Context
mContext
private android.os.Handler
mTarget
private android.content.IntentFilter
mFilter
private int
mWants
private int
mPhoneStateEventWhat
private int
mServiceStateEventWhat
private int
mAsuEventWhat
Constructors Summary
public PhoneStateIntentReceiver()


      
        super();
        mFilter = new IntentFilter();
    
public PhoneStateIntentReceiver(android.content.Context context, android.os.Handler target)

        this();
        setContext(context);
        setTarget(target);
    
Methods Summary
public booleangetNotifyPhoneCallState()

        return ((mWants & NOTIF_PHONE) != 0);
    
public booleangetNotifyServiceState()

        return ((mWants & NOTIF_SERVICE) != 0);
    
public booleangetNotifySignalStrength()

        return ((mWants & NOTIF_SIGNAL) != 0);
    
public PhoneConstants.StategetPhoneState()

        if ((mWants & NOTIF_PHONE) == 0) {
            throw new RuntimeException
                ("client must call notifyPhoneCallState(int)");
        }
        return mPhoneState;
    
public android.telephony.ServiceStategetServiceState()

        if ((mWants & NOTIF_SERVICE) == 0) {
            throw new RuntimeException
                ("client must call notifyServiceState(int)");
        }
        return mServiceState;
    
public intgetSignalStrengthDbm()
Return current signal strength in "dBm", ranging from -113 - -51dBm or -1 if unknown

return
signal strength in dBm, -1 if not yet updated Throws RuntimeException if client has not called notifySignalStrength()

        if ((mWants & NOTIF_SIGNAL) == 0) {
            throw new RuntimeException
                ("client must call notifySignalStrength(int)");
        }
        return mSignalStrength.getDbm();
    
public intgetSignalStrengthLevelAsu()
Returns current signal strength in as an asu 0..31 Throws RuntimeException if client has not called notifySignalStrength()

        // TODO: use new SignalStrength instead of asu
        if ((mWants & NOTIF_SIGNAL) == 0) {
            throw new RuntimeException
                ("client must call notifySignalStrength(int)");
        }
        return mSignalStrength.getAsuLevel();
    
public voidnotifyPhoneCallState(int eventWhat)

        mWants |= NOTIF_PHONE;
        mPhoneStateEventWhat = eventWhat;
        mFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    
public voidnotifyServiceState(int eventWhat)

        mWants |= NOTIF_SERVICE;
        mServiceStateEventWhat = eventWhat;
        mFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
    
public voidnotifySignalStrength(int eventWhat)

        mWants |= NOTIF_SIGNAL;
        mAsuEventWhat = eventWhat;
        mFilter.addAction(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
    
public voidonReceive(android.content.Context context, android.content.Intent intent)

        String action = intent.getAction();

        try {
            if (TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED.equals(action)) {
                mSignalStrength = SignalStrength.newFromBundle(intent.getExtras());

                if (mTarget != null && getNotifySignalStrength()) {
                    Message message = Message.obtain(mTarget, mAsuEventWhat);
                    mTarget.sendMessage(message);
                }
            } else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) {
                if (DBG) Rlog.d(LOG_TAG, "onReceiveIntent: ACTION_PHONE_STATE_CHANGED, state="
                               + intent.getStringExtra(PhoneConstants.STATE_KEY));
                String phoneState = intent.getStringExtra(PhoneConstants.STATE_KEY);
                mPhoneState = Enum.valueOf(
                        PhoneConstants.State.class, phoneState);

                if (mTarget != null && getNotifyPhoneCallState()) {
                    Message message = Message.obtain(mTarget,
                            mPhoneStateEventWhat);
                    mTarget.sendMessage(message);
                }
            } else if (TelephonyIntents.ACTION_SERVICE_STATE_CHANGED.equals(action)) {
                mServiceState = ServiceState.newFromBundle(intent.getExtras());

                if (mTarget != null && getNotifyServiceState()) {
                    Message message = Message.obtain(mTarget,
                            mServiceStateEventWhat);
                    mTarget.sendMessage(message);
                }
            }
        } catch (Exception ex) {
            Rlog.e(LOG_TAG, "[PhoneStateIntentRecv] caught " + ex);
            ex.printStackTrace();
        }
    
public voidregisterIntent()

        mContext.registerReceiver(this, mFilter);
    
public voidsetContext(android.content.Context c)

        mContext = c;
    
public voidsetTarget(android.os.Handler h)

        mTarget = h;
    
public voidunregisterIntent()

        mContext.unregisterReceiver(this);