@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == START_VPN_PROFILE) {
      if (resultCode == Activity.RESULT_OK) {
        int needpw = mSelectedProfile.needUserPWInput(false);
        if (needpw != 0) {
          VpnStatus.updateStateString(
              "USER_VPN_PASSWORD",
              "",
              R.string.openvpn_state_user_vpn_password,
              ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT);
          askForPW(needpw);
        } else {
          SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
          boolean showLogWindow = prefs.getBoolean("showlogwindow", true);

          if (!mhideLog && showLogWindow) showLogWindow();
          new startOpenVpnThread().start();
        }
      } else if (resultCode == Activity.RESULT_CANCELED) {
        // User does not want us to start, so we just vanish
        VpnStatus.updateStateString(
            "USER_VPN_PERMISSION_CANCELLED",
            "",
            R.string.openvpn_state_user_vpn_permission_cancelled,
            ConnectionStatus.LEVEL_NOTCONNECTED);

        finish();
      }
    }
  }
  void launchVPN() {
    int vpnok = mSelectedProfile.checkProfile(this);
    if (vpnok != R.string.openvpn_no_error_found) {
      showConfigErrorDialog(vpnok);
      return;
    }

    Intent intent = VpnService.prepare(this);
    // Check if we want to fix /dev/tun
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean usecm9fix = prefs.getBoolean("useCM9Fix", false);
    boolean loadTunModule = prefs.getBoolean("loadTunModule", false);

    if (loadTunModule) execeuteSUcmd("insmod /system/lib/modules/tun.ko");

    if (usecm9fix && !mCmfixed) {
      execeuteSUcmd("chown system /dev/tun");
    }

    if (intent != null) {
      VpnStatus.updateStateString(
          "USER_VPN_PERMISSION",
          "",
          R.string.openvpn_state_user_vpn_permission,
          ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT);
      // Start the query
      try {
        startActivityForResult(intent, START_VPN_PROFILE);
      } catch (ActivityNotFoundException ane) {
        // Shame on you Sony! At least one user reported that
        // an official Sony Xperia Arc S image triggers this exception
        VpnStatus.logError(R.string.openvpn_no_vpn_support_image);
        showLogWindow();
      }
    } else {
      onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null);
    }
  }