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