66
77import android .content .Context ;
88import android .support .annotation .NonNull ;
9- import android .support .annotation .Nullable ;
109
1110import io .flutter .app .FlutterPluginRegistry ;
1211import io .flutter .embedding .engine .dart .DartExecutor ;
1312import 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 ;
1422
1523/**
1624 * A single Flutter execution environment.
3543 * {@link FlutterRenderer} and then attach a {@link FlutterRenderer.RenderSurface}. Consider using
3644 * a {@link io.flutter.embedding.android.FlutterView} as a {@link FlutterRenderer.RenderSurface}.
3745 */
46+ // TODO(mattcarroll): re-evaluate system channel APIs - some are not well named or differentiated
3847public class FlutterEngine {
3948 private static final String TAG = "FlutterEngine" ;
4049
@@ -44,10 +53,29 @@ public class FlutterEngine {
4453 private final FlutterRenderer renderer ;
4554 @ NonNull
4655 private final DartExecutor dartExecutor ;
47- // TODO(mattcarroll): integrate system channels with FlutterEngine
4856 @ NonNull
4957 private final FlutterPluginRegistry pluginRegistry ;
5058
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+
5179 private final EngineLifecycleListener engineLifecycleListener = new EngineLifecycleListener () {
5280 @ SuppressWarnings ("unused" )
5381 public void onPreEngineRestart () {
@@ -82,6 +110,16 @@ public FlutterEngine(@NonNull Context context) {
82110 // TODO(mattcarroll): FlutterRenderer is temporally coupled to attach(). Remove that coupling if possible.
83111 this .renderer = new FlutterRenderer (flutterJNI );
84112
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+
85123 this .pluginRegistry = new FlutterPluginRegistry (this , context );
86124 }
87125
@@ -150,6 +188,80 @@ public FlutterRenderer getRenderer() {
150188 return renderer ;
151189 }
152190
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+
153265 // TODO(mattcarroll): propose a robust story for plugin backward compability and future facing API.
154266 @ NonNull
155267 public FlutterPluginRegistry getPluginRegistry () {
0 commit comments