HdmiUtils.java revision 63a2e0696ce2a04fbe0f1f00cfe9c93189f944da
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.HdmiCecMessage; 21import android.util.Slog; 22 23/** 24 * Various utilities to handle HDMI CEC messages. 25 */ 26final class HdmiUtils { 27 28 private HdmiUtils() { /* cannot be instantiated */ } 29 30 /** 31 * Verify if the given address is for the given device type. If not it will throw 32 * {@link IllegalArgumentException}. 33 * 34 * @param logicalAddress the logical address to verify 35 * @param deviceType the device type to check 36 * @throw IllegalArgumentException 37 */ 38 static void verifyAddressType(int logicalAddress, int deviceType) { 39 int actualDeviceType = HdmiCec.getTypeFromAddress(logicalAddress); 40 if (actualDeviceType != deviceType) { 41 throw new IllegalArgumentException("Device type missmatch:[Expected:" + deviceType 42 + ", Actual:" + actualDeviceType); 43 } 44 } 45 46 /** 47 * Check if the given CEC message come from the given address. 48 * 49 * @param cmd the CEC message to check 50 * @param expectedAddress the expected source address of the given message 51 * @param tag the tag of caller module (for log message) 52 * @return true if the CEC message comes from the given address 53 */ 54 static boolean checkCommandSource(HdmiCecMessage cmd, int expectedAddress, String tag) { 55 int src = cmd.getSource(); 56 if (src != expectedAddress) { 57 Slog.w(tag, "Invalid source [Expected:" + expectedAddress + ", Actual:" + src + "]"); 58 return false; 59 } 60 return true; 61 } 62 63 /** 64 * Parse the parameter block of CEC message as [System Audio Status]. 65 * 66 * @param cmd the CEC message to parse 67 * @return true if the given parameter has [ON] value 68 */ 69 static boolean parseCommandParamSystemAudioStatus(HdmiCecMessage cmd) { 70 // TODO: Handle the exception when the length is wrong. 71 return cmd.getParams().length > 0 72 && cmd.getParams()[0] == HdmiConstants.SYSTEM_AUDIO_STATUS_ON; 73 } 74} 75