6
6
7
7
import android .content .Context ;
8
8
import android .support .annotation .NonNull ;
9
- import android .support .annotation .Nullable ;
10
9
11
10
import io .flutter .app .FlutterPluginRegistry ;
12
11
import io .flutter .embedding .engine .dart .DartExecutor ;
13
12
import io .flutter .embedding .engine .renderer .FlutterRenderer ;
13
+ import io .flutter .embedding .engine .systemchannels .AccessibilityChannel ;
14
+ import io .flutter .embedding .engine .systemchannels .KeyEventChannel ;
15
+ import io .flutter .embedding .engine .systemchannels .LifecycleChannel ;
16
+ import io .flutter .embedding .engine .systemchannels .LocalizationChannel ;
17
+ import io .flutter .embedding .engine .systemchannels .NavigationChannel ;
18
+ import io .flutter .embedding .engine .systemchannels .PlatformChannel ;
19
+ import io .flutter .embedding .engine .systemchannels .SettingsChannel ;
20
+ import io .flutter .embedding .engine .systemchannels .SystemChannel ;
21
+ import io .flutter .embedding .engine .systemchannels .TextInputChannel ;
14
22
15
23
/**
16
24
* A single Flutter execution environment.
35
43
* {@link FlutterRenderer} and then attach a {@link FlutterRenderer.RenderSurface}. Consider using
36
44
* a {@link io.flutter.embedding.android.FlutterView} as a {@link FlutterRenderer.RenderSurface}.
37
45
*/
46
+ // TODO(mattcarroll): re-evaluate system channel APIs - some are not well named or differentiated
38
47
public class FlutterEngine {
39
48
private static final String TAG = "FlutterEngine" ;
40
49
@@ -44,10 +53,29 @@ public class FlutterEngine {
44
53
private final FlutterRenderer renderer ;
45
54
@ NonNull
46
55
private final DartExecutor dartExecutor ;
47
- // TODO(mattcarroll): integrate system channels with FlutterEngine
48
56
@ NonNull
49
57
private final FlutterPluginRegistry pluginRegistry ;
50
58
59
+ // System channels.
60
+ @ NonNull
61
+ private final AccessibilityChannel accessibilityChannel ;
62
+ @ NonNull
63
+ private final KeyEventChannel keyEventChannel ;
64
+ @ NonNull
65
+ private final LifecycleChannel lifecycleChannel ;
66
+ @ NonNull
67
+ private final LocalizationChannel localizationChannel ;
68
+ @ NonNull
69
+ private final NavigationChannel navigationChannel ;
70
+ @ NonNull
71
+ private final PlatformChannel platformChannel ;
72
+ @ NonNull
73
+ private final SettingsChannel settingsChannel ;
74
+ @ NonNull
75
+ private final SystemChannel systemChannel ;
76
+ @ NonNull
77
+ private final TextInputChannel textInputChannel ;
78
+
51
79
private final EngineLifecycleListener engineLifecycleListener = new EngineLifecycleListener () {
52
80
@ SuppressWarnings ("unused" )
53
81
public void onPreEngineRestart () {
@@ -82,6 +110,16 @@ public FlutterEngine(@NonNull Context context) {
82
110
// TODO(mattcarroll): FlutterRenderer is temporally coupled to attach(). Remove that coupling if possible.
83
111
this .renderer = new FlutterRenderer (flutterJNI );
84
112
113
+ accessibilityChannel = new AccessibilityChannel (dartExecutor );
114
+ keyEventChannel = new KeyEventChannel (dartExecutor );
115
+ lifecycleChannel = new LifecycleChannel (dartExecutor );
116
+ localizationChannel = new LocalizationChannel (dartExecutor );
117
+ navigationChannel = new NavigationChannel (dartExecutor );
118
+ platformChannel = new PlatformChannel (dartExecutor );
119
+ settingsChannel = new SettingsChannel (dartExecutor );
120
+ systemChannel = new SystemChannel (dartExecutor );
121
+ textInputChannel = new TextInputChannel (dartExecutor );
122
+
85
123
this .pluginRegistry = new FlutterPluginRegistry (this , context );
86
124
}
87
125
@@ -150,6 +188,80 @@ public FlutterRenderer getRenderer() {
150
188
return renderer ;
151
189
}
152
190
191
+ /**
192
+ * System channel that sends accessibility requests and events from Flutter to Android.
193
+ */
194
+ @ NonNull
195
+ public AccessibilityChannel getAccessibilityChannel () {
196
+ return accessibilityChannel ;
197
+ }
198
+
199
+ /**
200
+ * System channel that sends key events from Android to Flutter.
201
+ */
202
+ @ NonNull
203
+ public KeyEventChannel getKeyEventChannel () {
204
+ return keyEventChannel ;
205
+ }
206
+
207
+ /**
208
+ * System channel that sends Android lifecycle events to Flutter.
209
+ */
210
+ @ NonNull
211
+ public LifecycleChannel getLifecycleChannel () {
212
+ return lifecycleChannel ;
213
+ }
214
+
215
+ /**
216
+ * System channel that sends locale data from Android to Flutter.
217
+ */
218
+ @ NonNull
219
+ public LocalizationChannel getLocalizationChannel () {
220
+ return localizationChannel ;
221
+ }
222
+
223
+ /**
224
+ * System channel that sends Flutter navigation commands from Android to Flutter.
225
+ */
226
+ @ NonNull
227
+ public NavigationChannel getNavigationChannel () {
228
+ return navigationChannel ;
229
+ }
230
+
231
+ /**
232
+ * System channel that sends platform-oriented requests and information to Flutter,
233
+ * e.g., requests to play sounds, requests for haptics, system chrome settings, etc.
234
+ */
235
+ @ NonNull
236
+ public PlatformChannel getPlatformChannel () {
237
+ return platformChannel ;
238
+ }
239
+
240
+ /**
241
+ * System channel that sends platform/user settings from Android to Flutter, e.g.,
242
+ * time format, scale factor, etc.
243
+ */
244
+ @ NonNull
245
+ public SettingsChannel getSettingsChannel () {
246
+ return settingsChannel ;
247
+ }
248
+
249
+ /**
250
+ * System channel that sends memory pressure warnings from Android to Flutter.
251
+ */
252
+ @ NonNull
253
+ public SystemChannel getSystemChannel () {
254
+ return systemChannel ;
255
+ }
256
+
257
+ /**
258
+ * System channel that sends and receives text input requests and state.
259
+ */
260
+ @ NonNull
261
+ public TextInputChannel getTextInputChannel () {
262
+ return textInputChannel ;
263
+ }
264
+
153
265
// TODO(mattcarroll): propose a robust story for plugin backward compability and future facing API.
154
266
@ NonNull
155
267
public FlutterPluginRegistry getPluginRegistry () {
0 commit comments