HdmiClient.java revision 119160a68195bcb2f5bdf4a269807e01228eca97
1package android.hardware.hdmi; 2 3import android.annotation.SystemApi; 4import android.hardware.hdmi.HdmiControlManager.VendorCommandListener; 5import android.hardware.hdmi.IHdmiVendorCommandListener; 6import android.os.RemoteException; 7import android.util.Log; 8 9/** 10 * Parent for classes of various HDMI-CEC device type used to access 11 * {@link HdmiControlService}. Contains methods and data used in common. 12 * 13 * @hide 14 */ 15public abstract class HdmiClient { 16 private static final String TAG = "HdmiClient"; 17 18 protected final IHdmiControlService mService; 19 20 protected abstract int getDeviceType(); 21 22 public HdmiClient(IHdmiControlService service) { 23 mService = service; 24 } 25 26 public void sendVendorCommand(int targetAddress, byte[] params, boolean hasVendorId) { 27 try { 28 mService.sendVendorCommand(getDeviceType(), targetAddress, params, hasVendorId); 29 } catch (RemoteException e) { 30 Log.e(TAG, "failed to send vendor command: ", e); 31 } 32 } 33 34 public void addVendorCommandListener(VendorCommandListener listener) { 35 try { 36 mService.addVendorCommandListener(getListenerWrapper(listener), getDeviceType()); 37 } catch (RemoteException e) { 38 Log.e(TAG, "failed to add vendor command listener: ", e); 39 } 40 } 41 42 private static IHdmiVendorCommandListener getListenerWrapper( 43 final VendorCommandListener listener) { 44 return new IHdmiVendorCommandListener.Stub() { 45 @Override 46 public void onReceived(int srcAddress, byte[] params, boolean hasVendorId) { 47 listener.onReceived(srcAddress, params, hasVendorId); 48 } 49 }; 50 } 51} 52