Skip to content

Commit

Permalink
v1.2.1-rc1: remove old channels and updated boot receiver permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Javinator9889 committed Dec 10, 2020
1 parent 80a3438 commit f894c34
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@

<receiver
android:name=".jobs.BootCompletedJob"
android:enabled="true">
android:enabled="true"
android:exported="true">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ import com.javinator9889.handwashingreminder.jobs.alarms.AlarmHandler
import com.javinator9889.handwashingreminder.utils.Preferences
import timber.log.Timber

const val ACTION_QBP = "android.intent.action.QUICKBOOT_POWERON"

class BootCompletedJob : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
if (intent.action in setOf(Intent.ACTION_BOOT_COMPLETED, ACTION_QBP)) {
val activityHandler = ActivityHandler.getInstance(context)
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
val preferences =
PreferenceManager.getDefaultSharedPreferences(context)
if (preferences.getBoolean(
Preferences.ACTIVITY_TRACKING_ENABLED,
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
*/
package com.javinator9889.handwashingreminder.jobs

import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.javinator9889.handwashingreminder.BuildConfig
import com.javinator9889.handwashingreminder.jobs.alarms.AlarmHandler
import com.javinator9889.handwashingreminder.utils.ACTIVITY_CHANNEL_ID
import com.javinator9889.handwashingreminder.utils.AndroidVersion
import com.javinator9889.handwashingreminder.utils.isAtLeast
import timber.log.Timber

class UpdateReceiver : BroadcastReceiver() {
Expand All @@ -31,6 +36,27 @@ class UpdateReceiver : BroadcastReceiver() {
with(AlarmHandler(context)) {
scheduleAllAlarms()
}
// Here, we need to remove all the notifications channels
// previously created as they have changed
if (BuildConfig.VERSION_CODE == 141 && isAtLeast(AndroidVersion.O)) {
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
for (id in setOf(
"notifications:breakfast",
"notifications:lunch",
"notifications:dinner",
ACTIVITY_CHANNEL_ID
)) {
notificationManager.deleteNotificationChannel(id)
}
for (id in setOf(
"alarms:breakfast",
"alarms:lunch",
"alarms:dinner"
)) {
notificationManager.deleteNotificationChannelGroup(id)
}
}
}
}
}

0 comments on commit f894c34

Please sign in to comment.