HdmiTvClient.java revision 41d974631c5f525da49c88d34cecedd5a4cfeda8
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 */ 16package android.hardware.hdmi; 17 18import android.annotation.SystemApi; 19import android.os.RemoteException; 20import android.util.Log; 21 22/** 23 * HdmiTvClient represents HDMI-CEC logical device of type TV in the Android system 24 * which acts as TV/Display. It provides with methods that manage, interact with other 25 * devices on the CEC bus. 26 * 27 * @hide 28 */ 29@SystemApi 30public final class HdmiTvClient { 31 private static final String TAG = "HdmiTvClient"; 32 33 private final IHdmiControlService mService; 34 35 HdmiTvClient(IHdmiControlService service) { 36 mService = service; 37 } 38 39 // Factory method for HdmiTvClient. 40 // Declared package-private. Accessed by HdmiControlManager only. 41 static HdmiTvClient create(IHdmiControlService service) { 42 return new HdmiTvClient(service); 43 } 44 45 /** 46 * Callback interface used to get the result of {@link #deviceSelect}. 47 */ 48 public interface SelectCallback { 49 /** 50 * Called when the operation is finished. 51 * 52 * @param result the result value of {@link #deviceSelect} 53 */ 54 void onComplete(int result); 55 } 56 57 /** 58 * Select a CEC logical device to be a new active source. 59 * 60 * @param logicalAddress 61 * @param callback 62 */ 63 public void deviceSelect(int logicalAddress, SelectCallback callback) { 64 // TODO: Replace SelectCallback with PartialResult. 65 try { 66 mService.deviceSelect(logicalAddress, getCallbackWrapper(callback)); 67 } catch (RemoteException e) { 68 Log.e(TAG, "failed to select device: ", e); 69 } 70 } 71 72 /** 73 * Set system audio volume 74 * 75 * @param oldIndex current volume index 76 * @param newIndex volume index to be set 77 * @param maxIndex maximum volume index 78 */ 79 public void setSystemAudioVolume(int oldIndex, int newIndex, int maxIndex) { 80 try { 81 mService.setSystemAudioVolume(oldIndex, newIndex, maxIndex); 82 } catch (RemoteException e) { 83 Log.e(TAG, "failed to set volume: ", e); 84 } 85 } 86 87 /** 88 * Set system audio mute status 89 * 90 * @param mute {@code true} if muted; otherwise, {@code false} 91 */ 92 public void setSystemAudioMute(boolean mute) { 93 try { 94 mService.setSystemAudioMute(mute); 95 } catch (RemoteException e) { 96 Log.e(TAG, "failed to set mute: ", e); 97 } 98 } 99 100 private static IHdmiControlCallback getCallbackWrapper(final SelectCallback callback) { 101 return new IHdmiControlCallback.Stub() { 102 @Override 103 public void onComplete(int result) { 104 callback.onComplete(result); 105 } 106 }; 107 } 108} 109