mirror of
				https://github.com/oplus-giulia-dev/android_hardware_oplus
				synced 2025-11-04 05:45:34 +08:00 
			
		
		
		
	Introduce android.hardware.ir-service.oplus
Change-Id: Iffeb34f8c7864dad223d20e1de2a819a345678c6
This commit is contained in:
		
							
								
								
									
										19
									
								
								aidl/ir/Android.bp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								aidl/ir/Android.bp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
cc_binary {
 | 
			
		||||
    name: "android.hardware.ir-service.oplus",
 | 
			
		||||
    vendor: true,
 | 
			
		||||
    relative_install_path: "hw",
 | 
			
		||||
    init_rc: ["android.hardware.ir-service.oplus.rc"],
 | 
			
		||||
    vintf_fragments: ["android.hardware.ir-service.xml"],
 | 
			
		||||
    srcs: [
 | 
			
		||||
        "ConsumerIr.cpp",
 | 
			
		||||
        "service.cpp",
 | 
			
		||||
    ],
 | 
			
		||||
    shared_libs: [
 | 
			
		||||
        "android.hardware.ir-V1-ndk",
 | 
			
		||||
        "libbase",
 | 
			
		||||
        "libbinder_ndk",
 | 
			
		||||
    ],
 | 
			
		||||
    header_libs: [
 | 
			
		||||
        "kernel_headers.oplus",
 | 
			
		||||
    ],
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										77
									
								
								aidl/ir/ConsumerIr.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								aidl/ir/ConsumerIr.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,77 @@
 | 
			
		||||
/*
 | 
			
		||||
 * SPDX-FileCopyrightText: 2025 The LineageOS Project
 | 
			
		||||
 * SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "ConsumerIr.h"
 | 
			
		||||
 | 
			
		||||
#include <aidl/android/hardware/ir/ConsumerIrFreqRange.h>
 | 
			
		||||
#include <android-base/logging.h>
 | 
			
		||||
#include <android-base/unique_fd.h>
 | 
			
		||||
#include <oplus/oplus_ir_core.h>
 | 
			
		||||
 | 
			
		||||
namespace aidl {
 | 
			
		||||
namespace android {
 | 
			
		||||
namespace hardware {
 | 
			
		||||
namespace ir {
 | 
			
		||||
 | 
			
		||||
static constexpr int32_t MAX_PATTERN_TIME = 2000000;
 | 
			
		||||
static constexpr int32_t MIN_FREQ = 20000;
 | 
			
		||||
static constexpr int32_t MAX_FREQ = 60000;
 | 
			
		||||
 | 
			
		||||
ConsumerIr::ConsumerIr() : supportedFreqs({{MIN_FREQ, MAX_FREQ}}) {}
 | 
			
		||||
 | 
			
		||||
::ndk::ScopedAStatus ConsumerIr::getCarrierFreqs(std::vector<ConsumerIrFreqRange>* _aidl_return) {
 | 
			
		||||
    *_aidl_return = supportedFreqs;
 | 
			
		||||
    return ::ndk::ScopedAStatus::ok();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
::ndk::ScopedAStatus ConsumerIr::transmit(int32_t in_carrierFreqHz,
 | 
			
		||||
                                          const std::vector<int32_t>& in_pattern) {
 | 
			
		||||
    if (in_carrierFreqHz < MIN_FREQ || in_carrierFreqHz > MAX_FREQ) {
 | 
			
		||||
        LOG(ERROR) << "Invalid carrier frequency: " << in_carrierFreqHz;
 | 
			
		||||
        return ::ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int32_t totalTime = 0;
 | 
			
		||||
    for (int32_t value : in_pattern) {
 | 
			
		||||
        if (value < 0) {
 | 
			
		||||
            LOG(ERROR) << "Invalid pattern value: " << value;
 | 
			
		||||
            return ::ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
 | 
			
		||||
        }
 | 
			
		||||
        totalTime += value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (totalTime > MAX_PATTERN_TIME) {
 | 
			
		||||
        LOG(ERROR) << "Pattern is too long: " << totalTime << " us";
 | 
			
		||||
        return ::ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ::android::base::unique_fd fd(open("/dev/oplus_consumer_ir", O_WRONLY));
 | 
			
		||||
    if (!fd.ok()) {
 | 
			
		||||
        LOG(ERROR) << "Failed to open /dev/oplus_consumer_ir: " << strerror(errno);
 | 
			
		||||
        return ::ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    size_t paramsSize = sizeof(struct pattern_params) + in_pattern.size() * sizeof(int32_t);
 | 
			
		||||
    auto params = std::unique_ptr<struct pattern_params, decltype(&free)>(
 | 
			
		||||
            static_cast<pattern_params*>(malloc(paramsSize)), free);
 | 
			
		||||
    if (!params) {
 | 
			
		||||
        LOG(ERROR) << "Failed to allocate memory for IR params";
 | 
			
		||||
        return ::ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    params->carrier_freq = in_carrierFreqHz;
 | 
			
		||||
    params->size = in_pattern.size();
 | 
			
		||||
    memcpy(params->pattern, in_pattern.data(), in_pattern.size() * sizeof(int32_t));
 | 
			
		||||
 | 
			
		||||
    int result = ioctl(fd, IR_SEND_PATTERN, params.get());
 | 
			
		||||
 | 
			
		||||
    return result < 0 ? ::ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION)
 | 
			
		||||
                      : ::ndk::ScopedAStatus::ok();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}  // namespace ir
 | 
			
		||||
}  // namespace hardware
 | 
			
		||||
}  // namespace android
 | 
			
		||||
}  // namespace aidl
 | 
			
		||||
							
								
								
									
										30
									
								
								aidl/ir/ConsumerIr.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								aidl/ir/ConsumerIr.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
/*
 | 
			
		||||
 * SPDX-FileCopyrightText: 2025 The LineageOS Project
 | 
			
		||||
 * SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <aidl/android/hardware/ir/BnConsumerIr.h>
 | 
			
		||||
 | 
			
		||||
namespace aidl {
 | 
			
		||||
namespace android {
 | 
			
		||||
namespace hardware {
 | 
			
		||||
namespace ir {
 | 
			
		||||
 | 
			
		||||
class ConsumerIr : public BnConsumerIr {
 | 
			
		||||
  public:
 | 
			
		||||
    ConsumerIr();
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    ::ndk::ScopedAStatus getCarrierFreqs(std::vector<ConsumerIrFreqRange>* _aidl_return) override;
 | 
			
		||||
    ::ndk::ScopedAStatus transmit(int32_t in_carrierFreqHz,
 | 
			
		||||
                                  const std::vector<int32_t>& in_pattern) override;
 | 
			
		||||
 | 
			
		||||
    std::vector<ConsumerIrFreqRange> supportedFreqs;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}  // namespace ir
 | 
			
		||||
}  // namespace hardware
 | 
			
		||||
}  // namespace android
 | 
			
		||||
}  // namespace aidl
 | 
			
		||||
							
								
								
									
										9
									
								
								aidl/ir/android.hardware.ir-service.oplus.rc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								aidl/ir/android.hardware.ir-service.oplus.rc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
on boot
 | 
			
		||||
    chown system system /dev/oplus_consumer_ir
 | 
			
		||||
    chmod 0644 /dev/oplus_consumer_ir
 | 
			
		||||
 | 
			
		||||
service vendor.ir-default /vendor/bin/hw/android.hardware.ir-service.oplus
 | 
			
		||||
    class hal
 | 
			
		||||
    user system
 | 
			
		||||
    group system
 | 
			
		||||
    interface aidl android.hardware.ir.IConsumerIr/default
 | 
			
		||||
							
								
								
									
										7
									
								
								aidl/ir/android.hardware.ir-service.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								aidl/ir/android.hardware.ir-service.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
<manifest version="1.0" type="device">
 | 
			
		||||
    <hal format="aidl">
 | 
			
		||||
        <name>android.hardware.ir</name>
 | 
			
		||||
        <version>1</version>
 | 
			
		||||
        <fqname>IConsumerIr/default</fqname>
 | 
			
		||||
    </hal>
 | 
			
		||||
</manifest>
 | 
			
		||||
							
								
								
									
										25
									
								
								aidl/ir/service.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								aidl/ir/service.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
/*
 | 
			
		||||
 * SPDX-FileCopyrightText: 2025 The LineageOS Project
 | 
			
		||||
 * SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "ConsumerIr.h"
 | 
			
		||||
 | 
			
		||||
#include <android-base/logging.h>
 | 
			
		||||
#include <android/binder_manager.h>
 | 
			
		||||
#include <android/binder_process.h>
 | 
			
		||||
 | 
			
		||||
using ::aidl::android::hardware::ir::ConsumerIr;
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    ABinderProcess_setThreadPoolMaxThreadCount(0);
 | 
			
		||||
    std::shared_ptr<ConsumerIr> consumerIr = ndk::SharedRefBase::make<ConsumerIr>();
 | 
			
		||||
 | 
			
		||||
    const std::string instance = std::string() + ConsumerIr::descriptor + "/default";
 | 
			
		||||
    binder_status_t status =
 | 
			
		||||
            AServiceManager_addService(consumerIr->asBinder().get(), instance.c_str());
 | 
			
		||||
    CHECK_EQ(status, STATUS_OK);
 | 
			
		||||
 | 
			
		||||
    ABinderProcess_joinThreadPool();
 | 
			
		||||
    return EXIT_FAILURE;  // should not reach
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										30
									
								
								kernel-headers/include/oplus/oplus_ir_core.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								kernel-headers/include/oplus/oplus_ir_core.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2025 The LineageOS 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.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <sys/ioctl.h>
 | 
			
		||||
 | 
			
		||||
#define IR_IOCTL_GROUP 0xE5
 | 
			
		||||
 | 
			
		||||
#define IR_GET_INF _IO(IR_IOCTL_GROUP, 0x01)
 | 
			
		||||
#define IR_SEND_PATTERN _IO(IR_IOCTL_GROUP, 0x02)
 | 
			
		||||
 | 
			
		||||
struct pattern_params {
 | 
			
		||||
    int32_t carrier_freq;
 | 
			
		||||
    uint32_t size;
 | 
			
		||||
    uint32_t pattern[];
 | 
			
		||||
};
 | 
			
		||||
		Reference in New Issue
	
	Block a user