diff --git a/uhabits-android/build.gradle.kts b/uhabits-android/build.gradle.kts
index f4ee9b9cf..8e7103475 100644
--- a/uhabits-android/build.gradle.kts
+++ b/uhabits-android/build.gradle.kts
@@ -32,13 +32,13 @@ tasks.compileLint {
android {
- compileSdk = 30
+ compileSdk = 31
defaultConfig {
versionCode = 20003
versionName = "2.0.3"
minSdk = 23
- targetSdk = 30
+ targetSdk = 31
applicationId = "org.isoron.uhabits"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
diff --git a/uhabits-android/src/main/AndroidManifest.xml b/uhabits-android/src/main/AndroidManifest.xml
index b5d06f181..3b0851207 100644
--- a/uhabits-android/src/main/AndroidManifest.xml
+++ b/uhabits-android/src/main/AndroidManifest.xml
@@ -17,9 +17,10 @@
~ with this program. If not, see .
-->
+
+
@@ -48,11 +49,11 @@
android:name=".activities.habits.list.ListHabitsActivity"
android:exported="true"
android:label="@string/main_activity_title"
- android:launchMode="singleTop">
-
+ android:launchMode="singleTop" />
@@ -85,6 +86,7 @@
@@ -93,6 +95,7 @@
@@ -101,6 +104,7 @@
@@ -117,9 +121,10 @@
@@ -128,13 +133,14 @@
@@ -152,6 +158,7 @@
@@ -164,6 +171,7 @@
@@ -176,6 +184,7 @@
@@ -188,6 +197,7 @@
@@ -200,6 +210,7 @@
@@ -210,13 +221,17 @@
android:resource="@xml/widget_target_info" />
-
+
-
+
@@ -267,7 +282,7 @@
+ android:exported="false">
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt b/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt
index 5a4c79f1d..089af4af2 100644
--- a/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt
+++ b/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt
@@ -25,8 +25,6 @@ import android.app.AlarmManager.RTC_WAKEUP
import android.app.PendingIntent
import android.content.Context
import android.content.Context.ALARM_SERVICE
-import android.os.Build.VERSION.SDK_INT
-import android.os.Build.VERSION_CODES.M
import android.util.Log
import org.isoron.uhabits.core.AppScope
import org.isoron.uhabits.core.models.Habit
@@ -58,10 +56,7 @@ class IntentScheduler
)
return SchedulerResult.IGNORED
}
- if (SDK_INT >= M)
- manager.setExactAndAllowWhileIdle(alarmType, timestamp, intent)
- else
- manager.setExact(alarmType, timestamp, intent)
+ manager.setExactAndAllowWhileIdle(alarmType, timestamp, intent)
return SchedulerResult.OK
}
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/intents/PendingIntentFactory.kt b/uhabits-android/src/main/java/org/isoron/uhabits/intents/PendingIntentFactory.kt
index 5df329a95..841fa55e6 100644
--- a/uhabits-android/src/main/java/org/isoron/uhabits/intents/PendingIntentFactory.kt
+++ b/uhabits-android/src/main/java/org/isoron/uhabits/intents/PendingIntentFactory.kt
@@ -20,6 +20,7 @@
package org.isoron.uhabits.intents
import android.app.PendingIntent
+import android.app.PendingIntent.FLAG_IMMUTABLE
import android.app.PendingIntent.FLAG_UPDATE_CURRENT
import android.app.PendingIntent.getBroadcast
import android.content.Context
@@ -49,7 +50,7 @@ class PendingIntentFactory
action = WidgetReceiver.ACTION_ADD_REPETITION
if (timestamp != null) putExtra("timestamp", timestamp.unixTime)
},
- FLAG_UPDATE_CURRENT
+ FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT
)
fun dismissNotification(habit: Habit): PendingIntent =
@@ -60,7 +61,7 @@ class PendingIntentFactory
action = WidgetReceiver.ACTION_DISMISS_REMINDER
data = Uri.parse(habit.uriString)
},
- FLAG_UPDATE_CURRENT
+ FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT
)
fun removeRepetition(habit: Habit, timestamp: Timestamp?): PendingIntent =
@@ -72,7 +73,7 @@ class PendingIntentFactory
data = Uri.parse(habit.uriString)
if (timestamp != null) putExtra("timestamp", timestamp.unixTime)
},
- FLAG_UPDATE_CURRENT
+ FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT
)
fun showHabit(habit: Habit): PendingIntent =
@@ -84,7 +85,7 @@ class PendingIntentFactory
habit
)
)
- .getPendingIntent(0, FLAG_UPDATE_CURRENT)!!
+ .getPendingIntent(0, FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT)!!
fun showReminder(
habit: Habit,
@@ -100,7 +101,7 @@ class PendingIntentFactory
putExtra("timestamp", timestamp)
putExtra("reminderTime", reminderTime)
},
- FLAG_UPDATE_CURRENT
+ FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT
)
fun snoozeNotification(habit: Habit): PendingIntent =
@@ -111,7 +112,7 @@ class PendingIntentFactory
data = Uri.parse(habit.uriString)
action = ReminderReceiver.ACTION_SNOOZE_REMINDER
},
- FLAG_UPDATE_CURRENT
+ FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT
)
fun toggleCheckmark(habit: Habit, timestamp: Long?): PendingIntent =
@@ -123,7 +124,7 @@ class PendingIntentFactory
action = WidgetReceiver.ACTION_TOGGLE_REPETITION
if (timestamp != null) putExtra("timestamp", timestamp)
},
- FLAG_UPDATE_CURRENT
+ FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT
)
fun setNumericalValue(
@@ -142,7 +143,7 @@ class PendingIntentFactory
putExtra("numericalValue", numericalValue)
if (timestamp != null) putExtra("timestamp", timestamp)
},
- FLAG_UPDATE_CURRENT
+ FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT
)
fun updateWidgets(): PendingIntent =
@@ -152,6 +153,6 @@ class PendingIntentFactory
Intent(context, WidgetReceiver::class.java).apply {
action = WidgetReceiver.ACTION_UPDATE_WIDGETS_VALUE
},
- FLAG_UPDATE_CURRENT
+ FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT
)
}
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/notifications/AndroidNotificationTray.kt b/uhabits-android/src/main/java/org/isoron/uhabits/notifications/AndroidNotificationTray.kt
index 04f3d8d92..3721f04d5 100644
--- a/uhabits-android/src/main/java/org/isoron/uhabits/notifications/AndroidNotificationTray.kt
+++ b/uhabits-android/src/main/java/org/isoron/uhabits/notifications/AndroidNotificationTray.kt
@@ -153,13 +153,15 @@ class AndroidNotificationTray
if (preferences.shouldMakeNotificationsLed())
builder.setLights(Color.RED, 1000, 1000)
- val snoozeAction = Action(
- R.drawable.ic_action_snooze,
- context.getString(R.string.snooze),
- pendingIntents.snoozeNotification(habit)
- )
- wearableExtender.addAction(snoozeAction)
- builder.addAction(snoozeAction)
+ if (SDK_INT < Build.VERSION_CODES.S) {
+ val snoozeAction = Action(
+ R.drawable.ic_action_snooze,
+ context.getString(R.string.snooze),
+ pendingIntents.snoozeNotification(habit)
+ )
+ wearableExtender.addAction(snoozeAction)
+ builder.addAction(snoozeAction)
+ }
builder.extend(wearableExtender)
return builder.build()
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/receivers/ReminderReceiver.kt b/uhabits-android/src/main/java/org/isoron/uhabits/receivers/ReminderReceiver.kt
index 951b46ae8..6eb10dc7e 100644
--- a/uhabits-android/src/main/java/org/isoron/uhabits/receivers/ReminderReceiver.kt
+++ b/uhabits-android/src/main/java/org/isoron/uhabits/receivers/ReminderReceiver.kt
@@ -22,6 +22,8 @@ import android.content.BroadcastReceiver
import android.content.ContentUris
import android.content.Context
import android.content.Intent
+import android.os.Build
+import android.os.Build.VERSION.SDK_INT
import android.util.Log
import org.isoron.uhabits.HabitsApplication
import org.isoron.uhabits.core.models.Habit
@@ -76,8 +78,21 @@ class ReminderReceiver : BroadcastReceiver() {
}
ACTION_SNOOZE_REMINDER -> {
if (habit == null) return
- Log.d("ReminderReceiver", String.format("onSnoozePressed habit=%d", habit.id))
- reminderController.onSnoozePressed(habit, context)
+ if (SDK_INT < Build.VERSION_CODES.S) {
+ Log.d(
+ "ReminderReceiver",
+ String.format("onSnoozePressed habit=%d", habit.id)
+ )
+ reminderController.onSnoozePressed(habit, context)
+ } else {
+ Log.w(
+ "ReminderReceiver",
+ String.format(
+ "onSnoozePressed habit=%d, should be deactivated in recent versions.",
+ habit.id
+ )
+ )
+ }
}
Intent.ACTION_BOOT_COMPLETED -> {
Log.d("ReminderReceiver", "onBootCompleted")