Fixed Asynctask being executed when it shouldn't

#1 check if cancel was called in onPrepare
#2 if we currently don't have a Connection, don't show crash report dialogue to user
This commit is contained in:
Redirion 2019-02-26 19:23:54 +01:00 committed by GitHub
parent f4d215664e
commit a7afc23a9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@ import android.content.SharedPreferences;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.Signature; import android.content.pm.Signature;
import android.net.ConnectivityManager;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -69,6 +70,8 @@ public class CheckForNewAppVersionTask extends AsyncTask<Void, Void, String> {
@Override @Override
protected String doInBackground(Void... voids) { protected String doInBackground(Void... voids) {
if(isCancelled() || !isConnected()) return null;
// Make a network request to get latest NewPipe data. // Make a network request to get latest NewPipe data.
if (client == null) { if (client == null) {
@ -227,4 +230,12 @@ public class CheckForNewAppVersionTask extends AsyncTask<Void, Void, String> {
return getCertificateSHA1Fingerprint().equals(GITHUB_APK_SHA1); return getCertificateSHA1Fingerprint().equals(GITHUB_APK_SHA1);
} }
private boolean isConnected() {
ConnectivityManager cm =
(ConnectivityManager) app.getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().isConnected();
}
} }