A typical instrument cluster updates driving, call, and media information whenever new data comes in. Android provides the following API to enable an OEM's instrument cluster to receive up-to-date status easily.
Driving status
Driving direction events are sent while navigation is ongoing. The file
packages/services/Car/car-lib/src/android/car/cluster/renderer/NavigationRenderer.java
contains abstract methods for a navigation app renderer in the instrument cluster.
In an extended InstrumentClusterRenderingService
, these methods are as follows:
public class MyClusterRenderingService extends InstrumentClusterRenderingService { ... @Override protected NavigationRenderer getNavigationRenderer() { return new NavigationRenderer() { @Override CarNavigationInstrumentCluster getNavigationProperties() {...} @Override void onStartNavigation() {...} @Override void onStopNavigation() {...} @Override void onNextTurnChanged(int event, String road, int turnAngle, int turnNumber, Bitmap image, int turnSide) {...} @Override void onNextTurnDistanceChanged(int distanceMeters, int timeSeconds) {...} }; } }
You can add custom actions (such as rendering) to these methods to display desired information.
Call status
To monitor call status, use the following steps:
- Extend
android.telecom.InCallService
.public class ClusterInCallService extends InCallService { ...
- Register the service in
AndroidManifest.xml
.<service android:name="com.android.car.cluster.sample.ClusterInCallService" android:permission="android.permission.BIND_INCALL_SERVICE" android:exported="false">
- Override onCallAdded and onCallRemoved.
public void onCallAdded(Call call) { ... call.registerCallback(mPhoneCallback); mPhoneCallback.onStateChanged(call, call.getState()); } public void onCallRemoved(Call call) { ... call.unregisterCallback(mPhoneCallback); }
- Register callbacks to receive call status change events (
Call#registerCallback
).private static class PhoneCallback extends Callback { ... public void onStateChanged(Call call, int state) {...} }
- Use content providers to pull contact information:
ContactsContract.PhoneLookup, ContactsContract.Contacts#openContactPhotoInputStream
).
For call status monitor sample code, see:
packages/services/Car/tests/InstrumentClusterRendererSample/src/com/android/car/cluster/sample/ClusterInCallService.java
For content provider sample code, see:
packages/services/Car/tests/InstrumentClusterRendererSample/src/com/android/car/cluster/sample/TelecomUtils.java
.
Media status
You can configure the system to update the media status when it receive events related to a change in MediaMetadata (such as album or song title or cover image) or playback state (buffering, pause, play, and stop). To update the media status:
- Use
MediaSessionManager
and get primary controller (#getActiveSessions(null)[0]
). - Register callbacks (
MediaController#Callback
). - Subscribe to on active session changed
MediaSessionManager#addOnActiveSessionsChangedListener(...)
.
For details, see: