/* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.media.remotedisplay; import android.app.PendingIntent; import android.app.Service; import android.content.Context; import android.content.Intent; import android.media.IRemoteDisplayCallback; import android.media.IRemoteDisplayProvider; import android.media.RemoteDisplayState; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.RemoteException; import android.provider.Settings; import android.util.ArrayMap; import java.util.Collection; /** * 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. *
*/ public abstract class RemoteDisplayProvider { private static final int MSG_SET_CALLBACK = 1; private static final int MSG_SET_DISCOVERY_MODE = 2; private static final int MSG_CONNECT = 3; private static final int MSG_DISCONNECT = 4; private static final int MSG_SET_VOLUME = 5; private static final int MSG_ADJUST_VOLUME = 6; private final Context mContext; private final ProviderStub mStub; private final ProviderHandler mHandler; private final ArrayMap* 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_PASSIVE = RemoteDisplayState.DISCOVERY_MODE_PASSIVE; /** * 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. *
*/ public static final int DISCOVERY_MODE_ACTIVE = RemoteDisplayState.DISCOVERY_MODE_ACTIVE; /** * Creates a remote display provider. * * @param context The application context for the remote display provider. */ public RemoteDisplayProvider(Context context) { mContext = context; mStub = new ProviderStub(); mHandler = new ProviderHandler(context.getMainLooper()); } /** * Gets the context of the remote display provider. */ public final Context getContext() { return mContext; } /** * 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. */ public IBinder getBinder() { return mStub; } /** * Called when the current discovery mode changes. * * @param mode The new discovery mode. */ public void onDiscoveryModeChanged(int mode) { } /** * Called when the system would like to connect to a display. * * @param display The remote display. */ public void onConnect(RemoteDisplay display) { } /** * Called when the system would like to disconnect from a display. * * @param display The remote display. */ public void onDisconnect(RemoteDisplay display) { } /** * Called when the system would like to set the volume of a display. * * @param display The remote display. * @param volume The desired volume. */ public void onSetVolume(RemoteDisplay display, int volume) { } /** * 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 void onAdjustVolume(RemoteDisplay display, int delta) { } /** * Gets the current discovery mode. * * @return The current discovery mode. */ public int getDiscoveryMode() { return mDiscoveryMode; } /** * Gets the current collection of displays. * * @return The current collection of displays, which must not be modified. */ public Collection