Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/firebase_app_installations/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2026 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

include: ../../analysis_options.yaml

analyzer:
exclude:
- firebase_app_installations_platform_interface/lib/src/pigeon/messages.pigeon.dart
- firebase_app_installations_platform_interface/pigeons/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,128 +12,95 @@ import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugins.firebase.core.FlutterFirebasePlugin
import io.flutter.plugins.firebase.core.FlutterFirebasePluginRegistry

/** FirebaseInstallationsPlugin */
class FirebaseInstallationsPlugin : FlutterFirebasePlugin, FlutterPlugin, MethodCallHandler {
private var channel: MethodChannel? = null
class FirebaseInstallationsPlugin :
FlutterFirebasePlugin, FlutterPlugin, FirebaseAppInstallationsHostApi {
private var messenger: BinaryMessenger? = null
private val streamHandlers = mutableMapOf<EventChannel, EventChannel.StreamHandler>()

override fun onAttachedToEngine(binding: FlutterPluginBinding) {
messenger = binding.binaryMessenger
channel =
MethodChannel(binding.binaryMessenger, METHOD_CHANNEL_NAME).also {
it.setMethodCallHandler(this)
}

FirebaseAppInstallationsHostApi.setUp(binding.binaryMessenger, this)
FlutterFirebasePluginRegistry.registerPlugin(METHOD_CHANNEL_NAME, this)
}

override fun onDetachedFromEngine(binding: FlutterPluginBinding) {
channel?.setMethodCallHandler(null)
channel = null
FirebaseAppInstallationsHostApi.setUp(binding.binaryMessenger, null)
messenger = null
removeEventListeners()
}

private fun getInstallations(arguments: Map<String, Any>): FirebaseInstallations {
val appName = requireNotNull(arguments["appName"] as? String)
private fun getInstallations(appName: String): FirebaseInstallations {
return FirebaseInstallations.getInstance(FirebaseApp.getInstance(appName))
}

private fun getId(arguments: Map<String, Any>): Task<String> {
val taskCompletionSource = TaskCompletionSource<String>()

override fun delete(appName: String, callback: (Result<Unit>) -> Unit) {
FlutterFirebasePlugin.cachedThreadPool.execute {
try {
taskCompletionSource.setResult(Tasks.await(getInstallations(arguments).id))
Tasks.await(getInstallations(appName).delete())
callback(Result.success(Unit))
} catch (exception: Exception) {
taskCompletionSource.setException(exception)
callback(
Result.failure(
FlutterError(
"firebase_app_installations",
exception.message,
getExceptionDetails(exception))))
}
}

return taskCompletionSource.task
}

private fun getToken(arguments: Map<String, Any>): Task<String> {
val taskCompletionSource = TaskCompletionSource<String>()

override fun getId(appName: String, callback: (Result<String>) -> Unit) {
FlutterFirebasePlugin.cachedThreadPool.execute {
try {
val forceRefresh = requireNotNull(arguments["forceRefresh"] as? Boolean)
val tokenResult = Tasks.await(getInstallations(arguments).getToken(forceRefresh))
taskCompletionSource.setResult(tokenResult.token)
callback(Result.success(Tasks.await(getInstallations(appName).id)))
} catch (exception: Exception) {
taskCompletionSource.setException(exception)
callback(
Result.failure(
FlutterError(
"firebase_app_installations",
exception.message,
getExceptionDetails(exception))))
}
}

return taskCompletionSource.task
}

private fun registerIdChangeListener(arguments: Map<String, Any>): Task<String> {
val taskCompletionSource = TaskCompletionSource<String>()

override fun getToken(
appName: String,
forceRefresh: Boolean,
callback: (Result<String>) -> Unit
) {
FlutterFirebasePlugin.cachedThreadPool.execute {
try {
val appName = requireNotNull(arguments["appName"] as? String)
val handler = TokenChannelStreamHandler(getInstallations(arguments))
val name = "$METHOD_CHANNEL_NAME/token/$appName"
val eventChannel = EventChannel(requireNotNull(messenger), name)
eventChannel.setStreamHandler(handler)
streamHandlers[eventChannel] = handler
taskCompletionSource.setResult(name)
val tokenResult = Tasks.await(getInstallations(appName).getToken(forceRefresh))
callback(Result.success(tokenResult.token))
} catch (exception: Exception) {
taskCompletionSource.setException(exception)
callback(
Result.failure(
FlutterError(
"firebase_app_installations",
exception.message,
getExceptionDetails(exception))))
}
}

return taskCompletionSource.task
}

private fun deleteId(arguments: Map<String, Any>): Task<Void> {
val taskCompletionSource = TaskCompletionSource<Void>()

FlutterFirebasePlugin.cachedThreadPool.execute {
try {
Tasks.await(getInstallations(arguments).delete())
taskCompletionSource.setResult(null)
} catch (exception: Exception) {
taskCompletionSource.setException(exception)
}
}

return taskCompletionSource.task
}

override fun onMethodCall(call: MethodCall, result: Result) {
val arguments = requireNotNull(call.arguments<Map<String, Any>>())
val methodCallTask =
when (call.method) {
"FirebaseInstallations#getId" -> getId(arguments)
"FirebaseInstallations#getToken" -> getToken(arguments)
"FirebaseInstallations#delete" -> deleteId(arguments)
"FirebaseInstallations#registerIdChangeListener" -> registerIdChangeListener(arguments)
else -> {
result.notImplemented()
return
}
}

methodCallTask.addOnCompleteListener { task ->
if (task.isSuccessful) {
result.success(task.result)
} else {
val exception = task.exception
result.error(
"firebase_app_installations", exception?.message, getExceptionDetails(exception))
}
override fun registerIdChangeListener(appName: String, callback: (Result<String>) -> Unit) {
try {
val handler = TokenChannelStreamHandler(getInstallations(appName))
val name = "$METHOD_CHANNEL_NAME/token/$appName"
val eventChannel = EventChannel(requireNotNull(messenger), name)
eventChannel.setStreamHandler(handler)
streamHandlers[eventChannel] = handler
callback(Result.success(name))
} catch (exception: Exception) {
callback(
Result.failure(
FlutterError(
"firebase_app_installations", exception.message, getExceptionDetails(exception))))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
// Copyright 2026, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Autogenerated from Pigeon (v26.3.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")

package io.flutter.plugins.firebase.installations.firebase_app_installations

import android.util.Log
import io.flutter.plugin.common.BasicMessageChannel
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MessageCodec
import io.flutter.plugin.common.StandardMessageCodec
import java.io.ByteArrayOutputStream
import java.nio.ByteBuffer

private object GeneratedAndroidFirebaseAppInstallationsPigeonUtils {

fun wrapResult(result: Any?): List<Any?> {
return listOf(result)
}

fun wrapError(exception: Throwable): List<Any?> {
return if (exception is FlutterError) {
listOf(exception.code, exception.message, exception.details)
} else {
listOf(
exception.javaClass.simpleName,
exception.toString(),
"Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception))
}
}
}

/**
* Error class for passing custom error details to Flutter via a thrown PlatformException.
*
* @property code The error code.
* @property message The error message.
* @property details The error details. Must be a datatype supported by the api codec.
*/
class FlutterError(
val code: String,
override val message: String? = null,
val details: Any? = null
) : RuntimeException()

private open class GeneratedAndroidFirebaseAppInstallationsPigeonCodec : StandardMessageCodec() {
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
return super.readValueOfType(type, buffer)
}

override fun writeValue(stream: ByteArrayOutputStream, value: Any?) {
super.writeValue(stream, value)
}
}

/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
interface FirebaseAppInstallationsHostApi {
fun delete(appName: String, callback: (Result<Unit>) -> Unit)

fun getId(appName: String, callback: (Result<String>) -> Unit)

fun getToken(appName: String, forceRefresh: Boolean, callback: (Result<String>) -> Unit)

fun registerIdChangeListener(appName: String, callback: (Result<String>) -> Unit)

companion object {
/** The codec used by FirebaseAppInstallationsHostApi. */
val codec: MessageCodec<Any?> by lazy { GeneratedAndroidFirebaseAppInstallationsPigeonCodec() }
/**
* Sets up an instance of `FirebaseAppInstallationsHostApi` to handle messages through the
* `binaryMessenger`.
*/
@JvmOverloads
fun setUp(
binaryMessenger: BinaryMessenger,
api: FirebaseAppInstallationsHostApi?,
messageChannelSuffix: String = ""
) {
val separatedMessageChannelSuffix =
if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.firebase_app_installations_platform_interface.FirebaseAppInstallationsHostApi.delete$separatedMessageChannelSuffix",
codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val appNameArg = args[0] as String
api.delete(appNameArg) { result: Result<Unit> ->
val error = result.exceptionOrNull()
if (error != null) {
reply.reply(GeneratedAndroidFirebaseAppInstallationsPigeonUtils.wrapError(error))
} else {
reply.reply(GeneratedAndroidFirebaseAppInstallationsPigeonUtils.wrapResult(null))
}
}
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.firebase_app_installations_platform_interface.FirebaseAppInstallationsHostApi.getId$separatedMessageChannelSuffix",
codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val appNameArg = args[0] as String
api.getId(appNameArg) { result: Result<String> ->
val error = result.exceptionOrNull()
if (error != null) {
reply.reply(GeneratedAndroidFirebaseAppInstallationsPigeonUtils.wrapError(error))
} else {
val data = result.getOrNull()
reply.reply(GeneratedAndroidFirebaseAppInstallationsPigeonUtils.wrapResult(data))
}
}
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.firebase_app_installations_platform_interface.FirebaseAppInstallationsHostApi.getToken$separatedMessageChannelSuffix",
codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val appNameArg = args[0] as String
val forceRefreshArg = args[1] as Boolean
api.getToken(appNameArg, forceRefreshArg) { result: Result<String> ->
val error = result.exceptionOrNull()
if (error != null) {
reply.reply(GeneratedAndroidFirebaseAppInstallationsPigeonUtils.wrapError(error))
} else {
val data = result.getOrNull()
reply.reply(GeneratedAndroidFirebaseAppInstallationsPigeonUtils.wrapResult(data))
}
}
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.firebase_app_installations_platform_interface.FirebaseAppInstallationsHostApi.registerIdChangeListener$separatedMessageChannelSuffix",
codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val appNameArg = args[0] as String
api.registerIdChangeListener(appNameArg) { result: Result<String> ->
val error = result.exceptionOrNull()
if (error != null) {
reply.reply(GeneratedAndroidFirebaseAppInstallationsPigeonUtils.wrapError(error))
} else {
val data = result.getOrNull()
reply.reply(GeneratedAndroidFirebaseAppInstallationsPigeonUtils.wrapResult(data))
}
}
}
} else {
channel.setMessageHandler(null)
}
}
}
}
}
Loading
Loading