diff --git a/app/src/main/java/org/itxtech/daedalus/Daedalus.java b/app/src/main/java/org/itxtech/daedalus/Daedalus.java
index 8d86bb5..97f3e5a 100644
--- a/app/src/main/java/org/itxtech/daedalus/Daedalus.java
+++ b/app/src/main/java/org/itxtech/daedalus/Daedalus.java
@@ -199,23 +199,34 @@ public class Daedalus extends Application {
deactivateService(instance);
return false;
} else {
- activateService(instance);
+ prepareAndActivateService(instance);
return true;
}
}
- public static boolean activateService(Context context) {
+ public static boolean prepareAndActivateService(Context context) {
Intent intent = VpnService.prepare(context);
if (intent != null) {
return false;
} else {
- DaedalusVpnService.primaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getPrimary());
- DaedalusVpnService.secondaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getSecondary());
- context.startService(Daedalus.getServiceIntent(context).setAction(DaedalusVpnService.ACTION_ACTIVATE));
+ activateService(context);
return true;
}
}
+ public static void activateService(Context context) {
+ DaedalusVpnService.primaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getPrimary());
+ DaedalusVpnService.secondaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getSecondary());
+ if (getInstance().prefs.getBoolean("settings_foreground", false)
+ && Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
+ Logger.info("Starting foreground service");
+ context.startForegroundService(Daedalus.getServiceIntent(context).setAction(DaedalusVpnService.ACTION_ACTIVATE));
+ } else {
+ Logger.info("Starting background service");
+ context.startService(Daedalus.getServiceIntent(context).setAction(DaedalusVpnService.ACTION_ACTIVATE));
+ }
+ }
+
public static void deactivateService(Context context) {
context.startService(getServiceIntent(context).setAction(DaedalusVpnService.ACTION_DEACTIVATE));
context.stopService(getServiceIntent(context));
diff --git a/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java b/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java
index 23bf3c4..f8b22c3 100644
--- a/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java
+++ b/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java
@@ -166,9 +166,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
public void onActivityResult(int request, int result, Intent data) {
if (result == Activity.RESULT_OK) {
- DaedalusVpnService.primaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getPrimary());
- DaedalusVpnService.secondaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getSecondary());
- Daedalus.getInstance().startService(Daedalus.getServiceIntent(getApplicationContext()).setAction(DaedalusVpnService.ACTION_ACTIVATE));
+ Daedalus.activateService(Daedalus.getInstance());
updateMainButton(R.string.button_text_deactivate);
Daedalus.updateShortcut(getApplicationContext());
}
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index db68622..884fb2d 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -66,6 +66,7 @@
不缓存 DoH DNS 的 IP地址
使用暗主题
DNS 查询方式
+ 运行前台服务
规则名称
规则类型
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index 2d0bedc..965dbe9 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -76,6 +76,7 @@
内置
外部
DNS 查询方式
+ 運行前臺服務
伺服器名稱
伺服器網址
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9c1de0f..d85f09d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -65,6 +65,7 @@
Debug Output
Use Dark Theme
DNS Query Method
+ Run service in Foreground
TCP
UDP
diff --git a/app/src/main/res/xml/perf_rule.xml b/app/src/main/res/xml/perf_rule.xml
index 5e24c80..8753372 100644
--- a/app/src/main/res/xml/perf_rule.xml
+++ b/app/src/main/res/xml/perf_rule.xml
@@ -1,11 +1,14 @@
-
+
+
+
-
+
diff --git a/app/src/main/res/xml/perf_server.xml b/app/src/main/res/xml/perf_server.xml
index 2453e8b..0ec3b11 100644
--- a/app/src/main/res/xml/perf_server.xml
+++ b/app/src/main/res/xml/perf_server.xml
@@ -1,11 +1,14 @@
-
+
+
-
\ No newline at end of file
+
diff --git a/app/src/main/res/xml/perf_settings.xml b/app/src/main/res/xml/perf_settings.xml
index 5540e8c..cb4ed66 100644
--- a/app/src/main/res/xml/perf_settings.xml
+++ b/app/src/main/res/xml/perf_settings.xml
@@ -1,7 +1,8 @@
-
-
+
@@ -23,7 +24,9 @@
android:singleLine="true"
android:title="@string/settings_dns_test_servers"/>
+
@@ -39,6 +42,10 @@
android:key="settings_dark_theme"
android:title="@string/settings_dark_theme"
android:defaultValue="false"/>
+
+ app:iconSpaceReserved="false"
+ android:key="settings_app_filter"
+ android:title="@string/settings_app_filter">
+ android:key="settings_app_filter_switch"
+ android:title="@string/settings_app_filter"
+ android:defaultValue="false"/>
+ android:key="settings_app_filter_mode_switch"
+ android:title="@string/settings_app_filter_mode"
+ android:defaultValue="false"
+ android:enabled="false"/>
+ android:key="settings_app_filter_list"
+ android:title="@string/settings_app_filter_list"
+ android:summary="@string/settings_app_filter_list_summary"
+ android:enabled="false"/>
-
+