FileDocCategorySizeDatePackage
RemoteDisplayProviderProxy.javaAPI DocAndroid 5.1 API13857Thu Mar 12 22:22:42 GMT 2015com.android.server.media

RemoteDisplayProviderProxy

public final class RemoteDisplayProviderProxy extends Object implements android.content.ServiceConnection
Maintains a connection to a particular remote display provider service.

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private final android.content.Context
mContext
private final android.content.ComponentName
mComponentName
private final int
mUserId
private final android.os.Handler
mHandler
private Callback
mDisplayStateCallback
private boolean
mRunning
private boolean
mBound
private Connection
mActiveConnection
private boolean
mConnectionReady
private int
mDiscoveryMode
private String
mSelectedDisplayId
private android.media.RemoteDisplayState
mDisplayState
private boolean
mScheduledDisplayStateChangedCallback
private final Runnable
mDisplayStateChanged
Constructors Summary
public RemoteDisplayProviderProxy(android.content.Context context, android.content.ComponentName componentName, int userId)


        
              
        mContext = context;
        mComponentName = componentName;
        mUserId = userId;
        mHandler = new Handler();
    
Methods Summary
public voidadjustDisplayVolume(int delta)

        if (mConnectionReady && mSelectedDisplayId != null) {
            mActiveConnection.adjustVolume(mSelectedDisplayId, delta);
        }
    
private voidbind()

        if (!mBound) {
            if (DEBUG) {
                Slog.d(TAG, this + ": Binding");
            }

            Intent service = new Intent(RemoteDisplayState.SERVICE_INTERFACE);
            service.setComponent(mComponentName);
            try {
                mBound = mContext.bindServiceAsUser(service, this, Context.BIND_AUTO_CREATE,
                        new UserHandle(mUserId));
                if (!mBound && DEBUG) {
                    Slog.d(TAG, this + ": Bind failed");
                }
            } catch (SecurityException ex) {
                if (DEBUG) {
                    Slog.d(TAG, this + ": Bind failed", ex);
                }
            }
        }
    
private voiddisconnect()

        if (mActiveConnection != null) {
            if (mSelectedDisplayId != null) {
                mActiveConnection.disconnect(mSelectedDisplayId);
            }
            mConnectionReady = false;
            mActiveConnection.dispose();
            mActiveConnection = null;
            setDisplayState(null);
        }
    
public voiddump(java.io.PrintWriter pw, java.lang.String prefix)

        pw.println(prefix + "Proxy");
        pw.println(prefix + "  mUserId=" + mUserId);
        pw.println(prefix + "  mRunning=" + mRunning);
        pw.println(prefix + "  mBound=" + mBound);
        pw.println(prefix + "  mActiveConnection=" + mActiveConnection);
        pw.println(prefix + "  mConnectionReady=" + mConnectionReady);
        pw.println(prefix + "  mDiscoveryMode=" + mDiscoveryMode);
        pw.println(prefix + "  mSelectedDisplayId=" + mSelectedDisplayId);
        pw.println(prefix + "  mDisplayState=" + mDisplayState);
    
public android.media.RemoteDisplayStategetDisplayState()

        return mDisplayState;
    
public java.lang.StringgetFlattenedComponentName()

        return mComponentName.flattenToShortString();
    
public booleanhasComponentName(java.lang.String packageName, java.lang.String className)

        return mComponentName.getPackageName().equals(packageName)
                && mComponentName.getClassName().equals(className);
    
private voidonConnectionDied(com.android.server.media.RemoteDisplayProviderProxy$Connection connection)

        if (mActiveConnection == connection) {
            if (DEBUG) {
                Slog.d(TAG, this + ": Service connection died");
            }
            disconnect();
        }
    
private voidonConnectionReady(com.android.server.media.RemoteDisplayProviderProxy$Connection connection)

        if (mActiveConnection == connection) {
            mConnectionReady = true;

            if (mDiscoveryMode != RemoteDisplayState.DISCOVERY_MODE_NONE) {
                mActiveConnection.setDiscoveryMode(mDiscoveryMode);
            }
            if (mSelectedDisplayId != null) {
                mActiveConnection.connect(mSelectedDisplayId);
            }
        }
    
private voidonDisplayStateChanged(com.android.server.media.RemoteDisplayProviderProxy$Connection connection, android.media.RemoteDisplayState state)

        if (mActiveConnection == connection) {
            if (DEBUG) {
                Slog.d(TAG, this + ": State changed, state=" + state);
            }
            setDisplayState(state);
        }
    
public voidonServiceConnected(android.content.ComponentName name, android.os.IBinder service)

        if (DEBUG) {
            Slog.d(TAG, this + ": Connected");
        }

        if (mBound) {
            disconnect();

            IRemoteDisplayProvider provider = IRemoteDisplayProvider.Stub.asInterface(service);
            if (provider != null) {
                Connection connection = new Connection(provider);
                if (connection.register()) {
                    mActiveConnection = connection;
                } else {
                    if (DEBUG) {
                        Slog.d(TAG, this + ": Registration failed");
                    }
                }
            } else {
                Slog.e(TAG, this + ": Service returned invalid remote display provider binder");
            }
        }
    
public voidonServiceDisconnected(android.content.ComponentName name)

        if (DEBUG) {
            Slog.d(TAG, this + ": Service disconnected");
        }
        disconnect();
    
public voidrebindIfDisconnected()

        if (mActiveConnection == null && shouldBind()) {
            unbind();
            bind();
        }
    
public voidsetCallback(com.android.server.media.RemoteDisplayProviderProxy$Callback callback)

        mDisplayStateCallback = callback;
    
public voidsetDiscoveryMode(int mode)

        if (mDiscoveryMode != mode) {
            mDiscoveryMode = mode;
            if (mConnectionReady) {
                mActiveConnection.setDiscoveryMode(mode);
            }
            updateBinding();
        }
    
private voidsetDisplayState(android.media.RemoteDisplayState state)

        if (!Objects.equals(mDisplayState, state)) {
            mDisplayState = state;
            if (!mScheduledDisplayStateChangedCallback) {
                mScheduledDisplayStateChangedCallback = true;
                mHandler.post(mDisplayStateChanged);
            }
        }
    
public voidsetDisplayVolume(int volume)

        if (mConnectionReady && mSelectedDisplayId != null) {
            mActiveConnection.setVolume(mSelectedDisplayId, volume);
        }
    
public voidsetSelectedDisplay(java.lang.String id)

        if (!Objects.equals(mSelectedDisplayId, id)) {
            if (mConnectionReady && mSelectedDisplayId != null) {
                mActiveConnection.disconnect(mSelectedDisplayId);
            }
            mSelectedDisplayId = id;
            if (mConnectionReady && id != null) {
                mActiveConnection.connect(id);
            }
            updateBinding();
        }
    
private booleanshouldBind()

        if (mRunning) {
            // Bind whenever there is a discovery request or selected display.
            if (mDiscoveryMode != RemoteDisplayState.DISCOVERY_MODE_NONE
                    || mSelectedDisplayId != null) {
                return true;
            }
        }
        return false;
    
public voidstart()

        if (!mRunning) {
            if (DEBUG) {
                Slog.d(TAG, this + ": Starting");
            }

            mRunning = true;
            updateBinding();
        }
    
public voidstop()

        if (mRunning) {
            if (DEBUG) {
                Slog.d(TAG, this + ": Stopping");
            }

            mRunning = false;
            updateBinding();
        }
    
public java.lang.StringtoString()

        return "Service connection " + mComponentName.flattenToShortString();
    
private voidunbind()

        if (mBound) {
            if (DEBUG) {
                Slog.d(TAG, this + ": Unbinding");
            }

            mBound = false;
            disconnect();
            mContext.unbindService(this);
        }
    
private voidupdateBinding()

        if (shouldBind()) {
            bind();
        } else {
            unbind();
        }