Search in sources :

Example 1 with GetRemoteStatusOperation

use of com.owncloud.android.lib.resources.status.GetRemoteStatusOperation in project android by owncloud.

the class GetServerInfoOperation method run.

/**
     * Performs the operation
     * 
     * @return      Result of the operation. If successful, includes an instance of 
     *              {@link ServerInfo} with the information retrieved from the server. 
     *              Call {@link RemoteOperationResult#getData()}.get(0) to get it.
     */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    // first: check the status of the server (including its version)
    GetRemoteStatusOperation getStatus = new GetRemoteStatusOperation(mContext);
    RemoteOperationResult result = getStatus.execute(client);
    if (result.isSuccess()) {
        // second: get authentication method required by the server
        mResultData.mVersion = (OwnCloudVersion) (result.getData().get(0));
        mResultData.mIsSslConn = (result.getCode() == ResultCode.OK_SSL);
        mResultData.mBaseUrl = normalizeProtocolPrefix(mUrl, mResultData.mIsSslConn);
        RemoteOperationResult detectAuthResult = detectAuthorizationMethod(client);
        // third: merge results
        if (detectAuthResult.isSuccess()) {
            mResultData.mAuthMethod = (AuthenticationMethod) detectAuthResult.getData().get(0);
            ArrayList<Object> data = new ArrayList<Object>();
            data.add(mResultData);
            result.setData(data);
        } else {
            result = detectAuthResult;
        }
    }
    return result;
}
Also used : GetRemoteStatusOperation(com.owncloud.android.lib.resources.status.GetRemoteStatusOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArrayList(java.util.ArrayList)

Example 2 with GetRemoteStatusOperation

use of com.owncloud.android.lib.resources.status.GetRemoteStatusOperation in project android by owncloud.

the class SyncCapabilitiesOperation method run.

@Override
protected RemoteOperationResult<RemoteCapability> run(OwnCloudClient client) {
    RemoteCapability capabilities = null;
    OwnCloudVersion serverVersion = null;
    // / Get current value for capabilities from server
    GetRemoteCapabilitiesOperation getCapabilities = new GetRemoteCapabilitiesOperation();
    RemoteOperationResult<RemoteCapability> result = getCapabilities.execute(client);
    if (result.isSuccess()) {
        // Read data from the result
        if (result.getData() != null) {
            capabilities = result.getData();
            serverVersion = new OwnCloudVersion(capabilities.getVersionString());
        }
    } else {
        Timber.w("Remote capabilities not available");
        // server version is important; this fallback will try to get it from status.php
        // if capabilities API is not available.
        GetRemoteStatusOperation getStatus = new GetRemoteStatusOperation();
        RemoteOperationResult<RemoteServerInfo> statusResult = getStatus.execute(client);
        if (statusResult.isSuccess()) {
            serverVersion = statusResult.getData().getOwnCloudVersion();
        }
    }
    // / save data - capabilities in database
    if (capabilities != null) {
        getStorageManager().saveCapabilities(capabilities);
    }
    // and com.owncloud.android.lib.common.accounts.AccountUtils#getServerVersionForAccount(...)
    if (serverVersion != null) {
        AccountManager accountMngr = AccountManager.get(MainApp.Companion.getAppContext());
        accountMngr.setUserData(getStorageManager().getAccount(), com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_OC_VERSION, serverVersion.getVersion());
    }
    return result;
}
Also used : RemoteCapability(com.owncloud.android.lib.resources.status.RemoteCapability) GetRemoteStatusOperation(com.owncloud.android.lib.resources.status.GetRemoteStatusOperation) GetRemoteCapabilitiesOperation(com.owncloud.android.lib.resources.status.GetRemoteCapabilitiesOperation) AccountManager(android.accounts.AccountManager) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion) RemoteServerInfo(com.owncloud.android.lib.resources.status.RemoteServerInfo)

Aggregations

GetRemoteStatusOperation (com.owncloud.android.lib.resources.status.GetRemoteStatusOperation)2 AccountManager (android.accounts.AccountManager)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 GetRemoteCapabilitiesOperation (com.owncloud.android.lib.resources.status.GetRemoteCapabilitiesOperation)1 OwnCloudVersion (com.owncloud.android.lib.resources.status.OwnCloudVersion)1 RemoteCapability (com.owncloud.android.lib.resources.status.RemoteCapability)1 RemoteServerInfo (com.owncloud.android.lib.resources.status.RemoteServerInfo)1 ArrayList (java.util.ArrayList)1