FileDocCategorySizeDatePackage
RemoteDisplayProvider.javaAPI DocAndroid 5.1 API13612Thu Mar 12 22:22:30 GMT 2015com.android.media.remotedisplay

RemoteDisplayProvider

public abstract class RemoteDisplayProvider extends Object
Base class for remote display providers implemented as unbundled services.

To implement your remote display provider service, create a subclass of {@link Service} and override the {@link Service#onBind Service.onBind()} method to return the provider's binder when the {@link #SERVICE_INTERFACE} is requested.

public class SampleRemoteDisplayProviderService extends Service {
private SampleProvider mProvider;

public IBinder onBind(Intent intent) {
if (intent.getAction().equals(RemoteDisplayProvider.SERVICE_INTERFACE)) {
if (mProvider == null) {
mProvider = new SampleProvider(this);
}
return mProvider.getBinder();
}
return null;
}

class SampleProvider extends RemoteDisplayProvider {
public SampleProvider() {
super(SampleRemoteDisplayProviderService.this);
}

// --- Implementation goes here ---
}
}

Declare your remote display provider service in your application manifest like this:

<application>
<uses-library android:name="com.android.media.remotedisplay" />

<service android:name=".SampleRemoteDisplayProviderService"
android:label="@string/sample_remote_display_provider_service"
android:exported="true"
android:permission="android.permission.BIND_REMOTE_DISPLAY">
<intent-filter>
<action android:name="com.android.media.remotedisplay.RemoteDisplayProvider" />
</intent-filter>
</service>
</application>

This object is not thread safe. It is only intended to be accessed on the {@link Context#getMainLooper main looper thread} of an application.

IMPORTANT: This class is effectively a public API for unbundled applications, and must remain API stable. See README.txt in the root of this package for more information.

Fields Summary
private static final int
MSG_SET_CALLBACK
private static final int
MSG_SET_DISCOVERY_MODE
private static final int
MSG_CONNECT
private static final int
MSG_DISCONNECT
private static final int
MSG_SET_VOLUME
private static final int
MSG_ADJUST_VOLUME
private final android.content.Context
mContext
private final ProviderStub
mStub
private final ProviderHandler
mHandler
private final android.util.ArrayMap
mDisplays
private android.media.IRemoteDisplayCallback
mCallback
private int
mDiscoveryMode
private android.app.PendingIntent
mSettingsPendingIntent
public static final String
SERVICE_INTERFACE
The {@link Intent} that must be declared as handled by the service. Put this in your manifest.
public static final int
DISCOVERY_MODE_NONE
Discovery mode: Do not perform any discovery.
public static final int
DISCOVERY_MODE_PASSIVE
Discovery mode: Passive or low-power periodic discovery.

This mode indicates that an application is interested in knowing whether there are any remote displays paired or available but doesn't need the latest or most detailed information. The provider may scan at a lower rate or rely on knowledge of previously paired devices.

public static final int
DISCOVERY_MODE_ACTIVE
Discovery mode: Active discovery.

This mode indicates that the user is actively trying to connect to a route and we should perform continuous scans. This mode may use significantly more power but is intended to be short-lived.

Constructors Summary
public RemoteDisplayProvider(android.content.Context context)
Creates a remote display provider.

param
context The application context for the remote display provider.


                        
       
        mContext = context;
        mStub = new ProviderStub();
        mHandler = new ProviderHandler(context.getMainLooper());
    
Methods Summary
public voidaddDisplay(RemoteDisplay display)
Adds the specified remote display and notifies the system.

param
display The remote display that was added.
throws
IllegalStateException if there is already a display with the same id.

        if (display == null || mDisplays.containsKey(display.getId())) {
            throw new IllegalArgumentException("display");
        }
        mDisplays.put(display.getId(), display);
        publishState();
    
public RemoteDisplayfindRemoteDisplay(java.lang.String id)
Finds the remote display with the specified id, returns null if not found.

param
id Id of the remote display.
return
The display, or null if none.

        return mDisplays.get(id);
    
public android.os.IBindergetBinder()
Gets the Binder associated with the provider.

This is intended to be used for the onBind() method of a service that implements a remote display provider service.

return
The IBinder instance associated with the provider.

        return mStub;
    
public final android.content.ContextgetContext()
Gets the context of the remote display provider.

        return mContext;
    
public intgetDiscoveryMode()
Gets the current discovery mode.

return
The current discovery mode.

        return mDiscoveryMode;
    
public java.util.CollectiongetDisplays()
Gets the current collection of displays.

return
The current collection of displays, which must not be modified.

        return mDisplays.values();
    
public android.app.PendingIntentgetSettingsPendingIntent()
Gets a pending intent to launch the remote display settings activity.

return
A pending intent to launch the settings activity.

        if (mSettingsPendingIntent == null) {
            Intent settingsIntent = new Intent(Settings.ACTION_WIFI_DISPLAY_SETTINGS);
            settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                    | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            mSettingsPendingIntent = PendingIntent.getActivity(
                    mContext, 0, settingsIntent, 0, null);
        }
        return mSettingsPendingIntent;
    
public voidonAdjustVolume(RemoteDisplay display, int delta)
Called when the system would like to adjust the volume of a display.

param
display The remote display.
param
delta An increment to add to the current volume, such as +1 or -1.

    
public voidonConnect(RemoteDisplay display)
Called when the system would like to connect to a display.

param
display The remote display.

    
public voidonDisconnect(RemoteDisplay display)
Called when the system would like to disconnect from a display.

param
display The remote display.

    
public voidonDiscoveryModeChanged(int mode)
Called when the current discovery mode changes.

param
mode The new discovery mode.

    
public voidonSetVolume(RemoteDisplay display, int volume)
Called when the system would like to set the volume of a display.

param
display The remote display.
param
volume The desired volume.

    
voidpublishState()

        if (mCallback != null) {
            RemoteDisplayState state = new RemoteDisplayState();
            final int count = mDisplays.size();
            for (int i = 0; i < count; i++) {
                final RemoteDisplay display = mDisplays.valueAt(i);
                state.displays.add(display.getInfo());
            }
            try {
                mCallback.onStateChanged(state);
            } catch (RemoteException ex) {
                // system server died?
            }
        }
    
public voidremoveDisplay(RemoteDisplay display)
Removes the specified remote display and tells the system about it.

param
display The remote display that was removed.

        if (display == null || mDisplays.get(display.getId()) != display) {
            throw new IllegalArgumentException("display");
        }
        mDisplays.remove(display.getId());
        publishState();
    
voidsetCallback(android.media.IRemoteDisplayCallback callback)

        mCallback = callback;
        publishState();
    
voidsetDiscoveryMode(int mode)

        if (mDiscoveryMode != mode) {
            mDiscoveryMode = mode;
            onDiscoveryModeChanged(mode);
        }
    
public voidupdateDisplay(RemoteDisplay display)
Updates information about the specified remote display and notifies the system.

param
display The remote display that was added.
throws
IllegalStateException if the display was n

        if (display == null || mDisplays.get(display.getId()) != display) {
            throw new IllegalArgumentException("display");
        }
        publishState();