summaryrefslogtreecommitdiff
path: root/app/src/main/java/se
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2020-06-19 05:22:34 -0700
committercyberta <cyberta@riseup.net>2020-06-19 05:22:34 -0700
commit4198c9b3bb1fee4bfcb3009ac9d80610ead13466 (patch)
treee75f9115a76d00802af4a6906e8457fdba8d86a2 /app/src/main/java/se
parente4d66c554123a33b035b27999f1809593c5b6f17 (diff)
parent69e11a98f00f04d9a6996c3f2c98f9b75b603f55 (diff)
Merge branch 'fix_crashes' into 'master'
Fix crashes See merge request leap/bitmask_android!107
Diffstat (limited to 'app/src/main/java/se')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java37
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderAPICommand.java11
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java6
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/fragments/DonationReminderDialog.java7
4 files changed, 43 insertions, 18 deletions
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.
* <p/>
- * 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 65d01b22..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,7 +43,7 @@ public class ProviderAPICommand {
private void execute() {
if (isInitialized()) {
Intent intent = setUpIntent();
- context.startService(intent);
+ ProviderAPI.enqueueWork(context, intent);
}
}
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
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();