use of com.owncloud.android.lib.resources.status.OwnCloudVersion in project android by owncloud.
the class AuthenticatorActivity method onRestoreInstanceState.
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// AsyncTask
boolean inProgress = savedInstanceState.getBoolean(KEY_ASYNC_TASK_IN_PROGRESS);
if (inProgress) {
String username = savedInstanceState.getString(KEY_USERNAME);
String password = savedInstanceState.getString(KEY_PASSWORD);
OwnCloudCredentials credentials = null;
if (BASIC_TOKEN_TYPE.equals(mAuthTokenType)) {
String version = savedInstanceState.getString(KEY_OC_VERSION);
OwnCloudVersion ocVersion = (version != null) ? new OwnCloudVersion(version) : null;
credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password, (ocVersion != null && ocVersion.isPreemptiveAuthenticationPreferred()));
} else if (OAUTH_TOKEN_TYPE.equals(mAuthTokenType)) {
credentials = OwnCloudCredentialsFactory.newBearerCredentials(mAuthToken);
}
accessRootFolder(credentials);
}
}
use of com.owncloud.android.lib.resources.status.OwnCloudVersion in project android by owncloud.
the class AuthenticatorActivity method initServerPreFragment.
/**
*
* @param savedInstanceState Saved activity state, as in {{@link #onCreate(Bundle)}
*/
private void initServerPreFragment(Bundle savedInstanceState) {
boolean checkHostUrl = true;
/// step 1 - load and process relevant inputs (resources, intent, savedInstanceState)
boolean isUrlInputAllowed = getResources().getBoolean(R.bool.show_server_url_input);
if (savedInstanceState == null) {
if (mAccount != null) {
mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);
// TODO do next in a setter for mBaseUrl
mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");
mServerInfo.mVersion = AccountUtils.getServerVersion(mAccount);
} else {
mServerInfo.mBaseUrl = getString(R.string.server_url).trim();
mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");
}
} else {
mServerStatusText = savedInstanceState.getString(KEY_SERVER_STATUS_TEXT);
mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON);
mServerIsValid = savedInstanceState.getBoolean(KEY_SERVER_VALID);
mServerIsChecked = savedInstanceState.getBoolean(KEY_SERVER_CHECKED);
// TODO parcelable
mServerInfo.mIsSslConn = savedInstanceState.getBoolean(KEY_IS_SSL_CONN);
mServerInfo.mBaseUrl = savedInstanceState.getString(KEY_HOST_URL_TEXT);
String ocVersion = savedInstanceState.getString(KEY_OC_VERSION);
if (ocVersion != null) {
mServerInfo.mVersion = new OwnCloudVersion(ocVersion);
}
mServerInfo.mAuthMethod = AuthenticationMethod.valueOf(savedInstanceState.getString(KEY_SERVER_AUTH_METHOD));
}
/// step 2 - set properties of UI elements (text, visibility, enabled...)
mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput);
// Convert IDN to Unicode
mHostUrlInput.setText(DisplayUtils.convertIdn(mServerInfo.mBaseUrl, false));
if (mAction != ACTION_CREATE) {
/// lock things that should not change
mHostUrlInput.setEnabled(false);
mHostUrlInput.setFocusable(false);
}
if (isUrlInputAllowed) {
if (mServerInfo.mBaseUrl.isEmpty()) {
checkHostUrl = false;
}
mRefreshButton = findViewById(R.id.embeddedRefreshButton);
} else {
findViewById(R.id.hostUrlFrame).setVisibility(View.GONE);
mRefreshButton = findViewById(R.id.centeredRefreshButton);
}
showRefreshButton(mServerIsChecked && !mServerIsValid && mWaitingForOpId > Integer.MAX_VALUE);
mServerStatusView = (TextView) findViewById(R.id.server_status_text);
showServerStatus();
/// step 3 - bind some listeners and options
mHostUrlInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);
mHostUrlInput.setOnEditorActionListener(this);
/// step 4 - create listeners that will be bound at onResume
mHostUrlInputWatcher = new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
if (mOkButton.isEnabled() && !mServerInfo.mBaseUrl.equals(normalizeUrl(s.toString(), mServerInfo.mIsSslConn))) {
mOkButton.setEnabled(false);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (mAuthStatusIcon != 0) {
Log_OC.d(TAG, "onTextChanged: hiding authentication status");
mAuthStatusIcon = 0;
mAuthStatusText = "";
showAuthStatus();
}
}
};
// TODO find out if this is really necessary, or if it can done in a different way
findViewById(R.id.scroll).setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType) && mHostUrlInput.hasFocus()) {
checkOcServer();
}
}
return false;
}
});
/// step 4 - mark automatic check to be started when OperationsService is ready
mPendingAutoCheck = (savedInstanceState == null && (mAction != ACTION_CREATE || checkHostUrl));
}
use of com.owncloud.android.lib.resources.status.OwnCloudVersion in project android by owncloud.
the class UpdateOCVersionOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
AccountManager accountMngr = AccountManager.get(mContext);
String statUrl = accountMngr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);
statUrl += AccountUtils.STATUS_PATH;
RemoteOperationResult result = null;
GetMethod getMethod = null;
try {
getMethod = new GetMethod(statUrl);
int status = client.executeMethod(getMethod);
if (status != HttpStatus.SC_OK) {
result = new RemoteOperationResult(false, getMethod);
client.exhaustResponse(getMethod.getResponseBodyAsStream());
} else {
String response = getMethod.getResponseBodyAsString();
if (response != null) {
JSONObject json = new JSONObject(response);
if (json != null && json.getString("version") != null) {
String version = json.getString("version");
mOwnCloudVersion = new OwnCloudVersion(version);
if (mOwnCloudVersion.isVersionValid()) {
accountMngr.setUserData(mAccount, Constants.KEY_OC_VERSION, mOwnCloudVersion.getVersion());
Log_OC.d(TAG, "Got new OC version " + mOwnCloudVersion.toString());
result = new RemoteOperationResult(ResultCode.OK);
} else {
Log_OC.w(TAG, "Invalid version number received from server: " + json.getString("version"));
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.BAD_OC_VERSION);
}
}
}
if (result == null) {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
}
}
Log_OC.i(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage());
} catch (JSONException e) {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
Log_OC.e(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage(), e);
} catch (Exception e) {
result = new RemoteOperationResult(e);
Log_OC.e(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage(), e);
} finally {
if (getMethod != null)
getMethod.releaseConnection();
}
return result;
}
use of com.owncloud.android.lib.resources.status.OwnCloudVersion in project android by owncloud.
the class AccountUtilsTest method testGetWebdavPathAndOCVersion.
public void testGetWebdavPathAndOCVersion() {
OwnCloudVersion ocv12 = new OwnCloudVersion(0x010200);
OwnCloudVersion ocv12s = new OwnCloudVersion("1.2");
OwnCloudVersion ocv22 = new OwnCloudVersion(0x020200);
OwnCloudVersion ocv30 = new OwnCloudVersion(0x030000);
OwnCloudVersion ocv33s = new OwnCloudVersion("3.3.3");
OwnCloudVersion ocv45 = new OwnCloudVersion(0x040500);
OwnCloudVersion ocv70 = new OwnCloudVersion(0x070000);
assertTrue(AccountUtils.getWebdavPath(ocv12, false, false).equals("/webdav/owncloud.php"));
assertTrue(AccountUtils.getWebdavPath(ocv12s, false, false).equals("/webdav/owncloud.php"));
assertTrue(AccountUtils.getWebdavPath(ocv22, false, false).equals("/files/webdav.php"));
assertTrue(AccountUtils.getWebdavPath(ocv30, false, false).equals("/files/webdav.php"));
assertTrue(AccountUtils.getWebdavPath(ocv33s, false, false).equals("/files/webdav.php"));
assertTrue(AccountUtils.getWebdavPath(ocv45, false, false).equals("/remote.php/webdav"));
assertTrue(AccountUtils.getWebdavPath(ocv70, false, false).equals("/remote.php/webdav"));
assertNull(AccountUtils.getWebdavPath(null, false, false));
assertTrue(AccountUtils.getWebdavPath(ocv12, true, false).equals("/remote.php/odav"));
assertTrue(AccountUtils.getWebdavPath(ocv12s, true, false).equals("/remote.php/odav"));
assertTrue(AccountUtils.getWebdavPath(ocv22, true, false).equals("/remote.php/odav"));
assertTrue(AccountUtils.getWebdavPath(ocv30, true, false).equals("/remote.php/odav"));
assertTrue(AccountUtils.getWebdavPath(ocv33s, true, false).equals("/remote.php/odav"));
assertTrue(AccountUtils.getWebdavPath(ocv45, true, false).equals("/remote.php/odav"));
assertTrue(AccountUtils.getWebdavPath(ocv70, true, false).equals("/remote.php/odav"));
OwnCloudVersion invalidVer = new OwnCloudVersion("a.b.c");
assertFalse(invalidVer.isVersionValid());
assertTrue(ocv45.toString().equals("4.5.0"));
}
Aggregations