HDMICEC: Edit device selection API

Rename SelectDeviceCallback to OnDeviceSelectedListener.
Add an Executor parameter to HdmiClient#selectDevice.
Deprecate HdmiSwitchClient#selectDevice.

Bug: 196043550
Bug: 200698880
Bug: 202145001
Test: make
Change-Id: Ic2411283933203fc3a41bb02fa77416ad896ab24
This commit is contained in:
Paul Colța
2021-10-05 18:05:39 +00:00
parent 5154782c90
commit b9a07e322d
3 changed files with 28 additions and 16 deletions

View File

@@ -3325,14 +3325,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 {

View File

@@ -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)));
}
};
}

View File

@@ -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,