EmergencyCallHandler.javaAPI DocAndroid 1.5 API7745Wed May 06 22:42:46 BST


public class EmergencyCallHandler extends
This class coordinates with the InCallScreen by throwing the original intent (from the dialer) back and forth. An extra integer referenced by EMERGENCY_CALL_RETRY_KEY, is used to convey all the information we need.

Fields Summary
public static final String
the key used to get the count from our Intent's extra(s)
public static final int
count indicating an initial attempt at the call should be made.
public static final int
number of times to retry the call and the time spent in between attempts
public static final int
private static final int
private static final int
private static EmergencyCallEventHandler
static handler class, used to handle the two relevent events.
Constructors Summary
Methods Summary
private retryCount)
create the dialog and hand it back to caller.

        // figure out the message to display. 
        int msgId = (retryCount == INITIAL_ATTEMPT) ? 
                R.string.emergency_enable_radio_dialog_message :

        // create a system dialog that will persist outside this activity.
        ProgressDialog pd = new ProgressDialog(getApplication());
        // show the dialog;
        return pd;
protected voidonCreate(android.os.Bundle icicle)

        // setup the phone and get the retry count embedded in the intent.
        Phone phone = PhoneFactory.getDefaultPhone();
        int retryCount = getIntent().getIntExtra(EMERGENCY_CALL_RETRY_KEY, INITIAL_ATTEMPT);
        // create a new message object.
        EmergencyCallInfo eci = new EmergencyCallInfo(); = phone; = getApplication();
        eci.dialog = constructDialog(retryCount);
        eci.intent = getIntent().setComponent(null);
        // create the handler.
        if (sHandler == null) {
            sHandler = new EmergencyCallEventHandler();
        // If this is the initial attempt, we need to register for a radio state
        // change and turn the radio on.  Otherwise, this is just a retry, and
        // we simply wait the alloted time before sending the request to try
        // the call again.
        // Note: The radio logic ITSELF will try its best to put the emergency
        // call through once the radio is turned on.  The retry we have here 
        // is in case it fails; the current constants we have include making
        // 6 attempts, with a 5 second delay between each.
        if (retryCount == INITIAL_ATTEMPT) {
            // place the number of pending retries in the intent.
            eci.intent.putExtra(EMERGENCY_CALL_RETRY_KEY, NUMBER_OF_RETRIES);
            // turn the radio on and listen for it to complete.
                    EVENT_SERVICE_STATE_CHANGED, eci);

            // If airplane mode is on, we turn it off the same way that the 
            // Settings activity turns it off.
            if (Settings.System.getInt(getContentResolver(), 
                    Settings.System.AIRPLANE_MODE_ON, 0) > 0) {
                // Change the system setting
                Settings.System.putInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0);
                // Post the intent
                Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
                intent.putExtra("state", false);

            // Otherwise, for some strange reason the radio is just off, so 
            // we just turn it back on.
            } else {
        } else {
            // decrement and store the number of retries.
            eci.intent.putExtra(EMERGENCY_CALL_RETRY_KEY, (retryCount - 1));
            // get the message and attach the data, then wait the alloted
            // time and send.
            Message m = sHandler.obtainMessage(EVENT_TIMEOUT_EMERGENCY_CALL);
            m.obj = eci;
            sHandler.sendMessageDelayed(m, TIME_BETWEEN_RETRIES_MS);