summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/AndroidManifest.xml11
-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
5 files changed, 46 insertions, 26 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 83394209..c2ae2cb3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -51,7 +51,9 @@
</service>
<service
android:name=".ProviderAPI"
- android:enabled="true" />
+ android:exported="false"
+ android:permission="android.permission.BIND_JOB_SERVICE">
+ </service>
<receiver
android:name=".OnBootReceiver"
@@ -111,13 +113,6 @@
android:name=".eip.EIP"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE">
- <intent-filter>
- <action android:name="se.leap.bitmaskclient.EIP.UPDATE"/>
- <action android:name="se.leap.bitmaskclient.EIP.START"/>
- <action android:name="se.leap.bitmaskclient.EIP.STOP"/>
- <action android:name="se.leap.bitmaskclient.START_ALWAYS_ON_EIP"/>
- <action android:name="se.leap.bitmaskclient.EIP.IS_RUNNING"/>
- </intent-filter>
</service>
</application>
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();