aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-09-17 12:49:35 -0400
committerAllan Wang <me@allanwang.ca>2017-09-17 12:49:35 -0400
commit44608c79ae79e698bfd815290f07cec090bd9f83 (patch)
tree9e66445268160c65ac41139eb22e185b1c009b33
parent715596aa1e6a594cafba5de54c6c8bbd4832e3b2 (diff)
downloadfrost-44608c79ae79e698bfd815290f07cec090bd9f83.tar.gz
frost-44608c79ae79e698bfd815290f07cec090bd9f83.tar.bz2
frost-44608c79ae79e698bfd815290f07cec090bd9f83.zip
Add checks to ensure job service exists
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
index 2ab15fac..b892af91 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
@@ -168,7 +168,11 @@ const val NOTIFICATION_PERIODIC_JOB = 7
* returns false if an error occurs; true otherwise
*/
fun Context.scheduleNotifications(minutes: Long): Boolean {
- val scheduler = getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
+ val scheduler = getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler?
+ if (scheduler == null) {
+ L.e("JobScheduler not found; cannot schedule notifications")
+ return false
+ }
scheduler.cancel(NOTIFICATION_PERIODIC_JOB)
if (minutes < 0L) return true
val serviceComponent = ComponentName(this, NotificationService::class.java)
@@ -190,7 +194,11 @@ const val NOTIFICATION_JOB_NOW = 6
* Run notification job right now
*/
fun Context.fetchNotifications(): Boolean {
- val scheduler = getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler? ?: return false
+ val scheduler = getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler?
+ if (scheduler == null) {
+ L.e("JobScheduler not found")
+ return false
+ }
val serviceComponent = ComponentName(this, NotificationService::class.java)
val builder = JobInfo.Builder(NOTIFICATION_JOB_NOW, serviceComponent)
.setMinimumLatency(0L)