2 * ownCloud Android client application
4 * @author masensio on 09/02/2015.
5 * Copyright (C) 2015 ownCloud Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 package com
.owncloud
.android
.authentication
;
22 import android
.app
.Activity
;
23 import android
.content
.Context
;
24 import android
.net
.Uri
;
25 import android
.os
.AsyncTask
;
27 import com
.owncloud
.android
.MainApp
;
28 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
29 import com
.owncloud
.android
.lib
.common
.OwnCloudClientFactory
;
30 import com
.owncloud
.android
.lib
.common
.OwnCloudCredentials
;
31 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
32 import com
.owncloud
.android
.lib
.resources
.files
.ExistenceCheckRemoteOperation
;
34 import java
.lang
.ref
.WeakReference
;
38 * Async Task to verify the credentials of a user
40 public class AuthenticatorAsyncTask
extends AsyncTask
<Object
, Void
, RemoteOperationResult
> {
42 private static String REMOTE_PATH
= "/";
43 private static boolean SUCCESS_IF_ABSENT
= false
;
45 private Context mContext
;
46 private final WeakReference
<OnAuthenticatorTaskListener
> mListener
;
47 protected Activity mActivity
;
49 public AuthenticatorAsyncTask(Activity activity
) {
50 mContext
= activity
.getApplicationContext();
51 mListener
= new WeakReference
<OnAuthenticatorTaskListener
>((OnAuthenticatorTaskListener
)activity
);
55 protected RemoteOperationResult
doInBackground(Object
... params
) {
57 RemoteOperationResult result
;
58 if (params
!= null
&& params
.length
==2) {
59 String url
= (String
)params
[0];
60 OwnCloudCredentials credentials
= (OwnCloudCredentials
)params
[1];
63 Uri uri
= Uri
.parse(url
);
64 OwnCloudClient client
= OwnCloudClientFactory
.createOwnCloudClient(uri
, mContext
, true
);
66 client
.setCredentials(credentials
);
69 ExistenceCheckRemoteOperation operation
= new ExistenceCheckRemoteOperation(
74 result
= operation
.execute(client
);
77 result
= new RemoteOperationResult(RemoteOperationResult
.ResultCode
.UNKNOWN_ERROR
);
84 protected void onPostExecute(RemoteOperationResult result
) {
88 OnAuthenticatorTaskListener listener
= mListener
.get();
91 listener
.onAuthenticatorTaskCallback(result
);
96 * Interface to retrieve data from recognition task
98 public interface OnAuthenticatorTaskListener
{
100 void onAuthenticatorTaskCallback(RemoteOperationResult result
);