FileDocCategorySizeDatePackage
HdmiTvClient.javaAPI DocAndroid 5.1 API14467Thu Mar 12 22:22:10 GMT 2015android.hardware.hdmi

HdmiTvClient

public final class HdmiTvClient extends HdmiClient
HdmiTvClient represents HDMI-CEC logical device of type TV in the Android system which acts as TV/Display. It provides with methods that manage, interact with other devices on the CEC bus.
hide

Fields Summary
private static final String
TAG
public static final int
VENDOR_DATA_SIZE
Size of MHL register for vendor command
Constructors Summary
HdmiTvClient(IHdmiControlService service)


    /* package */   
        super(service);
    
Methods Summary
private voidcheckTimerRecordingSourceType(int sourceType)

        switch (sourceType) {
            case HdmiControlManager.TIMER_RECORDING_TYPE_DIGITAL:
            case HdmiControlManager.TIMER_RECORDING_TYPE_ANALOGUE:
            case HdmiControlManager.TIMER_RECORDING_TYPE_EXTERNAL:
                break;
            default:
                throw new IllegalArgumentException("Invalid source type:" + sourceType);
        }
    
public voidclearTimerRecording(int recorderAddress, int sourceType, android.hardware.hdmi.HdmiTimerRecordSources.TimerRecordSource source)
Clears timer recording with the given recorder address and recording source. For more details, please refer {@link #startTimerRecording(int, int, TimerRecordSource)}.

        if (source == null) {
            throw new IllegalArgumentException("source must not be null.");
        }

        checkTimerRecordingSourceType(sourceType);
        try {
            byte[] data = new byte[source.getDataSize()];
            source.toByteArray(data, 0);
            mService.clearTimerRecording(recorderAddress, sourceType, data);
        } catch (RemoteException e) {
            Log.e(TAG, "failed to start record: ", e);
        }
    
static android.hardware.hdmi.HdmiTvClientcreate(IHdmiControlService service)

        return new HdmiTvClient(service);
    
public voiddeviceSelect(int logicalAddress, android.hardware.hdmi.HdmiTvClient$SelectCallback callback)
Selects a CEC logical device to be a new active source.

param
logicalAddress logical address of the device to select
param
callback callback to get the result with
throws
{@link IllegalArgumentException} if the {@code callback} is null

        if (callback == null) {
            throw new IllegalArgumentException("callback must not be null.");
        }
        try {
            mService.deviceSelect(logicalAddress, getCallbackWrapper(callback));
        } catch (RemoteException e) {
            Log.e(TAG, "failed to select device: ", e);
        }
    
private static IHdmiControlCallbackgetCallbackWrapper(android.hardware.hdmi.HdmiTvClient$SelectCallback callback)

        return new IHdmiControlCallback.Stub() {
            @Override
            public void onComplete(int result) {
                callback.onComplete(result);
            }
        };
    
public java.util.ListgetDeviceList()
Returns all the CEC devices connected to TV.

return
list of {@link HdmiDeviceInfo} for connected CEC devices. Empty list is returned if there is none.

        try {
            return mService.getDeviceList();
        } catch (RemoteException e) {
            Log.e("TAG", "Failed to call getDeviceList():", e);
            return Collections.<HdmiDeviceInfo>emptyList();
        }
    
public intgetDeviceType()

        return HdmiDeviceInfo.DEVICE_TV;
    
private static IHdmiRecordListenergetListenerWrapper(HdmiRecordListener callback)

        return new IHdmiRecordListener.Stub() {
            @Override
            public byte[] getOneTouchRecordSource(int recorderAddress) {
                HdmiRecordSources.RecordSource source =
                        callback.onOneTouchRecordSourceRequested(recorderAddress);
                if (source == null) {
                    return EmptyArray.BYTE;
                }
                byte[] data = new byte[source.getDataSize(true)];
                source.toByteArray(true, data, 0);
                return data;
            }

            @Override
            public void onOneTouchRecordResult(int recorderAddress, int result) {
                callback.onOneTouchRecordResult(recorderAddress, result);
            }

            @Override
            public void onTimerRecordingResult(int recorderAddress, int result) {
                callback.onTimerRecordingResult(recorderAddress,
                        HdmiRecordListener.TimerStatusData.parseFrom(result));
            }

            @Override
            public void onClearTimerRecordingResult(int recorderAddress, int result) {
                callback.onClearTimerRecordingResult(recorderAddress, result);
            }
        };
    
private IHdmiMhlVendorCommandListenergetListenerWrapper(android.hardware.hdmi.HdmiTvClient$HdmiMhlVendorCommandListener listener)

        return new IHdmiMhlVendorCommandListener.Stub() {
            @Override
            public void onReceived(int portId, int offset, int length, byte[] data) {
                listener.onReceived(portId, offset, length, data);
            }
        };
    
private static IHdmiInputChangeListenergetListenerWrapper(android.hardware.hdmi.HdmiTvClient$InputChangeListener listener)

        return new IHdmiInputChangeListener.Stub() {
            @Override
            public void onChanged(HdmiDeviceInfo info) {
                listener.onChanged(info);
            }
        };
    
public voidportSelect(int portId, android.hardware.hdmi.HdmiTvClient$SelectCallback callback)
Selects a HDMI port to be a new route path.

param
portId HDMI port to select
param
callback callback to get the result with
throws
{@link IllegalArgumentException} if the {@code callback} is null

        if (callback == null) {
            throw new IllegalArgumentException("Callback must not be null");
        }
        try {
            mService.portSelect(portId, getCallbackWrapper(callback));
        } catch (RemoteException e) {
            Log.e(TAG, "failed to select port: ", e);
        }
    
public voidsendMhlVendorCommand(int portId, int offset, int length, byte[] data)
Sends MHL vendor command to the device connected to a port of the given portId.

param
portId id of port to send MHL vendor command
param
offset offset in the in given data
param
length length of data. offset + length should be bound to length of data.
param
data container for vendor command data. It should be 16 bytes.
throws
IllegalArgumentException if the given parameters are invalid

        if (data == null || data.length != VENDOR_DATA_SIZE) {
            throw new IllegalArgumentException("Invalid vendor command data.");
        }
        if (offset < 0 || offset >= VENDOR_DATA_SIZE) {
            throw new IllegalArgumentException("Invalid offset:" + offset);
        }
        if (length < 0 || offset + length > VENDOR_DATA_SIZE) {
            throw new IllegalArgumentException("Invalid length:" + length);
        }

        try {
            mService.sendMhlVendorCommand(portId, offset, length, data);
        } catch (RemoteException e) {
            Log.e(TAG, "failed to send vendor command: ", e);
        }
    
public voidsetHdmiMhlVendorCommandListener(android.hardware.hdmi.HdmiTvClient$HdmiMhlVendorCommandListener listener)
Sets {@link HdmiMhlVendorCommandListener} to get incoming MHL vendor command.

param
listener to receive incoming MHL vendor command

        if (listener == null) {
            throw new IllegalArgumentException("listener must not be null.");
        }
        try {
            mService.addHdmiMhlVendorCommandListener(getListenerWrapper(listener));
        } catch (RemoteException e) {
            Log.e(TAG, "failed to set hdmi mhl vendor command listener: ", e);
        }
    
public voidsetInputChangeListener(android.hardware.hdmi.HdmiTvClient$InputChangeListener listener)
Sets the listener used to get informed of the input change event.

param
listener listener object

        if (listener == null) {
            throw new IllegalArgumentException("listener must not be null.");
        }
        try {
            mService.setInputChangeListener(getListenerWrapper(listener));
        } catch (RemoteException e) {
            Log.e("TAG", "Failed to set InputChangeListener:", e);
        }
    
public voidsetRecordListener(HdmiRecordListener listener)
Sets record listener

param
listener

        if (listener == null) {
            throw new IllegalArgumentException("listener must not be null.");
        }
        try {
            mService.setHdmiRecordListener(getListenerWrapper(listener));
        } catch (RemoteException e) {
            Log.e(TAG, "failed to set record listener.", e);
        }
    
public voidsetSystemAudioMute(boolean mute)
Sets system audio mute status

param
mute {@code true} if muted; otherwise, {@code false}

        try {
            mService.setSystemAudioMute(mute);
        } catch (RemoteException e) {
            Log.e(TAG, "failed to set mute: ", e);
        }
    
public voidsetSystemAudioVolume(int oldIndex, int newIndex, int maxIndex)
Sets system audio volume

param
oldIndex current volume index
param
newIndex volume index to be set
param
maxIndex maximum volume index

        try {
            mService.setSystemAudioVolume(oldIndex, newIndex, maxIndex);
        } catch (RemoteException e) {
            Log.e(TAG, "failed to set volume: ", e);
        }
    
public voidstartOneTouchRecord(int recorderAddress, android.hardware.hdmi.HdmiRecordSources.RecordSource source)
Starts one touch recording with the given recorder address and recorder source.

Usage

HdmiTvClient tvClient = ....;
// for own source.
OwnSource ownSource = HdmiRecordSources.ofOwnSource();
tvClient.startOneTouchRecord(recorderAddress, ownSource);

        if (source == null) {
            throw new IllegalArgumentException("source must not be null.");
        }

        try {
            byte[] data = new byte[source.getDataSize(true)];
            source.toByteArray(true, data, 0);
            mService.startOneTouchRecord(recorderAddress, data);
        } catch (RemoteException e) {
            Log.e(TAG, "failed to start record: ", e);
        }
    
public voidstartTimerRecording(int recorderAddress, int sourceType, android.hardware.hdmi.HdmiTimerRecordSources.TimerRecordSource source)
Starts timer recording with the given recoder address and recorder source.

Usage

HdmiTvClient tvClient = ....;
// create timer info
TimerInfo timerInfo = HdmiTimerRecourdSources.timerInfoOf(...);
// for digital source.
DigitalServiceSource recordSource = HdmiRecordSources.ofDigitalService(...);
// create timer recording source.
TimerRecordSource source = HdmiTimerRecourdSources.ofDigitalSource(timerInfo, recordSource);
tvClient.startTimerRecording(recorderAddress, source);

param
recorderAddress target recorder address
param
sourceType type of record source. It should be one of {@link HdmiControlManager#TIMER_RECORDING_TYPE_DIGITAL}, {@link HdmiControlManager#TIMER_RECORDING_TYPE_ANALOGUE}, {@link HdmiControlManager#TIMER_RECORDING_TYPE_EXTERNAL}.
param
source record source to be used

        if (source == null) {
            throw new IllegalArgumentException("source must not be null.");
        }

        checkTimerRecordingSourceType(sourceType);

        try {
            byte[] data = new byte[source.getDataSize()];
            source.toByteArray(data, 0);
            mService.startTimerRecording(recorderAddress, sourceType, data);
        } catch (RemoteException e) {
            Log.e(TAG, "failed to start record: ", e);
        }
    
public voidstopOneTouchRecord(int recorderAddress)
Stops one touch record.

param
recorderAddress recorder address where recoding will be stopped

        try {
            mService.stopOneTouchRecord(recorderAddress);
        } catch (RemoteException e) {
            Log.e(TAG, "failed to stop record: ", e);
        }