boolean interactHostname(X509Certificate cert, String hostname) {
   switch (interact(hostNameMessage(cert, hostname), R.string.mtm_accept_servername)) {
     case MTMDecision.DECISION_ALWAYS:
       storeCert(hostname, cert);
     case MTMDecision.DECISION_ONCE:
       return true;
     default:
       return false;
   }
 }
 void interactCert(final X509Certificate[] chain, String authType, CertificateException cause)
     throws CertificateException {
   switch (interact(certChainMessage(chain, cause), R.string.mtm_accept_cert)) {
     case MTMDecision.DECISION_ALWAYS:
       storeCert(chain[0]); // only store the server cert, not the whole chain
     case MTMDecision.DECISION_ONCE:
       break;
     default:
       throw (cause);
   }
 }
  void interact(final X509Certificate[] chain, String authType, CertificateException cause)
      throws CertificateException {
    /* prepare the MTMDecision blocker object */
    MTMDecision choice = new MTMDecision();
    final int myId = createDecisionId(choice);
    final String certMessage = certChainMessage(chain, cause);
    BroadcastReceiver decisionReceiver =
        new BroadcastReceiver() {
          public void onReceive(Context ctx, Intent i) {
            interactResult(i);
          }
        };
    master.registerReceiver(
        decisionReceiver, new IntentFilter(DECISION_INTENT + "/" + master.getPackageName()));
    LaunchRunnable lr = new LaunchRunnable(myId, certMessage);
    masterHandler.post(lr);

    Log.d(TAG, "openDecisions: " + openDecisions);
    Log.d(TAG, "waiting on " + myId);
    try {
      synchronized (choice) {
        choice.wait();
      }
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    master.unregisterReceiver(decisionReceiver);
    if (lr.launchNotifReceiver != null) master.unregisterReceiver(lr.launchNotifReceiver);
    Log.d(TAG, "finished wait on " + myId + ": " + choice.state);
    switch (choice.state) {
      case MTMDecision.DECISION_ALWAYS:
        storeCert(chain);
      case MTMDecision.DECISION_ONCE:
        break;
      default:
        throw (cause);
    }
  }
 void storeCert(X509Certificate cert) {
   storeCert(cert.getSubjectDN().toString(), cert);
 }