FileDocCategorySizeDatePackage
HdmiCecMessageCache.javaAPI DocAndroid 5.1 API3320Thu Mar 12 22:22:42 GMT 2015com.android.server.hdmi

HdmiCecMessageCache

public final class HdmiCecMessageCache extends Object
Cache for incoming message. It caches {@link HdmiCecMessage} with source address and opcode as a key.

Note that whenever a device is removed it should call {@link #flushMessagesFrom(int)} to clean up messages come from the device.

Fields Summary
private static final android.util.FastImmutableArraySet
CACHEABLE_OPCODES
private final android.util.SparseArray
mCache
Constructors Summary
HdmiCecMessageCache()


     
    
Methods Summary
public voidcacheMessage(HdmiCecMessage message)
Cache incoming {@link HdmiCecMessage}. If opcode of message is not listed on cacheable opcodes list, just ignore it.

param
message a {@link HdmiCecMessage} to be cached

        int opcode = message.getOpcode();
        if (!isCacheable(opcode)) {
            return;
        }

        int source = message.getSource();
        SparseArray<HdmiCecMessage> messages = mCache.get(source);
        if (messages == null) {
            messages = new SparseArray<>();
            mCache.put(source, messages);
        }
        messages.put(opcode, message);
    
public voidflushAll()
Flush all cached {@link HdmiCecMessage}s.

        mCache.clear();
    
public voidflushMessagesFrom(int address)
Flush all {@link HdmiCecMessage}s sent from the given {@code address}.

param
address a logical address of source device

        mCache.remove(address);
    
public HdmiCecMessagegetMessage(int address, int opcode)
Return a {@link HdmiCecMessage} corresponding to the given {@code address} and {@code opcode}.

param
address a logical address of source device
param
opcode opcode of message
return
null if has no {@link HdmiCecMessage} matched to the given {@code address} and {code opcode}

        SparseArray<HdmiCecMessage> messages = mCache.get(address);
        if (messages == null) {
            return null;
        }

        return messages.get(opcode);
    
private booleanisCacheable(int opcode)

        return CACHEABLE_OPCODES.contains(opcode);