diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 55ad59448..4df7ded3e 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -53,6 +53,16 @@
+
+
+
+
+
+
+
+
+
diff --git a/android/app/src/main/java/org/musicpd/AutomationReceiver.kt b/android/app/src/main/java/org/musicpd/AutomationReceiver.kt
index bb7f42a91..c1a31dcc1 100644
--- a/android/app/src/main/java/org/musicpd/AutomationReceiver.kt
+++ b/android/app/src/main/java/org/musicpd/AutomationReceiver.kt
@@ -5,5 +5,20 @@ import android.content.Context
import android.content.Intent
class AutomationReceiver : BroadcastReceiver() {
- override fun onReceive(context: Context, intent: Intent) {}
+ override fun onReceive(context: Context, intent: Intent) {
+
+ when(intent.action) {
+ "org.musicpd.action.StartService" -> {
+ val wakelock = Preferences.getBoolean(
+ context,
+ Preferences.KEY_WAKELOCK, false
+ )
+ Main.startService(context, wakelock)
+ }
+ "org.musicpd.action.StopService" -> {
+ context.startService(Intent(context, Main::class.java)
+ .setAction(Main.SHUTDOWN_ACTION))
+ }
+ }
+ }
}
diff --git a/android/app/src/main/java/org/musicpd/Main.java b/android/app/src/main/java/org/musicpd/Main.java
index cc5a52837..3c4ad5464 100644
--- a/android/app/src/main/java/org/musicpd/Main.java
+++ b/android/app/src/main/java/org/musicpd/Main.java
@@ -24,10 +24,12 @@ import androidx.annotation.OptIn;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.session.MediaSession;
+import org.jetbrains.annotations.NotNull;
import org.musicpd.data.LoggingRepository;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
+import java.util.Objects;
import javax.inject.Inject;
@@ -35,8 +37,10 @@ import dagger.hilt.android.AndroidEntryPoint;
@AndroidEntryPoint
public class Main extends Service implements Runnable {
+
private static final String TAG = "Main";
private static final String WAKELOCK_TAG = "mpd:wakelockmain";
+
private static final int MAIN_STATUS_ERROR = -1;
private static final int MAIN_STATUS_STOPPED = 0;
private static final int MAIN_STATUS_STARTED = 1;
@@ -57,6 +61,9 @@ public class Main extends Service implements Runnable {
@Inject
LoggingRepository logging;
+ @NotNull
+ public static final String SHUTDOWN_ACTION = "org.musicpd.action.ShutdownMPD";
+
static class MainStub extends IMain.Stub {
private Main mService;
MainStub(Main service) {
@@ -126,9 +133,13 @@ public class Main extends Service implements Runnable {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- start();
- if (intent != null && intent.getBooleanExtra("wakelock", false))
- setWakelockEnabled(true);
+ if (Objects.equals(intent.getAction(), SHUTDOWN_ACTION)) {
+ stop();
+ } else {
+ start();
+ if (intent.getBooleanExtra("wakelock", false))
+ setWakelockEnabled(true);
+ }
return START_STICKY;
}
@@ -319,4 +330,9 @@ public class Main extends Service implements Runnable {
else
context.startService(intent);
}
+
+ public static void stopService(Context context) {
+ Intent intent = new Intent(context, Main.class);
+ context.stopService(intent);
+ }
}