From 2b265e3bd54b0e71e0560be6eea3f6450b794e37 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 9 May 2020 01:24:57 +0200 Subject: catch ActivityNotFoundException for the rare case when Android can't find any Activity which is able to open a intent containing a URL --- .../se/leap/bitmaskclient/fragments/DonationReminderDialog.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient') diff --git a/app/src/main/java/se/leap/bitmaskclient/fragments/DonationReminderDialog.java b/app/src/main/java/se/leap/bitmaskclient/fragments/DonationReminderDialog.java index d2454d77..046acad4 100644 --- a/app/src/main/java/se/leap/bitmaskclient/fragments/DonationReminderDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/fragments/DonationReminderDialog.java @@ -1,6 +1,7 @@ package se.leap.bitmaskclient.fragments; import android.app.Dialog; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.net.Uri; @@ -57,7 +58,11 @@ public class DonationReminderDialog extends AppCompatDialogFragment { builder.setView(view); btnDonate.setOnClickListener(v -> { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(DONATION_URL)); - startActivity(browserIntent); + try { + startActivity(browserIntent); + } catch (ActivityNotFoundException e) { + e.printStackTrace(); + } PreferenceHelper.putString(getContext(), LAST_DONATION_REMINDER_DATE, DateHelper.getCurrentDateString()); dismiss(); -- cgit v1.2.3 From 6af4af42f54d46190f2fb7f2a700f829a8f1a732 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 9 May 2020 01:27:57 +0200 Subject: catch IllegalStateException when app is not in a state that allows to start the provider API service --- app/src/main/java/se/leap/bitmaskclient/ProviderAPICommand.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient') diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderAPICommand.java b/app/src/main/java/se/leap/bitmaskclient/ProviderAPICommand.java index 65d01b22..04a53a47 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderAPICommand.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderAPICommand.java @@ -40,7 +40,11 @@ public class ProviderAPICommand { private void execute() { if (isInitialized()) { Intent intent = setUpIntent(); - context.startService(intent); + try { + context.startService(intent); + } catch (IllegalStateException e) { + e.printStackTrace(); + } } } -- cgit v1.2.3 From d4c0f2d288aed4ec49a0eaa1e369a98bf34cc1dc Mon Sep 17 00:00:00 2001 From: cyBerta Date: Wed, 10 Jun 2020 23:22:38 +0200 Subject: catch rare IllegalStateExceptions when enqueueing jobs --- app/src/main/java/se/leap/bitmaskclient/eip/EIP.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient') diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index 511a33bc..34c88ef9 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -123,7 +123,11 @@ public final class EIP extends JobIntentService implements Observer { * Convenience method for enqueuing work in to this service. */ static void enqueueWork(Context context, Intent work) { - enqueueWork(context, EIP.class, JOB_ID, work); + try { + enqueueWork(context, EIP.class, JOB_ID, work); + } catch (IllegalStateException e) { + e.printStackTrace(); + } } @Override -- cgit v1.2.3 From 69e11a98f00f04d9a6996c3f2c98f9b75b603f55 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 11 Jun 2020 02:05:35 +0200 Subject: ProviderAPI as JobIntentService --- .../java/se/leap/bitmaskclient/ProviderAPI.java | 37 +++++++++++++++------- .../se/leap/bitmaskclient/ProviderAPICommand.java | 15 ++++----- 2 files changed, 32 insertions(+), 20 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient') diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java index 57bea0d3..9d34b38f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java @@ -17,25 +17,32 @@ package se.leap.bitmaskclient; import android.annotation.SuppressLint; -import android.app.IntentService; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; +import androidx.annotation.NonNull; +import androidx.core.app.JobIntentService; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES; /** * Implements HTTP api methods (encapsulated in {{@link ProviderApiManager}}) * used to manage communications with the provider server. *

- * It's an IntentService because it downloads data from the Internet, so it operates in the background. + * It's an JobIntentService because it downloads data from the Internet, so it operates in the background. * * @author parmegv * @author MeanderingCode * @author cyberta */ -public class ProviderAPI extends IntentService implements ProviderApiManagerBase.ProviderApiServiceCallback { +public class ProviderAPI extends JobIntentService implements ProviderApiManagerBase.ProviderApiServiceCallback { + + /** + * Unique job ID for this service. + */ + static final int JOB_ID = 161375; final public static String TAG = ProviderAPI.class.getSimpleName(), @@ -74,10 +81,6 @@ public class ProviderAPI extends IntentService implements ProviderApiManagerBase ProviderApiManager providerApiManager; - public ProviderAPI() { - super(TAG); - } - //TODO: refactor me, please! //used in insecure flavor only @SuppressLint("unused") @@ -91,14 +94,24 @@ public class ProviderAPI extends IntentService implements ProviderApiManagerBase providerApiManager = initApiManager(); } + /** + * Convenience method for enqueuing work in to this service. + */ + static void enqueueWork(Context context, Intent work) { + try { + enqueueWork(context, ProviderAPI.class, JOB_ID, work); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } @Override - public void broadcastEvent(Intent intent) { - LocalBroadcastManager.getInstance(this).sendBroadcast(intent); + protected void onHandleWork(@NonNull Intent command) { + providerApiManager.handleIntent(command); } @Override - protected void onHandleIntent(Intent command) { - providerApiManager.handleIntent(command); + public void broadcastEvent(Intent intent) { + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } private ProviderApiManager initApiManager() { diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderAPICommand.java b/app/src/main/java/se/leap/bitmaskclient/ProviderAPICommand.java index 04a53a47..f3122376 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderAPICommand.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderAPICommand.java @@ -1,9 +1,12 @@ package se.leap.bitmaskclient; -import android.content.*; -import android.os.*; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.os.ResultReceiver; -import org.jetbrains.annotations.*; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class ProviderAPICommand { private Context context; @@ -40,11 +43,7 @@ public class ProviderAPICommand { private void execute() { if (isInitialized()) { Intent intent = setUpIntent(); - try { - context.startService(intent); - } catch (IllegalStateException e) { - e.printStackTrace(); - } + ProviderAPI.enqueueWork(context, intent); } } -- cgit v1.2.3