Anroid u hdmi cec aidl hal service

1.initService

可见从u开始,会优先使用aidl的hal service,其次是1.1的hidl,再其次是1.0的hidl。

initService(){
....
        if (mCecController == null) {
            mCecController = HdmiCecController.create(this, getAtomWriter());
        }
...
}
    static HdmiCecController create(HdmiControlService service, HdmiCecAtomWriter atomWriter) {
        HdmiCecController controller =
                createWithNativeWrapper(service, new NativeWrapperImplAidl(), atomWriter);
        if (controller != null) {
            return controller;
        }
        HdmiLogger.warning("Unable to use CEC and HDMI Connection AIDL HALs");

        controller = createWithNativeWrapper(service, new NativeWrapperImpl11(), atomWriter);
        if (controller != null) {
            return controller;
        }
        HdmiLogger.warning("Unable to use cec@1.1");
        return createWithNativeWrapper(service, new NativeWrapperImpl(), atomWriter);
    }

2.aidl serivce wrapper

每个NativeWrapper的实例都实现了NativeWrapper接口和DeathRecipient. 其中binderDied回调函数里面处理了hal service的重连。

    private static final class NativeWrapperImplAidl
            implements NativeWrapper, IBinder.DeathRecipient {
        private IHdmiCec mHdmiCec;
        private IHdmiConnection mHdmiConnection;
        @Nullable private HdmiCecCallback mCallback;

        private final Object mLock = new Object();

        @Override
        public String nativeInit() {
            return connectToHal() ? mHdmiCec.toString() + " " + mHdmiConnection.toString() : null;
        }

        boolean connectToHal() {
            mHdmiCec =
                    IHdmiCec.Stub.asInterface(
                            ServiceManager.getService(IHdmiCec.DESCRIPTOR + "/default"));
            if (mHdmiCec == null) {
                HdmiLogger.error("Could not initialize HDMI CEC AIDL HAL");
                return false;
            }
            try {
                mHdmiCec.asBinder().linkToDeath(this, 0);
            } catch (RemoteException e) {
                HdmiLogger.error("Couldn't link to death : ", e);
            }

            mHdmiConnection =
                    IHdmiConnection.Stub.asInterface(
                            ServiceManager.getService(IHdmiConnection.DESCRIPTOR + "/default"));
            if (mHdmiConnection == null) {
                HdmiLogger.error("Could not initialize HDMI Connection AIDL HAL");
                return false;
            }
            try {
                mHdmiConnection.asBinder().linkToDeath(this, 0);
            } catch (RemoteException e) {
                HdmiLogger.error("Couldn't link to death : ", e);
            }
            return true;
        }

        @Override
        public void binderDied() {
            // One of the services died, try to reconnect to both.
            mHdmiCec.asBinder().unlinkToDeath(this, 0);
            mHdmiConnection.asBinder().unlinkToDeath(this, 0);
            HdmiLogger.error("HDMI Connection or CEC service died, reconnecting");
            connectToHal();
            // Reconnect the callback
            if (mCallback != null) {
                setCallback(mCallback);
            }
        }
....
}

NativeWrapper, 将之前的setOption接口拆分一下,并且新增了setHpd和getHpd两个接口,在earc协议实现时会使用。


    protected interface NativeWrapper {
        String nativeInit();
        void setCallback(HdmiCecCallback callback);
        int nativeSendCecCommand(int srcAddress, int dstAddress, byte[] body);
        int nativeAddLogicalAddress(int logicalAddress);
        void nativeClearLogicalAddress();
        int nativeGetPhysicalAddress();
        int nativeGetVersion();
        int nativeGetVendorId();
        HdmiPortInfo[] nativeGetPortInfos();

        void enableWakeupByOtp(boolean enabled);

        void enableCec(boolean enabled);

        void enableSystemCecControl(boolean enabled);

        void nativeSetLanguage(String language);
        void nativeEnableAudioReturnChannel(int port, boolean flag);
        boolean nativeIsConnected(int port);
        void nativeSetHpdSignalType(int signal, int portId);
        int nativeGetHpdSignalType(int portId);
    }

3.IHdmiCec

import android.hardware.tv.hdmi.cec.CecMessage;
import android.hardware.tv.hdmi.cec.IHdmiCec;
import android.hardware.tv.hdmi.cec.IHdmiCecCallback;

hardware/interfaces/tv/hdmi/cec/aidl/android/hardware/tv/hdmi/cec/IHdmiCec.aidl

/*
 * Copyright (C) 2022 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.tv.hdmi.cec;

import android.hardware.tv.hdmi.cec.CecLogicalAddress;
import android.hardware.tv.hdmi.cec.CecMessage;
import android.hardware.tv.hdmi.cec.IHdmiCecCallback;
import android.hardware.tv.hdmi.cec.Result;
import android.hardware.tv.hdmi.cec.SendMessageResult;

/**
 * HDMI-CEC HAL interface definition.
 */
@VintfStability
interface IHdmiCec {
    /**
     * Passes the logical address that must be used in this system.
     *
     * HAL must use it to configure the hardware so that the CEC commands
     * addressed the given logical address can be filtered in. This method must
     * be able to be called as many times as necessary in order to support
     * multiple logical devices.
     *
     * @param addr Logical address that must be used in this system. It must be
     *        in the range of valid logical addresses for the call to succeed.
     * @return Result status of the operation. SUCCESS if successful,
     *         FAILURE_INVALID_ARGS if the given logical address is invalid,
     *         FAILURE_BUSY if device or resource is busy
     */
    Result addLogicalAddress(in CecLogicalAddress addr);

    /**
     * Clears all the logical addresses.
     *
     * It is used when the system doesn't need to process CEC command any more,
     * hence to tell HAL to stop receiving commands from the CEC bus, and change
     * the state back to the beginning.
     */
    void clearLogicalAddress();

    /**
     * Configures ARC circuit in the hardware logic to start or stop the
     * feature.
     *
     * @param portId Port id to be configured.
     * @param enable Flag must be either true to start the feature or false to
     *        stop it.
     */
    void enableAudioReturnChannel(in int portId, in boolean enable);

    /**
     * Returns the CEC version supported by underlying hardware.
     *
     * @return the CEC version supported by underlying hardware.
     */
    int getCecVersion();

    /**
     * Gets the CEC physical address.
     *
     * The physical address depends on the topology of the network formed by
     * connected HDMI devices. It is therefore likely to change if the cable is
     * plugged off and on again. It is advised to call getPhysicalAddress to get
     * the updated address when hot plug event takes place.
     *
     * @return Physical address of this device.
     */
    int getPhysicalAddress();

    /**
     * Gets the identifier of the vendor.
     *
     * @return Identifier of the vendor that is the 24-bit unique
     *         company ID obtained from the IEEE Registration Authority
     *         Committee (RAC). The upper 8 bits must be 0.
     */
    int getVendorId();

    /**
     * Transmits HDMI-CEC message to other HDMI device.
     *
     * The method must be designed to return in a certain amount of time and not
     * hanging forever which may happen if CEC signal line is pulled low for
     * some reason.
     *
     * It must try retransmission at least once as specified in the section '7.1
     * Frame Re-transmissions' of the CEC Spec 1.4b.
     *
     * @param message CEC message to be sent to other HDMI device.
     * @return Result status of the operation. SUCCESS if successful,
     *         NACK if the sent message is not acknowledged,
     *         BUSY if the CEC bus is busy,
     *         FAIL if the message could not be sent.
     */
    SendMessageResult sendMessage(in CecMessage message);

    /**
     * Sets a callback that HDMI-CEC HAL must later use for incoming CEC
     * messages.
     *
     * @param callback Callback object to pass hdmi events to the system. The
     *        previously registered callback must be replaced with this one.
     *        setCallback(null) should deregister the callback.
     */
    void setCallback(in @nullable IHdmiCecCallback callback);

    /**
     * Passes the updated language information of Android system. Contains
     * three-letter code as defined in ISO/FDIS 639-2. Must be used for HAL to
     * respond to <Get Menu Language> while in standby mode.
     *
     * @param language Three-letter code defined in ISO/FDIS 639-2. Must be
     *        lowercase letters. (e.g., eng for English)
     */
    void setLanguage(in String language);

    /**
     * Determines whether a TV panel device in standby mode should wake up when
     * it receives an OTP (One Touch Play) from a source device.
     *
     * @param value If true, the TV device will wake up when OTP is received
     *              and if false, the TV device will not wake up for an OTP.
     */
    void enableWakeupByOtp(in boolean value);

    /**
     * Switch to enable or disable CEC on the device.
     *
     * @param value If true, the device will have all CEC functionalities
     *              and if false, the device will not perform any CEC functions.
     */
    void enableCec(in boolean value);

    /**
     * Determines which module processes CEC messages - the Android framework or
     * the HAL.
     *
     * @param value If true, the Android framework will actively process CEC
     *        messages and if false, only the HAL will process the CEC messages.
     */
    void enableSystemCecControl(in boolean value);
}

 Android.bp

// Copyright (C) 2022 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 {
    default_applicable_licenses: ["hardware_interfaces_license"],
}

aidl_interface {
    name: "android.hardware.tv.hdmi.cec",
    vendor_available: true,
    srcs: ["android/hardware/tv/hdmi/cec/*.aidl"],
    stability: "vintf",
    backend: {
        java: {
            sdk_version: "module_current",
        },
    },
    versions_with_info: [
        {
            version: "1",
            imports: [],
        },
    ],
    frozen: true,

}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值