@Override
  public void onEventReceived(BaseEvent bEvent) {
    if (bEvent instanceof SwitchedRomEvent) {
      SwitchedRomEvent event = (SwitchedRomEvent) bEvent;

      boolean reboot = getIntent().getBooleanExtra(EXTRA_REBOOT, false);
      if (event.result == SwitchRomResult.SUCCEEDED && reboot) {
        // Don't return if we're rebooting
        SwitcherUtils.reboot(this);
        return;
      }

      GenericProgressDialog d =
          (GenericProgressDialog)
              getFragmentManager().findFragmentByTag("automated_switch_rom_waiting");
      if (d != null) {
        d.dismiss();
      }

      Intent intent = new Intent();

      switch (event.result) {
        case SUCCEEDED:
          intent.putExtra(RESULT_CODE, "SWITCHING_SUCCEEDED");
          Toast.makeText(this, R.string.choose_rom_success, Toast.LENGTH_LONG).show();
          break;
        case FAILED:
          intent.putExtra(RESULT_CODE, "SWITCHING_FAILED");
          intent.putExtra(RESULT_MESSAGE, String.format("Failed to switch to %s", event.kernelId));
          Toast.makeText(this, R.string.choose_rom_failure, Toast.LENGTH_LONG).show();
          break;
        case CHECKSUM_INVALID:
          intent.putExtra(RESULT_CODE, "SWITCHING_FAILED");
          intent.putExtra(
              RESULT_MESSAGE,
              String.format("Mismatched checksums for %s's images", event.kernelId));
          Toast.makeText(this, R.string.choose_rom_checksums_invalid, Toast.LENGTH_LONG).show();
          break;
        case CHECKSUM_NOT_FOUND:
          intent.putExtra(RESULT_CODE, "SWITCHING_FAILED");
          intent.putExtra(
              RESULT_MESSAGE, String.format("Missing checksums for %s's images", event.kernelId));
          Toast.makeText(this, R.string.choose_rom_checksums_missing, Toast.LENGTH_LONG).show();
          break;
        case UNKNOWN_BOOT_PARTITION:
          intent.putExtra(RESULT_CODE, "UNKNOWN_BOOT_PARTITION");
          intent.putExtra(RESULT_MESSAGE, "Failed to determine boot partition");
          String codename = RomUtils.getDeviceCodename(this);
          Toast.makeText(
                  this, getString(R.string.unknown_boot_partition, codename), Toast.LENGTH_SHORT)
              .show();
          break;
      }

      setResult(Activity.RESULT_OK, intent);
      finish();
    }
  }
  public static synchronized Device getCurrentDevice(Context context, PatcherConfig pc) {
    String realCodename = RomUtils.getDeviceCodename(context);

    Device device = null;
    for (Device d : pc.getDevices()) {
      for (String codename : d.getCodenames()) {
        if (realCodename.equals(codename)) {
          device = d;
          break;
        }
      }
      if (device != null) {
        break;
      }
    }

    return device;
  }