Home | History | Annotate | Download | only in hdmi
      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  * It provides with methods that control, get information from TV/Display device
     27  * connected through HDMI bus.
     28  *
     29  * @hide
     30  */
     31 @SystemApi
     32 public 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. It should be one of the following values.
     56          *            <ul>
     57          *            <li>{@link HdmiControlManager#POWER_STATUS_ON}
     58          *            <li>{@link HdmiControlManager#POWER_STATUS_STANDBY}
     59          *            <li>{@link HdmiControlManager#POWER_STATUS_TRANSIENT_TO_ON}
     60          *            <li>{@link HdmiControlManager#POWER_STATUS_TRANSIENT_TO_STANDBY}
     61          *            <li>{@link HdmiControlManager#POWER_STATUS_UNKNOWN}
     62          *            </ul>
     63          */
     64         public void onComplete(int status);
     65     }
     66 
     67     HdmiPlaybackClient(IHdmiControlService service) {
     68         super(service);
     69     }
     70 
     71     /**
     72      * Perform the feature 'one touch play' from playback device to turn on display
     73      * and switch the input.
     74      *
     75      * @param callback {@link OneTouchPlayCallback} object to get informed
     76      *         of the result
     77      */
     78     public void oneTouchPlay(OneTouchPlayCallback callback) {
     79         // TODO: Use PendingResult.
     80         try {
     81             mService.oneTouchPlay(getCallbackWrapper(callback));
     82         } catch (RemoteException e) {
     83             Log.e(TAG, "oneTouchPlay threw exception ", e);
     84         }
     85     }
     86 
     87     @Override
     88     public int getDeviceType() {
     89         return HdmiDeviceInfo.DEVICE_PLAYBACK;
     90     }
     91 
     92     /**
     93      * Get the status of display device connected through HDMI bus.
     94      *
     95      * @param callback {@link DisplayStatusCallback} object to get informed
     96      *         of the result
     97      */
     98     public void queryDisplayStatus(DisplayStatusCallback callback) {
     99         try {
    100             mService.queryDisplayStatus(getCallbackWrapper(callback));
    101         } catch (RemoteException e) {
    102             Log.e(TAG, "queryDisplayStatus threw exception ", e);
    103         }
    104     }
    105 
    106     private IHdmiControlCallback getCallbackWrapper(final OneTouchPlayCallback callback) {
    107         return new IHdmiControlCallback.Stub() {
    108             @Override
    109             public void onComplete(int result) {
    110                 callback.onComplete(result);
    111             }
    112         };
    113     }
    114 
    115     private IHdmiControlCallback getCallbackWrapper(final DisplayStatusCallback callback) {
    116         return new IHdmiControlCallback.Stub() {
    117             @Override
    118             public void onComplete(int status) {
    119                 callback.onComplete(status);
    120             }
    121         };
    122     }
    123 }
    124