Skip to content

[flutter_tools] Implement Device Service extension and flutter devices integration - #192126

Merged
auto-submit[bot] merged 30 commits into
flutter:masterfrom
bkonyi:ft-ext-step06-device-slice
Oct 2, 2026
Merged

auto-submit[bot] merged 30 commits into
flutter:masterfrom
bkonyi:ft-ext-step06-device-slice

Conversation

@bkonyi

@bkonyi bkonyi commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Implement DeviceService and integrate it with FlutterDeviceManager to support dynamic custom devices from tool extensions.

  • Define Category (web, desktop, mobile, other) and TargetDevice in package:flutter_tools_core.
  • Define the DeviceService extension service interface (device.getDevices and device.isSupportedForProject) in package:flutter_tools_extension.
  • Implement LinuxDeviceService in package:flutter_tools_extension_linux_prototype.
  • Implement ExtensionDevices, ExtensionDeviceClient, and ExtensionBackedDevice in packages/flutter_tools/lib/src/experimental/extension_device_manager.dart, and update Device.isSupportedForProject to return FutureOr<bool>.
  • Bootstrap ExtensionManager in ToolDependencies.bootstrap and wire it into FlutterDeviceManager.
  • Add unit, hermetic, and integration test coverage across flutter_tools_core, flutter_tools_extension_linux_prototype, and flutter_tools.

Part of #190692

bkonyi and others added 15 commits August 26, 2026 01:35
Implements the Templates extension service and integrates dynamic custom template support into `flutter create` and `package:flutter_tools_core`.

- `package:flutter_tools_core`:
  - Adds `ProjectTemplate` and `ExtensionProjectTemplate` domain models with JSON serialization, hashing, and equality in `lib/src/templates.dart`.
  - Exports template models from `lib/flutter_tools_core.dart`.
- `package:flutter_tools_extension`:
  - Defines `TemplateService` RPC interface and handlers for `template.getAppTemplates`, `template.getPluginTemplates`, `template.getProjectTemplates`, and `template.generateTemplateParameters` in `lib/src/templates.dart`.
- `package:flutter_tools_extension_linux_prototype`:
  - Implements `LinuxTemplateService` and `LinuxProjectTemplate` declaring custom template `'custom-linux-app'` with `templateDependencies: {'app'}`.
  - Adds prototype template assets for `'custom-linux-app'`.
- `packages/flutter_tools`:
  - Adds `ExtensionTemplateManager` in `lib/src/experimental/templates.dart` to discover custom templates over RPC, cache them, resolve directories, and delegate parameter generation.
  - Updates `Template.fromDirectories` in `lib/src/template.dart` to merge directory sources with base template dependencies.
  - Updates `CreateCommand` and `ExtensionArgParserMixin` to dynamically populate `--template` CLI options and help entries.
  - Updates `FlutterProjectMetadata` and `ParsedFlutterTemplateType` to support `ExtensionProjectTemplateType`.
  - Wires `ExtensionTemplateManager` through `executable.dart` into `CreateCommand`.
  - Adds unit, hermetic usage, and integration test coverage across all layers.
…plates-slice

# Conflicts:
#	packages/flutter_tools/lib/src/experimental/extension_arg_parser.dart
…s integration

Implement the Device Service and integrate it with device discovery and `flutter devices` CLI command to support dynamic custom devices from tool extensions.

- Define `TargetDevice` core data structure in `package:flutter_tools_core`.
- Define `DeviceService` extension service interface in `package:flutter_tools_extension`.
- Implement `LinuxDeviceService` prototype in `package:flutter_tools_extension_linux_prototype`.
- Implement `ExtensionDeviceDiscovery`, `ExtensionDeviceClient`, and `ExtensionBackedDevice` in `packages/flutter_tools/lib/src/experimental/extension_device_manager.dart`.
- Inject `ExtensionDeviceDiscovery` into `FlutterDeviceManager`.
- Add hermetic CLI integration tests in `tool_extensions_device_test.dart`.
@bkonyi bkonyi added the CICD Run CI/CD label Sep 1, 2026
@bkonyi
bkonyi requested a review from a team as a code owner September 1, 2026 18:00
@bkonyi bkonyi added the CICD Run CI/CD label Sep 1, 2026
@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. team-linux Owned by the Linux platform team labels Sep 1, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for custom project templates and target devices provided dynamically by tool extensions. It adds ExtensionTemplateManager and ExtensionDeviceDiscovery to handle querying templates and discovering devices from active extensions, integrating these into the create and devices commands. It also defines core models and services in flutter_tools_core and flutter_tools_extension, along with a prototype implementation for Linux. Feedback on the changes includes fixing invalid Dart syntax in TargetDevice.toMap() where ? is used in a map literal, adding a null check for Cache.flutterRoot in ExtensionTemplateManager.resolveTemplateDirectory to prevent potential null pointer exceptions, and fully populating the allowed list with both static and dynamic templates when rebuilding the dynamic parser in CreateCommand to enable automatic CLI validation.

…ommand

- Guard `Cache.flutterRoot` with an explicit null check in `ExtensionTemplateManager.resolveTemplateDirectory`.
- Populate `allowed` option values for dynamic and static templates in `CreateCommand.buildDynamicArgParser`.
…ice-slice

# Conflicts:
#	packages/flutter_tools/lib/src/commands/create.dart
#	packages/flutter_tools/lib/src/experimental/templates.dart
#	packages/flutter_tools/packages/flutter_tools_extension_linux_prototype/lib/flutter_tools_extension_linux_prototype.dart
@bkonyi

bkonyi commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for tool extension-backed devices in flutter_tools by adding ExtensionDeviceDiscovery and ExtensionBackedDevice to discover and wrap devices registered by active extensions, and integrating them into FlutterDeviceManager and DevicesCommand. Feedback highlights a compilation error in TargetDevice.toMap() due to invalid Dart syntax (?sdkNameAndVersion and ?targetPlatform), and raises an architectural concern regarding the dynamic mutation of globals.deviceManager?.deviceDiscoverers inside DevicesCommand, suggesting global initialization instead.

@bkonyi
bkonyi requested review from loic-sharma and removed request for a team September 1, 2026 20:11

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Apologies for the very delayed review. Overall this looks good to me! My only real concern is the dependency injection.

…sionDevices

- Wire `ExtensionManager` into `FlutterDeviceManager` via `executable.dart` and `context_runner.dart`, reverting `DevicesCommand` changes.
- Make `ExtensionBackedDevice.connection` required and non-nullable.
- Rename `ExtensionDeviceDiscovery` to `ExtensionDevices`.
- Expand documentation on `TargetDevice.ephemeral`.
- Pass `projectRoot` to `DeviceService.getDevices` so extensions can compute `isSupportedForProject`.
- Move `Category` enum to `package:flutter_tools_core` and use `Category` on `TargetDevice`.
- Remove `platformType` from `TargetDevice` and default `ExtensionBackedDevice.platformType` to `PlatformType.custom`.
…ILD export

- Alias `Category` in `packages/flutter_tools/lib/src/device.dart` via `typedef Category = tools_core.Category;` instead of re-exporting from `package:flutter_tools_core`.
- Hide `Category` from `package:flutter_tools_core` import in `doctor_test.dart`.
- Use private initializing formals in `ExtensionDeviceClient` and `ExtensionDevices` constructors.
… and Category.other

- Add `globals.extensionManager` getter and instantiate `ExtensionManager` directly in the `overrides` callback in `executable.dart`.
- Use `globals.extensionManager` when constructing `FlutterDeviceManager` in `context_runner.dart`.
- Add `Category.other` to `enum Category` in `package:flutter_tools_core`.
- Initialize `late final ExtensionManager extensionManager` in `executable.dart` using `ToolDependencies` and expose it in `overrides` via `ExtensionManager: () => extensionManager`.
- Read `overrides?[ExtensionManager]?.call() as ExtensionManager?` in `context_runner.dart` instead of adding `globals.extensionManager` to `globals.dart`.
@loic-sharma

Copy link
Copy Markdown
Member

@bkonyi FYI, there are still some unaddressed questions above :)

bkonyi added 3 commits October 1, 2026 21:02
…oolDependencies

- Merge `upstream/master` (flutter#193524) and pass `ExtensionManager` directly to `FlutterDeviceManager` inside `ToolDependencies.bootstrap`.
- Forward `extensionEntryPoints` from `executable.dart` through `runner.run` into `ToolDependencies.bootstrap`.
- Remove the `overrides[ExtensionManager]` workaround from `executable.dart` and `context_runner.dart`.
- Fix formatting in `packages/flutter_tools_extension/lib/src/device.dart` and `packages/flutter_tools/lib/src/commands/devices.dart`.
…tstrap and generateCommands

Removes the unused `ExtensionManager? extensionManager` parameter from `ToolDependencies.bootstrap` and `generateCommands`, reading `toolDependencies.extensionManager` directly inside `generateCommands`.
…isSupportedForProject FutureOr<bool>

Decouples project support checks from device discovery by adding a separate `device.isSupportedForProject` RPC method on `DeviceService` (`isSupportedForProject({required String deviceId, required Uri projectRoot})`), removing `isSupportedForProject` from `TargetDevice`, and updating `Device.isSupportedForProject` to return `FutureOr<bool>`.

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 2, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 2, 2026
@auto-submit

auto-submit Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/192126, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label.

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 2, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Oct 2, 2026
Merged via the queue into flutter:master with commit 2ac3209 Oct 2, 2026
30 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 2, 2026
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
…s integration (flutter#192126)

Implement `DeviceService` and integrate it with `FlutterDeviceManager`
to support dynamic custom devices from tool extensions.

- Define `Category` (`web`, `desktop`, `mobile`, `other`) and
`TargetDevice` in `package:flutter_tools_core`.
- Define the `DeviceService` extension service interface
(`device.getDevices` and `device.isSupportedForProject`) in
`package:flutter_tools_extension`.
- Implement `LinuxDeviceService` in
`package:flutter_tools_extension_linux_prototype`.
- Implement `ExtensionDevices`, `ExtensionDeviceClient`, and
`ExtensionBackedDevice` in
`packages/flutter_tools/lib/src/experimental/extension_device_manager.dart`,
and update `Device.isSupportedForProject` to return `FutureOr<bool>`.
- Bootstrap `ExtensionManager` in `ToolDependencies.bootstrap` and wire
it into `FlutterDeviceManager`.
- Add unit, hermetic, and integration test coverage across
`flutter_tools_core`, `flutter_tools_extension_linux_prototype`, and
`flutter_tools`.

Part of flutter#190692

---------

Co-authored-by: Loïc Sharma <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD team-linux Owned by the Linux platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants