1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.hardware.hdmi; 18 19 import android.annotation.SystemApi; 20 import android.os.RemoteException; 21 import android.util.Log; 22 23 /** 24 * HdmiPlaybackClient represents HDMI-CEC logical device of type Playback 25 * in the Android system which acts as a playback device such as set-top box. 26 * 27 * <p>HdmiPlaybackClient provides methods that control, get information from TV/Display device 28 * connected through HDMI bus. 29 * 30 * @hide 31 */ 32 @SystemApi 33 public final class HdmiPlaybackClient extends HdmiClient { 34 private static final String TAG = "HdmiPlaybackClient"; 35 36 // Logical address of TV. The secondary TV is not handled. 37 private static final int ADDR_TV = 0; 38 39 /** 40 * Listener used by the client to get the result of one touch play operation. 41 */ 42 public interface OneTouchPlayCallback { 43 /** 44 * Called when the result of the feature one touch play is returned. 45 * 46 * @param result the result of the operation. {@link HdmiControlManager#RESULT_SUCCESS} 47 * if successful. 48 */ onComplete(int result)49 public void onComplete(int result); 50 } 51 52 /** 53 * Listener used by the client to get display device status. 54 */ 55 public interface DisplayStatusCallback { 56 /** 57 * Called when display device status is reported. 58 * 59 * @param status display device status. It should be one of the following values. 60 * <ul> 61 * <li>{@link HdmiControlManager#POWER_STATUS_ON} 62 * <li>{@link HdmiControlManager#POWER_STATUS_STANDBY} 63 * <li>{@link HdmiControlManager#POWER_STATUS_TRANSIENT_TO_ON} 64 * <li>{@link HdmiControlManager#POWER_STATUS_TRANSIENT_TO_STANDBY} 65 * <li>{@link HdmiControlManager#POWER_STATUS_UNKNOWN} 66 * </ul> 67 */ onComplete(int status)68 public void onComplete(int status); 69 } 70 HdmiPlaybackClient(IHdmiControlService service)71 /* package */ HdmiPlaybackClient(IHdmiControlService service) { 72 super(service); 73 } 74 75 /** 76 * Performs the feature 'one touch play' from playback device to turn on display 77 * and switch the input. 78 * 79 * @param callback {@link OneTouchPlayCallback} object to get informed 80 * of the result 81 */ oneTouchPlay(OneTouchPlayCallback callback)82 public void oneTouchPlay(OneTouchPlayCallback callback) { 83 // TODO: Use PendingResult. 84 try { 85 mService.oneTouchPlay(getCallbackWrapper(callback)); 86 } catch (RemoteException e) { 87 Log.e(TAG, "oneTouchPlay threw exception ", e); 88 } 89 } 90 91 @Override getDeviceType()92 public int getDeviceType() { 93 return HdmiDeviceInfo.DEVICE_PLAYBACK; 94 } 95 96 /** 97 * Gets the status of display device connected through HDMI bus. 98 * 99 * @param callback {@link DisplayStatusCallback} object to get informed 100 * of the result 101 */ queryDisplayStatus(DisplayStatusCallback callback)102 public void queryDisplayStatus(DisplayStatusCallback callback) { 103 try { 104 mService.queryDisplayStatus(getCallbackWrapper(callback)); 105 } catch (RemoteException e) { 106 Log.e(TAG, "queryDisplayStatus threw exception ", e); 107 } 108 } 109 110 /** 111 * Sends a <Standby> command to TV. 112 */ sendStandby()113 public void sendStandby() { 114 try { 115 mService.sendStandby(getDeviceType(), HdmiDeviceInfo.idForCecDevice(ADDR_TV)); 116 } catch (RemoteException e) { 117 Log.e(TAG, "sendStandby threw exception ", e); 118 } 119 } 120 getCallbackWrapper(final OneTouchPlayCallback callback)121 private IHdmiControlCallback getCallbackWrapper(final OneTouchPlayCallback callback) { 122 return new IHdmiControlCallback.Stub() { 123 @Override 124 public void onComplete(int result) { 125 callback.onComplete(result); 126 } 127 }; 128 } 129 130 private IHdmiControlCallback getCallbackWrapper(final DisplayStatusCallback callback) { 131 return new IHdmiControlCallback.Stub() { 132 @Override 133 public void onComplete(int status) { 134 callback.onComplete(status); 135 } 136 }; 137 } 138 } 139