Skip to content

Atualização do foreground service - #10

Merged
brunonahornygaudium merged 39 commits into
masterfrom
feat/atualizacao-foreground-service
Oct 20, 2026
Merged

brunonahornygaudium merged 39 commits into
masterfrom
feat/atualizacao-foreground-service

Conversation

@JCPistori

@JCPistori JCPistori commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Tem vários comentários estranhos da IA, mas por enquanto deixei eles aí porque explicam a intenção de cada alteração e ajuda a diferir o que veio da atualização do repositório do que foi alteração pontual para tratar o merge. Depois eu apago eles.

simonpham and others added 30 commits December 23, 2025 13:37
Resolves an UninitializedPropertyAccessException that occurs when the ForegroundService is destroyed by the OS before foregroundTaskOptions has been initialized.

This change adds a defensive check using '::foregroundTaskOptions.isInitialized' before accessing the property in the onDestroy method, ensuring the app does not crash in this edge case.
Migrates the plugin to use built-in Kotlin per the official Flutter
migration guide:
https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors

AGP 9.0 will remove support for plugins that apply the Kotlin Gradle
Plugin. This PR removes the legacy `apply plugin: "kotlin-android"`
line and the KGP classpath from `android/build.gradle`, and the same
from the example app's `example/android/app/build.gradle`.

The example app builds cleanly with `flutter build apk --debug` on
Flutter 3.44.1 with no KGP deprecation warnings.

Bumps the minimum Flutter version to 3.44.0 and Dart SDK to 3.12.0,
as required by the new `kotlin.compilerOptions` DSL.

Fixes the warning: "Your app uses the following plugins that apply
Kotlin Gradle Plugin (KGP)".
- Bump Gradle wrapper to 8.14
- Bump AGP to 8.11.1
- Bump Kotlin to 2.2.20
- Set compileSdk to 36 (required by shared_preferences_android)
bohdansnappic and others added 8 commits September 7, 2026 09:19
The shim added in 11.0.2 is never compiled under CocoaPods, so 11.0.2 still
fails exactly like 11.0.1 (Dev-hwang#395, Dev-hwang#396):

  Semantic Issue (Xcode): Unknown receiver 'FlutterForegroundTaskPlugin';
  did you mean 'SwiftFlutterForegroundTaskPlugin'?
  ios/Runner/GeneratedPluginRegistrant.m

Both globs in source_files are resolved relative to the podspec's directory
(ios/). The Swift glob carries the `flutter_foreground_task/` prefix, but the
Obj-C one does not, so CocoaPods looks for ios/Classes/ while the files
actually live in ios/flutter_foreground_task/Classes/. The glob matches
nothing and the shim is silently dropped from the pod.

Add the missing prefix so the shim is compiled.

Verified on a CocoaPods (non-SPM) app, clean Pods/ and build/ each time,
changing only this glob:

  before -> Unknown receiver ...; 0 references to
            FlutterForegroundTaskPlugin.m in the generated Pods.xcodeproj
  after  -> builds and links; 4 references
Ship the podspec fix so CocoaPods users are unblocked; 11.0.2 still fails
with "Unknown receiver 'FlutterForegroundTaskPlugin'" because the shim it
added never reaches the pod.
Traz 9.2.0, 9.2.1 e 9.2.2 do upstream:
- fix DidNotStartInTime / DidNotStopInTime: update e stop passam a usar
  startService em vez de startForegroundService, sem abrir o contrato de 5s
- fix de crash no onDestroy
- opcao stopWithTask + TrackVisibilityUtils
- fix do bitmask FLAG_STOP_WITH_TASK
- foreground service type mediaProcessing

Conflitos resolvidos mantendo o lado do fork:
- PreferencesKey: mantidas as chaves do orcamento de auto-restart, somadas ao
  STOP_WITH_TASK do upstream
- ForegroundService.onDestroy: mantida a guarda de lateinit do fork e o
  orcamento de auto-restart; descartada a versao do upstream, que resolve o
  mesmo lateinit de outra forma e reintroduziria o alarme fixo de 5s

Ajustes no codigo vindo do upstream:
- TrackVisibilityUtils chamava stopForegroundService() sem argumento, o que nao
  compila com a assinatura do fork; passou a chamar stopForegroundService(true)
  para preservar o reattach de OEM

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Suporte ao ciclo de vida UIScene no iOS e bump do minimo para Flutter 3.38.0.
Merge sem conflitos -- nao toca em nenhum dos workarounds de OEM do fork.

ATENCAO: a partir daqui o app consumidor precisa estar em Flutter >= 3.38.0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Traz 11.0.0, 11.0.1, 11.0.2 e 11.0.3 do upstream:
- migracao para o plugin Kotlin embutido do Flutter e bump de Gradle/AGP/compileSdk
- suporte a Swift Package Manager no iOS (Package.swift, nova arvore de fontes)
- shim Objective-C do FlutterForegroundTaskPlugin, incluido no podspec
- shared_preferences 2.5.3 -> 2.5.5

Conflito resolvido:
- ios/Classes/service/VibrationManager.swift (arquivo so nosso) ficou orfao com a
  mudanca de ios/Classes/** para ios/flutter_foreground_task/Sources/**. Movido
  para o novo caminho; podspec e Package.swift usam glob, entao ele volta a ser
  compilado nos dois fluxos.

As demais customizacoes iOS do fork (som customizado, padrao de vibracao, guarda
de notificacao vazia) seguiram os renames do git e foram conferidas no destino.

ATENCAO: a partir daqui o app consumidor precisa estar em Flutter >= 3.44.0 /
Dart >= 3.12.0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Arquivos gerados pelo toolchain do Flutter, commitados por engano no fork.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@JCPistori JCPistori self-assigned this Sep 22, 2026
@gaudinho

gaudinho Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

✅ Review postada — #10 (review)

job_id: flutter_foreground_task-10-1790099538913-f966

@gaudinho gaudinho Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 blocker de Correctness: em ForegroundTaskOptions.updateData (chamado a cada updateService()), o tratamento de stopWithTask usa ?: remove(...) — diferente de todos os outros campos da mesma função, que só escrevem quando o valor vem presente no map. Como o Dart só serializa stopWithTask quando não é null, qualquer updateService() sem esse parâmetro apaga silenciosamente a preferência gravada em startService(), quebrando a própria feature que este PR está introduzindo (e o comportamento documentado no bloco [GAUDIUM] de ForegroundService.kt).

@brunonahornygaudium brunonahornygaudium left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pode liberar pra teste, só achei isso estranho

Comment on lines +65 to +67
// Use startService instead of startForegroundService because the service
// is already running in the foreground and we only need to deliver the
// update command. This avoids the startForeground() contract requirement.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esse comentário é seu ou da atualização?
Havíamos especificamente trocado para o contextCompat

pq voltou?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

É da atualização, e conferi que o contextCompat não tem startService, ele tem que ser usado para o startForegroundService.

O startService existe desde a API nível 1 e nisso não precisa de nenhuma compatibilidade com outros Androids, inclusive o ContextCompat para Androids abaixo do SDK 26 redireciona pro startService()
Image
https://developer.android.com/reference/android/content/Context#startService(android.content.Intent)

@JCPistori JCPistori Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pelo que entendi da alteração do repositório original, em um update chamar o startService() permite atualizar o serviço evitando que o startForeground() tenha que ser chamado em 5 segundos

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Base automatically changed from fix/crashes-foreground-service to master October 20, 2026 19:07
@brunonahornygaudium
brunonahornygaudium dismissed their stale review October 20, 2026 19:07

The base branch was changed.

@brunonahornygaudium
brunonahornygaudium merged commit 64c8cab into master Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.