FileDocCategorySizeDatePackage
ConsumerIrService.javaAPI DocAndroid 5.1 API3894Thu Mar 12 22:22:42 GMT 2015com.android.server

ConsumerIrService

public class ConsumerIrService extends IConsumerIrService.Stub

Fields Summary
private static final String
TAG
private static final int
MAX_XMIT_TIME
private final android.content.Context
mContext
private final PowerManager.WakeLock
mWakeLock
private final long
mNativeHal
private final Object
mHalLock
Constructors Summary
ConsumerIrService(android.content.Context context)


      
        mContext = context;
        PowerManager pm = (PowerManager)context.getSystemService(
                Context.POWER_SERVICE);
        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
        mWakeLock.setReferenceCounted(true);

        mNativeHal = halOpen();
        if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CONSUMER_IR)) {
            if (mNativeHal == 0) {
                throw new RuntimeException("FEATURE_CONSUMER_IR present, but no IR HAL loaded!");
            }
        } else if (mNativeHal != 0) {
            throw new RuntimeException("IR HAL present, but FEATURE_CONSUMER_IR is not set!");
        }
    
Methods Summary
public int[]getCarrierFrequencies()

        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.TRANSMIT_IR)
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Requires TRANSMIT_IR permission");
        }

        throwIfNoIrEmitter();

        synchronized(mHalLock) {
            return halGetCarrierFrequencies(mNativeHal);
        }
    
private static native int[]halGetCarrierFrequencies(long halObject)

private static native longhalOpen()

private static native inthalTransmit(long halObject, int carrierFrequency, int[] pattern)

public booleanhasIrEmitter()

        return mNativeHal != 0;
    
private voidthrowIfNoIrEmitter()

        if (mNativeHal == 0) {
            throw new UnsupportedOperationException("IR emitter not available");
        }
    
public voidtransmit(java.lang.String packageName, int carrierFrequency, int[] pattern)

        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.TRANSMIT_IR)
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Requires TRANSMIT_IR permission");
        }

        long totalXmitTime = 0;

        for (int slice : pattern) {
            if (slice <= 0) {
                throw new IllegalArgumentException("Non-positive IR slice");
            }
            totalXmitTime += slice;
        }

        if (totalXmitTime > MAX_XMIT_TIME ) {
            throw new IllegalArgumentException("IR pattern too long");
        }

        throwIfNoIrEmitter();

        // Right now there is no mechanism to ensure fair queing of IR requests
        synchronized (mHalLock) {
            int err = halTransmit(mNativeHal, carrierFrequency, pattern);

            if (err < 0) {
                Slog.e(TAG, "Error transmitting: " + err);
            }
        }