From 93b9dbf95ddb7e615ac08dd8c3ae3efc42347c20 Mon Sep 17 00:00:00 2001 From: Afsar Pasha <25363752+Afsar-Pasha@users.noreply.github.com> Date: Sat, 17 Aug 2019 16:23:41 +0000 Subject: [PATCH 1/7] Update AlarmService.java --- .../io/flutter/plugins/androidalarmmanager/AlarmService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/android_alarm_manager/android/src/main/java/io/flutter/plugins/androidalarmmanager/AlarmService.java b/packages/android_alarm_manager/android/src/main/java/io/flutter/plugins/androidalarmmanager/AlarmService.java index 16a6375a8070..f85bd37951eb 100644 --- a/packages/android_alarm_manager/android/src/main/java/io/flutter/plugins/androidalarmmanager/AlarmService.java +++ b/packages/android_alarm_manager/android/src/main/java/io/flutter/plugins/androidalarmmanager/AlarmService.java @@ -211,7 +211,7 @@ public void notImplemented() { // provided. // TODO(mattcarroll): consider giving a method name anyway for the purpose of developer discoverability // when reading the source code. Especially on the Dart side. - sBackgroundChannel.invokeMethod("", new Object[] {callbackHandle}, result); + sBackgroundChannel.invokeMethod("", new Object[] {callbackHandle, intent.getIntExtra("id", -1)}, result); } private static void scheduleAlarm( @@ -242,6 +242,7 @@ private static void scheduleAlarm( // Create an Intent for the alarm and set the desired Dart callback handle. Intent alarm = new Intent(context, AlarmBroadcastReceiver.class); + alarm.putExtra("id", requestCode); alarm.putExtra("callbackHandle", callbackHandle); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, requestCode, alarm, PendingIntent.FLAG_UPDATE_CURRENT); From d0707ffc1ac85121264c6f682f71f0954790edb5 Mon Sep 17 00:00:00 2001 From: Afsar Pasha <25363752+Afsar-Pasha@users.noreply.github.com> Date: Sat, 17 Aug 2019 16:32:50 +0000 Subject: [PATCH 2/7] Update android_alarm_manager.dart --- .../lib/android_alarm_manager.dart | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/packages/android_alarm_manager/lib/android_alarm_manager.dart b/packages/android_alarm_manager/lib/android_alarm_manager.dart index 05ead109c36f..22e642fe8703 100644 --- a/packages/android_alarm_manager/lib/android_alarm_manager.dart +++ b/packages/android_alarm_manager/lib/android_alarm_manager.dart @@ -38,7 +38,13 @@ void _alarmManagerCallbackDispatcher() { print('Fatal: could not find callback'); exit(-1); } - closure(); + + if (closure is Function()) { + closure(); + } else if (closure is Function(int)) { + final int id = args[1]; + closure(id); + } }); // Once we've finished initializing, let the native portion of the plugin @@ -80,9 +86,13 @@ class AndroidAlarmManager { /// `callback` must be either a top-level function or a static method from a /// class. /// + /// `callback` can be `Function()` or `Function(int)` + /// /// The timer is uniquely identified by `id`. Calling this function again /// again with the same `id` will cancel and replace the existing timer. /// + /// `id` will passed to `callback` if it is of type `Function(int)` + /// /// If `alarmClock` is passed as `true`, the timer will be created with /// Android's `AlarmManagerCompat.setAlarmClock`. /// @@ -107,7 +117,7 @@ class AndroidAlarmManager { static Future oneShot( Duration delay, int id, - dynamic Function() callback, { + Function callback, { bool alarmClock = false, bool allowWhileIdle = false, bool exact = false, @@ -134,9 +144,13 @@ class AndroidAlarmManager { /// `callback` must be either a top-level function or a static method from a /// class. /// + /// `callback` can be `Function()` or `Function(int)` + /// /// The timer is uniquely identified by `id`. Calling this function again /// again with the same `id` will cancel and replace the existing timer. /// + /// `id` will passed to `callback` if it is of type `Function(int)` + /// /// If `alarmClock` is passed as `true`, the timer will be created with /// Android's `AlarmManagerCompat.setAlarmClock`. /// @@ -161,13 +175,15 @@ class AndroidAlarmManager { static Future oneShotAt( DateTime time, int id, - dynamic Function() callback, { + Function callback, { bool alarmClock = false, bool allowWhileIdle = false, bool exact = false, bool wakeup = false, bool rescheduleOnReboot = false, }) async { + assert(callback is Function() || callback is Function(int)); + assert(id.bitLength < 32); final int startMillis = time.millisecondsSinceEpoch; final CallbackHandle handle = PluginUtilities.getCallbackHandle(callback); if (handle == null) { @@ -196,9 +212,13 @@ class AndroidAlarmManager { /// `callback` must be either a top-level function or a static method from a /// class. /// - /// The repeating timer is uniquely identified by `id`. Calling this function + /// `callback` can be `Function()` or `Function(int)` + /// + /// The timer is uniquely identified by `id`. Calling this function again /// again with the same `id` will cancel and replace the existing timer. /// + /// `id` will passed to `callback` if it is of type `Function(int)` + /// /// If `startAt` is passed, the timer will first go off at that time and /// subsequently run with period `duration`. /// @@ -219,12 +239,14 @@ class AndroidAlarmManager { static Future periodic( Duration duration, int id, - dynamic Function() callback, { + Function callback, { DateTime startAt, bool exact = false, bool wakeup = false, bool rescheduleOnReboot = false, }) async { + assert(callback is Function() || callback is Function(int)); + assert(id.bitLength < 32); final int now = DateTime.now().millisecondsSinceEpoch; final int period = duration.inMilliseconds; final int first = From 2a71aa8157f7fe70d67e1203971be1b400e3a62d Mon Sep 17 00:00:00 2001 From: Afsar Pasha <25363752+Afsar-Pasha@users.noreply.github.com> Date: Sat, 17 Aug 2019 16:33:34 +0000 Subject: [PATCH 3/7] Update pubspec.yaml --- packages/android_alarm_manager/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/android_alarm_manager/pubspec.yaml b/packages/android_alarm_manager/pubspec.yaml index b164970fcc97..9742dae02f81 100644 --- a/packages/android_alarm_manager/pubspec.yaml +++ b/packages/android_alarm_manager/pubspec.yaml @@ -1,7 +1,7 @@ name: android_alarm_manager description: Flutter plugin for accessing the Android AlarmManager service, and running Dart code in the background when alarms fire. -version: 0.4.3 +version: 0.4.4 author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/android_alarm_manager From bfb95b17c870680d39bde6467505675a58b9604d Mon Sep 17 00:00:00 2001 From: Afsar Pasha <25363752+Afsar-Pasha@users.noreply.github.com> Date: Sat, 17 Aug 2019 16:37:13 +0000 Subject: [PATCH 4/7] Update CHANGELOG.md --- packages/android_alarm_manager/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/android_alarm_manager/CHANGELOG.md b/packages/android_alarm_manager/CHANGELOG.md index f7537a5b62f5..7da9c3d6db89 100644 --- a/packages/android_alarm_manager/CHANGELOG.md +++ b/packages/android_alarm_manager/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.4.4 + +* Now `id` will passed to `callback` if it is of type `Function(int)` + ## 0.4.3 * Added `oneShotAt` method to run `callback` at a given DateTime `time`. From 616c0e5c26a48c9f652079a0f5f7e3948539de31 Mon Sep 17 00:00:00 2001 From: Afsar Pasha <25363752+Afsar-Pasha@users.noreply.github.com> Date: Sat, 17 Aug 2019 16:47:01 +0000 Subject: [PATCH 5/7] Update android_alarm_manager.dart --- .../android_alarm_manager/lib/android_alarm_manager.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/android_alarm_manager/lib/android_alarm_manager.dart b/packages/android_alarm_manager/lib/android_alarm_manager.dart index 22e642fe8703..b90823e5c9d4 100644 --- a/packages/android_alarm_manager/lib/android_alarm_manager.dart +++ b/packages/android_alarm_manager/lib/android_alarm_manager.dart @@ -89,7 +89,7 @@ class AndroidAlarmManager { /// `callback` can be `Function()` or `Function(int)` /// /// The timer is uniquely identified by `id`. Calling this function again - /// again with the same `id` will cancel and replace the existing timer. + /// with the same `id` will cancel and replace the existing timer. /// /// `id` will passed to `callback` if it is of type `Function(int)` /// @@ -147,7 +147,7 @@ class AndroidAlarmManager { /// `callback` can be `Function()` or `Function(int)` /// /// The timer is uniquely identified by `id`. Calling this function again - /// again with the same `id` will cancel and replace the existing timer. + /// with the same `id` will cancel and replace the existing timer. /// /// `id` will passed to `callback` if it is of type `Function(int)` /// @@ -214,7 +214,7 @@ class AndroidAlarmManager { /// /// `callback` can be `Function()` or `Function(int)` /// - /// The timer is uniquely identified by `id`. Calling this function again + /// The repeating timer is uniquely identified by `id`. Calling this function /// again with the same `id` will cancel and replace the existing timer. /// /// `id` will passed to `callback` if it is of type `Function(int)` From 43cbf3c8268d080ea8947ebf9f1df8b37aa26b5f Mon Sep 17 00:00:00 2001 From: Afsar Pasha <25363752+Afsar-Pasha@users.noreply.github.com> Date: Sat, 17 Aug 2019 18:29:49 +0000 Subject: [PATCH 6/7] Update AlarmService.java --- .../io/flutter/plugins/androidalarmmanager/AlarmService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/android_alarm_manager/android/src/main/java/io/flutter/plugins/androidalarmmanager/AlarmService.java b/packages/android_alarm_manager/android/src/main/java/io/flutter/plugins/androidalarmmanager/AlarmService.java index f85bd37951eb..bb3d0c8db102 100644 --- a/packages/android_alarm_manager/android/src/main/java/io/flutter/plugins/androidalarmmanager/AlarmService.java +++ b/packages/android_alarm_manager/android/src/main/java/io/flutter/plugins/androidalarmmanager/AlarmService.java @@ -211,7 +211,8 @@ public void notImplemented() { // provided. // TODO(mattcarroll): consider giving a method name anyway for the purpose of developer discoverability // when reading the source code. Especially on the Dart side. - sBackgroundChannel.invokeMethod("", new Object[] {callbackHandle, intent.getIntExtra("id", -1)}, result); + sBackgroundChannel.invokeMethod( + "", new Object[] {callbackHandle, intent.getIntExtra("id", -1)}, result); } private static void scheduleAlarm( From 41e75c3fa8c406066d364d7fbade0ba8db2a9aa9 Mon Sep 17 00:00:00 2001 From: Afsar Pasha <25363752+Afsar-Pasha@users.noreply.github.com> Date: Mon, 19 Aug 2019 17:41:12 +0000 Subject: [PATCH 7/7] Update packages/android_alarm_manager/CHANGELOG.md Co-Authored-By: Charles Crete --- packages/android_alarm_manager/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/android_alarm_manager/CHANGELOG.md b/packages/android_alarm_manager/CHANGELOG.md index 7da9c3d6db89..2bb200dcc2fc 100644 --- a/packages/android_alarm_manager/CHANGELOG.md +++ b/packages/android_alarm_manager/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.4.4 -* Now `id` will passed to `callback` if it is of type `Function(int)` +* Add `id` to `callback` if it is of type `Function(int)` ## 0.4.3