aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2018-09-07 17:02:51 -0700
committerScott Jackson <daneren2005@gmail.com>2018-09-07 17:02:51 -0700
commitf96b9476bf4dd7e14b38f64b4288e62771d60b4e (patch)
treec100eb700d219d31ee66ae7a525a784bd0dcbf74 /app/src/main/java/github
parent0e97692e08be98d846043e283f52f2ed815dcaf6 (diff)
downloaddsub-f96b9476bf4dd7e14b38f64b4288e62771d60b4e.tar.gz
dsub-f96b9476bf4dd7e14b38f64b4288e62771d60b4e.tar.bz2
dsub-f96b9476bf4dd7e14b38f64b4288e62771d60b4e.zip
Fix Android O+ crashing if something isn't played within 5 seconds of startup
Diffstat (limited to 'app/src/main/java/github')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java6
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Notifications.java18
2 files changed, 23 insertions, 1 deletions
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 0c794c36..6c3cfbd7 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
@@ -274,7 +274,7 @@ public class DownloadService extends Service {
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
wakeLock.setReferenceCounted(false);
- WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
+ WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "downloadServiceLock");
try {
@@ -292,6 +292,10 @@ public class DownloadService extends Service {
shufflePlayBuffer = new ShufflePlayBuffer(this);
artistRadioBuffer = new ArtistRadioBuffer(this);
lifecycleSupport.onCreate();
+
+ if(Build.VERSION.SDK_INT >= 26) {
+ Notifications.shutGoogleUpNotification(this);
+ }
}
@Override
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
index f0bd6766..59341ebf 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
@@ -51,6 +51,7 @@ public final class Notifications {
// Notification IDs.
public static final int NOTIFICATION_ID_PLAYING = 100;
public static final int NOTIFICATION_ID_DOWNLOADING = 102;
+ public static final int NOTIFICATION_ID_SHUT_GOOGLE_UP = 103;
public static final String NOTIFICATION_SYNC_GROUP = "github.daneren2005.dsub.sync";
private static boolean playShowing = false;
@@ -447,6 +448,23 @@ public final class Notifications {
return downloadingChannel;
}
+ @TargetApi(Build.VERSION_CODES.O)
+ public static void shutGoogleUpNotification(final DownloadService downloadService) {
+ // On Android O+, service crashes if startForeground isn't called within 5 seconds of starting
+ getDownloadingNotificationChannel(downloadService);
+
+ NotificationCompat.Builder builder;
+ builder = new NotificationCompat.Builder(downloadService)
+ .setSmallIcon(android.R.drawable.stat_sys_download)
+ .setContentTitle(downloadService.getResources().getString(R.string.download_downloading_title, 0))
+ .setContentText(downloadService.getResources().getString(R.string.download_downloading_summary, "Temp"))
+ .setChannelId("downloading-channel");
+
+ final Notification notification = builder.build();
+ downloadService.startForeground(NOTIFICATION_ID_SHUT_GOOGLE_UP, notification);
+ downloadService.stopForeground(true);
+ }
+
public static void showSyncNotification(final Context context, int stringId, String extra) {
showSyncNotification(context, stringId, extra, null);
}