46 void onConnectCancel();
49 private final Activity activity;
51 private final Handler mainHandler =
new Handler(Looper.getMainLooper());
53 private final AlertDialog dlgVerifyCertificate;
54 private final AlertDialog dlgUserCredentials;
55 private final View userCredView;
57 private AlertDialog progressDialog;
59 private boolean callbackDialogResult;
63 this.activity = activity;
64 this.cancelListener = cancelListener;
66 dlgVerifyCertificate =
new AlertDialog.Builder(activity)
67 .setTitle(R.string.dlg_title_verify_certificate)
68 .setPositiveButton(android.R.string.yes,
70 callbackDialogResult = true;
76 .setNegativeButton(android.R.string.no,
78 callbackDialogResult = false;
88 userCredView = activity.getLayoutInflater().inflate(R.layout.credentials,
null,
true);
89 dlgUserCredentials =
new AlertDialog.Builder(activity)
90 .setView(userCredView)
91 .setTitle(R.string.dlg_title_credentials)
92 .setPositiveButton(android.R.string.ok,
94 callbackDialogResult = true;
100 .setNegativeButton(android.R.string.cancel,
102 callbackDialogResult = false;
104 synchronized (dialog)
109 .setCancelable(
false)
118 StringBuilder password)
120 callbackDialogResult =
false;
122 ((EditText)userCredView.findViewById(R.id.editTextUsername)).setText(username);
123 ((EditText)userCredView.findViewById(R.id.editTextDomain)).setText(domain);
124 ((EditText)userCredView.findViewById(R.id.editTextPassword)).setText(password);
126 showOnUiThread(dlgUserCredentials);
130 synchronized (dlgUserCredentials)
132 dlgUserCredentials.wait();
135 catch (InterruptedException e)
139 username.setLength(0);
141 password.setLength(0);
144 ((EditText)userCredView.findViewById(R.id.editTextUsername)).getText().toString());
146 ((EditText)userCredView.findViewById(R.id.editTextDomain)).getText().toString());
148 ((EditText)userCredView.findViewById(R.id.editTextPassword)).getText().toString());
150 return callbackDialogResult;
157 String fingerprint,
long flags)
159 String msg = activity.getResources().getString(R.string.dlg_msg_verify_certificate);
160 String type =
"RDP-Server";
161 if ((flags & LibFreeRDP.VERIFY_CERT_FLAG_GATEWAY) != 0)
162 type =
"RDP-Gateway";
163 if ((flags & LibFreeRDP.VERIFY_CERT_FLAG_REDIRECT) != 0)
164 type =
"RDP-Redirect";
165 msg +=
"\n\n" + type +
": " + host +
":" + port;
166 msg +=
"\n\nSubject: " + subject +
"\nIssuer: " + issuer;
167 if ((flags & LibFreeRDP.VERIFY_CERT_FLAG_FP_IS_PEM) != 0)
168 msg +=
"\nCertificate: " + fingerprint;
170 msg +=
"\nFingerprint: " + fingerprint;
172 return showVerifyDialog(msg);
179 String fingerprint,
long flags)
183 return verifyCertificate(host, port, subject, issuer, fingerprint, flags);
186 private int showVerifyDialog(String msg)
188 callbackDialogResult =
false;
189 dlgVerifyCertificate.setMessage(msg);
191 showOnUiThread(dlgVerifyCertificate);
195 synchronized (dlgVerifyCertificate)
197 dlgVerifyCertificate.wait();
200 catch (InterruptedException e)
204 return callbackDialogResult ? 1 : 0;
207 private void showOnUiThread(
final AlertDialog dialog)
209 mainHandler.post(dialog::show);
212 private void notifyCancel()
214 if (cancelListener !=
null)
215 cancelListener.onUserCancel();
226 int pad = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24,
227 activity.getResources().getDisplayMetrics());
228 LinearLayout content =
new LinearLayout(activity);
229 content.setOrientation(LinearLayout.HORIZONTAL);
230 content.setPadding(pad, pad, pad, pad);
231 content.setGravity(Gravity.CENTER_VERTICAL);
233 ProgressBar progressBar =
new ProgressBar(activity);
234 progressBar.setIndeterminate(
true);
235 content.addView(progressBar,
236 new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
237 ViewGroup.LayoutParams.WRAP_CONTENT));
239 TextView messageView =
new TextView(activity);
240 messageView.setText(R.string.dlg_msg_connecting);
241 LinearLayout.LayoutParams textParams =
new LinearLayout.LayoutParams(
242 ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
243 textParams.leftMargin = pad;
244 content.addView(messageView, textParams);
246 progressDialog =
new AlertDialog.Builder(activity)
249 .setNegativeButton(android.R.string.cancel,
251 if (listener != null)
252 listener.onConnectCancel();
254 .setCancelable(
false)
256 progressDialog.show();
262 if (progressDialog !=
null)
264 progressDialog.dismiss();
265 progressDialog =
null;