• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package io.flutter.embedding.engine.plugins.service;
6 
7 import android.app.Service;
8 import android.arch.lifecycle.Lifecycle;
9 import android.support.annotation.NonNull;
10 
11 /**
12  * Control surface through which a {@link Service} attaches to a {@link FlutterEngine}.
13  * <p>
14  * A {@link Service} that contains a {@link FlutterEngine} should coordinate itself with the
15  * {@link FlutterEngine}'s {@code ServiceControlSurface}.
16  */
17 public interface ServiceControlSurface {
18   /**
19    * Call this method from the {@link Service} that is running the {@link FlutterEngine} that is
20    * associated with this {@code ServiceControlSurface}.
21    * <p>
22    * Once a {@link Service} is created, and its associated {@link FlutterEngine} is
23    * executing Dart code, the {@link Service} should invoke this method. At that point the
24    * {@link FlutterEngine} is considered "attached" to the {@link Service} and all
25    * {@link ServiceAware} plugins are given access to the {@link Service}.
26    * <p>
27    * {@code isForeground} should be true if the given {@link Service} is running in the foreground,
28    * false otherwise.
29    */
attachToService(@onNull Service service, @NonNull Lifecycle lifecycle, boolean isForeground)30   void attachToService(@NonNull Service service, @NonNull Lifecycle lifecycle, boolean isForeground);
31 
32   /**
33    * Call this method from the {@link Service} that is attached to this {@code ServiceControlSurfaces}'s
34    * {@link FlutterEngine} when the {@link Service} is about to be destroyed.
35    * <p>
36    * This method gives each {@link ServiceAware} plugin an opportunity to clean up its references
37    * before the {@link Service is destroyed}.
38    */
detachFromService()39   void detachFromService();
40 
41   /**
42    * Call this method from the {@link Service} that is attached to this {@code ServiceControlSurface}'s
43    * {@link FlutterEngine} when the {@link Service} goes from background to foreground.
44    */
onMoveToForeground()45   void onMoveToForeground();
46 
47   /**
48    * Call this method from the {@link Service} that is attached to this {@code ServiceControlSurface}'s
49    * {@link FlutterEngine} when the {@link Service} goes from foreground to background.
50    */
onMoveToBackground()51   void onMoveToBackground();
52 }
53