@Override
  protected void onCreate(Bundle icicle) {
    Log.i(TAG, "onCreate()...  intent = " + getIntent());
    super.onCreate(icicle);

    // Watch out: the intent action we get here should always be
    // ACTION_CALL_EMERGENCY, since the whole point of this activity
    // is for it to be launched using the same intent originally
    // passed to the InCallScreen, which will always be
    // ACTION_CALL_EMERGENCY when making an emergency call.
    //
    // If we ever get launched with any other action, especially if it's
    // "com.android.phone.InCallScreen.UNDEFINED" (as in bug 3094858), that
    // almost certainly indicates a logic bug in the InCallScreen.
    if (!Intent.ACTION_CALL_EMERGENCY.equals(getIntent().getAction())) {
      Log.w(
          TAG,
          "Unexpected intent action!  Should be ACTION_CALL_EMERGENCY, "
              + "but instead got: "
              + getIntent().getAction());
    }

    // 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();
    eci.phone = phone;
    eci.app = getApplication();
    eci.dialog = constructDialog(retryCount);

    // The Intent we're going to fire off to retry the call is the
    // same one that got us here (except that we *don't* explicitly
    // specify this class as the component!)
    eci.intent = getIntent().setComponent(null);
    // And we'll be firing this Intent from the PhoneApp's context
    // (see the startActivity() calls above) so the
    // FLAG_ACTIVITY_NEW_TASK flag is required.
    eci.intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (DBG) Log.d(TAG, "- initial eci.intent: " + eci.intent);

    // 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);
      int sub = PhoneApp.getInstance().getVoiceSubscriptionInService();
      eci.intent.putExtra(SUBSCRIPTION, sub);
      Log.d(TAG, "Attempting emergency call on sub :" + sub);

      // turn the radio on and listen for it to complete.
      phone.registerForServiceStateChanged(sHandler, 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) {
        if (DBG) Log.d(TAG, "Turning off airplane mode...");

        // 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);
        sendBroadcast(intent);

        // Otherwise, for some strange reason the radio is just off, so
        // we just turn it back on.
      } else {
        if (DBG) Log.d(TAG, "Manually powering radio on...");
        phone.setRadioPower(true);
      }

    } else {
      // decrement and store the number of retries.
      if (DBG) Log.d(TAG, "Retry attempt...  retryCount = " + retryCount);
      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);
    }
    finish();
  }