is responsible for providing the data for the tile. It is responsible for fetching the state of
the tile from the source of truth and providing that information to the tile. Typically the data
interactor will read system state from a repository or a controller and provide a flow of
domain-specific data model.
*[`QSTileUserActionInteractor`](/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileUserActionInteractor.kt) is responsible for handling the user actions on the tile.
This interactor decides what should happen when the user clicks, long clicks on the tile.
5| State in the device changes. This is normally outside of SystemUI's control. Controller receives a callback (or `Intent`) indicating the change in the device. | Same as legacy tiles.
7| `QSTileImpl#handleUpdateState` is called to update the state with the new information. This information can be obtained both from the `Object` passed to `refreshState` as well as from the controller. | The data that was generated by the data interactor is read by the `QSTileViewModelImpl.state` flow which calls `QSTileMapper#map` on the data to generate a new `QSTileState`.
8| If the state has changed (in at least one element `QSTileImpl#handleStateChanged` is called. This will trigger a call to all the associated `QSTile.Callback#onStateChanged`, passing the new `State`. | The newly mapped QSTileState is read by the `QSTileViewModelAdapter` which then maps it to a legacy `State`. Similarly to the legacy tiles, the new state is compared to the old one and if there is a difference, `QSTile.Callback#onStateChanged` is called for all the associated callbacks.
9 | `QSTileView#onStateChanged` is called and this calls `QSTileView#handleStateChanged`. This method maps the state updating tile color and label, and calling `QSIconView.setIcon` | Same as legacy tiles.
## Third party tiles (TileService)
A third party tile is any Quick Settings tile that is provided by an app (that's not SystemUI). This
is implemented by developers
A third party tile is any Quick Settings tile that is provided by an app (that's not SystemUI).
This is implemented by developers
subclassing [`TileService`](/core/java/android/service/quicksettings/TileService.java) and
interacting with its API.
@@ -221,8 +245,8 @@ from SystemUI:
***`onTileRemoved`**: called when the tile is removed from QS.
***`onStartListening`**: called when QS is opened and the tile is showing. This marks the start of
the window when calling `getQSTile` is safe and will provide the correct object.
***`onStopListening`**: called when QS is closed or the tile is no longer visible by the user. This
marks the end of the window described in `onStartListening`.
***`onStopListening`**: called when QS is closed or the tile is no longer visible by the user.
This marks the end of the window described in `onStartListening`.
***`onClick`**: called when the user clicks on the tile.
Additionally, the following final methods are provided:
@@ -379,13 +403,14 @@ correct list of tiles.
### QSFactory
`CurrentTilesInteractorImpl` uses the `QSFactory` interface to create the tiles.
This interface provides a way of creating tiles and views from a spec. It can be used in plugins to
provide different definitions for tiles.
In SystemUI there is only one implementation of this factory and that is the default
factory (`QSFactoryImpl`) in `CurrentTilesInteractorImpl`.
In SystemUI there are two implementation of this factory. The first one is `QSFactoryImpl` in used for legacy tiles. The second one is `NewQSFactory` used for [NEW-ARCH] tiles.
#### QSFactoryImpl
#### QSFactoryImpl (legacy tiles)
This class implements the following method as specified in the `QSFactory` interface:
@@ -402,6 +427,12 @@ This class implements the following method as specified in the `QSFactory` inter
As part of filtering not valid tiles, custom tiles that don't have a corresponding valid service
component are never instantiated.
#### NewQSFactory ([NEW-ARCH] tiles)
This class also implements the `createTile` method as specified in the `QSFactory` interface.
However, it first uses the spec to get a `QSTileViewModel`. The view model is then adapted into a
`QSTile` using the `QSTileViewModelAdapter`.
### Lifecycle of a Tile
We describe first the parts of the lifecycle that are common to SystemUI tiles and third party
@@ -415,7 +446,7 @@ tiles.
2. This updates the flow that `CurrentTilesInteractor` is collecting from, triggering the process
described above.
3.`CurrentTilesInteractor` calls the available `QSFactory` classes in order to find one that will
be able to create a tile with that spec. Assuming that `QSFactoryImpl` managed to create the
be able to create a tile with that spec. Assuming that some factory managed to create the
tile, which is some implementation of `QSTile` (either a SystemUI subclass
of `QSTileImpl` or a `CustomTile`) it will be added to the current list.
If the tile is available, it's stored in a map and things proceed forward.
@@ -452,7 +483,7 @@ in [Third party tiles (TileService)](#third-party-tiles-tileservice).
This section describes necessary and recommended steps when implementing a Quick Settings tile. Some
of them are optional and depend on the requirements of the tile.
### Implementing a SystemUI tile
### Implementing a legacy SystemUI tile
1. Create a class (preferably
in [`SystemUI/src/com/android/systemui/qs/tiles`](/packages/SystemUI/src/com/android/systemui/qs/tiles))
@@ -579,6 +610,70 @@ type variable of type `State`.
Provides a default label for this Tile. Used by the QS Panel customizer to show a name next to
each available tile.
### Implementing a [NEW-ARCH] SystemUI tile
In the new system the tiles are created in the path