aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2018-09-01 13:51:00 -0700
committerScott Jackson <daneren2005@gmail.com>2018-09-01 13:51:00 -0700
commit0e97692e08be98d846043e283f52f2ed815dcaf6 (patch)
tree8e5469b215ad91a0ae213b7be8401741ecdb4111 /app
parent7f55a43e3d59015d03277fa77cf626c68e3bbded (diff)
downloaddsub-0e97692e08be98d846043e283f52f2ed815dcaf6.tar.gz
dsub-0e97692e08be98d846043e283f52f2ed815dcaf6.tar.bz2
dsub-0e97692e08be98d846043e283f52f2ed815dcaf6.zip
Fixed #880: Use explicit startForegroundService for Android 8+
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java4
-rw-r--r--app/src/main/java/github/daneren2005/dsub/receiver/HeadphonePlugReceiver.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/receiver/MediaButtonIntentReceiver.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/receiver/PlayActionReceiver.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java12
6 files changed, 18 insertions, 6 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java
index a1c5ceef..5948064d 100644
--- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -144,7 +144,7 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
applyTheme();
applyFullscreen();
super.onCreate(bundle);
- startService(new Intent(this, DownloadService.class));
+ DownloadService.startService(this);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
if(getIntent().hasExtra(Constants.FRAGMENT_POSITION)) {
@@ -1003,7 +1003,7 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
break;
}
Log.w(TAG, "DownloadService not running. Attempting to start it.");
- startService(new Intent(this, DownloadService.class));
+ DownloadService.startService(this);
Util.sleepQuietly(50L);
}
diff --git a/app/src/main/java/github/daneren2005/dsub/receiver/HeadphonePlugReceiver.java b/app/src/main/java/github/daneren2005/dsub/receiver/HeadphonePlugReceiver.java
index 041eb8e1..ebf50936 100644
--- a/app/src/main/java/github/daneren2005/dsub/receiver/HeadphonePlugReceiver.java
+++ b/app/src/main/java/github/daneren2005/dsub/receiver/HeadphonePlugReceiver.java
@@ -33,7 +33,7 @@ public class HeadphonePlugReceiver extends BroadcastReceiver {
if(headphoneState == 1 && Util.shouldStartOnHeadphones(context)) {
Intent start = new Intent(context, DownloadService.class);
start.setAction(DownloadService.START_PLAY);
- context.startService(start);
+ DownloadService.startService(context, start);
}
}
}
diff --git a/app/src/main/java/github/daneren2005/dsub/receiver/MediaButtonIntentReceiver.java b/app/src/main/java/github/daneren2005/dsub/receiver/MediaButtonIntentReceiver.java
index 8119ef2d..0f050801 100644
--- a/app/src/main/java/github/daneren2005/dsub/receiver/MediaButtonIntentReceiver.java
+++ b/app/src/main/java/github/daneren2005/dsub/receiver/MediaButtonIntentReceiver.java
@@ -45,7 +45,7 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
Intent serviceIntent = new Intent(context, DownloadService.class);
serviceIntent.putExtra(Intent.EXTRA_KEY_EVENT, event);
- context.startService(serviceIntent);
+ DownloadService.startService(context, serviceIntent);
if (isOrderedBroadcast()) {
try {
abortBroadcast();
diff --git a/app/src/main/java/github/daneren2005/dsub/receiver/PlayActionReceiver.java b/app/src/main/java/github/daneren2005/dsub/receiver/PlayActionReceiver.java
index 2c04d829..aa3b9173 100644
--- a/app/src/main/java/github/daneren2005/dsub/receiver/PlayActionReceiver.java
+++ b/app/src/main/java/github/daneren2005/dsub/receiver/PlayActionReceiver.java
@@ -40,7 +40,7 @@ public class PlayActionReceiver extends BroadcastReceiver {
start.putExtra(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, data.getString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR));
start.putExtra(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, data.getString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE));
start.putExtra(Constants.PREFERENCES_KEY_OFFLINE, data.getInt(Constants.PREFERENCES_KEY_OFFLINE));
- context.startService(start);
+ DownloadService.startService(context, start);
}
}
}
diff --git a/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java b/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java
index d4e544c6..e4edabc4 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java
@@ -524,7 +524,7 @@ public class AutoMediaBrowserService extends MediaBrowserService {
public void getDownloadService() {
if(DownloadService.getInstance() == null) {
- startService(new Intent(this, DownloadService.class));
+ DownloadService.startService(this);
}
waitForDownloadService();
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
index a4ca705c..0c794c36 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
@@ -71,6 +71,7 @@ import java.util.TimerTask;
import java.util.concurrent.CopyOnWriteArrayList;
import android.annotation.TargetApi;
+import android.app.Activity;
import android.app.Service;
import android.content.ComponentCallbacks2;
import android.content.ComponentName;
@@ -375,6 +376,17 @@ public class DownloadService extends Service {
Notifications.hideDownloadingNotification(this, this, handler);
}
+ public static void startService(Context context) {
+ startService(context, new Intent(context, DownloadService.class));
+ }
+ public static void startService(Context context, Intent intent) {
+ PowerManager powerManager = (PowerManager) context.getSystemService(POWER_SERVICE);
+ if (Build.VERSION.SDK_INT < 26 || (powerManager != null && powerManager.isIgnoringBatteryOptimizations(intent.getPackage()))) {
+ context.startService(intent);
+ } else {
+ context.startForegroundService(intent);
+ }
+ }
public static DownloadService getInstance() {
return instance;
}