-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Updated android_alarm_manager to work after engine refactor.
#642
Changes from all commits
0808e48
e1992ec
e6b6160
cda6d7b
9c93bd3
3d736df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,9 +25,16 @@ public static void registerWith(Registrar registrar) { | |
| registrar.messenger(), | ||
| "plugins.flutter.io/android_alarm_manager", | ||
| JSONMethodCodec.INSTANCE); | ||
| final MethodChannel backgroundChannel = | ||
| new MethodChannel( | ||
| registrar.messenger(), | ||
| "plugins.flutter.io/android_alarm_manager_background", | ||
| JSONMethodCodec.INSTANCE); | ||
| AndroidAlarmManagerPlugin plugin = new AndroidAlarmManagerPlugin(registrar.context()); | ||
| channel.setMethodCallHandler(plugin); | ||
| backgroundChannel.setMethodCallHandler(plugin); | ||
| registrar.addViewDestroyListener(plugin); | ||
| AlarmService.setBackgroundChannel(backgroundChannel); | ||
| } | ||
|
|
||
| private Context mContext; | ||
|
|
@@ -41,7 +48,12 @@ public void onMethodCall(MethodCall call, Result result) { | |
| String method = call.method; | ||
| Object arguments = call.arguments; | ||
| try { | ||
| if (method.equals("Alarm.periodic")) { | ||
| if (method.equals("AlarmService.start")) { | ||
| startService((JSONArray) arguments); | ||
| result.success(true); | ||
| } else if (method.equals("AlarmService.initialized")) { | ||
| AlarmService.onInitialized(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bkonyi I think we're missing the invocation of the result callback? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, looks like it. I don't think it causes any problems though, does it? I don't believe the background isolate cares if it gets a response here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just going through the fun task of auditing all of our invokeMethod calls as part of reviewing #1365 and was confused when looking at this. I'm guessing it will result in the future here never completing: Probably best to clean it up anyway. |
||
| } else if (method.equals("Alarm.periodic")) { | ||
| periodic((JSONArray) arguments); | ||
| result.success(true); | ||
| } else if (method.equals("Alarm.oneShot")) { | ||
|
|
@@ -58,13 +70,18 @@ public void onMethodCall(MethodCall call, Result result) { | |
| } | ||
| } | ||
|
|
||
| private void startService(JSONArray arguments) throws JSONException { | ||
| long callbackHandle = arguments.getLong(0); | ||
| AlarmService.startAlarmService(mContext, callbackHandle); | ||
| } | ||
|
|
||
| private void oneShot(JSONArray arguments) throws JSONException { | ||
| int requestCode = arguments.getInt(0); | ||
| boolean exact = arguments.getBoolean(1); | ||
| boolean wakeup = arguments.getBoolean(2); | ||
| long startMillis = arguments.getLong(3); | ||
| String entrypoint = arguments.getString(4); | ||
| AlarmService.setOneShot(mContext, requestCode, exact, wakeup, startMillis, entrypoint); | ||
| long callbackHandle = arguments.getLong(4); | ||
| AlarmService.setOneShot(mContext, requestCode, exact, wakeup, startMillis, callbackHandle); | ||
| } | ||
|
|
||
| private void periodic(JSONArray arguments) throws JSONException { | ||
|
|
@@ -73,9 +90,9 @@ private void periodic(JSONArray arguments) throws JSONException { | |
| boolean wakeup = arguments.getBoolean(2); | ||
| long startMillis = arguments.getLong(3); | ||
| long intervalMillis = arguments.getLong(4); | ||
| String entrypoint = arguments.getString(5); | ||
| long callbackHandle = arguments.getLong(5); | ||
| AlarmService.setPeriodic( | ||
| mContext, requestCode, exact, wakeup, startMillis, intervalMillis, entrypoint); | ||
| mContext, requestCode, exact, wakeup, startMillis, intervalMillis, callbackHandle); | ||
| } | ||
|
|
||
| private void cancel(JSONArray arguments) throws JSONException { | ||
|
|
@@ -85,6 +102,6 @@ private void cancel(JSONArray arguments) throws JSONException { | |
|
|
||
| @Override | ||
| public boolean onViewDestroy(FlutterNativeView nativeView) { | ||
| return AlarmService.setSharedFlutterView(nativeView); | ||
| return AlarmService.setBackgroundFlutterView(nativeView); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.