Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 63859536 authored by Jungshik Jang's avatar Jungshik Jang Committed by Android (Google) Code Review
Browse files

Merge "Implement interfaces for MHL scratchpad command" into lmp-dev

parents bc070818 f424932c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@ LOCAL_SRC_FILES += \
	core/java/android/hardware/hdmi/IHdmiDeviceEventListener.aidl \
	core/java/android/hardware/hdmi/IHdmiHotplugEventListener.aidl \
	core/java/android/hardware/hdmi/IHdmiInputChangeListener.aidl \
	core/java/android/hardware/hdmi/IHdmiMhlScratchpadCommandListener.aidl \
	core/java/android/hardware/hdmi/IHdmiRecordListener.aidl \
	core/java/android/hardware/hdmi/IHdmiSystemAudioModeChangeListener.aidl \
	core/java/android/hardware/hdmi/IHdmiVendorCommandListener.aidl \
+1 −1
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ public abstract class HdmiClient {
        try {
            mService.sendKeyEvent(getDeviceType(), keyCode, isPressed);
        } catch (RemoteException e) {
            Log.e(TAG, "queryDisplayStatus threw exception ", e);
            Log.e(TAG, "sendKeyEvent threw exception ", e);
        }
    }

+105 −40
Original line number Diff line number Diff line
@@ -35,6 +35,11 @@ import libcore.util.EmptyArray;
public final class HdmiTvClient extends HdmiClient {
    private static final String TAG = "HdmiTvClient";

    /**
     * Size of MHL scratchpad register.
     */
    public static final int SCRATCHPAD_DATA_SIZE = 16;

    HdmiTvClient(IHdmiControlService service) {
        super(service);
    }
@@ -80,6 +85,15 @@ public final class HdmiTvClient extends HdmiClient {
        }
    }

    private static IHdmiControlCallback getCallbackWrapper(final SelectCallback callback) {
        return new IHdmiControlCallback.Stub() {
            @Override
            public void onComplete(int result) {
                callback.onComplete(result);
            }
        };
    }

    /**
     * Select a HDMI port to be a new route path.
     *
@@ -126,6 +140,15 @@ public final class HdmiTvClient extends HdmiClient {
        }
    }

    private static IHdmiInputChangeListener getListenerWrapper(final InputChangeListener listener) {
        return new IHdmiInputChangeListener.Stub() {
            @Override
            public void onChanged(HdmiDeviceInfo info) {
                listener.onChanged(info);
            }
        };
    }

    /**
     * Set system audio volume
     *
@@ -170,6 +193,38 @@ public final class HdmiTvClient extends HdmiClient {
        }
    }

    private static IHdmiRecordListener getListenerWrapper(final HdmiRecordListener callback) {
        return new IHdmiRecordListener.Stub() {
            @Override
            public byte[] getOneTouchRecordSource(int recorderAddress) {
                HdmiRecordSources.RecordSource source =
                        callback.getOneTouchRecordSource(recorderAddress);
                if (source == null) {
                    return EmptyArray.BYTE;
                }
                byte[] data = new byte[source.getDataSize(true)];
                source.toByteArray(true, data, 0);
                return data;
            }

            @Override
            public void onOneTouchRecordResult(int result) {
                callback.onOneTouchRecordResult(result);
            }

            @Override
            public void onTimerRecordingResult(int result) {
                callback.onTimerRecordingResult(
                        HdmiRecordListener.TimerStatusData.parseFrom(result));
            }

            @Override
            public void onClearTimerRecordingResult(int result) {
                callback.onClearTimerRecordingResult(result);
            }
        };
    }

    /**
     * Start one touch recording with the given recorder address and recorder source.
     * <p>
@@ -276,53 +331,63 @@ public final class HdmiTvClient extends HdmiClient {
        }
    }

    private static IHdmiControlCallback getCallbackWrapper(final SelectCallback callback) {
        return new IHdmiControlCallback.Stub() {
            @Override
            public void onComplete(int result) {
                callback.onComplete(result);
            }
        };
    /**
     * Interface used to get incoming MHL scratchpad command.
     */
    public interface HdmiMhlScratchpadCommandListener {
        void onReceived(int portId, int offset, int length, byte[] data);
    }

    private static IHdmiInputChangeListener getListenerWrapper(final InputChangeListener listener) {
        return new IHdmiInputChangeListener.Stub() {
            @Override
            public void onChanged(HdmiDeviceInfo info) {
                listener.onChanged(info);
    /**
     * Set {@link HdmiMhlScratchpadCommandListener} to get incoming MHL sSratchpad command.
     *
     * @param listener to receive incoming MHL Scratchpad command
     */
    public void setHdmiMhlScratchpadCommandListener(HdmiMhlScratchpadCommandListener listener) {
        if (listener == null) {
            throw new IllegalArgumentException("listener must not be null.");
        }
        try {
            mService.addHdmiMhlScratchpadCommandListener(getListenerWrapper(listener));
        } catch (RemoteException e) {
            Log.e(TAG, "failed to set hdmi mhl scratchpad command listener: ", e);
        }
        };
    }

    private static IHdmiRecordListener getListenerWrapper(final HdmiRecordListener callback) {
        return new IHdmiRecordListener.Stub() {
    private IHdmiMhlScratchpadCommandListener getListenerWrapper(
            final HdmiMhlScratchpadCommandListener listener) {
        return new IHdmiMhlScratchpadCommandListener.Stub() {
            @Override
            public byte[] getOneTouchRecordSource(int recorderAddress) {
                HdmiRecordSources.RecordSource source =
                        callback.getOneTouchRecordSource(recorderAddress);
                if (source == null) {
                    return EmptyArray.BYTE;
            public void onReceived(int portId, int offset, int length, byte[] data) {
                listener.onReceived(portId, offset, length, data);
            }
                byte[] data = new byte[source.getDataSize(true)];
                source.toByteArray(true, data, 0);
                return data;
        };
    }

            @Override
            public void onOneTouchRecordResult(int result) {
                callback.onOneTouchRecordResult(result);
    /**
     * Send MHL Scratchpad command to the device connected to a port of the given portId.
     *
     * @param portId id of port to send MHL Scratchpad command
     * @param offset offset in the in given data
     * @param length length of data. offset + length should be bound to length of data.
     * @param data container for Scratchpad data. It should be 16 bytes.
     * @throws IllegalArgumentException if the given parameters are invalid
     */
    public void sendScratchpadCommand(int portId, int offset, int length, byte[] data) {
        if (data == null || data.length != SCRATCHPAD_DATA_SIZE) {
            throw new IllegalArgumentException("Invalid scratchpad data.");
        }

            @Override
            public void onTimerRecordingResult(int result) {
                callback.onTimerRecordingResult(
                        HdmiRecordListener.TimerStatusData.parseFrom(result));
        if (offset < 0 || offset >= SCRATCHPAD_DATA_SIZE) {
            throw new IllegalArgumentException("Invalid offset:" + offset);
        }
        if (length < 0 || offset + length > SCRATCHPAD_DATA_SIZE) {
            throw new IllegalArgumentException("Invalid length:" + length);
        }

            @Override
            public void onClearTimerRecordingResult(int result) {
                callback.onClearTimerRecordingResult(result);
        try {
            mService.sendScratchpadCommand(portId, offset, length, data);
        } catch (RemoteException e) {
            Log.e(TAG, "failed to send scratchpad command: ", e);
        }
        };
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.hardware.hdmi.IHdmiControlCallback;
import android.hardware.hdmi.IHdmiDeviceEventListener;
import android.hardware.hdmi.IHdmiHotplugEventListener;
import android.hardware.hdmi.IHdmiInputChangeListener;
import android.hardware.hdmi.IHdmiMhlScratchpadCommandListener;
import android.hardware.hdmi.IHdmiRecordListener;
import android.hardware.hdmi.IHdmiSystemAudioModeChangeListener;
import android.hardware.hdmi.IHdmiVendorCommandListener;
@@ -66,4 +67,6 @@ interface IHdmiControlService {
    void stopOneTouchRecord(int recorderAddress);
    void startTimerRecording(int recorderAddress, int sourceType, in byte[] recordSource);
    void clearTimerRecording(int recorderAddress, int sourceType, in byte[] recordSource);
    void sendScratchpadCommand(int portId, int offset, int length, in byte[] data);
    void addHdmiMhlScratchpadCommandListener(IHdmiMhlScratchpadCommandListener listener);
}
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.hdmi;

 /**
 * Callback interface definition for MHL client to get the scratchpad
 * command.
 *
 * @hide
 */
 oneway interface IHdmiMhlScratchpadCommandListener {
      void onReceived(int portId, int offset, int length, in byte[] data);
 }
Loading