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