HdmiCecLocalDevicePlayback.java revision 79c58a4b97f27ede6a1b680d2fece9c2a0edf7b7
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 com.android.server.hdmi; 18 19import android.hardware.hdmi.HdmiCec; 20import android.hardware.hdmi.IHdmiControlCallback; 21import android.os.RemoteException; 22import android.util.Slog; 23 24/** 25 * Represent a logical device of type Playback residing in Android system. 26 */ 27final class HdmiCecLocalDevicePlayback extends HdmiCecLocalDevice { 28 private static final String TAG = "HdmiCecLocalDevicePlayback"; 29 30 HdmiCecLocalDevicePlayback(HdmiControlService service) { 31 super(service, HdmiCec.DEVICE_PLAYBACK); 32 } 33 34 @Override 35 protected void onAddressAllocated(int logicalAddress) { 36 mService.sendCecCommand(HdmiCecMessageBuilder.buildReportPhysicalAddressCommand( 37 mAddress, mService.getPhysicalAddress(), mDeviceType)); 38 } 39 40 void oneTouchPlay(IHdmiControlCallback callback) { 41 assertRunOnServiceThread(); 42 if (hasAction(OneTouchPlayAction.class)) { 43 Slog.w(TAG, "oneTouchPlay already in progress"); 44 invokeCallback(callback, HdmiCec.RESULT_ALREADY_IN_PROGRESS); 45 return; 46 } 47 48 // TODO: Consider the case of multiple TV sets. For now we always direct the command 49 // to the primary one. 50 OneTouchPlayAction action = OneTouchPlayAction.create(this, HdmiCec.ADDR_TV, callback); 51 if (action == null) { 52 Slog.w(TAG, "Cannot initiate oneTouchPlay"); 53 invokeCallback(callback, HdmiCec.RESULT_EXCEPTION); 54 return; 55 } 56 addAndStartAction(action); 57 } 58 59 void queryDisplayStatus(IHdmiControlCallback callback) { 60 assertRunOnServiceThread(); 61 if (hasAction(DevicePowerStatusAction.class)) { 62 Slog.w(TAG, "queryDisplayStatus already in progress"); 63 invokeCallback(callback, HdmiCec.RESULT_ALREADY_IN_PROGRESS); 64 return; 65 } 66 DevicePowerStatusAction action = DevicePowerStatusAction.create(this, 67 HdmiCec.ADDR_TV, callback); 68 if (action == null) { 69 Slog.w(TAG, "Cannot initiate queryDisplayStatus"); 70 invokeCallback(callback, HdmiCec.RESULT_EXCEPTION); 71 return; 72 } 73 addAndStartAction(action); 74 } 75 76 private void invokeCallback(IHdmiControlCallback callback, int result) { 77 try { 78 callback.onComplete(result); 79 } catch (RemoteException e) { 80 Slog.e(TAG, "Invoking callback failed:" + e); 81 } 82 } 83 84 @Override 85 void onHotplug(int portId, boolean connected) { 86 // TODO: clear devices connected to the given port id. 87 mCecMessageCache.flushAll(); 88 } 89} 90