HdmiPlaybackClient.java revision 8e93c84739902f5adaa499b474f39e3c4807bc1c
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 17package android.hardware.hdmi; 18 19import android.annotation.SystemApi; 20import android.os.RemoteException; 21import 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 * It provides with methods that control, get information from TV/Display device 27 * connected through HDMI bus. 28 * 29 * @hide 30 */ 31@SystemApi 32public final class HdmiPlaybackClient extends HdmiClient { 33 private static final String TAG = "HdmiPlaybackClient"; 34 35 /** 36 * Listener used by the client to get the result of one touch play operation. 37 */ 38 public interface OneTouchPlayCallback { 39 /** 40 * Called when the result of the feature one touch play is returned. 41 * 42 * @param result the result of the operation. {@link HdmiControlManager#RESULT_SUCCESS} 43 * if successful. 44 */ 45 public void onComplete(int result); 46 } 47 48 /** 49 * Listener used by the client to get display device status. 50 */ 51 public interface DisplayStatusCallback { 52 /** 53 * Called when display device status is reported. 54 * 55 * @param status display device status 56 * @see {@link HdmiControlManager#POWER_STATUS_ON} 57 * @see {@link HdmiControlManager#POWER_STATUS_STANDBY} 58 * @see {@link HdmiControlManager#POWER_STATUS_TRANSIENT_TO_ON} 59 * @see {@link HdmiControlManager#POWER_STATUS_TRANSIENT_TO_STANDBY} 60 * @see {@link HdmiControlManager#POWER_STATUS_UNKNOWN} 61 */ 62 public void onComplete(int status); 63 } 64 65 HdmiPlaybackClient(IHdmiControlService service) { 66 super(service); 67 } 68 69 /** 70 * Perform the feature 'one touch play' from playback device to turn on display 71 * and switch the input. 72 * 73 * @param callback {@link OneTouchPlayCallback} object to get informed 74 * of the result 75 */ 76 public void oneTouchPlay(OneTouchPlayCallback callback) { 77 // TODO: Use PendingResult. 78 try { 79 mService.oneTouchPlay(getCallbackWrapper(callback)); 80 } catch (RemoteException e) { 81 Log.e(TAG, "oneTouchPlay threw exception ", e); 82 } 83 } 84 85 @Override 86 public int getDeviceType() { 87 return HdmiCecDeviceInfo.DEVICE_PLAYBACK; 88 } 89 90 /** 91 * Get the status of display device connected through HDMI bus. 92 * 93 * @param callback {@link DisplayStatusCallback} object to get informed 94 * of the result 95 */ 96 public void queryDisplayStatus(DisplayStatusCallback callback) { 97 try { 98 mService.queryDisplayStatus(getCallbackWrapper(callback)); 99 } catch (RemoteException e) { 100 Log.e(TAG, "queryDisplayStatus threw exception ", e); 101 } 102 } 103 104 private IHdmiControlCallback getCallbackWrapper(final OneTouchPlayCallback callback) { 105 return new IHdmiControlCallback.Stub() { 106 @Override 107 public void onComplete(int result) { 108 callback.onComplete(result); 109 } 110 }; 111 } 112 113 private IHdmiControlCallback getCallbackWrapper(final DisplayStatusCallback callback) { 114 return new IHdmiControlCallback.Stub() { 115 @Override 116 public void onComplete(int status) { 117 callback.onComplete(status); 118 } 119 }; 120 } 121} 122