diff options
author | Amith Dsouza <amithds@google.com> | 2022-08-09 22:55:00 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-08-09 22:55:00 +0000 |
commit | 9e503465e11ddc8c44a87b51defaa393a8858373 (patch) | |
tree | 73f2684507c36d4187a8c145f769e0902f8f2527 | |
parent | e78953922e239dd05c4d5aa46c416933608c1ccf (diff) | |
parent | a35d6ae6837a62fcdf5d0123c3d23bfda559d5e9 (diff) | |
download | DeskClock-9e503465e11ddc8c44a87b51defaa393a8858373.tar.gz |
Merge changes I976533b0,I1528bb3e am: a35d6ae683temp_sam_242648940
Original change: https://android-review.googlesource.com/c/platform/packages/apps/DeskClock/+/2180716
Change-Id: Iaee36919acbb9f80d651e4a3d99399093b5addc1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | Android.bp | 2 | ||||
-rw-r--r-- | AndroidManifest.xml | 11 | ||||
-rw-r--r-- | OWNERS | 2 | ||||
-rw-r--r-- | src/com/android/deskclock/data/TimerModel.kt | 25 | ||||
-rw-r--r-- | src/com/android/deskclock/data/TimerNotificationBuilder.kt | 13 |
5 files changed, 33 insertions, 20 deletions
diff --git a/Android.bp b/Android.bp index a6e42742e..235bad983 100644 --- a/Android.bp +++ b/Android.bp @@ -7,7 +7,7 @@ android_app { name: "DeskClock", resource_dirs: ["res"], sdk_version: "current", - target_sdk_version: "24", + target_sdk_version: "30", overrides: [ "AlarmClock", ], diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 963afe474..04a53e479 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -22,7 +22,7 @@ <original-package android:name="com.android.alarmclock" /> <original-package android:name="com.android.deskclock" /> - <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="24" /> + <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="30" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> @@ -35,15 +35,6 @@ <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> - <!-- WRITE_SETTINGS is required to record the upcoming alarm prior to L --> - <uses-permission - android:name="android.permission.WRITE_SETTINGS" - android:maxSdkVersion="19" /> - <!-- READ_PHONE_STATE is required to determine when a phone call exists prior to M --> - <uses-permission - android:name="android.permission.READ_PHONE_STATE" - android:maxSdkVersion="22" /> - <application android:name=".DeskClockApplication" android:allowBackup="false" @@ -1,3 +1,5 @@ # This project has no significant updates recently. # Please update this list if you find better candidates. +iankaz@google.com +amithds@google.com rtenneti@google.com diff --git a/src/com/android/deskclock/data/TimerModel.kt b/src/com/android/deskclock/data/TimerModel.kt index 08f6fb1ef..dae15102e 100644 --- a/src/com/android/deskclock/data/TimerModel.kt +++ b/src/com/android/deskclock/data/TimerModel.kt @@ -683,12 +683,6 @@ internal class TimerModel( * when the application is not open. */ fun updateNotification() { - // Notifications should be hidden if the app is open. - if (mNotificationModel.isApplicationInForeground) { - mNotificationManager.cancel(mNotificationModel.unexpiredTimerNotificationId) - return - } - // Filter the timers to just include unexpired ones. val unexpired: MutableList<Timer> = mutableListOf() for (timer in mutableTimers) { @@ -699,18 +693,33 @@ internal class TimerModel( // If no unexpired timers exist, cancel the notification. if (unexpired.isEmpty()) { - mNotificationManager.cancel(mNotificationModel.unexpiredTimerNotificationId) + if(mNotificationBuilder.isChannelCreated(mNotificationManager)) { + LogUtils.i("Cancelling Notifications when list is empty") + mNotificationManager.cancel(mNotificationModel.unexpiredTimerNotificationId) + } return } // Sort the unexpired timers to locate the next one scheduled to expire. unexpired.sortWith(Timer.EXPIRY_COMPARATOR) + //Build and setup a channel for notifications + LogUtils.i("Channel being setup!!!!") // Otherwise build and post a notification reflecting the latest unexpired timers. val notification: Notification = mNotificationBuilder.build(mContext, mNotificationModel, unexpired) val notificationId = mNotificationModel.unexpiredTimerNotificationId mNotificationBuilder.buildChannel(mContext, mNotificationManager) + + // Notifications should be hidden if the app is open. + if (mNotificationModel.isApplicationInForeground) { + if(mNotificationBuilder.isChannelCreated(mNotificationManager)) { + LogUtils.i("Cancelling notifications when the app is in foreground") + mNotificationManager.cancel(mNotificationModel.unexpiredTimerNotificationId) + } + return + } + mNotificationManager.notify(notificationId, notification) } @@ -806,4 +815,4 @@ internal class TimerModel( } } } -}
\ No newline at end of file +} diff --git a/src/com/android/deskclock/data/TimerNotificationBuilder.kt b/src/com/android/deskclock/data/TimerNotificationBuilder.kt index 98e2a92e2..66601cf82 100644 --- a/src/com/android/deskclock/data/TimerNotificationBuilder.kt +++ b/src/com/android/deskclock/data/TimerNotificationBuilder.kt @@ -50,6 +50,17 @@ import com.android.deskclock.timer.TimerService */ internal class TimerNotificationBuilder { + fun isChannelCreated(notificationManager: NotificationManagerCompat): Boolean { + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + if(notificationManager.getNotificationChannelCompat(TIMER_MODEL_NOTIFICATION_CHANNEL_ID) != null) { + return true + } else { + return false + } + } + return false + } + fun buildChannel(context: Context, notificationManager: NotificationManagerCompat) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { val channel = NotificationChannel( @@ -420,4 +431,4 @@ internal class TimerNotificationBuilder { return SystemClock.elapsedRealtime() + adjustedRemaining } } -}
\ No newline at end of file +} |