Merge changes I7ac3a378,Id06a24d2 into rvc-dev
* changes: Controls API - Docs + method name change Controls API - Publisher change - Phase 2
This commit is contained in:
@@ -43448,12 +43448,12 @@ package android.service.controls {
|
|||||||
|
|
||||||
public abstract class ControlsProviderService extends android.app.Service {
|
public abstract class ControlsProviderService extends android.app.Service {
|
||||||
ctor public ControlsProviderService();
|
ctor public ControlsProviderService();
|
||||||
method @Deprecated public void loadAvailableControls(@NonNull java.util.function.Consumer<java.util.List<android.service.controls.Control>>);
|
method @NonNull public abstract java.util.concurrent.Flow.Publisher<android.service.controls.Control> createPublisherFor(@NonNull java.util.List<java.lang.String>);
|
||||||
|
method @NonNull public abstract java.util.concurrent.Flow.Publisher<android.service.controls.Control> createPublisherForAllAvailable();
|
||||||
|
method @Nullable public java.util.concurrent.Flow.Publisher<android.service.controls.Control> createPublisherForSuggested();
|
||||||
method @NonNull public final android.os.IBinder onBind(@NonNull android.content.Intent);
|
method @NonNull public final android.os.IBinder onBind(@NonNull android.content.Intent);
|
||||||
|
method public final boolean onUnbind(@NonNull android.content.Intent);
|
||||||
method public abstract void performControlAction(@NonNull String, @NonNull android.service.controls.actions.ControlAction, @NonNull java.util.function.Consumer<java.lang.Integer>);
|
method public abstract void performControlAction(@NonNull String, @NonNull android.service.controls.actions.ControlAction, @NonNull java.util.function.Consumer<java.lang.Integer>);
|
||||||
method @NonNull public abstract java.util.concurrent.Flow.Publisher<android.service.controls.Control> publisherFor(@NonNull java.util.List<java.lang.String>);
|
|
||||||
method @Nullable public java.util.concurrent.Flow.Publisher<android.service.controls.Control> publisherForAllAvailable();
|
|
||||||
method @Nullable public java.util.concurrent.Flow.Publisher<android.service.controls.Control> publisherForSuggested();
|
|
||||||
method public static void requestAddControl(@NonNull android.content.Context, @NonNull android.content.ComponentName, @NonNull android.service.controls.Control);
|
method public static void requestAddControl(@NonNull android.content.Context, @NonNull android.content.ComponentName, @NonNull android.service.controls.Control);
|
||||||
field public static final String SERVICE_CONTROLS = "android.service.controls.ControlsProviderService";
|
field public static final String SERVICE_CONTROLS = "android.service.controls.ControlsProviderService";
|
||||||
field @NonNull public static final String TAG = "ControlsProviderService";
|
field @NonNull public static final String TAG = "ControlsProviderService";
|
||||||
|
|||||||
@@ -209,61 +209,116 @@ public final class Control implements Parcelable {
|
|||||||
mStatusText = in.readCharSequence();
|
mStatusText = in.readCharSequence();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the identifier for the {@link Control}
|
||||||
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getControlId() {
|
public String getControlId() {
|
||||||
return mControlId;
|
return mControlId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return type of device represented by this {@link Control}, used to determine the default
|
||||||
|
* icon and color
|
||||||
|
*/
|
||||||
@DeviceTypes.DeviceType
|
@DeviceTypes.DeviceType
|
||||||
public int getDeviceType() {
|
public int getDeviceType() {
|
||||||
return mDeviceType;
|
return mDeviceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the user facing name of the {@link Control}
|
||||||
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public CharSequence getTitle() {
|
public CharSequence getTitle() {
|
||||||
return mTitle;
|
return mTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return additional information about the {@link Control}, to appear underneath the title
|
||||||
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public CharSequence getSubtitle() {
|
public CharSequence getSubtitle() {
|
||||||
return mSubtitle;
|
return mSubtitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional top-level group to help define the {@link Control}'s location, visible to the user.
|
||||||
|
* If not present, the application name will be used as the top-level group. A structure
|
||||||
|
* contains zones which contains controls.
|
||||||
|
*
|
||||||
|
* @return name of the structure containing the control
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public CharSequence getStructure() {
|
public CharSequence getStructure() {
|
||||||
return mStructure;
|
return mStructure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional group name to help define the {@link Control}'s location within a structure,
|
||||||
|
* visible to the user. A structure contains zones which contains controls.
|
||||||
|
*
|
||||||
|
* @return name of the zone containing the control
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public CharSequence getZone() {
|
public CharSequence getZone() {
|
||||||
return mZone;
|
return mZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a {@link PendingIntent} linking to an Activity for the {@link Control}
|
||||||
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public PendingIntent getAppIntent() {
|
public PendingIntent getAppIntent() {
|
||||||
return mAppIntent;
|
return mAppIntent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional icon to be shown with the {@link Control}. It is highly recommended
|
||||||
|
* to let the system default the icon unless the default icon is not suitable.
|
||||||
|
*
|
||||||
|
* @return icon to show
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Icon getCustomIcon() {
|
public Icon getCustomIcon() {
|
||||||
return mCustomIcon;
|
return mCustomIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional color to be shown with the {@link Control}. It is highly recommended
|
||||||
|
* to let the system default the color unless the default is not suitable for the
|
||||||
|
* application.
|
||||||
|
*
|
||||||
|
* @return background color to use
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public ColorStateList getCustomColor() {
|
public ColorStateList getCustomColor() {
|
||||||
return mCustomColor;
|
return mCustomColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return status of the {@link Control}, used to convey information about the attempt to
|
||||||
|
* fetch the current state
|
||||||
|
*/
|
||||||
@Status
|
@Status
|
||||||
public int getStatus() {
|
public int getStatus() {
|
||||||
return mStatus;
|
return mStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return instance of {@link ControlTemplate}, that defines how the {@link Control} will
|
||||||
|
* behave and what interactions are available to the user
|
||||||
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public ControlTemplate getControlTemplate() {
|
public ControlTemplate getControlTemplate() {
|
||||||
return mControlTemplate;
|
return mControlTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return user-facing text description of the {@link Control}'s status, describing its current
|
||||||
|
* state
|
||||||
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public CharSequence getStatusText() {
|
public CharSequence getStatusText() {
|
||||||
return mStatusText;
|
return mStatusText;
|
||||||
@@ -326,7 +381,10 @@ public final class Control implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Builder class for {@link Control}.
|
* Builder class for {@link Control}.
|
||||||
*
|
*
|
||||||
* This class facilitates the creation of {@link Control} with no state.
|
* This class facilitates the creation of {@link Control} with no state. Must be used to
|
||||||
|
* provide controls for {@link ControlsProviderService#createPublisherForAllAvailable} and
|
||||||
|
* {@link ControlsProviderService#createPublisherForSuggested}.
|
||||||
|
*
|
||||||
* It provides the following defaults for non-optional parameters:
|
* It provides the following defaults for non-optional parameters:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li> Device type: {@link DeviceTypes#TYPE_UNKNOWN}
|
* <li> Device type: {@link DeviceTypes#TYPE_UNKNOWN}
|
||||||
@@ -334,7 +392,7 @@ public final class Control implements Parcelable {
|
|||||||
* <li> Subtitle: {@code ""}
|
* <li> Subtitle: {@code ""}
|
||||||
* </ul>
|
* </ul>
|
||||||
* This fixes the values relating to state of the {@link Control} as required by
|
* This fixes the values relating to state of the {@link Control} as required by
|
||||||
* {@link ControlsProviderService#loadAvailableControls}:
|
* {@link ControlsProviderService#createPublisherForAllAvailable}:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li> Status: {@link Status#STATUS_UNKNOWN}
|
* <li> Status: {@link Status#STATUS_UNKNOWN}
|
||||||
* <li> Control template: {@link ControlTemplate#NO_TEMPLATE}
|
* <li> Control template: {@link ControlTemplate#NO_TEMPLATE}
|
||||||
@@ -355,8 +413,8 @@ public final class Control implements Parcelable {
|
|||||||
private @Nullable ColorStateList mCustomColor;
|
private @Nullable ColorStateList mCustomColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param controlId the identifier for the {@link Control}.
|
* @param controlId the identifier for the {@link Control}
|
||||||
* @param appIntent the pending intent linking to the device Activity.
|
* @param appIntent the pending intent linking to the device Activity
|
||||||
*/
|
*/
|
||||||
public StatelessBuilder(@NonNull String controlId,
|
public StatelessBuilder(@NonNull String controlId,
|
||||||
@NonNull PendingIntent appIntent) {
|
@NonNull PendingIntent appIntent) {
|
||||||
@@ -368,6 +426,7 @@ public final class Control implements Parcelable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link StatelessBuilder} using an existing {@link Control} as a base.
|
* Creates a {@link StatelessBuilder} using an existing {@link Control} as a base.
|
||||||
|
*
|
||||||
* @param control base for the builder.
|
* @param control base for the builder.
|
||||||
*/
|
*/
|
||||||
public StatelessBuilder(@NonNull Control control) {
|
public StatelessBuilder(@NonNull Control control) {
|
||||||
@@ -384,7 +443,7 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param controlId the identifier for the {@link Control}.
|
* @param controlId the identifier for the {@link Control}
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -395,8 +454,8 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param deviceType the device type for the {@link Control}. Setting an invalid value not
|
* @param deviceType type of device represented by this {@link Control}, used to
|
||||||
* in {@link DeviceTypes} will set it to {@link DeviceTypes#TYPE_UNKNOWN}.
|
* determine the default icon and color
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -422,7 +481,8 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param subtitle the user facing subtitle for the {@link Control}
|
* @param subtitle additional information about the {@link Control}, to appear underneath
|
||||||
|
* the title
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -433,8 +493,11 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param structure the user facing name of the structure for the {@link Control}.
|
* Optional top-level group to help define the {@link Control}'s location, visible to the
|
||||||
* {@code null} indicates that it's not associated with any structure.
|
* user. If not present, the application name will be used as the top-level group. A
|
||||||
|
* structure contains zones which contains controls.
|
||||||
|
*
|
||||||
|
* @param structure name of the structure containing the control
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -444,8 +507,10 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param zone the user facing name of the zone for the {@link Control}. {@code null}
|
* Optional group name to help define the {@link Control}'s location within a structure,
|
||||||
* indicates that it's not associated with any zone.
|
* visible to the user. A structure contains zones which contains controls.
|
||||||
|
*
|
||||||
|
* @param zone name of the zone containing the control
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -455,7 +520,7 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param appIntent an {@link Intent} linking to an Activity for the {@link Control}
|
* @param appIntent a {@link PendingIntent} linking to an Activity for the {@link Control}
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -466,7 +531,10 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param customIcon an {@link Icon} to override the one determined by the device type.
|
* Optional icon to be shown with the {@link Control}. It is highly recommended
|
||||||
|
* to let the system default the icon unless the default icon is not suitable.
|
||||||
|
*
|
||||||
|
* @param customIcon icon to show
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -476,7 +544,11 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param customColor a list of colors to override the ones determined by the device type.
|
* Optional color to be shown with the {@link Control}. It is highly recommended
|
||||||
|
* to let the system default the color unless the default is not suitable for the
|
||||||
|
* application.
|
||||||
|
*
|
||||||
|
* @param customColor background color to use
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -486,7 +558,6 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a stateless {@link Control}
|
|
||||||
* @return a valid {@link Control}
|
* @return a valid {@link Control}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -507,9 +578,15 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder class for {@link Control}.
|
* Builder class for {@link Control} that contains state information.
|
||||||
|
*
|
||||||
|
* State information is passed through an instance of a {@link ControlTemplate} and will
|
||||||
|
* determine how the user can interact with the {@link Control}. User interactions will
|
||||||
|
* be sent through the method call {@link ControlsProviderService#performControlAction}
|
||||||
|
* with an instance of {@link ControlAction} to convey any potential new value.
|
||||||
|
*
|
||||||
|
* Must be used to provide controls for {@link ControlsProviderService#createPublisherFor}.
|
||||||
*
|
*
|
||||||
* This class facilitates the creation of {@link Control} with an associated state.
|
|
||||||
* It provides the following defaults for non-optional parameters:
|
* It provides the following defaults for non-optional parameters:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li> Device type: {@link DeviceTypes#TYPE_UNKNOWN}
|
* <li> Device type: {@link DeviceTypes#TYPE_UNKNOWN}
|
||||||
@@ -549,6 +626,7 @@ public final class Control implements Parcelable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link StatelessBuilder} using an existing {@link Control} as a base.
|
* Creates a {@link StatelessBuilder} using an existing {@link Control} as a base.
|
||||||
|
*
|
||||||
* @param control base for the builder.
|
* @param control base for the builder.
|
||||||
*/
|
*/
|
||||||
public StatefulBuilder(@NonNull Control control) {
|
public StatefulBuilder(@NonNull Control control) {
|
||||||
@@ -579,8 +657,8 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param deviceType the device type for the {@link Control}. Setting an invalid value not
|
* @param deviceType type of device represented by this {@link Control}, used to
|
||||||
* in {@link DeviceTypes} will set it to {@link DeviceTypes#TYPE_UNKNOWN}.
|
* determine the default icon and color
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -606,7 +684,8 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param subtitle the user facing subtitle for the {@link Control}
|
* @param subtitle additional information about the {@link Control}, to appear underneath
|
||||||
|
* the title
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -617,8 +696,11 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param structure the user facing name of the structure for the {@link Control}.
|
* Optional top-level group to help define the {@link Control}'s location, visible to the
|
||||||
* {@code null} indicates that it's not associated with any structure.
|
* user. If not present, the application name will be used as the top-level group. A
|
||||||
|
* structure contains zones which contains controls.
|
||||||
|
*
|
||||||
|
* @param structure name of the structure containing the control
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -628,8 +710,10 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param zone the user facing name of the zone for the {@link Control}. {@code null}
|
* Optional group name to help define the {@link Control}'s location within a structure,
|
||||||
* indicates that it's not associated with any zone.
|
* visible to the user. A structure contains zones which contains controls.
|
||||||
|
*
|
||||||
|
* @param zone name of the zone containing the control
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -639,7 +723,7 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param appIntent an {@link Intent} linking to an Activity for the {@link Control}
|
* @param appIntent a {@link PendingIntent} linking to an Activity for the {@link Control}
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -650,7 +734,10 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param customIcon an {@link Icon} to override the one determined by the device type.
|
* Optional icon to be shown with the {@link Control}. It is highly recommended
|
||||||
|
* to let the system default the icon unless the default icon is not suitable.
|
||||||
|
*
|
||||||
|
* @param customIcon icon to show
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -660,7 +747,11 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param customColor a list of colors to override the ones determined by the device type.
|
* Optional color to be shown with the {@link Control}. It is highly recommended
|
||||||
|
* to let the system default the color unless the default is not suitable for the
|
||||||
|
* application.
|
||||||
|
*
|
||||||
|
* @param customColor background color to use
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -670,8 +761,8 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param status the status of the {@link Control}. Setting an invalid value not in
|
* @param status status of the {@link Control}, used to convey information about the
|
||||||
* {@link Control} will set it to {@link Control#STATUS_UNKNOWN}.
|
* attempt to fetch the current state
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -686,7 +777,9 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param controlTemplate a template for the {@link Control}
|
* @param controlTemplate instance of {@link ControlTemplate}, that defines how the
|
||||||
|
* {@link Control} will behave and what interactions are
|
||||||
|
* available to the user
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -697,7 +790,8 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param statusText a user facing text representing the status of the {@link Control}.
|
* @param statusText user-facing text description of the {@link Control}'s status,
|
||||||
|
* describing its current state
|
||||||
* @return {@code this}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -708,7 +802,6 @@ public final class Control implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a stateless {@link Control}
|
|
||||||
* @return a valid {@link Control}
|
* @return a valid {@link Control}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.android.internal.util.Preconditions;
|
import com.android.internal.util.Preconditions;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Flow.Publisher;
|
import java.util.concurrent.Flow.Publisher;
|
||||||
import java.util.concurrent.Flow.Subscriber;
|
import java.util.concurrent.Flow.Subscriber;
|
||||||
@@ -83,19 +82,6 @@ public abstract class ControlsProviderService extends Service {
|
|||||||
private IBinder mToken;
|
private IBinder mToken;
|
||||||
private RequestHandler mHandler;
|
private RequestHandler mHandler;
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve all available controls, using the stateless builder
|
|
||||||
* {@link Control.StatelessBuilder} to build each Control, then use the
|
|
||||||
* provided consumer to callback to the call originator.
|
|
||||||
*
|
|
||||||
* @deprecated Removing consumer-based load apis. Use publisherForAllAvailable() instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public void loadAvailableControls(@NonNull Consumer<List<Control>> consumer) {
|
|
||||||
// pending removal
|
|
||||||
consumer.accept(Collections.emptyList());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publisher for all available controls
|
* Publisher for all available controls
|
||||||
*
|
*
|
||||||
@@ -104,11 +90,8 @@ public abstract class ControlsProviderService extends Service {
|
|||||||
* controls, or {@link Subscriber#onError} for error scenarios. Duplicate Controls will
|
* controls, or {@link Subscriber#onError} for error scenarios. Duplicate Controls will
|
||||||
* replace the original.
|
* replace the original.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@NonNull
|
||||||
public Publisher<Control> publisherForAllAvailable() {
|
public abstract Publisher<Control> createPublisherForAllAvailable();
|
||||||
// will be abstract and @nonnull when consumers are removed
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Optional) Publisher for suggested controls
|
* (Optional) Publisher for suggested controls
|
||||||
@@ -120,7 +103,7 @@ public abstract class ControlsProviderService extends Service {
|
|||||||
* when done, or {@link Subscriber#onError} for error scenarios.
|
* when done, or {@link Subscriber#onError} for error scenarios.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Publisher<Control> publisherForSuggested() {
|
public Publisher<Control> createPublisherForSuggested() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,10 +111,11 @@ public abstract class ControlsProviderService extends Service {
|
|||||||
* Return a valid Publisher for the given controlIds. This publisher will be asked to provide
|
* Return a valid Publisher for the given controlIds. This publisher will be asked to provide
|
||||||
* updates for the given list of controlIds as long as the {@link Subscription} is valid.
|
* updates for the given list of controlIds as long as the {@link Subscription} is valid.
|
||||||
* Calls to {@link Subscriber#onComplete} will not be expected. Instead, wait for the call from
|
* Calls to {@link Subscriber#onComplete} will not be expected. Instead, wait for the call from
|
||||||
* {@link Subscription#cancel} to indicate that updates are no longer required.
|
* {@link Subscription#cancel} to indicate that updates are no longer required. It is expected
|
||||||
|
* that controls provided by this publisher were created using {@link Control.StatefulBuilder}.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public abstract Publisher<Control> publisherFor(@NonNull List<String> controlIds);
|
public abstract Publisher<Control> createPublisherFor(@NonNull List<String> controlIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user has interacted with a Control. The action is dictated by the type of
|
* The user has interacted with a Control. The action is dictated by the type of
|
||||||
@@ -177,7 +161,7 @@ public abstract class ControlsProviderService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onUnbind(@NonNull Intent intent) {
|
public final boolean onUnbind(@NonNull Intent intent) {
|
||||||
mHandler = null;
|
mHandler = null;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -198,13 +182,7 @@ public abstract class ControlsProviderService extends Service {
|
|||||||
final IControlsSubscriber cs = (IControlsSubscriber) msg.obj;
|
final IControlsSubscriber cs = (IControlsSubscriber) msg.obj;
|
||||||
final SubscriberProxy proxy = new SubscriberProxy(true, mToken, cs);
|
final SubscriberProxy proxy = new SubscriberProxy(true, mToken, cs);
|
||||||
|
|
||||||
Publisher<Control> publisher =
|
ControlsProviderService.this.createPublisherForAllAvailable().subscribe(proxy);
|
||||||
ControlsProviderService.this.publisherForAllAvailable();
|
|
||||||
if (publisher == null) {
|
|
||||||
ControlsProviderService.this.loadAvailableControls(consumerFor(proxy));
|
|
||||||
} else {
|
|
||||||
publisher.subscribe(proxy);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,7 +191,7 @@ public abstract class ControlsProviderService extends Service {
|
|||||||
final SubscriberProxy proxy = new SubscriberProxy(true, mToken, cs);
|
final SubscriberProxy proxy = new SubscriberProxy(true, mToken, cs);
|
||||||
|
|
||||||
Publisher<Control> publisher =
|
Publisher<Control> publisher =
|
||||||
ControlsProviderService.this.publisherForSuggested();
|
ControlsProviderService.this.createPublisherForSuggested();
|
||||||
if (publisher == null) {
|
if (publisher == null) {
|
||||||
Log.i(TAG, "No publisher provided for suggested controls");
|
Log.i(TAG, "No publisher provided for suggested controls");
|
||||||
proxy.onComplete();
|
proxy.onComplete();
|
||||||
@@ -228,7 +206,8 @@ public abstract class ControlsProviderService extends Service {
|
|||||||
final SubscriberProxy proxy = new SubscriberProxy(false, mToken,
|
final SubscriberProxy proxy = new SubscriberProxy(false, mToken,
|
||||||
sMsg.mSubscriber);
|
sMsg.mSubscriber);
|
||||||
|
|
||||||
ControlsProviderService.this.publisherFor(sMsg.mControlIds).subscribe(proxy);
|
ControlsProviderService.this.createPublisherFor(sMsg.mControlIds)
|
||||||
|
.subscribe(proxy);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,37 +235,6 @@ public abstract class ControlsProviderService extends Service {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method will be removed during migration to publisher
|
|
||||||
*/
|
|
||||||
private Consumer<List<Control>> consumerFor(final Subscriber<Control> subscriber) {
|
|
||||||
return (@NonNull final List<Control> controls) -> {
|
|
||||||
Preconditions.checkNotNull(controls);
|
|
||||||
|
|
||||||
subscriber.onSubscribe(new Subscription() {
|
|
||||||
public void request(long n) {
|
|
||||||
for (Control control: controls) {
|
|
||||||
Control c;
|
|
||||||
if (control == null) {
|
|
||||||
Log.e(TAG, "onLoad: null control.");
|
|
||||||
}
|
|
||||||
if (isStatelessControl(control)) {
|
|
||||||
c = control;
|
|
||||||
} else {
|
|
||||||
Log.w(TAG, "onLoad: control is not stateless.");
|
|
||||||
c = new Control.StatelessBuilder(control).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
subscriber.onNext(c);
|
|
||||||
}
|
|
||||||
subscriber.onComplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancel() {}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isStatelessControl(Control control) {
|
private static boolean isStatelessControl(Control control) {
|
||||||
|
|||||||
@@ -284,12 +284,7 @@ public class ControlProviderServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadAvailableControls(Consumer<List<Control>> cb) {
|
public Publisher<Control> createPublisherForAllAvailable() {
|
||||||
cb.accept(mControls);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Publisher<Control> publisherFor(List<String> ids) {
|
|
||||||
return new Publisher<Control>() {
|
return new Publisher<Control>() {
|
||||||
public void subscribe(final Subscriber s) {
|
public void subscribe(final Subscriber s) {
|
||||||
s.onSubscribe(createSubscription(s, mControls));
|
s.onSubscribe(createSubscription(s, mControls));
|
||||||
@@ -298,7 +293,16 @@ public class ControlProviderServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Publisher<Control> publisherForSuggested() {
|
public Publisher<Control> createPublisherFor(List<String> ids) {
|
||||||
|
return new Publisher<Control>() {
|
||||||
|
public void subscribe(final Subscriber s) {
|
||||||
|
s.onSubscribe(createSubscription(s, mControls));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Publisher<Control> createPublisherForSuggested() {
|
||||||
return new Publisher<Control>() {
|
return new Publisher<Control>() {
|
||||||
public void subscribe(final Subscriber s) {
|
public void subscribe(final Subscriber s) {
|
||||||
s.onSubscribe(createSubscription(s, mControls));
|
s.onSubscribe(createSubscription(s, mControls));
|
||||||
|
|||||||
Reference in New Issue
Block a user