fix "static context is leaked"

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2018-09-19 15:23:32 +02:00 committed by AndyScherzinger
parent febc475634
commit 7a17e13d55
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B

View file

@ -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()) {