X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/9ed8579df25d60461e8c5dc56f6d0178232114c1..1eed6a6812f41d17c44a3c0d8d87a265165fb2cb:/src/com/owncloud/android/authentication/AuthenticatorActivity.java diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index 919a40ad..05789059 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -18,7 +18,6 @@ package com.owncloud.android.authentication; -import com.owncloud.android.AccountUtils; import com.owncloud.android.Log_OC; import com.owncloud.android.ui.dialog.SslValidatorDialog; import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener; @@ -84,6 +83,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList public static final String EXTRA_USER_NAME = "USER_NAME"; public static final String EXTRA_HOST_NAME = "HOST_NAME"; public static final String EXTRA_ACTION = "ACTION"; + public static final String EXTRA_ENFORCED_UPDATE = "ENFORCE_UPDATE"; private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT"; private static final String KEY_OC_VERSION = "OC_VERSION"; @@ -97,6 +97,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList private static final String KEY_PASSWORD_VISIBLE = "PASSWORD_VISIBLE"; private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT"; private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON"; + private static final String KEY_REFRESH_BUTTON_ENABLED = "KEY_REFRESH_BUTTON_ENABLED"; private static final String OAUTH_MODE_ON = "on"; private static final String OAUTH_MODE_OFF = "off"; @@ -110,7 +111,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList public static final byte ACTION_CREATE = 0; public static final byte ACTION_UPDATE_TOKEN = 1; - private String mHostBaseUrl; private OwnCloudVersion mDiscoveredVersion; @@ -132,6 +132,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList private Account mAccount; private EditText mHostUrlInput; + private View mRefreshButton; private EditText mUsernameInput; private EditText mPasswordInput; private CheckBox mOAuth2Check; @@ -141,6 +142,10 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList private TextView mOAuthAuthEndpointText; private TextView mOAuthTokenEndpointText; + + private boolean mRefreshButtonEnabled; + + private boolean mHostUrlInputEnabled; /** @@ -163,6 +168,10 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList mOAuth2Check = (CheckBox) findViewById(R.id.oauth_onOff_check); mOkButton = findViewById(R.id.buttonOK); mAuthStatusLayout = (TextView) findViewById(R.id.auth_status_text); + + /// set Host Url Input Enabled + mHostUrlInputEnabled = getResources().getBoolean(R.bool.show_server_url_input); + /// complete label for 'register account' button Button b = (Button) findViewById(R.id.account_register); @@ -176,6 +185,19 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList mAction = getIntent().getByteExtra(EXTRA_ACTION, ACTION_CREATE); mAccount = null; mHostBaseUrl = ""; + boolean refreshButtonEnabled = false; + + // URL input configuration applied + if (!mHostUrlInputEnabled) + { + mHostUrlInput.setText(getString(R.string.server_url)); + findViewById(R.id.hostUrlFrame).setVisibility(View.GONE); + + mRefreshButton = findViewById(R.id.centeredRefreshButton); + + } else { + mRefreshButton = findViewById(R.id.embeddedRefreshButton); + } if (savedInstanceState == null) { /// connection state and info @@ -203,7 +225,11 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList } mOAuth2Check.setChecked(oAuthRequired); changeViewByOAuth2Check(oAuthRequired); - + mJustCreated = true; + + if (mAction == ACTION_UPDATE_TOKEN || !mHostUrlInputEnabled) { + checkOcServer(); + } } else { /// connection state and info @@ -231,43 +257,38 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList // check if server check was interrupted by a configuration change if (savedInstanceState.getBoolean(KEY_SERVER_CHECK_IN_PROGRESS, false)) { checkOcServer(); - } + } + + // refresh button enabled + refreshButtonEnabled = savedInstanceState.getBoolean(KEY_REFRESH_BUTTON_ENABLED); + } showServerStatus(); showAuthStatus(); - if (mServerIsChecked && !mServerIsValid) showRefreshButton(); - mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes - - if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) { - mOAuth2Check.setVisibility(View.GONE); - } if (mAction == ACTION_UPDATE_TOKEN) { /// lock things that should not change mHostUrlInput.setEnabled(false); + mHostUrlInput.setFocusable(false); mUsernameInput.setEnabled(false); + mUsernameInput.setFocusable(false); + mOAuth2Check.setVisibility(View.GONE); + } + + //if (mServerIsChecked && !mServerIsValid && mRefreshButtonEnabled) showRefreshButton(); + if (mServerIsChecked && !mServerIsValid && refreshButtonEnabled) showRefreshButton(); + mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes + + if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) { mOAuth2Check.setVisibility(View.GONE); - if (!mServerIsValid && mOcServerChkOperation == null) { - checkOcServer(); - } } mPasswordInput.setText(""); // clean password to avoid social hacking (disadvantage: password in removed if the device is turned aside) - mJustCreated = true; /// bind view elements to listeners mHostUrlInput.setOnFocusChangeListener(this); - mHostUrlInput.setOnTouchListener(new RightDrawableOnTouchListener() { - @Override - public boolean onDrawableTouch(final MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_UP) { - AuthenticatorActivity.this.onRefreshClick(); - } - return true; - } - }); mHostUrlInput.addTextChangedListener(new TextWatcher() { @Override @@ -286,7 +307,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList }); mPasswordInput.setOnFocusChangeListener(this); mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE); - mPasswordInput.setOnEditorActionListener(this); + mPasswordInput.setOnEditorActionListener(this); mPasswordInput.setOnTouchListener(new RightDrawableOnTouchListener() { @Override public boolean onDrawableTouch(final MotionEvent event) { @@ -295,7 +316,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList } return true; } - }); + }); } /** @@ -331,6 +352,10 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList if (mAccount != null) { outState.putParcelable(KEY_ACCOUNT, mAccount); } + + // refresh button enabled + //outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, mRefreshButtonEnabled); + outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE)); } @@ -361,7 +386,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList super.onResume(); // the state of mOAuth2Check is automatically recovered between configuration changes, but not before onCreate() finishes; so keep the next lines here changeViewByOAuth2Check(mOAuth2Check.isChecked()); - if (mAction == ACTION_UPDATE_TOKEN && mJustCreated) { + if (mAction == ACTION_UPDATE_TOKEN && mJustCreated && getIntent().getBooleanExtra(EXTRA_ENFORCED_UPDATE, false)) { if (mOAuth2Check.isChecked()) Toast.makeText(this, R.string.auth_expired_oauth_token_toast, Toast.LENGTH_LONG).show(); else @@ -434,12 +459,20 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList checkOcServer(); } else { mOkButton.setEnabled(mServerIsValid); + if (!mServerIsValid) { + showRefreshButton(); + } } } private void checkOcServer() { - String uri = mHostUrlInput.getText().toString().trim(); + String uri = trimUrlWebdav(mHostUrlInput.getText().toString().trim()); + + if (!mHostUrlInputEnabled){ + uri = getString(R.string.server_url); + } + mServerIsValid = false; mServerIsChecked = false; mOkButton.setEnabled(false); @@ -681,15 +714,33 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList } else { url = "http://" + url; } - } + + // OC-208: Add suffix remote.php/webdav to normalize (OC-34) + url = trimUrlWebdav(url); + if (url.endsWith("/")) { url = url.substring(0, url.length() - 1); } + } + Log_OC.d(TAG, "URL Normalize " + url); return (url != null ? url : ""); } + + private String trimUrlWebdav(String url){ + if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_4_0)){ + url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_4_0.length()); + } else if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_2_0)){ + url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_2_0.length()); + } else if (url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_1_2)){ + url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_1_2.length()); + } + return (url != null ? url : ""); + } + + /** * Chooses the right icon and text to show to the user for the received operation result. * @@ -906,7 +957,33 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList finish(); - } else { + } else if (result.isServerFail() || result.isException()) { + /// if server fail or exception in authorization, the UI is updated as when a server check failed + mServerIsChecked = true; + mServerIsValid = false; + mIsSslConn = false; + mOcServerChkOperation = null; + mDiscoveredVersion = null; + mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString()); + + // update status icon and text + updateServerStatusIconAndText(result); + showServerStatus(); + mAuthStatusIcon = 0; + mAuthStatusText = 0; + showAuthStatus(); + + // update input controls state + showRefreshButton(); + mOkButton.setEnabled(false); + + // very special case (TODO: move to a common place for all the remote operations) (dangerous here?) + if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) { + mLastSslUntrustedServerResult = result; + showDialog(DIALOG_SSL_VALIDATOR); + } + + } else { // authorization fail due to client side - probably wrong credentials updateAuthStatusIconAndText(result); showAuthStatus(); Log_OC.d(TAG, "Access failed: " + result.getLogMessage()); @@ -1139,11 +1216,11 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList private void showRefreshButton() { - mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0); + mRefreshButton.setVisibility(View.VISIBLE); } private void hideRefreshButton() { - mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + mRefreshButton.setVisibility(View.GONE); } /** @@ -1153,7 +1230,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList * * @param view Refresh 'button' */ - public void onRefreshClick() { + public void onRefreshClick(View view) { checkOcServer(); } @@ -1214,7 +1291,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList * Called from SslValidatorDialog when a new server certificate was correctly saved. */ public void onSavedCertificate() { - mOperationThread = mOcServerChkOperation.retry(this, mHandler); + checkOcServer(); } /**