mirror of
https://github.com/nextcloud/android.git
synced 2024-12-01 03:43:43 +03:00
fix "static context is leaked"
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
febc475634
commit
7a17e13d55
1 changed files with 7 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* ownCloud Android client application
|
* ownCloud Android client application
|
||||||
*
|
*
|
||||||
* @author masensio on 09/02/2015.
|
* @author masensio on 09/02/2015.
|
||||||
|
@ -43,11 +43,11 @@ public class AuthenticatorAsyncTask extends AsyncTask<Object, Void, RemoteOpera
|
||||||
private static final String REMOTE_PATH = "/";
|
private static final String REMOTE_PATH = "/";
|
||||||
private static final boolean SUCCESS_IF_ABSENT = false;
|
private static final boolean SUCCESS_IF_ABSENT = false;
|
||||||
|
|
||||||
private Context mContext;
|
private WeakReference<Context> mWeakContext;
|
||||||
private final WeakReference<OnAuthenticatorTaskListener> mListener;
|
private final WeakReference<OnAuthenticatorTaskListener> mListener;
|
||||||
|
|
||||||
public AuthenticatorAsyncTask(Activity activity) {
|
public AuthenticatorAsyncTask(Activity activity) {
|
||||||
mContext = activity.getApplicationContext();
|
mWeakContext = new WeakReference<>(activity.getApplicationContext());
|
||||||
mListener = new WeakReference<>((OnAuthenticatorTaskListener)activity);
|
mListener = new WeakReference<>((OnAuthenticatorTaskListener)activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,21 +55,18 @@ public class AuthenticatorAsyncTask extends AsyncTask<Object, Void, RemoteOpera
|
||||||
protected RemoteOperationResult doInBackground(Object... params) {
|
protected RemoteOperationResult doInBackground(Object... params) {
|
||||||
|
|
||||||
RemoteOperationResult result;
|
RemoteOperationResult result;
|
||||||
if (params!= null && params.length==2) {
|
if (params != null && params.length == 2 && mWeakContext.get() != null) {
|
||||||
String url = (String)params[0];
|
String url = (String)params[0];
|
||||||
|
Context context = mWeakContext.get();
|
||||||
OwnCloudCredentials credentials = (OwnCloudCredentials)params[1];
|
OwnCloudCredentials credentials = (OwnCloudCredentials)params[1];
|
||||||
|
|
||||||
// Client
|
// Client
|
||||||
Uri uri = Uri.parse(url);
|
Uri uri = Uri.parse(url);
|
||||||
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(uri, mContext, true);
|
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(uri, context, true);
|
||||||
client.setCredentials(credentials);
|
client.setCredentials(credentials);
|
||||||
|
|
||||||
// Operation - try credentials
|
// Operation - try credentials
|
||||||
ExistenceCheckRemoteOperation operation = new ExistenceCheckRemoteOperation(
|
ExistenceCheckRemoteOperation operation = new ExistenceCheckRemoteOperation(REMOTE_PATH, SUCCESS_IF_ABSENT);
|
||||||
REMOTE_PATH,
|
|
||||||
mContext,
|
|
||||||
SUCCESS_IF_ABSENT
|
|
||||||
);
|
|
||||||
result = operation.execute(client);
|
result = operation.execute(client);
|
||||||
|
|
||||||
if (operation.wasRedirected()) {
|
if (operation.wasRedirected()) {
|
||||||
|
|
Loading…
Reference in a new issue