[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [orbot/master] improve how service starts happen on Android O+
commit 3e8a92ac9c687d8164666afec91a268bfb0739c3
Author: n8fr8 <nathan@xxxxxxxxxxx>
Date: Tue May 1 23:56:20 2018 -0400
improve how service starts happen on Android O+
---
app/src/main/java/org/torproject/android/OnBootReceiver.java | 10 +++++++++-
.../java/org/torproject/android/vpn/VPNEnableActivity.java | 9 ++++++++-
.../java/org/torproject/android/service/StartTorReceiver.java | 9 ++++++++-
3 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/OnBootReceiver.java b/app/src/main/java/org/torproject/android/OnBootReceiver.java
index f915a201..21984952 100644
--- a/app/src/main/java/org/torproject/android/OnBootReceiver.java
+++ b/app/src/main/java/org/torproject/android/OnBootReceiver.java
@@ -4,6 +4,7 @@ package org.torproject.android;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.os.Build;
import org.torproject.android.service.util.Prefs;
import org.torproject.android.service.TorService;
@@ -33,6 +34,7 @@ public class OnBootReceiver extends BroadcastReceiver {
Intent intent = new Intent(context,VPNEnableActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
+
}
private void startService (String action, Context context)
@@ -40,7 +42,13 @@ public class OnBootReceiver extends BroadcastReceiver {
Intent torService = new Intent(context, TorService.class);
torService.setAction(action);
- context.startService(torService);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ context.startForegroundService(torService);
+ }
+ else
+ {
+ context.startService(torService);
+ }
}
diff --git a/app/src/main/java/org/torproject/android/vpn/VPNEnableActivity.java b/app/src/main/java/org/torproject/android/vpn/VPNEnableActivity.java
index c6de072e..551f2e62 100644
--- a/app/src/main/java/org/torproject/android/vpn/VPNEnableActivity.java
+++ b/app/src/main/java/org/torproject/android/vpn/VPNEnableActivity.java
@@ -12,6 +12,7 @@ import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.VpnService;
+import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
@@ -122,7 +123,13 @@ public class VPNEnableActivity extends AppCompatActivity {
private void sendIntentToService(String action) {
Intent torService = new Intent(this, TorService.class);
torService.setAction(action);
- startService(torService);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ startForegroundService(torService);
+ }
+ else
+ {
+ startService(torService);
+ }
}
diff --git a/orbotservice/src/main/java/org/torproject/android/service/StartTorReceiver.java b/orbotservice/src/main/java/org/torproject/android/service/StartTorReceiver.java
index 2b0ebf89..0876174b 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/StartTorReceiver.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/StartTorReceiver.java
@@ -4,6 +4,7 @@ package org.torproject.android.service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.os.Build;
import android.text.TextUtils;
import org.torproject.android.service.util.Prefs;
@@ -23,7 +24,13 @@ public class StartTorReceiver extends BroadcastReceiver implements TorServiceCon
startTorIntent.setAction(action);
if (packageName != null)
startTorIntent.putExtra(EXTRA_PACKAGE_NAME, packageName);
- context.startService(startTorIntent);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ context.startForegroundService(startTorIntent);
+ }
+ else
+ {
+ context.startService(startTorIntent);
+ }
} else if (!TextUtils.isEmpty(packageName)) {
// let the requesting app know that the user has disabled
// starting via Intent
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits