2121import io .flutter .plugin .common .MethodChannel .Result ;
2222import io .flutter .plugins .firebase .core .FlutterFirebasePlugin ;
2323import io .flutter .plugins .firebase .core .FlutterFirebasePluginRegistry ;
24+ import io .flutter .plugins .firebase .installations .GeneratedAndroidFirebaseAppInstallations ;
25+ import io .flutter .plugins .firebase .installations .GeneratedAndroidFirebaseAppInstallations .AppInstallationsPigeonFirebaseApp ;
26+ import io .flutter .plugins .firebase .installations .GeneratedAndroidFirebaseAppInstallations .AppInstallationsPigeonSettings ;
2427import java .util .HashMap ;
2528import java .util .Map ;
2629import java .util .Objects ;
2730
2831/** FirebaseInstallationsPlugin */
2932public class FirebaseInstallationsPlugin
30- implements FlutterFirebasePlugin , FlutterPlugin , MethodCallHandler {
33+ implements FlutterFirebasePlugin ,
34+ FlutterPlugin ,
35+ MethodCallHandler ,
36+ GeneratedAndroidFirebaseAppInstallations .FirebaseAppInstallationsHostApi {
3137 private MethodChannel channel ;
3238 private static final String METHOD_CHANNEL_NAME = "plugins.flutter.io/firebase_app_installations" ;
3339 private final Map <EventChannel , EventChannel .StreamHandler > streamHandlers = new HashMap <>();
@@ -38,6 +44,9 @@ private MethodChannel setup(BinaryMessenger binaryMessenger) {
3844 final MethodChannel channel = new MethodChannel (binaryMessenger , METHOD_CHANNEL_NAME );
3945 channel .setMethodCallHandler (this );
4046 this .messenger = binaryMessenger ;
47+ // Set up Pigeon host API handlers.
48+ GeneratedAndroidFirebaseAppInstallations .FirebaseAppInstallationsHostApi .setUp (
49+ binaryMessenger , this );
4150 return channel ;
4251 }
4352
@@ -64,6 +73,12 @@ private FirebaseInstallations getInstallations(Map<String, Object> arguments) {
6473 return FirebaseInstallations .getInstance (app );
6574 }
6675
76+ private FirebaseInstallations getInstallations (AppInstallationsPigeonFirebaseApp appArg ) {
77+ @ NonNull String appName = appArg .getAppName ();
78+ FirebaseApp app = FirebaseApp .getInstance (appName );
79+ return FirebaseInstallations .getInstance (app );
80+ }
81+
6782 private Task <String > getId (Map <String , Object > arguments ) {
6883 TaskCompletionSource <String > taskCompletionSource = new TaskCompletionSource <>();
6984
@@ -145,6 +160,85 @@ private Task<Void> deleteId(Map<String, Object> arguments) {
145160 return taskCompletionSource .getTask ();
146161 }
147162
163+ // Pigeon FirebaseAppInstallationsHostApi implementation.
164+
165+ @ Override
166+ public void initializeApp (
167+ @ NonNull AppInstallationsPigeonFirebaseApp app ,
168+ @ NonNull AppInstallationsPigeonSettings settings ,
169+ @ NonNull GeneratedAndroidFirebaseAppInstallations .VoidResult result ) {
170+ // Currently there is no per-app configurable behavior required on Android for these settings.
171+ // We execute asynchronously to keep the threading model consistent.
172+ cachedThreadPool .execute (
173+ () -> {
174+ try {
175+ // Touch the instance to ensure it's initialized.
176+ getInstallations (app );
177+ result .success ();
178+ } catch (Exception e ) {
179+ result .error (e );
180+ }
181+ });
182+ }
183+
184+ @ Override
185+ public void delete (
186+ @ NonNull AppInstallationsPigeonFirebaseApp app ,
187+ @ NonNull GeneratedAndroidFirebaseAppInstallations .VoidResult result ) {
188+ cachedThreadPool .execute (
189+ () -> {
190+ try {
191+ Tasks .await (getInstallations (app ).delete ());
192+ result .success ();
193+ } catch (Exception e ) {
194+ result .error (e );
195+ }
196+ });
197+ }
198+
199+ @ Override
200+ public void getId (
201+ @ NonNull AppInstallationsPigeonFirebaseApp app ,
202+ @ NonNull GeneratedAndroidFirebaseAppInstallations .Result <String > result ) {
203+ cachedThreadPool .execute (
204+ () -> {
205+ try {
206+ String id = Tasks .await (getInstallations (app ).getId ());
207+ result .success (id );
208+ } catch (Exception e ) {
209+ result .error (e );
210+ }
211+ });
212+ }
213+
214+ @ Override
215+ public void getToken (
216+ @ NonNull AppInstallationsPigeonFirebaseApp app ,
217+ @ NonNull Boolean forceRefresh ,
218+ @ NonNull GeneratedAndroidFirebaseAppInstallations .Result <String > result ) {
219+ cachedThreadPool .execute (
220+ () -> {
221+ try {
222+ FirebaseInstallations firebaseInstallations = getInstallations (app );
223+ InstallationTokenResult tokenResult =
224+ Tasks .await (firebaseInstallations .getToken (forceRefresh ));
225+ result .success (tokenResult .getToken ());
226+ } catch (Exception e ) {
227+ result .error (e );
228+ }
229+ });
230+ }
231+
232+ @ Override
233+ public void onIdChange (
234+ @ NonNull AppInstallationsPigeonFirebaseApp app ,
235+ @ NonNull String newId ,
236+ @ NonNull GeneratedAndroidFirebaseAppInstallations .VoidResult result ) {
237+ // The Dart side currently uses an EventChannel-based listener, so this Pigeon hook
238+ // is a no-op placeholder to satisfy the interface.
239+ result .success ();
240+ }
241+
148242 @ Override
149243 public void onMethodCall (@ NonNull MethodCall call , @ NonNull Result result ) {
150244 Task <?> methodCallTask ;
0 commit comments