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
diff --git a/api/current.txt b/api/current.txt
index a2f2c06..43c082b 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -43426,11 +43426,10 @@
 
   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";
diff --git a/core/java/android/service/controls/Control.java b/core/java/android/service/controls/Control.java
index 0cffe71..ad93995 100644
--- a/core/java/android/service/controls/Control.java
+++ b/core/java/android/service/controls/Control.java
@@ -334,7 +334,7 @@
      *     <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}
diff --git a/core/java/android/service/controls/ControlsProviderService.java b/core/java/android/service/controls/ControlsProviderService.java
index b23d0cd..4441488 100644
--- a/core/java/android/service/controls/ControlsProviderService.java
+++ b/core/java/android/service/controls/ControlsProviderService.java
@@ -38,7 +38,6 @@
 
 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;
@@ -84,19 +83,6 @@
     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
      *
      * Retrieve all available controls. Use the stateless builder {@link Control.StatelessBuilder}
@@ -104,11 +90,8 @@
      * 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 @@
                     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 @@
                 }
             };
         }
-
-        /**
-         * 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) {
diff --git a/core/tests/coretests/src/android/service/controls/ControlProviderServiceTest.java b/core/tests/coretests/src/android/service/controls/ControlProviderServiceTest.java
index 4c2ca7e..c980ccb 100644
--- a/core/tests/coretests/src/android/service/controls/ControlProviderServiceTest.java
+++ b/core/tests/coretests/src/android/service/controls/ControlProviderServiceTest.java
@@ -284,8 +284,12 @@
         }
 
         @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