AuthenticatorActivity.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /* ownCloud Android client application
  2. * Copyright (C) 2012 Bartek Przybylski
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. */
  18. package com.owncloud.android.ui.activity;
  19. import java.net.MalformedURLException;
  20. import java.net.URL;
  21. import com.owncloud.android.AccountUtils;
  22. import com.owncloud.android.authenticator.AccountAuthenticator;
  23. import com.owncloud.android.authenticator.AuthenticationRunnable;
  24. import com.owncloud.android.authenticator.OnAuthenticationResultListener;
  25. import com.owncloud.android.authenticator.OnConnectCheckListener;
  26. import com.owncloud.android.ui.dialog.SslValidatorDialog;
  27. import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;
  28. import com.owncloud.android.network.OwnCloudClientUtils;
  29. import com.owncloud.android.operations.ConnectionCheckOperation;
  30. import com.owncloud.android.operations.OnRemoteOperationListener;
  31. import com.owncloud.android.operations.RemoteOperation;
  32. import com.owncloud.android.operations.RemoteOperationResult;
  33. import android.accounts.Account;
  34. import android.accounts.AccountAuthenticatorActivity;
  35. import android.accounts.AccountManager;
  36. import android.app.AlertDialog;
  37. import android.app.Dialog;
  38. import android.app.ProgressDialog;
  39. import android.content.ContentResolver;
  40. import android.content.DialogInterface;
  41. import android.content.Intent;
  42. import android.content.SharedPreferences;
  43. import android.net.Uri;
  44. import android.os.Bundle;
  45. import android.os.Handler;
  46. import android.preference.PreferenceManager;
  47. import android.text.InputType;
  48. import android.util.Log;
  49. import android.view.View;
  50. import android.view.View.OnClickListener;
  51. import android.view.View.OnFocusChangeListener;
  52. import android.view.Window;
  53. import android.widget.Button;
  54. import android.widget.ImageView;
  55. import android.widget.TextView;
  56. import com.owncloud.android.R;
  57. import eu.alefzero.webdav.WebdavClient;
  58. /**
  59. * This Activity is used to add an ownCloud account to the App
  60. *
  61. * @author Bartek Przybylski
  62. *
  63. */
  64. public class AuthenticatorActivity extends AccountAuthenticatorActivity
  65. implements OnAuthenticationResultListener, OnConnectCheckListener, OnRemoteOperationListener, OnSslValidatorListener,
  66. OnFocusChangeListener, OnClickListener {
  67. private static final int DIALOG_LOGIN_PROGRESS = 0;
  68. private static final int DIALOG_SSL_VALIDATOR = 1;
  69. private static final int DIALOG_CERT_NOT_SAVED = 2;
  70. private static final String TAG = "AuthActivity";
  71. private Thread mAuthThread;
  72. private AuthenticationRunnable mAuthRunnable;
  73. //private ConnectionCheckerRunnable mConnChkRunnable = null;
  74. private ConnectionCheckOperation mConnChkRunnable;
  75. private final Handler mHandler = new Handler();
  76. private String mBaseUrl;
  77. private static final String STATUS_TEXT = "STATUS_TEXT";
  78. private static final String STATUS_ICON = "STATUS_ICON";
  79. private static final String STATUS_CORRECT = "STATUS_CORRECT";
  80. private static final String IS_SSL_CONN = "IS_SSL_CONN";
  81. private int mStatusText, mStatusIcon;
  82. private boolean mStatusCorrect, mIsSslConn;
  83. private RemoteOperationResult mLastSslUntrustedServerResult;
  84. public static final String PARAM_USERNAME = "param_Username";
  85. public static final String PARAM_HOSTNAME = "param_Hostname";
  86. @Override
  87. protected void onCreate(Bundle savedInstanceState) {
  88. super.onCreate(savedInstanceState);
  89. getWindow().requestFeature(Window.FEATURE_NO_TITLE);
  90. setContentView(R.layout.account_setup);
  91. ImageView iv = (ImageView) findViewById(R.id.refreshButton);
  92. ImageView iv2 = (ImageView) findViewById(R.id.viewPassword);
  93. TextView tv = (TextView) findViewById(R.id.host_URL);
  94. TextView tv2 = (TextView) findViewById(R.id.account_password);
  95. if (savedInstanceState != null) {
  96. mStatusIcon = savedInstanceState.getInt(STATUS_ICON);
  97. mStatusText = savedInstanceState.getInt(STATUS_TEXT);
  98. mStatusCorrect = savedInstanceState.getBoolean(STATUS_CORRECT);
  99. mIsSslConn = savedInstanceState.getBoolean(IS_SSL_CONN);
  100. setResultIconAndText(mStatusIcon, mStatusText);
  101. findViewById(R.id.buttonOK).setEnabled(mStatusCorrect);
  102. if (!mStatusCorrect)
  103. iv.setVisibility(View.VISIBLE);
  104. else
  105. iv.setVisibility(View.INVISIBLE);
  106. } else {
  107. mStatusText = mStatusIcon = 0;
  108. mStatusCorrect = false;
  109. mIsSslConn = false;
  110. }
  111. iv.setOnClickListener(this);
  112. iv2.setOnClickListener(this);
  113. tv.setOnFocusChangeListener(this);
  114. tv2.setOnFocusChangeListener(this);
  115. Button b = (Button) findViewById(R.id.account_register);
  116. if (b != null) {
  117. b.setText(String.format(getString(R.string.auth_register), getString(R.string.app_name)));
  118. }
  119. }
  120. @Override
  121. protected void onSaveInstanceState(Bundle outState) {
  122. outState.putInt(STATUS_ICON, mStatusIcon);
  123. outState.putInt(STATUS_TEXT, mStatusText);
  124. outState.putBoolean(STATUS_CORRECT, mStatusCorrect);
  125. super.onSaveInstanceState(outState);
  126. }
  127. @Override
  128. protected Dialog onCreateDialog(int id) {
  129. Dialog dialog = null;
  130. switch (id) {
  131. case DIALOG_LOGIN_PROGRESS: {
  132. ProgressDialog working_dialog = new ProgressDialog(this);
  133. working_dialog.setMessage(getResources().getString(
  134. R.string.auth_trying_to_login));
  135. working_dialog.setIndeterminate(true);
  136. working_dialog.setCancelable(true);
  137. working_dialog
  138. .setOnCancelListener(new DialogInterface.OnCancelListener() {
  139. @Override
  140. public void onCancel(DialogInterface dialog) {
  141. Log.i(TAG, "Login canceled");
  142. if (mAuthThread != null) {
  143. mAuthThread.interrupt();
  144. finish();
  145. }
  146. }
  147. });
  148. dialog = working_dialog;
  149. break;
  150. }
  151. case DIALOG_SSL_VALIDATOR: {
  152. dialog = SslValidatorDialog.newInstance(this, mLastSslUntrustedServerResult, this);
  153. break;
  154. }
  155. case DIALOG_CERT_NOT_SAVED: {
  156. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  157. builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));
  158. builder.setCancelable(false);
  159. builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
  160. @Override
  161. public void onClick(DialogInterface dialog, int which) {
  162. dialog.dismiss();
  163. };
  164. });
  165. dialog = builder.create();
  166. break;
  167. }
  168. default:
  169. Log.e(TAG, "Incorrect dialog called with id = " + id);
  170. }
  171. return dialog;
  172. }
  173. @Override
  174. protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {
  175. switch (id) {
  176. case DIALOG_LOGIN_PROGRESS:
  177. case DIALOG_CERT_NOT_SAVED:
  178. break;
  179. case DIALOG_SSL_VALIDATOR: {
  180. ((SslValidatorDialog)dialog).updateResult(mLastSslUntrustedServerResult);
  181. break;
  182. }
  183. default:
  184. Log.e(TAG, "Incorrect dialog called with id = " + id);
  185. }
  186. }
  187. public void onAuthenticationResult(boolean success, String message) {
  188. if (success) {
  189. TextView username_text = (TextView) findViewById(R.id.account_username), password_text = (TextView) findViewById(R.id.account_password);
  190. URL url;
  191. try {
  192. url = new URL(message);
  193. } catch (MalformedURLException e) {
  194. // should never happen
  195. Log.e(getClass().getName(), "Malformed URL: " + message);
  196. return;
  197. }
  198. String username = username_text.getText().toString().trim();
  199. String accountName = username + "@" + url.getHost();
  200. if (url.getPort() >= 0) {
  201. accountName += ":" + url.getPort();
  202. }
  203. Account account = new Account(accountName,
  204. AccountAuthenticator.ACCOUNT_TYPE);
  205. AccountManager accManager = AccountManager.get(this);
  206. accManager.addAccountExplicitly(account, password_text.getText()
  207. .toString(), null);
  208. // Add this account as default in the preferences, if there is none
  209. // already
  210. Account defaultAccount = AccountUtils
  211. .getCurrentOwnCloudAccount(this);
  212. if (defaultAccount == null) {
  213. SharedPreferences.Editor editor = PreferenceManager
  214. .getDefaultSharedPreferences(this).edit();
  215. editor.putString("select_oc_account", accountName);
  216. editor.commit();
  217. }
  218. final Intent intent = new Intent();
  219. intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE,
  220. AccountAuthenticator.ACCOUNT_TYPE);
  221. intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, account.name);
  222. intent.putExtra(AccountManager.KEY_AUTHTOKEN,
  223. AccountAuthenticator.ACCOUNT_TYPE);
  224. intent.putExtra(AccountManager.KEY_USERDATA, username);
  225. accManager.setUserData(account,
  226. AccountAuthenticator.KEY_OC_VERSION, mConnChkRunnable
  227. .getDiscoveredVersion().toString());
  228. accManager.setUserData(account,
  229. AccountAuthenticator.KEY_OC_BASE_URL, mBaseUrl);
  230. setAccountAuthenticatorResult(intent.getExtras());
  231. setResult(RESULT_OK, intent);
  232. Bundle bundle = new Bundle();
  233. bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
  234. //getContentResolver().startSync(ProviderTableMeta.CONTENT_URI,
  235. // bundle);
  236. ContentResolver.requestSync(account, "org.owncloud", bundle);
  237. /*
  238. * if
  239. * (mConnChkRunnable.getDiscoveredVersion().compareTo(OwnCloudVersion
  240. * .owncloud_v2) >= 0) { Intent i = new Intent(this,
  241. * ExtensionsAvailableActivity.class); startActivity(i); }
  242. */
  243. finish();
  244. } else {
  245. try {
  246. dismissDialog(DIALOG_LOGIN_PROGRESS);
  247. } catch (IllegalArgumentException e) {
  248. // NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens
  249. }
  250. TextView tv = (TextView) findViewById(R.id.account_username);
  251. tv.setError(message + " "); // the extra spaces are a workaround for an ugly bug:
  252. // 1. insert wrong credentials and connect
  253. // 2. put the focus on the user name field with using hardware controls (don't touch the screen); the error is shown UNDER the field
  254. // 3. touch the user name field; the software keyboard appears; the error popup is moved OVER the field and SHRINKED in width, losing the last word
  255. // Seen, at least, in Android 2.x devices
  256. }
  257. }
  258. public void onCancelClick(View view) {
  259. setResult(RESULT_CANCELED);
  260. finish();
  261. }
  262. public void onOkClick(View view) {
  263. String prefix = "";
  264. String url = ((TextView) findViewById(R.id.host_URL)).getText()
  265. .toString().trim();
  266. if (mIsSslConn) {
  267. prefix = "https://";
  268. } else {
  269. prefix = "http://";
  270. }
  271. if (url.toLowerCase().startsWith("http://")
  272. || url.toLowerCase().startsWith("https://")) {
  273. prefix = "";
  274. }
  275. continueConnection(prefix);
  276. }
  277. public void onRegisterClick(View view) {
  278. Intent register = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.url_account_register)));
  279. setResult(RESULT_CANCELED);
  280. startActivity(register);
  281. }
  282. private void continueConnection(String prefix) {
  283. String url = ((TextView) findViewById(R.id.host_URL)).getText()
  284. .toString().trim();
  285. String username = ((TextView) findViewById(R.id.account_username))
  286. .getText().toString();
  287. String password = ((TextView) findViewById(R.id.account_password))
  288. .getText().toString();
  289. if (url.endsWith("/"))
  290. url = url.substring(0, url.length() - 1);
  291. URL uri = null;
  292. String webdav_path = AccountUtils.getWebdavPath(mConnChkRunnable
  293. .getDiscoveredVersion());
  294. if (webdav_path == null) {
  295. onAuthenticationResult(false, getString(R.string.auth_bad_oc_version_title));
  296. return;
  297. }
  298. try {
  299. mBaseUrl = prefix + url;
  300. String url_str = prefix + url + webdav_path;
  301. uri = new URL(url_str);
  302. } catch (MalformedURLException e) {
  303. // should never happen
  304. onAuthenticationResult(false, getString(R.string.auth_incorrect_address_title));
  305. return;
  306. }
  307. showDialog(DIALOG_LOGIN_PROGRESS);
  308. mAuthRunnable = new AuthenticationRunnable(uri, username, password, this);
  309. mAuthRunnable.setOnAuthenticationResultListener(this, mHandler);
  310. mAuthThread = new Thread(mAuthRunnable);
  311. mAuthThread.start();
  312. }
  313. @Override
  314. public void onConnectionCheckResult(ResultType type) {
  315. mStatusText = mStatusIcon = 0;
  316. mStatusCorrect = false;
  317. String t_url = ((TextView) findViewById(R.id.host_URL)).getText()
  318. .toString().trim().toLowerCase();
  319. switch (type) {
  320. case OK_SSL:
  321. mIsSslConn = true;
  322. mStatusIcon = android.R.drawable.ic_secure;
  323. mStatusText = R.string.auth_secure_connection;
  324. mStatusCorrect = true;
  325. break;
  326. case OK_NO_SSL:
  327. mIsSslConn = false;
  328. mStatusCorrect = true;
  329. if (t_url.startsWith("http://") ) {
  330. mStatusText = R.string.auth_connection_established;
  331. mStatusIcon = R.drawable.ic_ok;
  332. } else {
  333. mStatusText = R.string.auth_nossl_plain_ok_title;
  334. mStatusIcon = android.R.drawable.ic_partial_secure;
  335. }
  336. break;
  337. case BAD_OC_VERSION:
  338. mStatusIcon = R.drawable.common_error;
  339. mStatusText = R.string.auth_bad_oc_version_title;
  340. break;
  341. case WRONG_CONNECTION:
  342. mStatusIcon = R.drawable.common_error;
  343. mStatusText = R.string.auth_wrong_connection_title;
  344. break;
  345. case TIMEOUT:
  346. mStatusIcon = R.drawable.common_error;
  347. mStatusText = R.string.auth_timeout_title;
  348. break;
  349. case INCORRECT_ADDRESS:
  350. mStatusIcon = R.drawable.common_error;
  351. mStatusText = R.string.auth_incorrect_address_title;
  352. break;
  353. case SSL_UNVERIFIED_SERVER:
  354. mStatusIcon = R.drawable.common_error;
  355. mStatusText = R.string.auth_ssl_unverified_server_title;
  356. break;
  357. case SSL_INIT_ERROR:
  358. mStatusIcon = R.drawable.common_error;
  359. mStatusText = R.string.auth_ssl_general_error_title;
  360. break;
  361. case HOST_NOT_AVAILABLE:
  362. mStatusIcon = R.drawable.common_error;
  363. mStatusText = R.string.auth_unknown_host_title;
  364. break;
  365. case NO_NETWORK_CONNECTION:
  366. mStatusIcon = R.drawable.no_network;
  367. mStatusText = R.string.auth_no_net_conn_title;
  368. break;
  369. case INSTANCE_NOT_CONFIGURED:
  370. mStatusIcon = R.drawable.common_error;
  371. mStatusText = R.string.auth_not_configured_title;
  372. break;
  373. case UNKNOWN_ERROR:
  374. mStatusIcon = R.drawable.common_error;
  375. mStatusText = R.string.auth_unknown_error_title;
  376. break;
  377. case FILE_NOT_FOUND:
  378. mStatusIcon = R.drawable.common_error;
  379. mStatusText = R.string.auth_incorrect_path_title;
  380. break;
  381. default:
  382. Log.e(TAG, "Incorrect connection checker result type: " + type);
  383. }
  384. setResultIconAndText(mStatusIcon, mStatusText);
  385. if (!mStatusCorrect)
  386. findViewById(R.id.refreshButton).setVisibility(View.VISIBLE);
  387. else
  388. findViewById(R.id.refreshButton).setVisibility(View.INVISIBLE);
  389. findViewById(R.id.buttonOK).setEnabled(mStatusCorrect);
  390. }
  391. @Override
  392. public void onFocusChange(View view, boolean hasFocus) {
  393. if (view.getId() == R.id.host_URL) {
  394. if (!hasFocus) {
  395. TextView tv = ((TextView) findViewById(R.id.host_URL));
  396. String uri = tv.getText().toString().trim();
  397. if (uri.length() != 0) {
  398. setResultIconAndText(R.drawable.progress_small,
  399. R.string.auth_testing_connection);
  400. //mConnChkRunnable = new ConnectionCheckerRunnable(uri, this);
  401. mConnChkRunnable = new ConnectionCheckOperation(uri, this);
  402. //mConnChkRunnable.setListener(this, mHandler);
  403. //mAuthThread = new Thread(mConnChkRunnable);
  404. //mAuthThread.start();
  405. WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(uri), this);
  406. mAuthThread = mConnChkRunnable.execute(client, this, mHandler);
  407. } else {
  408. findViewById(R.id.refreshButton).setVisibility(
  409. View.INVISIBLE);
  410. setResultIconAndText(0, 0);
  411. }
  412. } else {
  413. // avoids that the 'connect' button can be clicked if the test was previously passed
  414. findViewById(R.id.buttonOK).setEnabled(false);
  415. }
  416. } else if (view.getId() == R.id.account_password) {
  417. ImageView iv = (ImageView) findViewById(R.id.viewPassword);
  418. if (hasFocus) {
  419. iv.setVisibility(View.VISIBLE);
  420. } else {
  421. TextView v = (TextView) findViewById(R.id.account_password);
  422. int input_type = InputType.TYPE_CLASS_TEXT
  423. | InputType.TYPE_TEXT_VARIATION_PASSWORD;
  424. v.setInputType(input_type);
  425. iv.setVisibility(View.INVISIBLE);
  426. }
  427. }
  428. }
  429. private void setResultIconAndText(int drawable_id, int text_id) {
  430. ImageView iv = (ImageView) findViewById(R.id.action_indicator);
  431. TextView tv = (TextView) findViewById(R.id.status_text);
  432. if (drawable_id == 0 && text_id == 0) {
  433. iv.setVisibility(View.INVISIBLE);
  434. tv.setVisibility(View.INVISIBLE);
  435. } else {
  436. iv.setImageResource(drawable_id);
  437. tv.setText(text_id);
  438. iv.setVisibility(View.VISIBLE);
  439. tv.setVisibility(View.VISIBLE);
  440. }
  441. }
  442. @Override
  443. public void onClick(View v) {
  444. if (v.getId() == R.id.refreshButton) {
  445. onFocusChange(findViewById(R.id.host_URL), false);
  446. } else if (v.getId() == R.id.viewPassword) {
  447. TextView view = (TextView) findViewById(R.id.account_password);
  448. int input_type = view.getInputType();
  449. if ((input_type & InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
  450. input_type = InputType.TYPE_CLASS_TEXT
  451. | InputType.TYPE_TEXT_VARIATION_PASSWORD;
  452. } else {
  453. input_type = InputType.TYPE_CLASS_TEXT
  454. | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
  455. }
  456. view.setInputType(input_type);
  457. }
  458. }
  459. @Override
  460. public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
  461. if (operation.equals(mConnChkRunnable)) {
  462. mStatusText = mStatusIcon = 0;
  463. mStatusCorrect = false;
  464. String t_url = ((TextView) findViewById(R.id.host_URL)).getText()
  465. .toString().trim().toLowerCase();
  466. switch (result.getCode()) {
  467. case OK_SSL:
  468. mIsSslConn = true;
  469. mStatusIcon = android.R.drawable.ic_secure;
  470. mStatusText = R.string.auth_secure_connection;
  471. mStatusCorrect = true;
  472. break;
  473. case OK_NO_SSL:
  474. case OK:
  475. mIsSslConn = false;
  476. mStatusCorrect = true;
  477. if (t_url.startsWith("http://") ) {
  478. mStatusText = R.string.auth_connection_established;
  479. mStatusIcon = R.drawable.ic_ok;
  480. } else {
  481. mStatusText = R.string.auth_nossl_plain_ok_title;
  482. mStatusIcon = android.R.drawable.ic_partial_secure;
  483. }
  484. break;
  485. case BAD_OC_VERSION:
  486. mStatusIcon = R.drawable.common_error;
  487. mStatusText = R.string.auth_bad_oc_version_title;
  488. break;
  489. case WRONG_CONNECTION:
  490. mStatusIcon = R.drawable.common_error;
  491. mStatusText = R.string.auth_wrong_connection_title;
  492. break;
  493. case TIMEOUT:
  494. mStatusIcon = R.drawable.common_error;
  495. mStatusText = R.string.auth_timeout_title;
  496. break;
  497. case INCORRECT_ADDRESS:
  498. mStatusIcon = R.drawable.common_error;
  499. mStatusText = R.string.auth_incorrect_address_title;
  500. break;
  501. case SSL_RECOVERABLE_PEER_UNVERIFIED:
  502. mStatusIcon = R.drawable.common_error;
  503. mStatusText = R.string.auth_ssl_unverified_server_title;
  504. mLastSslUntrustedServerResult = result;
  505. showDialog(DIALOG_SSL_VALIDATOR);
  506. break;
  507. case SSL_ERROR:
  508. mStatusIcon = R.drawable.common_error;
  509. mStatusText = R.string.auth_ssl_general_error_title;
  510. break;
  511. case HOST_NOT_AVAILABLE:
  512. mStatusIcon = R.drawable.common_error;
  513. mStatusText = R.string.auth_unknown_host_title;
  514. break;
  515. case NO_NETWORK_CONNECTION:
  516. mStatusIcon = R.drawable.no_network;
  517. mStatusText = R.string.auth_no_net_conn_title;
  518. break;
  519. case INSTANCE_NOT_CONFIGURED:
  520. mStatusIcon = R.drawable.common_error;
  521. mStatusText = R.string.auth_not_configured_title;
  522. break;
  523. case FILE_NOT_FOUND:
  524. mStatusIcon = R.drawable.common_error;
  525. mStatusText = R.string.auth_incorrect_path_title;
  526. break;
  527. case UNHANDLED_HTTP_CODE:
  528. case UNKNOWN_ERROR:
  529. mStatusIcon = R.drawable.common_error;
  530. mStatusText = R.string.auth_unknown_error_title;
  531. break;
  532. default:
  533. Log.e(TAG, "Incorrect connection checker result type: " + result.getHttpCode());
  534. }
  535. setResultIconAndText(mStatusIcon, mStatusText);
  536. if (!mStatusCorrect)
  537. findViewById(R.id.refreshButton).setVisibility(View.VISIBLE);
  538. else
  539. findViewById(R.id.refreshButton).setVisibility(View.INVISIBLE);
  540. findViewById(R.id.buttonOK).setEnabled(mStatusCorrect);
  541. }
  542. }
  543. public void onSavedCertificate() {
  544. mAuthThread = mConnChkRunnable.retry(this, mHandler);
  545. }
  546. @Override
  547. public void onFailedSavingCertificate() {
  548. showDialog(DIALOG_CERT_NOT_SAVED);
  549. }
  550. }