1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 package com
.owncloud
.android
.ui
.activity
;
22 import com
.owncloud
.android
.AccountUtils
;
23 import com
.owncloud
.android
.authenticator
.AccountAuthenticator
;
24 import com
.owncloud
.android
.authenticator
.oauth2
.OAuth2Context
;
25 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
;
26 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
.OnSslValidatorListener
;
27 import com
.owncloud
.android
.utils
.OwnCloudVersion
;
28 import com
.owncloud
.android
.network
.OwnCloudClientUtils
;
29 import com
.owncloud
.android
.operations
.OwnCloudServerCheckOperation
;
30 import com
.owncloud
.android
.operations
.ExistenceCheckOperation
;
31 import com
.owncloud
.android
.operations
.OAuth2GetAccessToken
;
32 import com
.owncloud
.android
.operations
.OnRemoteOperationListener
;
33 import com
.owncloud
.android
.operations
.RemoteOperation
;
34 import com
.owncloud
.android
.operations
.RemoteOperationResult
;
35 import com
.owncloud
.android
.operations
.RemoteOperationResult
.ResultCode
;
37 import android
.accounts
.Account
;
38 import android
.accounts
.AccountAuthenticatorActivity
;
39 import android
.accounts
.AccountManager
;
40 import android
.app
.AlertDialog
;
41 import android
.app
.Dialog
;
42 import android
.app
.ProgressDialog
;
43 import android
.content
.ContentResolver
;
44 import android
.content
.DialogInterface
;
45 import android
.content
.Intent
;
46 import android
.content
.SharedPreferences
;
47 import android
.net
.Uri
;
48 import android
.os
.Bundle
;
49 import android
.os
.Handler
;
50 import android
.preference
.PreferenceManager
;
51 import android
.text
.InputType
;
52 import android
.util
.Log
;
53 import android
.view
.View
;
54 import android
.view
.View
.OnFocusChangeListener
;
55 import android
.view
.Window
;
56 import android
.widget
.CheckBox
;
57 import android
.widget
.EditText
;
58 import android
.widget
.Button
;
59 import android
.widget
.ImageView
;
60 import android
.widget
.TextView
;
61 import android
.widget
.Toast
;
63 import com
.owncloud
.android
.R
;
65 import eu
.alefzero
.webdav
.WebdavClient
;
68 * This Activity is used to add an ownCloud account to the App
70 * @author Bartek Przybylski
71 * @author David A. Velasco
73 public class AuthenticatorActivity
extends AccountAuthenticatorActivity
74 implements OnRemoteOperationListener
, OnSslValidatorListener
, OnFocusChangeListener
{
76 private static final String TAG
= AuthenticatorActivity
.class.getSimpleName();
78 public static final String EXTRA_ACCOUNT
= "ACCOUNT";
79 public static final String EXTRA_USER_NAME
= "USER_NAME";
80 public static final String EXTRA_HOST_NAME
= "HOST_NAME";
81 public static final String EXTRA_ACTION
= "ACTION";
83 private static final String KEY_HOST_URL_TEXT
= "HOST_URL_TEXT";
84 private static final String KEY_OC_VERSION
= "OC_VERSION";
85 private static final String KEY_ACCOUNT
= "ACCOUNT";
86 private static final String KEY_STATUS_TEXT
= "STATUS_TEXT";
87 private static final String KEY_STATUS_ICON
= "STATUS_ICON";
88 private static final String KEY_STATUS_CORRECT
= "STATUS_CORRECT";
89 private static final String KEY_IS_SSL_CONN
= "IS_SSL_CONN";
90 private static final String KEY_OAUTH2_STATUS_TEXT
= "OAUTH2_STATUS_TEXT";
91 private static final String KEY_OAUTH2_STATUS_ICON
= "OAUTH2_STATUS_ICON";
93 private static final int DIALOG_LOGIN_PROGRESS
= 0;
94 private static final int DIALOG_SSL_VALIDATOR
= 1;
95 private static final int DIALOG_CERT_NOT_SAVED
= 2;
96 private static final int DIALOG_OAUTH2_LOGIN_PROGRESS
= 3;
98 public static final byte ACTION_CREATE
= 0;
99 public static final byte ACTION_UPDATE_TOKEN
= 1;
102 private String mHostBaseUrl
;
103 private OwnCloudVersion mDiscoveredVersion
;
105 private int mStatusText
, mStatusIcon
;
106 private boolean mStatusCorrect
, mIsSslConn
;
107 private int mOAuth2StatusText
, mOAuth2StatusIcon
;
109 private final Handler mHandler
= new Handler();
110 private Thread mOperationThread
;
111 private OwnCloudServerCheckOperation mOcServerChkOperation
;
112 private ExistenceCheckOperation mAuthCheckOperation
;
113 private RemoteOperationResult mLastSslUntrustedServerResult
;
115 //private Thread mOAuth2GetCodeThread;
116 //private OAuth2GetAuthorizationToken mOAuth2GetCodeRunnable;
117 //private TokenReceiver tokenReceiver;
118 //private JSONObject mCodeResponseJson;
119 private Uri mNewCapturedUriFromOAuth2Redirection
;
121 private AccountManager mAccountMgr
;
122 private boolean mJustCreated
;
123 private byte mAction
;
124 private Account mAccount
;
126 private ImageView mRefreshButton
;
127 private ImageView mViewPasswordButton
;
128 private EditText mHostUrlInput
;
129 private EditText mUsernameInput
;
130 private EditText mPasswordInput
;
131 private CheckBox mOAuth2Check
;
132 private String mOAuthAccessToken
;
133 private View mOkButton
;
134 private TextView mAuthStatusLayout
;
136 private TextView mOAuthAuthEndpointText
;
137 private TextView mOAuthTokenEndpointText
;
143 * IMPORTANT ENTRY POINT 1: activity is shown to the user
146 protected void onCreate(Bundle savedInstanceState
) {
147 super.onCreate(savedInstanceState
);
148 getWindow().requestFeature(Window
.FEATURE_NO_TITLE
);
150 /// set view and get references to view elements
151 setContentView(R
.layout
.account_setup
);
152 mRefreshButton
= (ImageView
) findViewById(R
.id
.refreshButton
);
153 mViewPasswordButton
= (ImageView
) findViewById(R
.id
.viewPasswordButton
);
154 mHostUrlInput
= (EditText
) findViewById(R
.id
.hostUrlInput
);
155 mUsernameInput
= (EditText
) findViewById(R
.id
.account_username
);
156 mPasswordInput
= (EditText
) findViewById(R
.id
.account_password
);
157 mOAuthAuthEndpointText
= (TextView
)findViewById(R
.id
.oAuthEntryPoint_1
);
158 mOAuthTokenEndpointText
= (TextView
)findViewById(R
.id
.oAuthEntryPoint_2
);
159 mOAuth2Check
= (CheckBox
) findViewById(R
.id
.oauth_onOff_check
);
160 mOkButton
= findViewById(R
.id
.buttonOK
);
161 mAuthStatusLayout
= (TextView
) findViewById(R
.id
.auth_status_text
);
164 /// complete label for 'register account' button
165 Button b
= (Button
) findViewById(R
.id
.account_register
);
167 b
.setText(String
.format(getString(R
.string
.auth_register
), getString(R
.string
.app_name
)));
170 /// bind view elements to listeners
171 mHostUrlInput
.setOnFocusChangeListener(this);
172 mPasswordInput
.setOnFocusChangeListener(this);
175 mAccountMgr
= AccountManager
.get(this);
176 mNewCapturedUriFromOAuth2Redirection
= null
; // TODO save?
177 mAction
= getIntent().getByteExtra(EXTRA_ACTION
, ACTION_CREATE
);
180 if (savedInstanceState
== null
) {
181 /// connection state and info
182 mStatusText
= mStatusIcon
= 0;
183 mStatusCorrect
= false
;
186 /// retrieve extras from intent
187 String tokenType
= getIntent().getExtras().getString(AccountAuthenticator
.KEY_AUTH_TOKEN_TYPE
);
188 boolean oAuthRequired
= AccountAuthenticator
.AUTH_TOKEN_TYPE_ACCESS_TOKEN
.equals(tokenType
);
190 mAccount
= getIntent().getExtras().getParcelable(EXTRA_ACCOUNT
);
191 if (mAccount
!= null
) {
192 String ocVersion
= mAccountMgr
.getUserData(mAccount
, AccountAuthenticator
.KEY_OC_VERSION
);
193 if (ocVersion
!= null
) {
194 mDiscoveredVersion
= new OwnCloudVersion(ocVersion
);
196 mHostBaseUrl
= mAccountMgr
.getUserData(mAccount
, AccountAuthenticator
.KEY_OC_BASE_URL
);
197 mHostUrlInput
.setText(mHostBaseUrl
);
198 String userName
= mAccount
.name
.substring(0, mAccount
.name
.lastIndexOf('@'));
199 mUsernameInput
.setText(userName
);
200 oAuthRequired
= (mAccountMgr
.getUserData(mAccount
, AccountAuthenticator
.KEY_SUPPORTS_OAUTH2
) != null
);
202 mOAuth2Check
.setChecked(oAuthRequired
);
203 changeViewByOAuth2Check(oAuthRequired
);
207 loadSavedInstanceState(savedInstanceState
);
210 if (mAction
== ACTION_UPDATE_TOKEN
) {
211 /// lock things that should not change
212 mHostUrlInput
.setEnabled(false
);
213 mUsernameInput
.setEnabled(false
);
214 mOAuth2Check
.setVisibility(View
.GONE
);
218 mPasswordInput
.setText(""); // clean password to avoid social hacking (disadvantage: password in removed if the device is turned aside)
224 * Saves relevant state before {@link #onPause()}
226 * Do NOT save {@link #mNewCapturedUriFromOAuth2Redirection}; it keeps a temporal flag, intended to defer the
227 * processing of the redirection caught in {@link #onNewIntent(Intent)} until {@link #onResume()}
229 * See {@link #loadSavedInstanceState(Bundle)}
232 protected void onSaveInstanceState(Bundle outState
) {
233 super.onSaveInstanceState(outState
);
235 /// connection state and info
236 outState
.putInt(KEY_STATUS_TEXT
, mStatusText
);
237 outState
.putInt(KEY_STATUS_ICON
, mStatusIcon
);
238 outState
.putBoolean(KEY_STATUS_CORRECT
, mStatusCorrect
);
239 outState
.putBoolean(KEY_IS_SSL_CONN
, mIsSslConn
);
242 if (mDiscoveredVersion
!= null
)
243 outState
.putString(KEY_OC_VERSION
, mDiscoveredVersion
.toString());
244 outState
.putString(KEY_HOST_URL_TEXT
, mHostBaseUrl
);
246 /// account data, if updating
247 if (mAccount
!= null
)
248 outState
.putParcelable(KEY_ACCOUNT
, mAccount
);
250 // Saving the state of oAuth2 components.
251 outState
.putInt(KEY_OAUTH2_STATUS_ICON
, mOAuth2StatusIcon
);
252 outState
.putInt(KEY_OAUTH2_STATUS_TEXT
, mOAuth2StatusText
);
254 /* Leave old OAuth flow
255 if (codeResponseJson != null){
256 outState.putString(KEY_OAUTH2_CODE_RESULT, codeResponseJson.toString());
265 * See {@link #onSaveInstanceState(Bundle)}.
267 * @param savedInstanceState Saved state, as received in {@link #onCreate(Bundle)}.
269 private void loadSavedInstanceState(Bundle savedInstanceState
) {
270 /// connection state and info
271 mStatusCorrect
= savedInstanceState
.getBoolean(KEY_STATUS_CORRECT
);
272 mIsSslConn
= savedInstanceState
.getBoolean(KEY_IS_SSL_CONN
);
273 mStatusText
= savedInstanceState
.getInt(KEY_STATUS_TEXT
);
274 mStatusIcon
= savedInstanceState
.getInt(KEY_STATUS_ICON
);
277 /// UI settings depending upon connection
278 mOkButton
.setEnabled(mStatusCorrect
); // TODO really necessary?
280 mRefreshButton
.setVisibility(View
.VISIBLE
); // seems that setting visibility is necessary
282 mRefreshButton
.setVisibility(View
.INVISIBLE
);
285 String ocVersion
= savedInstanceState
.getString(KEY_OC_VERSION
);
286 if (ocVersion
!= null
)
287 mDiscoveredVersion
= new OwnCloudVersion(ocVersion
);
288 mHostBaseUrl
= savedInstanceState
.getString(KEY_HOST_URL_TEXT
);
290 // account data, if updating
291 mAccount
= savedInstanceState
.getParcelable(KEY_ACCOUNT
);
293 // state of oAuth2 components
294 mOAuth2StatusIcon
= savedInstanceState
.getInt(KEY_OAUTH2_STATUS_ICON
);
295 mOAuth2StatusText
= savedInstanceState
.getInt(KEY_OAUTH2_STATUS_TEXT
);
297 /* Leave old OAuth flow
298 // We store a JSon object with all the data returned from oAuth2 server when we get user_code.
299 // Is better than store variable by variable. We use String object to serialize from/to it.
301 if (savedInstanceState.containsKey(KEY_OAUTH2_CODE_RESULT)) {
302 codeResponseJson = new JSONObject(savedInstanceState.getString(KEY_OAUTH2_CODE_RESULT));
304 } catch (JSONException e) {
305 Log.e(TAG, "onCreate->JSONException: " + e.toString());
307 // END of getting the state of oAuth2 components.
313 * The redirection triggered by the OAuth authentication server as response to the GET AUTHORIZATION request
316 * To make this possible, this activity needs to be qualified with android:launchMode = "singleTask" in the
317 * AndroidManifest.xml file.
320 protected void onNewIntent (Intent intent
) {
321 Log
.d(TAG
, "onNewIntent()");
322 Uri data
= intent
.getData();
323 if (data
!= null
&& data
.toString().startsWith(OAuth2Context
.MY_REDIRECT_URI
)) {
324 mNewCapturedUriFromOAuth2Redirection
= data
;
330 * The redirection triggered by the OAuth authentication server as response to the GET AUTHORIZATION, and
331 * deferred in {@link #onNewIntent(Intent)}, is processed here.
334 protected void onResume() {
336 // the state of mOAuth2Check is automatically recovered between configuration changes, but not before onCreate() finishes; so keep the next lines here
337 changeViewByOAuth2Check(mOAuth2Check
.isChecked());
338 if (mAction
== ACTION_UPDATE_TOKEN
&& mJustCreated
) {
339 if (mOAuth2Check
.isChecked())
340 Toast
.makeText(this, R
.string
.auth_expired_oauth_token_toast
, Toast
.LENGTH_LONG
).show();
342 Toast
.makeText(this, R
.string
.auth_expired_basic_auth_toast
, Toast
.LENGTH_LONG
).show();
346 /* LEAVE OLD OAUTH FLOW ;
347 // (old oauth code) Registering token receiver. We must listening to the service that is pooling to the oAuth server for a token.
348 if (tokenReceiver == null) {
349 IntentFilter tokenFilter = new IntentFilter(OAuth2GetTokenService.TOKEN_RECEIVED_MESSAGE);
350 tokenReceiver = new TokenReceiver();
351 this.registerReceiver(tokenReceiver,tokenFilter);
354 if (mNewCapturedUriFromOAuth2Redirection
!= null
) {
355 getOAuth2AccessTokenFromCapturedRedirection();
358 mJustCreated
= false
;
362 @Override protected void onDestroy() {
365 /* LEAVE OLD OAUTH FLOW
366 // We must stop the service thats it's pooling to oAuth2 server for a token.
367 Intent tokenService = new Intent(this, OAuth2GetTokenService.class);
368 stopService(tokenService);
370 // We stop listening the result of the pooling service.
371 if (tokenReceiver != null) {
372 unregisterReceiver(tokenReceiver);
373 tokenReceiver = null;
380 * Parses the redirection with the response to the GET AUTHORIZATION request to the
381 * oAuth server and requests for the access token (GET ACCESS TOKEN)
383 private void getOAuth2AccessTokenFromCapturedRedirection() {
384 /// Parse data from OAuth redirection
385 String queryParameters
= mNewCapturedUriFromOAuth2Redirection
.getQuery();
386 mNewCapturedUriFromOAuth2Redirection
= null
;
388 /// Showing the dialog with instructions for the user.
389 showDialog(DIALOG_OAUTH2_LOGIN_PROGRESS
);
391 /// GET ACCESS TOKEN to the oAuth server
392 RemoteOperation operation
= new OAuth2GetAccessToken(queryParameters
);
393 WebdavClient client
= OwnCloudClientUtils
.createOwnCloudClient(Uri
.parse(getString(R
.string
.oauth_url_endpoint_access
)), getApplicationContext());
394 operation
.execute(client
, this, mHandler
);
400 * Handles the change of focus on the text inputs for the server URL and the password
402 public void onFocusChange(View view
, boolean hasFocus
) {
403 if (view
.getId() == R
.id
.hostUrlInput
) {
404 onUrlInputFocusChanged((TextView
) view
, hasFocus
);
406 } else if (view
.getId() == R
.id
.account_password
) {
407 onPasswordFocusChanged((TextView
) view
, hasFocus
);
413 * Handles changes in focus on the text input for the server URL.
415 * IMPORTANT ENTRY POINT 2: When (!hasFocus), user wrote the server URL and changed to
416 * other field. The operation to check the existence of the server in the entered URL is
419 * When hasFocus: user 'comes back' to write again the server URL.
421 * @param hostInput TextView with the URL input field receiving the change of focus.
422 * @param hasFocus 'True' if focus is received, 'false' if is lost
424 private void onUrlInputFocusChanged(TextView hostInput
, boolean hasFocus
) {
429 // avoids that the 'connect' button can be clicked if the test was previously passed
430 mOkButton
.setEnabled(false
);
435 private void checkOcServer() {
436 String uri
= mHostUrlInput
.getText().toString().trim();
437 if (uri
.length() != 0) {
438 mStatusText
= R
.string
.auth_testing_connection
;
439 mStatusIcon
= R
.drawable
.progress_small
;
441 /** TODO cancel previous connection check if the user tries to ammend a wrong URL
442 if(mConnChkOperation != null) {
443 mConnChkOperation.cancel();
445 mOcServerChkOperation
= new OwnCloudServerCheckOperation(uri
, this);
446 WebdavClient client
= OwnCloudClientUtils
.createOwnCloudClient(Uri
.parse(uri
), this);
448 mDiscoveredVersion
= null
;
449 mOperationThread
= mOcServerChkOperation
.execute(client
, this, mHandler
);
451 mRefreshButton
.setVisibility(View
.INVISIBLE
);
460 * Handles changes in focus on the text input for the password (basic authorization).
462 * When (hasFocus), the button to toggle password visibility is shown.
464 * When (!hasFocus), the button is made invisible and the password is hidden.
466 * @param passwordInput TextView with the password input field receiving the change of focus.
467 * @param hasFocus 'True' if focus is received, 'false' if is lost
469 private void onPasswordFocusChanged(TextView passwordInput
, boolean hasFocus
) {
471 mViewPasswordButton
.setVisibility(View
.VISIBLE
);
473 int input_type
= InputType
.TYPE_CLASS_TEXT
| InputType
.TYPE_TEXT_VARIATION_PASSWORD
;
474 passwordInput
.setInputType(input_type
);
475 mViewPasswordButton
.setVisibility(View
.INVISIBLE
);
482 * Cancels the authenticator activity
484 * IMPORTANT ENTRY POINT 3: Never underestimate the importance of cancellation
486 * This method is bound in the layout/acceoun_setup.xml resource file.
488 * @param view Cancel button
490 public void onCancelClick(View view
) {
491 setResult(RESULT_CANCELED
); // TODO review how is this related to AccountAuthenticator
498 * Checks the credentials of the user in the root of the ownCloud server
499 * before creating a new local account.
501 * For basic authorization, a check of existence of the root folder is
504 * For OAuth, starts the flow to get an access token; the credentials test
505 * is postponed until it is available.
507 * IMPORTANT ENTRY POINT 4
509 * @param view OK button
511 public void onOkClick(View view
) {
512 // this check should be unnecessary
513 if (mDiscoveredVersion
== null
|| !mDiscoveredVersion
.isVersionValid() || mHostBaseUrl
== null
|| mHostBaseUrl
.length() == 0) {
514 mStatusIcon
= R
.drawable
.common_error
;
515 mStatusText
= R
.string
.auth_wtf_reenter_URL
;
517 mOkButton
.setEnabled(false
);
518 Log
.wtf(TAG
, "The user was allowed to click 'connect' to an unchecked server!!");
522 if (mOAuth2Check
.isChecked()) {
523 startOauthorization();
526 checkBasicAuthorization();
532 * Tests the credentials entered by the user performing a check of existence on
533 * the root folder of the ownCloud server.
535 private void checkBasicAuthorization() {
536 /// get the path to the root folder through WebDAV from the version server
537 String webdav_path
= AccountUtils
.getWebdavPath(mDiscoveredVersion
, false
);
539 /// get basic credentials entered by user
540 String username
= mUsernameInput
.getText().toString();
541 String password
= mPasswordInput
.getText().toString();
543 /// be gentle with the user
544 showDialog(DIALOG_LOGIN_PROGRESS
);
546 /// test credentials accessing the root folder
547 mAuthCheckOperation
= new ExistenceCheckOperation("", this, false
);
548 WebdavClient client
= OwnCloudClientUtils
.createOwnCloudClient(Uri
.parse(mHostBaseUrl
+ webdav_path
), this);
549 client
.setBasicCredentials(username
, password
);
550 mOperationThread
= mAuthCheckOperation
.execute(client
, this, mHandler
);
555 * Starts the OAuth 'grant type' flow to get an access token, with
556 * a GET AUTHORIZATION request to the BUILT-IN authorization server.
558 private void startOauthorization() {
559 // be gentle with the user
560 mStatusIcon
= R
.drawable
.progress_small
;
561 mStatusText
= R
.string
.oauth_login_connection
;
564 // GET AUTHORIZATION request
566 mOAuth2GetCodeRunnable = new OAuth2GetAuthorizationToken(, this);
567 mOAuth2GetCodeRunnable.setListener(this, mHandler);
568 mOAuth2GetCodeThread = new Thread(mOAuth2GetCodeRunnable);
569 mOAuth2GetCodeThread.start();
572 //if (mGrantType.equals(OAuth2Context.OAUTH2_AUTH_CODE_GRANT_TYPE)) {
573 Uri uri
= Uri
.parse(getString(R
.string
.oauth_url_endpoint_auth
));
574 Uri
.Builder uriBuilder
= uri
.buildUpon();
575 uriBuilder
.appendQueryParameter(OAuth2Context
.CODE_RESPONSE_TYPE
, OAuth2Context
.OAUTH2_CODE_RESPONSE_TYPE
);
576 uriBuilder
.appendQueryParameter(OAuth2Context
.CODE_REDIRECT_URI
, OAuth2Context
.MY_REDIRECT_URI
);
577 uriBuilder
.appendQueryParameter(OAuth2Context
.CODE_CLIENT_ID
, OAuth2Context
.OAUTH2_F_CLIENT_ID
);
578 uriBuilder
.appendQueryParameter(OAuth2Context
.CODE_SCOPE
, OAuth2Context
.OAUTH2_F_SCOPE
);
579 //uriBuilder.appendQueryParameter(OAuth2Context.CODE_STATE, whateverwewant);
580 uri
= uriBuilder
.build();
581 Log
.d(TAG
, "Starting browser to view " + uri
.toString());
582 Intent i
= new Intent(Intent
.ACTION_VIEW
, uri
);
589 * Callback method invoked when a RemoteOperation executed by this Activity finishes.
591 * Dispatches the operation flow to the right method.
594 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
596 if (operation
instanceof OwnCloudServerCheckOperation
) {
597 onOcServerCheckFinish((OwnCloudServerCheckOperation
) operation
, result
);
599 } else if (operation
instanceof OAuth2GetAccessToken
) {
600 onGetOAuthAccessTokenFinish((OAuth2GetAccessToken
)operation
, result
);
602 } else if (operation
instanceof ExistenceCheckOperation
) {
603 onAuthorizationCheckFinish((ExistenceCheckOperation
)operation
, result
);
610 * Processes the result of the server check performed when the user finishes the enter of the
613 * @param operation Server check performed.
614 * @param result Result of the check.
616 private void onOcServerCheckFinish(OwnCloudServerCheckOperation operation
, RemoteOperationResult result
) {
617 /// update status icon and text
618 updateStatusIconAndText(result
);
621 /// save result state
622 mStatusCorrect
= result
.isSuccess();
623 mIsSslConn
= (result
.getCode() == ResultCode
.OK_SSL
);
625 /// very special case (TODO: move to a common place for all the remote operations)
626 if (result
.getCode() == ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
) {
627 mLastSslUntrustedServerResult
= result
;
628 showDialog(DIALOG_SSL_VALIDATOR
);
631 /// update the visibility of the 'retry connection' button
633 mRefreshButton
.setVisibility(View
.VISIBLE
);
635 mRefreshButton
.setVisibility(View
.INVISIBLE
);
637 /// retrieve discovered version and normalize server URL
638 mDiscoveredVersion
= operation
.getDiscoveredVersion();
639 mHostBaseUrl
= mHostUrlInput
.getText().toString().trim();
640 if (!mHostBaseUrl
.toLowerCase().startsWith("http://") &&
641 !mHostBaseUrl
.toLowerCase().startsWith("https://")) {
644 mHostBaseUrl
= "https://" + mHostBaseUrl
;
646 mHostBaseUrl
= "http://" + mHostBaseUrl
;
650 if (mHostBaseUrl
.endsWith("/"))
651 mHostBaseUrl
= mHostBaseUrl
.substring(0, mHostBaseUrl
.length() - 1);
653 /// allow or not the user try to access the server
654 mOkButton
.setEnabled(mStatusCorrect
);
659 * Chooses the right icon and text to show to the user for the received operation result.
661 * @param result Result of a remote operation performed in this activity
663 private void updateStatusIconAndText(RemoteOperationResult result
) {
664 mStatusText
= mStatusIcon
= 0;
666 switch (result
.getCode()) {
668 mStatusIcon
= android
.R
.drawable
.ic_secure
;
669 mStatusText
= R
.string
.auth_secure_connection
;
674 if (mHostUrlInput
.getText().toString().trim().toLowerCase().startsWith("http://") ) {
675 mStatusText
= R
.string
.auth_connection_established
;
676 mStatusIcon
= R
.drawable
.ic_ok
;
678 mStatusText
= R
.string
.auth_nossl_plain_ok_title
;
679 mStatusIcon
= android
.R
.drawable
.ic_partial_secure
;
683 case SSL_RECOVERABLE_PEER_UNVERIFIED
:
684 mStatusIcon
= R
.drawable
.common_error
;
685 mStatusText
= R
.string
.auth_ssl_unverified_server_title
;
689 mStatusIcon
= R
.drawable
.common_error
;
690 mStatusText
= R
.string
.auth_bad_oc_version_title
;
692 case WRONG_CONNECTION
:
693 mStatusIcon
= R
.drawable
.common_error
;
694 mStatusText
= R
.string
.auth_wrong_connection_title
;
697 mStatusIcon
= R
.drawable
.common_error
;
698 mStatusText
= R
.string
.auth_timeout_title
;
700 case INCORRECT_ADDRESS
:
701 mStatusIcon
= R
.drawable
.common_error
;
702 mStatusText
= R
.string
.auth_incorrect_address_title
;
706 mStatusIcon
= R
.drawable
.common_error
;
707 mStatusText
= R
.string
.auth_ssl_general_error_title
;
711 mStatusIcon
= R
.drawable
.common_error
;
712 mStatusText
= R
.string
.auth_unauthorized
;
714 case HOST_NOT_AVAILABLE
:
715 mStatusIcon
= R
.drawable
.common_error
;
716 mStatusText
= R
.string
.auth_unknown_host_title
;
718 case NO_NETWORK_CONNECTION
:
719 mStatusIcon
= R
.drawable
.no_network
;
720 mStatusText
= R
.string
.auth_no_net_conn_title
;
722 case INSTANCE_NOT_CONFIGURED
:
723 mStatusIcon
= R
.drawable
.common_error
;
724 mStatusText
= R
.string
.auth_not_configured_title
;
727 mStatusIcon
= R
.drawable
.common_error
;
728 mStatusText
= R
.string
.auth_incorrect_path_title
;
731 mStatusIcon
= R
.drawable
.common_error
;
732 mStatusText
= R
.string
.auth_oauth_error
;
734 case OAUTH2_ERROR_ACCESS_DENIED
:
735 mStatusIcon
= R
.drawable
.common_error
;
736 mStatusText
= R
.string
.auth_oauth_error_access_denied
;
738 case UNHANDLED_HTTP_CODE
:
740 mStatusIcon
= R
.drawable
.common_error
;
741 mStatusText
= R
.string
.auth_unknown_error_title
;
751 * Processes the result of the request for and access token send
752 * to an OAuth authorization server.
754 * @param operation Operation performed requesting the access token.
755 * @param result Result of the operation.
757 private void onGetOAuthAccessTokenFinish(OAuth2GetAccessToken operation
, RemoteOperationResult result
) {
759 dismissDialog(DIALOG_OAUTH2_LOGIN_PROGRESS
);
760 } catch (IllegalArgumentException e
) {
761 // NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens
764 String webdav_path
= AccountUtils
.getWebdavPath(mDiscoveredVersion
, true
);
765 if (result
.isSuccess() && webdav_path
!= null
) {
766 /// be gentle with the user
767 showDialog(DIALOG_LOGIN_PROGRESS
);
769 /// time to test the retrieved access token on the ownCloud server
770 mOAuthAccessToken
= ((OAuth2GetAccessToken
)operation
).getResultTokenMap().get(OAuth2Context
.KEY_ACCESS_TOKEN
);
771 Log
.d(TAG
, "Got ACCESS TOKEN: " + mOAuthAccessToken
);
772 mAuthCheckOperation
= new ExistenceCheckOperation("", this, false
);
773 WebdavClient client
= OwnCloudClientUtils
.createOwnCloudClient(Uri
.parse(mHostBaseUrl
+ webdav_path
), this);
774 client
.setBearerCredentials(mOAuthAccessToken
);
775 mAuthCheckOperation
.execute(client
, this, mHandler
);
778 updateStatusIconAndText(result
);
780 Log
.d(TAG
, "Access failed: " + result
.getLogMessage());
786 * Processes the result of the access check performed to try the user credentials.
788 * Creates a new account through the AccountManager.
790 * @param operation Access check performed.
791 * @param result Result of the operation.
793 private void onAuthorizationCheckFinish(ExistenceCheckOperation operation
, RemoteOperationResult result
) {
795 dismissDialog(DIALOG_LOGIN_PROGRESS
);
796 } catch (IllegalArgumentException e
) {
797 // NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens
800 if (result
.isSuccess()) {
801 Log
.d(TAG
, "Successful access - time to save the account");
803 if (mAction
== ACTION_CREATE
) {
813 updateStatusIconAndText(result
);
815 Log
.d(TAG
, "Access failed: " + result
.getLogMessage());
821 * Sets the proper response to get that the Account Authenticator that started this activity saves
822 * a new authorization token for mAccount.
824 private void updateToken() {
825 Bundle response
= new Bundle();
826 response
.putString(AccountManager
.KEY_ACCOUNT_NAME
, mAccount
.name
);
827 response
.putString(AccountManager
.KEY_ACCOUNT_TYPE
, mAccount
.type
);
828 boolean isOAuth
= mOAuth2Check
.isChecked();
830 response
.putString(AccountManager
.KEY_AUTHTOKEN
, mOAuthAccessToken
);
831 // the next line is necessary; by now, notifications are calling directly to the AuthenticatorActivity to update, without AccountManager intervention
832 mAccountMgr
.setAuthToken(mAccount
, AccountAuthenticator
.AUTH_TOKEN_TYPE_ACCESS_TOKEN
, mOAuthAccessToken
);
834 response
.putString(AccountManager
.KEY_AUTHTOKEN
, mPasswordInput
.getText().toString());
835 mAccountMgr
.setPassword(mAccount
, mPasswordInput
.getText().toString());
837 setAccountAuthenticatorResult(response
);
842 * Creates a new account through the Account Authenticator that started this activity.
844 * This makes the account permanent.
846 * TODO Decide how to name the OAuth accounts
847 * TODO Minimize the direct interactions with the account manager; seems that not all the operations
848 * in the current code are really necessary, provided that right extras are returned to the Account
849 * Authenticator through setAccountAuthenticatorResult
851 private void createAccount() {
852 /// create and save new ownCloud account
853 boolean isOAuth
= mOAuth2Check
.isChecked();
855 Uri uri
= Uri
.parse(mHostBaseUrl
);
856 String username
= mUsernameInput
.getText().toString().trim();
858 username
= "OAuth_user" + (new java
.util
.Random(System
.currentTimeMillis())).nextLong(); // TODO change this to something readable
860 String accountName
= username
+ "@" + uri
.getHost();
861 if (uri
.getPort() >= 0) {
862 accountName
+= ":" + uri
.getPort();
864 mAccount
= new Account(accountName
, AccountAuthenticator
.ACCOUNT_TYPE
);
866 mAccountMgr
.addAccountExplicitly(mAccount
, "", null
); // with our implementation, the password is never input in the app
868 mAccountMgr
.addAccountExplicitly(mAccount
, mPasswordInput
.getText().toString(), null
);
871 /// add the new account as default in preferences, if there is none already
872 Account defaultAccount
= AccountUtils
.getCurrentOwnCloudAccount(this);
873 if (defaultAccount
== null
) {
874 SharedPreferences
.Editor editor
= PreferenceManager
875 .getDefaultSharedPreferences(this).edit();
876 editor
.putString("select_oc_account", accountName
);
880 /// prepare result to return to the Authenticator
881 // TODO check again what the Authenticator makes with it; probably has the same effect as addAccountExplicitly, but it's not well done
882 final Intent intent
= new Intent();
883 intent
.putExtra(AccountManager
.KEY_ACCOUNT_TYPE
, AccountAuthenticator
.ACCOUNT_TYPE
);
884 intent
.putExtra(AccountManager
.KEY_ACCOUNT_NAME
, mAccount
.name
);
886 intent
.putExtra(AccountManager
.KEY_AUTHTOKEN
, AccountAuthenticator
.ACCOUNT_TYPE
); // TODO check this; not sure it's right; maybe
887 intent
.putExtra(AccountManager
.KEY_USERDATA
, username
);
889 mAccountMgr
.setAuthToken(mAccount
, AccountAuthenticator
.AUTH_TOKEN_TYPE_ACCESS_TOKEN
, mOAuthAccessToken
);
891 /// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA
892 mAccountMgr
.setUserData(mAccount
, AccountAuthenticator
.KEY_OC_VERSION
, mDiscoveredVersion
.toString());
893 mAccountMgr
.setUserData(mAccount
, AccountAuthenticator
.KEY_OC_BASE_URL
, mHostBaseUrl
);
895 mAccountMgr
.setUserData(mAccount
, AccountAuthenticator
.KEY_SUPPORTS_OAUTH2
, "TRUE"); // TODO this flag should be unnecessary
897 setAccountAuthenticatorResult(intent
.getExtras());
898 setResult(RESULT_OK
, intent
);
900 /// immediately request for the synchronization of the new account
901 Bundle bundle
= new Bundle();
902 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
903 ContentResolver
.requestSync(mAccount
, AccountAuthenticator
.AUTHORITY
, bundle
);
910 * Necessary to update the contents of the SSL Dialog
912 * TODO move to some common place for all possible untrusted SSL failures
915 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
917 case DIALOG_LOGIN_PROGRESS
:
918 case DIALOG_CERT_NOT_SAVED
:
919 case DIALOG_OAUTH2_LOGIN_PROGRESS
:
921 case DIALOG_SSL_VALIDATOR
: {
922 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
926 Log
.e(TAG
, "Incorrect dialog called with id = " + id
);
935 protected Dialog
onCreateDialog(int id
) {
936 Dialog dialog
= null
;
938 case DIALOG_LOGIN_PROGRESS
: {
939 /// simple progress dialog
940 ProgressDialog working_dialog
= new ProgressDialog(this);
941 working_dialog
.setMessage(getResources().getString(R
.string
.auth_trying_to_login
));
942 working_dialog
.setIndeterminate(true
);
943 working_dialog
.setCancelable(true
);
945 .setOnCancelListener(new DialogInterface
.OnCancelListener() {
947 public void onCancel(DialogInterface dialog
) {
948 /// TODO study if this is enough
949 Log
.i(TAG
, "Login canceled");
950 if (mOperationThread
!= null
) {
951 mOperationThread
.interrupt();
956 dialog
= working_dialog
;
959 case DIALOG_OAUTH2_LOGIN_PROGRESS
: {
960 /// oAuth2 dialog. We show here to the user the URL and user_code that the user must validate in a web browser. - OLD!
961 // TODO optimize this dialog
962 ProgressDialog working_dialog
= new ProgressDialog(this);
963 /* Leave the old OAuth flow
965 if (mCodeResponseJson != null && mCodeResponseJson.has(OAuth2GetCodeRunnable.CODE_VERIFICATION_URL)) {
966 working_dialog.setMessage(String.format(getString(R.string.oauth_code_validation_message),
967 mCodeResponseJson.getString(OAuth2GetCodeRunnable.CODE_VERIFICATION_URL),
968 mCodeResponseJson.getString(OAuth2GetCodeRunnable.CODE_USER_CODE)));
970 working_dialog
.setMessage(String
.format("Getting authorization"));
972 } catch (JSONException e) {
973 Log.e(TAG, "onCreateDialog->JSONException: " + e.toString());
975 working_dialog
.setIndeterminate(true
);
976 working_dialog
.setCancelable(true
);
978 .setOnCancelListener(new DialogInterface
.OnCancelListener() {
980 public void onCancel(DialogInterface dialog
) {
981 Log
.i(TAG
, "Login canceled");
982 /*if (mOAuth2GetCodeThread != null) {
983 mOAuth2GetCodeThread.interrupt();
986 /*if (tokenReceiver != null) {
987 unregisterReceiver(tokenReceiver);
988 tokenReceiver = null;
994 dialog
= working_dialog
;
997 case DIALOG_SSL_VALIDATOR
: {
998 /// TODO start to use new dialog interface, at least for this (it is a FragmentDialog already)
999 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
1002 case DIALOG_CERT_NOT_SAVED
: {
1003 AlertDialog
.Builder builder
= new AlertDialog
.Builder(this);
1004 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
1005 builder
.setCancelable(false
);
1006 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
1008 public void onClick(DialogInterface dialog
, int which
) {
1012 dialog
= builder
.create();
1016 Log
.e(TAG
, "Incorrect dialog called with id = " + id
);
1023 * Starts and activity to open the 'new account' page in the ownCloud web site
1025 * @param view 'Account register' button
1027 public void onRegisterClick(View view
) {
1028 Intent register
= new Intent(Intent
.ACTION_VIEW
, Uri
.parse(getString(R
.string
.url_account_register
)));
1029 setResult(RESULT_CANCELED
);
1030 startActivity(register
);
1035 * Updates the content and visibility state of the icon and text associated
1036 * to the last check on the ownCloud server.
1038 private void updateConnStatus() {
1039 ImageView iv
= (ImageView
) findViewById(R
.id
.action_indicator
);
1040 TextView tv
= (TextView
) findViewById(R
.id
.status_text
);
1042 if (mStatusIcon
== 0 && mStatusText
== 0) {
1043 iv
.setVisibility(View
.INVISIBLE
);
1044 tv
.setVisibility(View
.INVISIBLE
);
1046 iv
.setImageResource(mStatusIcon
);
1047 tv
.setText(mStatusText
);
1048 iv
.setVisibility(View
.VISIBLE
);
1049 tv
.setVisibility(View
.VISIBLE
);
1055 * Updates the content and visibility state of the icon and text associated
1056 * to the interactions with the OAuth authorization server.
1058 private void updateAuthStatus() {
1059 /*ImageView iv = (ImageView) findViewById(R.id.auth_status_icon);
1060 TextView tv = (TextView) findViewById(R.id.auth_status_text);*/
1062 if (mStatusIcon
== 0 && mStatusText
== 0) {
1063 mAuthStatusLayout
.setVisibility(View
.INVISIBLE
);
1064 /*iv.setVisibility(View.INVISIBLE);
1065 tv.setVisibility(View.INVISIBLE);*/
1067 mAuthStatusLayout
.setText(mStatusText
);
1068 mAuthStatusLayout
.setCompoundDrawablesWithIntrinsicBounds(mStatusIcon
, 0, 0, 0);
1069 /*iv.setImageResource(mStatusIcon);
1070 tv.setText(mStatusText);
1071 /*iv.setVisibility(View.VISIBLE);
1072 tv.setVisibility(View.VISIBLE);^*/
1073 mAuthStatusLayout
.setVisibility(View
.VISIBLE
);
1079 * Called when the refresh button in the input field for ownCloud host is clicked.
1081 * Performs a new check on the URL in the input field.
1083 * @param view Refresh 'button'
1085 public void onRefreshClick(View view
) {
1086 onFocusChange(mRefreshButton
, false
);
1091 * Called when the eye icon in the password field is clicked.
1093 * Toggles the visibility of the password in the field.
1095 * @param view 'View password' 'button'
1097 public void onViewPasswordClick(View view
) {
1098 int selectionStart
= mPasswordInput
.getSelectionStart();
1099 int selectionEnd
= mPasswordInput
.getSelectionEnd();
1100 int input_type
= mPasswordInput
.getInputType();
1101 if ((input_type
& InputType
.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
) == InputType
.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
) {
1102 input_type
= InputType
.TYPE_CLASS_TEXT
1103 | InputType
.TYPE_TEXT_VARIATION_PASSWORD
;
1105 input_type
= InputType
.TYPE_CLASS_TEXT
1106 | InputType
.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
;
1108 mPasswordInput
.setInputType(input_type
);
1109 mPasswordInput
.setSelection(selectionStart
, selectionEnd
);
1114 * Called when the checkbox for OAuth authorization is clicked.
1116 * Hides or shows the input fields for user & password.
1118 * @param view 'View password' 'button'
1120 public void onCheckClick(View view
) {
1121 CheckBox oAuth2Check
= (CheckBox
)view
;
1122 changeViewByOAuth2Check(oAuth2Check
.isChecked());
1127 * Changes the visibility of input elements depending upon the kind of authorization
1128 * chosen by the user: basic or OAuth
1130 * @param checked 'True' when OAuth is selected.
1132 public void changeViewByOAuth2Check(Boolean checked
) {
1135 mOAuthAuthEndpointText
.setVisibility(View
.VISIBLE
);
1136 mOAuthTokenEndpointText
.setVisibility(View
.VISIBLE
);
1137 mUsernameInput
.setVisibility(View
.GONE
);
1138 mPasswordInput
.setVisibility(View
.GONE
);
1139 mViewPasswordButton
.setVisibility(View
.GONE
);
1141 mOAuthAuthEndpointText
.setVisibility(View
.GONE
);
1142 mOAuthTokenEndpointText
.setVisibility(View
.GONE
);
1143 mUsernameInput
.setVisibility(View
.VISIBLE
);
1144 mPasswordInput
.setVisibility(View
.VISIBLE
);
1145 mViewPasswordButton
.setVisibility(View
.INVISIBLE
);
1150 /* Leave the old OAuth flow
1151 // Results from the first call to oAuth2 server : getting the user_code and verification_url.
1153 public void onOAuth2GetCodeResult(ResultOAuthType type, JSONObject responseJson) {
1154 if ((type == ResultOAuthType.OK_SSL)||(type == ResultOAuthType.OK_NO_SSL)) {
1155 mCodeResponseJson = responseJson;
1156 if (mCodeResponseJson != null) {
1157 getOAuth2AccessTokenFromJsonResponse();
1158 } // else - nothing to do here - wait for callback !!!
1160 } else if (type == ResultOAuthType.HOST_NOT_AVAILABLE) {
1161 updateOAuth2IconAndText(R.drawable.common_error, R.string.oauth_connection_url_unavailable);
1165 // If the results of getting the user_code and verification_url are OK, we get the received data and we start
1166 // the polling service to oAuth2 server to get a valid token.
1167 private void getOAuth2AccessTokenFromJsonResponse() {
1168 String deviceCode = null;
1169 String verificationUrl = null;
1170 String userCode = null;
1174 Log.d(TAG, "ResponseOAuth2->" + mCodeResponseJson.toString());
1177 // We get data that we must show to the user or we will use internally.
1178 verificationUrl = mCodeResponseJson.getString(OAuth2GetAuthorizationToken.CODE_VERIFICATION_URL);
1179 userCode = mCodeResponseJson.getString(OAuth2GetAuthorizationToken.CODE_USER_CODE);
1180 expiresIn = mCodeResponseJson.getInt(OAuth2GetAuthorizationToken.CODE_EXPIRES_IN);
1182 // And we get data that we must use to get a token.
1183 deviceCode = mCodeResponseJson.getString(OAuth2GetAuthorizationToken.CODE_DEVICE_CODE);
1184 interval = mCodeResponseJson.getInt(OAuth2GetAuthorizationToken.CODE_INTERVAL);
1186 } catch (JSONException e) {
1187 Log.e(TAG, "Exception accesing data in Json object" + e.toString());
1190 // Updating status widget to OK.
1191 updateOAuth2IconAndText(R.drawable.ic_ok, R.string.auth_connection_established);
1193 // Showing the dialog with instructions for the user.
1194 showDialog(DIALOG_OAUTH2_LOGIN_PROGRESS);
1196 // Loggin all the data.
1197 Log.d(TAG, "verificationUrl->" + verificationUrl);
1198 Log.d(TAG, "userCode->" + userCode);
1199 Log.d(TAG, "deviceCode->" + deviceCode);
1200 Log.d(TAG, "expiresIn->" + expiresIn);
1201 Log.d(TAG, "interval->" + interval);
1203 // Starting the pooling service.
1205 Intent tokenService = new Intent(this, OAuth2GetTokenService.class);
1206 tokenService.putExtra(OAuth2GetTokenService.TOKEN_URI, OAuth2Context.OAUTH2_G_DEVICE_GETTOKEN_URL);
1207 tokenService.putExtra(OAuth2GetTokenService.TOKEN_DEVICE_CODE, deviceCode);
1208 tokenService.putExtra(OAuth2GetTokenService.TOKEN_INTERVAL, interval);
1210 startService(tokenService);
1212 catch (Exception e) {
1213 Log.e(TAG, "tokenService creation problem :", e);
1219 /* Leave the old OAuth flow
1220 // We get data from the oAuth2 token service with this broadcast receiver.
1221 private class TokenReceiver extends BroadcastReceiver {
1223 * The token is received.
1225 * {@link BroadcastReceiver} to enable oAuth2 token receiving.
1228 public void onReceive(Context context, Intent intent) {
1229 @SuppressWarnings("unchecked")
1230 HashMap<String, String> tokenResponse = (HashMap<String, String>)intent.getExtras().get(OAuth2GetTokenService.TOKEN_RECEIVED_DATA);
1231 Log.d(TAG, "TokenReceiver->" + tokenResponse.get(OAuth2GetTokenService.TOKEN_ACCESS_TOKEN));
1232 dismissDialog(DIALOG_OAUTH2_LOGIN_PROGRESS);
1240 * Called from SslValidatorDialog when a new server certificate was correctly saved.
1242 public void onSavedCertificate() {
1243 mOperationThread
= mOcServerChkOperation
.retry(this, mHandler
);
1247 * Called from SslValidatorDialog when a new server certificate could not be saved
1248 * when the user requested it.
1251 public void onFailedSavingCertificate() {
1252 showDialog(DIALOG_CERT_NOT_SAVED
);