import android.text.Editable;\r
import android.text.InputType;\r
import android.text.TextWatcher;\r
import android.text.Editable;\r
import android.text.InputType;\r
import android.text.TextWatcher;\r
import android.view.KeyEvent;\r
import android.view.MotionEvent;\r
import android.view.View;\r
import android.view.KeyEvent;\r
import android.view.MotionEvent;\r
import android.view.View;\r
private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT";\r
private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON";\r
private static final String KEY_SERVER_AUTH_METHOD = "SERVER_AUTH_METHOD";\r
private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT";\r
private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON";\r
private static final String KEY_SERVER_AUTH_METHOD = "SERVER_AUTH_METHOD";\r
private static final String KEY_AUTH_TOKEN = "AUTH_TOKEN";\r
\r
private static final String AUTH_ON = "on";\r
private static final String KEY_AUTH_TOKEN = "AUTH_TOKEN";\r
\r
private static final String AUTH_ON = "on";\r
\r
private GetServerInfoOperation.ServerInfo mServerInfo = \r
new GetServerInfoOperation.ServerInfo();\r
\r
private GetServerInfoOperation.ServerInfo mServerInfo = \r
new GetServerInfoOperation.ServerInfo();\r
/// initialize block to be moved to single Fragment to check server and get info about it \r
initServerPreFragment(savedInstanceState);\r
\r
/// initialize block to be moved to single Fragment to retrieve and validate credentials \r
initAuthorizationPreFragment(savedInstanceState);\r
\r
/// initialize block to be moved to single Fragment to check server and get info about it \r
initServerPreFragment(savedInstanceState);\r
\r
/// initialize block to be moved to single Fragment to retrieve and validate credentials \r
initAuthorizationPreFragment(savedInstanceState);\r
\r
\r
/// step 1 - load and process relevant inputs (resources, intent, savedInstanceState)\r
boolean isUrlInputAllowed = getResources().getBoolean(R.bool.show_server_url_input); \r
\r
/// step 1 - load and process relevant inputs (resources, intent, savedInstanceState)\r
boolean isUrlInputAllowed = getResources().getBoolean(R.bool.show_server_url_input); \r
if (savedInstanceState == null) {\r
if (mAccount != null) {\r
mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);\r
if (savedInstanceState == null) {\r
if (mAccount != null) {\r
mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);\r
mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT);\r
mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON);\r
\r
mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT);\r
mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON);\r
\r
findViewById(R.id.hostUrlFrame).setVisibility(View.GONE);\r
mRefreshButton = findViewById(R.id.centeredRefreshButton);\r
}\r
findViewById(R.id.hostUrlFrame).setVisibility(View.GONE);\r
mRefreshButton = findViewById(R.id.centeredRefreshButton);\r
}\r
- /// step 4 - automatic actions to start\r
- if (savedInstanceState == null) {\r
- if (mAction != ACTION_CREATE || !isUrlInputAllowed) {\r
- checkOcServer(); \r
- }\r
- }\r
+ /// step 4 - mark automatic check to be started when OperationsService is ready\r
+ mPendingAutoCheck = (savedInstanceState == null && \r
+ (mAction != ACTION_CREATE || !isUrlInputAllowed));\r
mUsernameInput = (EditText) findViewById(R.id.account_username);\r
mPasswordInput = (EditText) findViewById(R.id.account_password);\r
mAuthStatusView = (TextView) findViewById(R.id.auth_status_text); \r
mUsernameInput = (EditText) findViewById(R.id.account_username);\r
mPasswordInput = (EditText) findViewById(R.id.account_password);\r
mAuthStatusView = (TextView) findViewById(R.id.auth_status_text); \r
\r
/// step 1 - load and process relevant inputs (resources, intent, savedInstanceState)\r
String presetUserName = null;\r
\r
/// step 1 - load and process relevant inputs (resources, intent, savedInstanceState)\r
String presetUserName = null;\r
super.onSaveInstanceState(outState);\r
\r
/// global state\r
outState.putString(KEY_AUTH_TOKEN_TYPE, mAuthTokenType);\r
super.onSaveInstanceState(outState);\r
\r
/// global state\r
outState.putString(KEY_AUTH_TOKEN_TYPE, mAuthTokenType);\r
\r
/// Server PRE-fragment state\r
outState.putInt(KEY_SERVER_STATUS_TEXT, mServerStatusText);\r
\r
/// Server PRE-fragment state\r
outState.putInt(KEY_SERVER_STATUS_TEXT, mServerStatusText);\r
outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText);\r
outState.putString(KEY_AUTH_TOKEN, mAuthToken);\r
\r
outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText);\r
outState.putString(KEY_AUTH_TOKEN, mAuthToken);\r
\r
if (mOperationsServiceBinder != null) {\r
//Log_OC.wtf(TAG, "checking server..." );\r
mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
if (mOperationsServiceBinder != null) {\r
//Log_OC.wtf(TAG, "checking server..." );\r
mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
drawable = R.drawable.ic_hide;\r
}\r
mPasswordInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, drawable, 0);\r
drawable = R.drawable.ic_hide;\r
}\r
mPasswordInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, drawable, 0);\r
/// get basic credentials entered by user\r
String username = mUsernameInput.getText().toString();\r
String password = mPasswordInput.getText().toString();\r
/// get basic credentials entered by user\r
String username = mUsernameInput.getText().toString();\r
String password = mPasswordInput.getText().toString();\r
- startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, username, password, followRedirects);\r
+ startExistenceCheckRemoteOperation(\r
+ remotePath, this, successIfAbsent, username, password, followRedirects);\r
- private void startExistenceCheckRemoteOperation(String remotePath, Context context, boolean successIfAbsent, String webdav_path,\r
+ private void startExistenceCheckRemoteOperation(\r
+ String remotePath, Context context, boolean successIfAbsent,\r
String username, String password, boolean followRedirects) {\r
Intent existenceCheckIntent = new Intent();\r
existenceCheckIntent.setAction(OperationsService.ACTION_EXISTENCE_CHECK);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mServerInfo.mBaseUrl);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_REMOTE_PATH, remotePath);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_SUCCESS_IF_ABSENT, successIfAbsent);\r
String username, String password, boolean followRedirects) {\r
Intent existenceCheckIntent = new Intent();\r
existenceCheckIntent.setAction(OperationsService.ACTION_EXISTENCE_CHECK);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mServerInfo.mBaseUrl);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_REMOTE_PATH, remotePath);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_SUCCESS_IF_ABSENT, successIfAbsent);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_USERNAME, username);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_PASSWORD, password);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN, mAuthToken);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects);\r
\r
if (mOperationsServiceBinder != null) {\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_USERNAME, username);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_PASSWORD, password);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN, mAuthToken);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects);\r
\r
if (mOperationsServiceBinder != null) {\r
Uri uri = Uri.parse(mOAuthAuthEndpointText.getText().toString().trim());\r
Uri.Builder uriBuilder = uri.buildUpon();\r
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_RESPONSE_TYPE, getString(R.string.oauth2_response_type));\r
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_REDIRECT_URI, getString(R.string.oauth2_redirect_uri)); \r
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_CLIENT_ID, getString(R.string.oauth2_client_id));\r
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_SCOPE, getString(R.string.oauth2_scope));\r
Uri uri = Uri.parse(mOAuthAuthEndpointText.getText().toString().trim());\r
Uri.Builder uriBuilder = uri.buildUpon();\r
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_RESPONSE_TYPE, getString(R.string.oauth2_response_type));\r
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_REDIRECT_URI, getString(R.string.oauth2_redirect_uri)); \r
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_CLIENT_ID, getString(R.string.oauth2_client_id));\r
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_SCOPE, getString(R.string.oauth2_scope));\r
uri = uriBuilder.build();\r
Log_OC.d(TAG, "Starting browser to view " + uri.toString());\r
Intent i = new Intent(Intent.ACTION_VIEW, uri);\r
uri = uriBuilder.build();\r
Log_OC.d(TAG, "Starting browser to view " + uri.toString());\r
Intent i = new Intent(Intent.ACTION_VIEW, uri);\r
IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);\r
dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);\r
\r
IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);\r
dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);\r
\r
/// test credentials accessing the root folder\r
String remotePath ="";\r
boolean successIfAbsent = false;\r
boolean followRedirections = false;\r
/// test credentials accessing the root folder\r
String remotePath ="";\r
boolean successIfAbsent = false;\r
boolean followRedirections = false;\r
- startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, "", "", followRedirections);\r
+ startExistenceCheckRemoteOperation(\r
+ remotePath, this, successIfAbsent, "", "", followRedirections);\r
onGetOAuthAccessTokenFinish(result);\r
\r
} else if (operation instanceof ExistenceCheckRemoteOperation) {\r
onGetOAuthAccessTokenFinish(result);\r
\r
} else if (operation instanceof ExistenceCheckRemoteOperation) {\r
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) {\r
onSamlBasedFederatedSingleSignOnAuthorizationStart(result);\r
\r
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) {\r
onSamlBasedFederatedSingleSignOnAuthorizationStart(result);\r
\r
if (result.isSuccess()) {\r
boolean success = false;\r
String username = (String) result.getData().get(0);\r
if (result.isSuccess()) {\r
boolean success = false;\r
String username = (String) result.getData().get(0);\r
if (result.isIdPRedirection()) {
String url = result.getRedirectedLocation();\r
String targetUrl = mServerInfo.mBaseUrl \r
if (result.isIdPRedirection()) {
String url = result.getRedirectedLocation();\r
String targetUrl = mServerInfo.mBaseUrl \r
private void onGetServerInfoFinish(RemoteOperationResult result) {\r
/// update activity state\r
mServerIsChecked = true;\r
private void onGetServerInfoFinish(RemoteOperationResult result) {\r
/// update activity state\r
mServerIsChecked = true;\r
\r
// update server status, but don't show it yet\r
updateServerStatusIconAndText(result);\r
\r
// update server status, but don't show it yet\r
updateServerStatusIconAndText(result);\r
* @param result Result of the operation.\r
*/\r
private void onGetOAuthAccessTokenFinish(RemoteOperationResult result) {\r
* @param result Result of the operation.\r
*/\r
private void onGetOAuthAccessTokenFinish(RemoteOperationResult result) {\r
/// be gentle with the user\r
IndeterminateProgressDialog dialog = \r
IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);\r
/// be gentle with the user\r
IndeterminateProgressDialog dialog = \r
IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);\r
- startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, "", "", followRedirects);\r
+ startExistenceCheckRemoteOperation(\r
+ remotePath, this, successIfAbsent, "", "", followRedirects);\r
* @param result Result of the operation.\r
*/\r
private void onAuthorizationCheckFinish(RemoteOperationResult result) {\r
* @param result Result of the operation.\r
*/\r
private void onAuthorizationCheckFinish(RemoteOperationResult result) {\r
if (result.isSuccess()) {\r
Log_OC.d(TAG, "Successful access - time to save the account");\r
\r
if (result.isSuccess()) {\r
Log_OC.d(TAG, "Successful access - time to save the account");\r
\r
- /*\r
- mServerInfo.mIsSslConn = false;\r
- mServerInfo.mVersion = null;\r
- mServerInfo.mBaseUrl = \r
- normalizeUrl(mHostUrlInput.getText().toString(), mServerInfo.mIsSslConn); // TODO remove?\r
- */\r
String username = mUsernameInput.getText().toString().trim();\r
if (isOAuth) {\r
username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong();\r
String username = mUsernameInput.getText().toString().trim();\r
if (isOAuth) {\r
username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong();\r
Account newAccount = new Account(accountName, MainApp.getAccountType());\r
if (AccountUtils.exists(newAccount, getApplicationContext())) {\r
// fail - not a new account, but an existing one; disallow\r
Account newAccount = new Account(accountName, MainApp.getAccountType());\r
if (AccountUtils.exists(newAccount, getApplicationContext())) {\r
// fail - not a new account, but an existing one; disallow\r
- if (mWaitingForOpId != -1) {\r
- mOperationsServiceBinder.dispatchResultIfFinished(mWaitingForOpId, this);\r
+ if (mWaitingForOpId <= Integer.MAX_VALUE) {\r
+ mOperationsServiceBinder.dispatchResultIfFinished((int)mWaitingForOpId, this);\r
+ }\r
+ \r
+ if (mPendingAutoCheck) {\r
+ checkOcServer();\r
@Override\r
public void onServiceConnected(ComponentName component, IBinder service) {\r
if (component.equals(new ComponentName(AuthenticatorActivity.this, OperationsService.class))) {\r
@Override\r
public void onServiceConnected(ComponentName component, IBinder service) {\r
if (component.equals(new ComponentName(AuthenticatorActivity.this, OperationsService.class))) {\r