FileDocCategorySizeDatePackage
DisplaySourceService.javaAPI DocAndroid 5.1 API8961Thu Mar 12 22:22:42 GMT 2015com.android.accessorydisplay.source

DisplaySourceService

public class DisplaySourceService extends com.android.accessorydisplay.common.Service

Fields Summary
private static final int
MSG_DISPATCH_DISPLAY_ADDED
private static final int
MSG_DISPATCH_DISPLAY_REMOVED
private static final String
DISPLAY_NAME
private static final int
BIT_RATE
private static final int
FRAME_RATE
private static final int
I_FRAME_INTERVAL
private final Callbacks
mCallbacks
private final ServiceHandler
mHandler
private final android.hardware.display.DisplayManager
mDisplayManager
private boolean
mSinkAvailable
private int
mSinkWidth
private int
mSinkHeight
private int
mSinkDensityDpi
private VirtualDisplayThread
mVirtualDisplayThread
Constructors Summary
public DisplaySourceService(android.content.Context context, com.android.accessorydisplay.common.Transport transport, Callbacks callbacks)


           
        super(context, transport, Protocol.DisplaySourceService.ID);
        mCallbacks = callbacks;
        mHandler = new ServiceHandler();
        mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE);
    
Methods Summary
private voidcreateVirtualDisplay()

        releaseVirtualDisplay();

        mVirtualDisplayThread = new VirtualDisplayThread(
                mSinkWidth, mSinkHeight, mSinkDensityDpi);
        mVirtualDisplayThread.start();
    
private voidhandleSinkAvailable(int width, int height, int densityDpi)

        if (mSinkAvailable && mSinkWidth == width && mSinkHeight == height
                && mSinkDensityDpi == densityDpi) {
            return;
        }

        getLogger().log("Accessory display sink available: "
                + "width=" + width + ", height=" + height
                + ", densityDpi=" + densityDpi);
        mSinkAvailable = true;
        mSinkWidth = width;
        mSinkHeight = height;
        mSinkDensityDpi = densityDpi;
        createVirtualDisplay();
    
private voidhandleSinkNotAvailable()

        getLogger().log("Accessory display sink not available.");

        mSinkAvailable = false;
        mSinkWidth = 0;
        mSinkHeight = 0;
        mSinkDensityDpi = 0;
        releaseVirtualDisplay();
    
public voidonMessageReceived(int service, int what, java.nio.ByteBuffer content)

        switch (what) {
            case Protocol.DisplaySourceService.MSG_SINK_AVAILABLE: {
                getLogger().log("Received MSG_SINK_AVAILABLE");
                if (content.remaining() >= 12) {
                    final int width = content.getInt();
                    final int height = content.getInt();
                    final int densityDpi = content.getInt();
                    if (width >= 0 && width <= 4096
                            && height >= 0 && height <= 4096
                            && densityDpi >= 60 && densityDpi <= 640) {
                        handleSinkAvailable(width, height, densityDpi);
                        return;
                    }
                }
                getLogger().log("Receive invalid MSG_SINK_AVAILABLE message.");
                break;
            }

            case Protocol.DisplaySourceService.MSG_SINK_NOT_AVAILABLE: {
                getLogger().log("Received MSG_SINK_NOT_AVAILABLE");
                handleSinkNotAvailable();
                break;
            }
        }
    
private voidreleaseVirtualDisplay()

        if (mVirtualDisplayThread != null) {
            mVirtualDisplayThread.quit();
            mVirtualDisplayThread = null;
        }
    
public voidstart()

        super.start();

        getLogger().log("Sending MSG_QUERY.");
        getTransport().sendMessage(Protocol.DisplaySinkService.ID,
                Protocol.DisplaySinkService.MSG_QUERY, null);
    
public voidstop()

        super.stop();

        handleSinkNotAvailable();