diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 3373d4b334969..a9a9e2474b4d3 100755 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -3326,14 +3326,14 @@ package android.hardware.hdmi { public abstract class HdmiClient { method public android.hardware.hdmi.HdmiDeviceInfo getActiveSource(); - method public void selectDevice(int, @NonNull android.hardware.hdmi.HdmiClient.SelectDeviceCallback); + method public void selectDevice(int, @NonNull java.util.concurrent.Executor, @NonNull android.hardware.hdmi.HdmiClient.OnDeviceSelectedListener); 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.SelectDeviceCallback { - method public void onComplete(@android.hardware.hdmi.HdmiControlManager.ControlCallbackResult int, int); + public static interface HdmiClient.OnDeviceSelectedListener { + method public void onDeviceSelected(@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 c94a50768c467..1a52f11e7c04f 100644 --- a/core/java/android/hardware/hdmi/HdmiClient.java +++ b/core/java/android/hardware/hdmi/HdmiClient.java @@ -1,12 +1,16 @@ package android.hardware.hdmi; +import android.annotation.CallbackExecutor; import android.annotation.NonNull; import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.hardware.hdmi.HdmiControlManager.VendorCommandListener; +import android.os.Binder; import android.os.RemoteException; import android.util.Log; +import java.util.concurrent.Executor; + /** * Parent for classes of various HDMI-CEC device type used to access * the HDMI control system service. Contains methods and data used in common. @@ -28,16 +32,17 @@ public abstract class HdmiClient { } /** - * Callback interface used to get the result of {@link #selectDevice}. + * Listener interface used to get the result of {@link #selectDevice}. */ - public interface SelectDeviceCallback { + public interface OnDeviceSelectedListener { /** * 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(@HdmiControlManager.ControlCallbackResult int result, int logicalAddress); + void onDeviceSelected(@HdmiControlManager.ControlCallbackResult int result, + int logicalAddress); } /** @@ -48,15 +53,19 @@ public abstract class HdmiClient { * 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 + * @param listener listener to get the result with + * @throws {@link IllegalArgumentException} if the {@code listener} is null */ - public void selectDevice(int logicalAddress, @NonNull SelectDeviceCallback callback) { - if (callback == null) { - throw new IllegalArgumentException("callback must not be null."); + public void selectDevice( + int logicalAddress, + @NonNull @CallbackExecutor Executor executor, + @NonNull OnDeviceSelectedListener listener) { + if (listener == null) { + throw new IllegalArgumentException("listener must not be null."); } try { - mService.deviceSelect(logicalAddress, getCallbackWrapper(callback, logicalAddress)); + mService.deviceSelect(logicalAddress, + getCallbackWrapper(logicalAddress, executor, listener)); } catch (RemoteException e) { Log.e(TAG, "failed to select device: ", e); } @@ -65,12 +74,14 @@ public abstract class HdmiClient { /** * @hide */ - private static IHdmiControlCallback getCallbackWrapper(final SelectDeviceCallback callback, - int logicalAddress) { + private static IHdmiControlCallback getCallbackWrapper(int logicalAddress, + final Executor executor, final OnDeviceSelectedListener listener) { return new IHdmiControlCallback.Stub() { @Override public void onComplete(int result) { - callback.onComplete(result, logicalAddress); + Binder.withCleanCallingIdentity( + () -> executor.execute(() -> listener.onDeviceSelected(result, + logicalAddress))); } }; } diff --git a/core/java/android/hardware/hdmi/HdmiSwitchClient.java b/core/java/android/hardware/hdmi/HdmiSwitchClient.java index 79846cd70784e..0fb5894dc4d95 100644 --- a/core/java/android/hardware/hdmi/HdmiSwitchClient.java +++ b/core/java/android/hardware/hdmi/HdmiSwitchClient.java @@ -85,7 +85,6 @@ public class HdmiSwitchClient extends HdmiClient { * @see {@link android.media.tv.TvInputHardwareInfo#getHdmiPortId()} * to get portId of a specific TV Input. * @param listener listener to get the result with - * * @hide */ @SystemApi @@ -104,8 +103,10 @@ public class HdmiSwitchClient extends HdmiClient { * * @param logicalAddress logical address of the device to select * @param listener listener to get the result with + * @deprecated Please use {@link HdmiClient#selectDevice} instead. * @hide */ + @Deprecated public void selectDevice( int logicalAddress, @NonNull @CallbackExecutor Executor executor,