HDMICEC: Edit device select API

Rename SelectedDeviceCallback to SelectDeviceCallback.
Add @HdmiControlManager.ControlCallbackResult annotation to the result parameter of SelectDeviceCallback#onComplete.
Add logical address parameter to SelectDeviceCallback#onCompleted.
Add documentation about selectDevice() method.

Bug: 196043550
Bug: 200698880
Test: make
Change-Id: I735fbe65be3117cc7e42c8f40ec479aca719d9b9
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 0fc727f..d5abadb 100755
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -3321,14 +3321,14 @@
 
   public abstract class HdmiClient {
     method public android.hardware.hdmi.HdmiDeviceInfo getActiveSource();
-    method public void selectDevice(int, @NonNull android.hardware.hdmi.HdmiClient.SelectedDeviceCallback);
+    method public void selectDevice(int, @NonNull android.hardware.hdmi.HdmiClient.SelectDeviceCallback);
     method public void sendKeyEvent(int, boolean);
     method public void sendVendorCommand(int, byte[], boolean);
     method public void setVendorCommandListener(@NonNull android.hardware.hdmi.HdmiControlManager.VendorCommandListener);
   }
 
-  public static interface HdmiClient.SelectedDeviceCallback {
-    method public void onComplete(int);
+  public static interface HdmiClient.SelectDeviceCallback {
+    method public void onComplete(@android.hardware.hdmi.HdmiControlManager.ControlCallbackResult int, int);
   }
 
   public final class HdmiControlManager {
diff --git a/core/java/android/hardware/hdmi/HdmiClient.java b/core/java/android/hardware/hdmi/HdmiClient.java
index eb4cffd..c94a507 100644
--- a/core/java/android/hardware/hdmi/HdmiClient.java
+++ b/core/java/android/hardware/hdmi/HdmiClient.java
@@ -30,28 +30,33 @@
     /**
      * Callback interface used to get the result of {@link #selectDevice}.
      */
-    public interface SelectedDeviceCallback {
+    public interface SelectDeviceCallback {
         /**
          * Called when the operation is finished.
          * @param result the result value of {@link #selectDevice} and can have the values mentioned
          *               in {@link HdmiControlShellCommand#getResultString}
+         * @param logicalAddress logical address of the selected device
          */
-        void onComplete(int result);
+        void onComplete(@HdmiControlManager.ControlCallbackResult int result, int logicalAddress);
     }
 
     /**
      * Selects a CEC logical device to be a new active source.
      *
+     * <p> Multiple calls to this method are handled in parallel and independently, with no
+     * guarantees about the execution order. The caller receives a callback for each call,
+     * containing the result of that call only.
+     *
      * @param logicalAddress logical address of the device to select
      * @param callback callback to get the result with
      * @throws {@link IllegalArgumentException} if the {@code callback} is null
      */
-    public void selectDevice(int logicalAddress, @NonNull SelectedDeviceCallback callback) {
+    public void selectDevice(int logicalAddress, @NonNull SelectDeviceCallback callback) {
         if (callback == null) {
             throw new IllegalArgumentException("callback must not be null.");
         }
         try {
-            mService.deviceSelect(logicalAddress, getCallbackWrapper(callback));
+            mService.deviceSelect(logicalAddress, getCallbackWrapper(callback, logicalAddress));
         } catch (RemoteException e) {
             Log.e(TAG, "failed to select device: ", e);
         }
@@ -60,11 +65,12 @@
     /**
      * @hide
      */
-    private static IHdmiControlCallback getCallbackWrapper(final SelectedDeviceCallback callback) {
+    private static IHdmiControlCallback getCallbackWrapper(final SelectDeviceCallback callback,
+            int logicalAddress) {
         return new IHdmiControlCallback.Stub() {
             @Override
             public void onComplete(int result) {
-                callback.onComplete(result);
+                callback.onComplete(result, logicalAddress);
             }
         };
     }