Controls API - Publisher change - Phase 2
Complete the removal of consumer-based load API method. Update the publisher-based 'publisherForAllAvailable()' to be non-null and abstract, indicating it is now a required method. Bug: 149398610 Test: atest ControlsBindingControllerImplTest ServiceWrapperTest ControlsProviderLifecycleManagerTest Test: ControlProviderServiceTest Change-Id: Id06a24d2facf7621e8985ebe0396092752b6f59d
This commit is contained in:
@@ -43426,11 +43426,10 @@ package android.service.controls {
|
||||
|
||||
public abstract class ControlsProviderService extends android.app.Service {
|
||||
ctor public ControlsProviderService();
|
||||
method @Deprecated public void loadAvailableControls(@NonNull java.util.function.Consumer<java.util.List<android.service.controls.Control>>);
|
||||
method @NonNull public final android.os.IBinder onBind(@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 @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 @NonNull public abstract 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);
|
||||
field public static final String SERVICE_CONTROLS = "android.service.controls.ControlsProviderService";
|
||||
|
||||
@@ -334,7 +334,7 @@ public final class Control implements Parcelable {
|
||||
* <li> Subtitle: {@code ""}
|
||||
* </ul>
|
||||
* This fixes the values relating to state of the {@link Control} as required by
|
||||
* {@link ControlsProviderService#loadAvailableControls}:
|
||||
* {@link ControlsProviderService#publisherForAllAvailable}:
|
||||
* <ul>
|
||||
* <li> Status: {@link Status#STATUS_UNKNOWN}
|
||||
* <li> Control template: {@link ControlTemplate#NO_TEMPLATE}
|
||||
|
||||
@@ -38,7 +38,6 @@ import android.util.Log;
|
||||
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Flow.Publisher;
|
||||
import java.util.concurrent.Flow.Subscriber;
|
||||
@@ -83,19 +82,6 @@ public abstract class ControlsProviderService extends Service {
|
||||
private IBinder mToken;
|
||||
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
|
||||
*
|
||||
@@ -104,11 +90,8 @@ public abstract class ControlsProviderService extends Service {
|
||||
* controls, or {@link Subscriber#onError} for error scenarios. Duplicate Controls will
|
||||
* replace the original.
|
||||
*/
|
||||
@Nullable
|
||||
public Publisher<Control> publisherForAllAvailable() {
|
||||
// will be abstract and @nonnull when consumers are removed
|
||||
return null;
|
||||
}
|
||||
@NonNull
|
||||
public abstract Publisher<Control> publisherForAllAvailable();
|
||||
|
||||
/**
|
||||
* (Optional) Publisher for suggested controls
|
||||
@@ -198,13 +181,7 @@ public abstract class ControlsProviderService extends Service {
|
||||
final IControlsSubscriber cs = (IControlsSubscriber) msg.obj;
|
||||
final SubscriberProxy proxy = new SubscriberProxy(true, mToken, cs);
|
||||
|
||||
Publisher<Control> publisher =
|
||||
ControlsProviderService.this.publisherForAllAvailable();
|
||||
if (publisher == null) {
|
||||
ControlsProviderService.this.loadAvailableControls(consumerFor(proxy));
|
||||
} else {
|
||||
publisher.subscribe(proxy);
|
||||
}
|
||||
ControlsProviderService.this.publisherForAllAvailable().subscribe(proxy);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -256,37 +233,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) {
|
||||
|
||||
@@ -284,8 +284,12 @@ public class ControlProviderServiceTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAvailableControls(Consumer<List<Control>> cb) {
|
||||
cb.accept(mControls);
|
||||
public Publisher<Control> publisherForAllAvailable() {
|
||||
return new Publisher<Control>() {
|
||||
public void subscribe(final Subscriber s) {
|
||||
s.onSubscribe(createSubscription(s, mControls));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user