Google is committed to advancing racial equity for Black communities. See how.

Monitoring Status

A typical instrument cluster updates driving, call, and/or 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:

  1. Extend android.telecom.InCallService.
    public class ClusterInCallService extends InCallService {
    ...
    
  2. 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">
    
  3. 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);
    }
    
  4. Register callbacks to receive call status change events (Call#registerCallback).
    private static class PhoneCallback extends Callback {
        ...
        public void onStateChanged(Call call, int state) {...}
    }
    
  5. 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:

  1. Use MediaSessionManager and get primary controller (#getActiveSessions(null)[0]).
  2. Register callbacks (MediaController#Callback).
  3. Subscribe to on active session changed MediaSessionManager#addOnActiveSessionsChangedListener(...).

For details, see: