README.md
1# ClusterHomeSample
2
3`ClusterHomeSample` is a sample reference application that runs on the cluster display.
4It uses `ClusterHomeManager` API (a.k.a. Cluster2) to interact with the CarService.
5It supports both the FULL mode and the LIGHT mode. However, in actual production cases,
6the cluster service supports one specific mode, thus the actual cluster application
7only needs to run in one specific mode.
8
9## CarService Configuration
10In order to enable `ClusterHomeService`, remove `cluster_service` from
11`config_allowed_optional_car_features` and add `cluster_home_service`,
12in the RRO configuration of the CarService.
13```
14<string-array translatable="false" name="config_allowed_optional_car_features">
15 ...
16 <item>cluster_home_service</item>
17 ...
18</string-array>
19```
20Set `config_clusterHomeServiceMode` to select what mode the `ClusterHomeService` to run in.
21```
22<!-- Configures the mode in which ClusterHomeService operates.
23 Currently supported modes are:
24 0 (full mode): All VHAL properties in ClusterHalService#CORE_PROPERTIES must be
25 available. Otherwise, the entire ClusterHomeService is disabled.
26 1 (light mode): ClusterHomeService is always enabled even without any VHAL properties.
27-->
28<integer name="config_clusterHomeServiceMode">0</integer>
29```
30`config_clusterHomeActivity` sets the activity that runs on the cluster display.
31Note that the activity specified here will run as the system user,
32thus the activity's `showForAllUsers` attribute must be set to `true`
33in the application's `AndroidManifest.xml` file.
34```
35<!-- The name of Activity who is in charge of ClusterHome. -->
36<string name="config_clusterHomeActivity" translatable="false">com.android.car.cluster.home/.ClusterHomeActivity</string>
37```
38The followings are used by the `ClusterHomeManager#startVisibilityMonitoring(Activity)` method
39to configure parameters for visibility monitoring.
40```
41<!-- Configurations for ClusterHome visibility monitoring.
42 Please refer to {@link SurfaceControl#TrustedPresentationThresholds} for the detail.
43-->
44<fraction name="config_clusterHomeVisibility_minAlpha">100%</fraction>
45<fraction name="config_clusterHomeVisibility_minRendered">99.9%</fraction>
46<integer name="config_clusterHomeVisibility_stabilityMs">100</integer>
47```
48
49## Application Configuration
50### `directBootAware`
51A cluster application needs to be able to start regardless of user unlocked state.
52Therefore `dirctBootAware` must be set to `true` in the application's `AndroidManifest.xml`.
53```
54<application android:name=".ClusterHomeApplication"
55 ...
56 android:directBootAware="true">
57```
58See https://developer.android.com/privacy-and-security/direct-boot
59for more information on `directBootAware`.
60### `showForAllUsers`
61For the activities that run as the system user, the `showForAllUsers`
62attribute must be set to `true` in the `AndroidManifest.xml` file.
63```
64<activity android:name=".ClusterHomeActivity"
65 ...
66 android:showForAllUsers="true">
67```
68See https://developer.android.com/guide/topics/manifest/activity-element#showForAllUsers
69for more information on `showForAllUsers`.
70### `showWhenLocked`
71If your cluster activity needs to be shown even when the screen is locked,
72set `showWhenLocked` to `true` in the `AndroidManifest.xml` file.
73```
74<activity android:name=".ClusterHomeActivity"
75 ...
76 android:showWhenLocked="true">
77```
78See https://developer.android.com/reference/android/R.attr#showWhenLocked
79for more information on `showWhenLocked`.
80### `turnScreenOn`
81The `turnScreenOn` is set to specify whether the screen needs to be
82turned on when the activity is resumed. Usually `turnScreenOn` is specified
83with `showWhenLocked` to turn on the screen and show the activity
84when the lockscreen is up.
85```
86<activity android:name=".ClusterHomeActivity"
87 ...
88 android:turnScreenOn="true">
89```
90See https://developer.android.com/reference/android/R.attr#turnScreenOn
91for more information on `turnScreenOn`.
92
93``
94## FULL mode
95
96The cluster application makes full use of the `ClusterHomeManager` APIs in the FULL mode.
97It starts with the `UI_TYPE_HOME` activity running as user 0, and switches to `UI_TYPE_START`
98activity when the current user is unlocked. It can switch to other UI activity types
99(e.g. `UI_TYPE_MAPS`, `UI_TYPE_PHONE`, etc.) as necessary.
100
101See `ClusterHomeActivity` for more details.
102
103To run `ClusterHomeService` in the FULL mode, the device needs to have
104all the following VHAL properties defined:
105
106- `CLUSTER_SWITCH_UI`
107- `CLUSTER_REPORT_STATE`
108- `CLUSTER_DISPLAY_STATE`
109- `CLUSTER_REQUEST_DISPLAY`
110
111If the service is configured for the FULL mode but any of the above properties is not defined,
112`ClusterHomeManager` API will throw an `IllegalStateException`.
113
114## LIGHT mode
115
116In the LIGHT mode, it stays as the `UI_TYPE_HOME` activity that runs as user 0.
117`ClusterHomeManager#startVisibilityMonitoring` and `ClusterHomeManager#sendHeartbeat` are
118used in the LIGHT mode. The device must implement `CLUSTER_HEARTBEAT` VHAL property
119to be able to use these API.
120
121See `ClusterHomeActivityLightMode` for a sample implementation.