Compare commits
29 Commits
android-14
...
android-15
Author | SHA1 | Date | |
---|---|---|---|
|
aaaabffb91 | ||
|
a47cb47fba | ||
|
53f9d2ecfe | ||
|
87ece4d4b9 | ||
|
8a9e11b327 | ||
|
1ae3ede91b | ||
|
89eb1f3253 | ||
|
412e289949 | ||
|
4d3171fec4 | ||
|
a0126e7460 | ||
|
380ec34eed | ||
|
032720fcec | ||
|
6cffe9e82a | ||
|
9d943bb391 | ||
|
9bd2172543 | ||
|
c46596dec5 | ||
|
59dbe8e028 | ||
|
adc7d7b432 | ||
|
74c07a5877 | ||
|
eb8f018a5f | ||
|
d5e3af9b01 | ||
|
d730ccf1c6 | ||
|
8829ea27fa | ||
|
8b2e452bbd | ||
|
6906b29151 | ||
|
1c0420d518 | ||
|
c2277d28e8 | ||
|
be71876e39 | ||
|
4df4207d06 |
@@ -6,7 +6,12 @@
|
||||
|
||||
DEVICE_PATH := device/brcm/rpi5
|
||||
|
||||
# Architecture
|
||||
# Platform
|
||||
TARGET_NO_BOOTLOADER := true
|
||||
TARGET_NO_RECOVERY := true
|
||||
|
||||
TARGET_BOARD_PLATFORM := rpi
|
||||
|
||||
TARGET_ARCH := arm64
|
||||
TARGET_ARCH_VARIANT := armv8-a
|
||||
TARGET_CPU_ABI := arm64-v8a
|
||||
@@ -20,11 +25,9 @@ TARGET_2ND_CPU_ABI2 := armeabi
|
||||
TARGET_2ND_CPU_VARIANT := generic
|
||||
|
||||
# Bluetooth
|
||||
BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR := $(DEVICE_PATH)/bluetooth
|
||||
BOARD_HAVE_BLUETOOTH := true
|
||||
|
||||
# Bootloader
|
||||
TARGET_NO_BOOTLOADER := true
|
||||
|
||||
# Camera
|
||||
BOARD_LIBCAMERA_IPAS := rpi/pisp
|
||||
BOARD_LIBCAMERA_PIPELINES := rpi/pisp
|
||||
@@ -52,34 +55,26 @@ DEVICE_MATRIX_FILE := $(DEVICE_PATH)/compatibility_matrix.xml
|
||||
# Partition sizes
|
||||
BOARD_FLASH_BLOCK_SIZE := 4096
|
||||
BOARD_BOOTIMAGE_PARTITION_SIZE := 134217728 # 128M
|
||||
BOARD_SYSTEMIMAGE_PARTITION_SIZE := 2684354560 # 2560M
|
||||
BOARD_SYSTEMIMAGE_PARTITION_SIZE := 2147483648 # 2048M
|
||||
BOARD_USERDATAIMAGE_PARTITION_SIZE := 134217728 # 128M
|
||||
BOARD_VENDORIMAGE_PARTITION_SIZE := 268435456 # 256M
|
||||
BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE := ext4
|
||||
TARGET_USERIMAGES_SPARSE_EXT_DISABLED := true
|
||||
TARGET_USERIMAGES_USE_EXT4 := true
|
||||
|
||||
# Platform
|
||||
TARGET_BOARD_PLATFORM := bcm2712
|
||||
TARGET_BOOTLOADER_BOARD_NAME := bcm2712
|
||||
|
||||
# Properties
|
||||
TARGET_VENDOR_PROP += $(DEVICE_PATH)/vendor.prop
|
||||
|
||||
# Recovery
|
||||
TARGET_NO_RECOVERY := true
|
||||
|
||||
# SELinux
|
||||
BOARD_SEPOLICY_DIRS += device/brcm/rpi5/sepolicy
|
||||
BOARD_KERNEL_CMDLINE += androidboot.selinux=permissive
|
||||
|
||||
# Treble
|
||||
BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED := true
|
||||
BOARD_VNDK_VERSION := current
|
||||
PRODUCT_FULL_TREBLE_OVERRIDE := true
|
||||
TARGET_COPY_OUT_VENDOR := vendor
|
||||
|
||||
# Virtualization
|
||||
BOARD_KERNEL_CMDLINE += androidboot.hypervisor.vm.supported=1
|
||||
|
||||
# Wifi
|
||||
BOARD_WLAN_DEVICE := bcmdhd
|
||||
BOARD_HOSTAPD_DRIVER := NL80211
|
||||
|
@@ -1 +1 @@
|
||||
Raspberry Vanilla AOSP 14 device configuration for Raspberry Pi 5.
|
||||
Raspberry Vanilla AOSP 15 device configuration for Raspberry Pi 5.
|
||||
|
@@ -28,5 +28,6 @@ PRODUCT_COPY_FILES += \
|
||||
PRODUCT_DEVICE := rpi5
|
||||
PRODUCT_NAME := aosp_rpi5
|
||||
PRODUCT_BRAND := Raspberry
|
||||
PRODUCT_MODEL := Pi 5
|
||||
PRODUCT_MODEL := Raspberry Pi 5
|
||||
PRODUCT_MANUFACTURER := Raspberry
|
||||
PRODUCT_RELEASE_NAME := Raspberry Pi 5
|
||||
|
@@ -7,7 +7,7 @@
|
||||
# Inherit device configuration
|
||||
$(call inherit-product, device/brcm/rpi5/device.mk)
|
||||
|
||||
DEVICE_PATH_CAR := device/brcm/rpi5/car
|
||||
DEVICE_CAR_PATH := device/brcm/rpi5/car
|
||||
|
||||
PRODUCT_AAPT_CONFIG := normal mdpi hdpi
|
||||
PRODUCT_AAPT_PREF_CONFIG := hdpi
|
||||
@@ -20,14 +20,12 @@ PRODUCT_PACKAGES += \
|
||||
android.hardware.automotive.audiocontrol-service.example
|
||||
|
||||
PRODUCT_COPY_FILES += \
|
||||
$(DEVICE_PATH_CAR)/car_audio_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/car_audio_configuration.xml
|
||||
$(DEVICE_CAR_PATH)/car_audio_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/car_audio_configuration.xml
|
||||
|
||||
# Bluetooth
|
||||
PRODUCT_VENDOR_PROPERTIES += \
|
||||
bluetooth.device.class_of_device=38,4,8 \
|
||||
bluetooth.profile.a2dp.source.enabled=false \
|
||||
bluetooth.profile.asha.central.enabled=false \
|
||||
bluetooth.profile.avrcp.target.enabled=false \
|
||||
bluetooth.profile.bap.broadcast.assist.enabled=false \
|
||||
bluetooth.profile.bap.unicast.client.enabled=false \
|
||||
bluetooth.profile.bas.client.enabled=false \
|
||||
@@ -37,6 +35,7 @@ PRODUCT_VENDOR_PROPERTIES += \
|
||||
bluetooth.profile.hfp.ag.enabled=false \
|
||||
bluetooth.profile.hid.device.enabled=false \
|
||||
bluetooth.profile.hid.host.enabled=false \
|
||||
bluetooth.profile.map.client.enabled=false \
|
||||
bluetooth.profile.map.server.enabled=false \
|
||||
bluetooth.profile.mcp.server.enabled=false \
|
||||
bluetooth.profile.opp.enabled=false \
|
||||
@@ -65,7 +64,7 @@ PRODUCT_PACKAGES += \
|
||||
|
||||
# Display
|
||||
PRODUCT_COPY_FILES += \
|
||||
$(DEVICE_PATH_CAR)/display_settings.xml:$(TARGET_COPY_OUT_VENDOR)/etc/display_settings.xml
|
||||
$(DEVICE_CAR_PATH)/display_settings.xml:$(TARGET_COPY_OUT_VENDOR)/etc/display_settings.xml
|
||||
|
||||
# EVS
|
||||
ENABLE_CAREVSSERVICE_SAMPLE := true
|
||||
@@ -74,7 +73,7 @@ ENABLE_EVS_SERVICE := true
|
||||
ENABLE_REAR_VIEW_CAMERA_SAMPLE := true
|
||||
|
||||
PRODUCT_COPY_FILES += \
|
||||
$(DEVICE_PATH_CAR)/evs_config_override.json:${TARGET_COPY_OUT_VENDOR}/etc/automotive/evs/config_override.json
|
||||
$(DEVICE_CAR_PATH)/evs_config_override.json:${TARGET_COPY_OUT_VENDOR}/etc/automotive/evs/config_override.json
|
||||
|
||||
# Occupant awareness
|
||||
PRODUCT_PACKAGES += \
|
||||
@@ -102,5 +101,6 @@ PRODUCT_PACKAGES += \
|
||||
PRODUCT_DEVICE := rpi5
|
||||
PRODUCT_NAME := aosp_rpi5_car
|
||||
PRODUCT_BRAND := Raspberry
|
||||
PRODUCT_MODEL := Pi 5
|
||||
PRODUCT_MODEL := Raspberry Pi 5
|
||||
PRODUCT_MANUFACTURER := Raspberry
|
||||
PRODUCT_RELEASE_NAME := Raspberry Pi 5
|
||||
|
@@ -37,5 +37,6 @@ PRODUCT_PACKAGES += \
|
||||
PRODUCT_DEVICE := rpi5
|
||||
PRODUCT_NAME := aosp_rpi5_tv
|
||||
PRODUCT_BRAND := Raspberry
|
||||
PRODUCT_MODEL := Pi 5
|
||||
PRODUCT_MODEL := Raspberry Pi 5
|
||||
PRODUCT_MANUFACTURER := Raspberry
|
||||
PRODUCT_RELEASE_NAME := Raspberry Pi 5
|
||||
|
@@ -6,7 +6,7 @@
|
||||
cc_library_shared {
|
||||
name: "audio.primary.rpi",
|
||||
relative_install_path: "hw",
|
||||
vendor: true,
|
||||
proprietary: true,
|
||||
srcs: ["audio_hw.c"],
|
||||
include_dirs: [
|
||||
"external/expat/lib",
|
||||
@@ -26,7 +26,7 @@ cc_library_shared {
|
||||
cc_library_shared {
|
||||
name: "audio.primary.rpi_hdmi",
|
||||
relative_install_path: "hw",
|
||||
vendor: true,
|
||||
proprietary: true,
|
||||
srcs: ["audio_hw_hdmi.c"],
|
||||
include_dirs: [
|
||||
"external/expat/lib",
|
||||
|
@@ -57,9 +57,6 @@
|
||||
#define CHANNEL_STEREO 2
|
||||
#define MIN_WRITE_SLEEP_US 5000
|
||||
|
||||
int pcm_card;
|
||||
int pcm_device;
|
||||
|
||||
struct stub_stream_in {
|
||||
struct audio_stream_in stream;
|
||||
};
|
||||
@@ -151,7 +148,7 @@ static int start_output_stream(struct alsa_stream_out *out)
|
||||
out->config.start_threshold = PLAYBACK_PERIOD_START_THRESHOLD * PERIOD_SIZE;
|
||||
out->config.avail_min = PERIOD_SIZE;
|
||||
|
||||
out->pcm = pcm_open(pcm_card, pcm_device, PCM_OUT | PCM_MMAP | PCM_NOIRQ | PCM_MONOTONIC, &out->config);
|
||||
out->pcm = pcm_open(get_pcm_card(), get_pcm_device(), PCM_OUT | PCM_MMAP | PCM_NOIRQ | PCM_MONOTONIC, &out->config);
|
||||
|
||||
if (!pcm_is_ready(out->pcm)) {
|
||||
ALOGE("cannot open pcm_out driver: %s", pcm_get_error(out->pcm));
|
||||
@@ -487,7 +484,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
|
||||
struct pcm_params *params;
|
||||
int ret = 0;
|
||||
|
||||
params = pcm_params_get(pcm_card, pcm_device, PCM_OUT);
|
||||
params = pcm_params_get(get_pcm_card(), get_pcm_device(), PCM_OUT);
|
||||
if (!params)
|
||||
return -ENOSYS;
|
||||
|
||||
@@ -693,10 +690,6 @@ static int adev_open(const hw_module_t* module, const char* name,
|
||||
|
||||
ALOGV("adev_open: %s", name);
|
||||
|
||||
pcm_card = get_pcm_card();
|
||||
pcm_device = get_pcm_device();
|
||||
ALOGI("adev_open: pcm_card %d, pcm_device %d", pcm_card, pcm_device);
|
||||
|
||||
if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
|
||||
return -EINVAL;
|
||||
|
||||
|
@@ -55,8 +55,6 @@
|
||||
#define CHANNEL_STEREO 2
|
||||
#define MIN_WRITE_SLEEP_US 5000
|
||||
|
||||
char device_name[PROPERTY_VALUE_MAX];
|
||||
|
||||
struct stub_stream_in {
|
||||
struct audio_stream_in stream;
|
||||
};
|
||||
@@ -103,6 +101,8 @@ static int start_output_stream(struct alsa_stream_out *out)
|
||||
if (out->unavailable)
|
||||
return -ENODEV;
|
||||
|
||||
char device_name[PROPERTY_VALUE_MAX];
|
||||
get_alsa_device_name(device_name);
|
||||
ALOGI("start_output_stream: %s", device_name);
|
||||
|
||||
int r;
|
||||
@@ -717,9 +717,6 @@ static int adev_open(const hw_module_t* module, const char* name,
|
||||
|
||||
ALOGV("adev_open: %s", name);
|
||||
|
||||
get_alsa_device_name(device_name);
|
||||
ALOGI("adev_open: %s", device_name);
|
||||
|
||||
if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
|
||||
return -EINVAL;
|
||||
|
||||
|
33
bluetooth/Android.bp
Normal file
33
bluetooth/Android.bp
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2020 The Android Open Source Project
|
||||
// Copyright (C) 2024 KonstaKANG
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cc_binary {
|
||||
name: "android.hardware.bluetooth-service.rpi",
|
||||
relative_install_path: "hw",
|
||||
init_rc: ["bluetooth-service-rpi.rc"],
|
||||
vintf_fragments: ["bluetooth-service-rpi.xml"],
|
||||
vendor: true,
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
],
|
||||
srcs: [
|
||||
"BluetoothHci.cpp",
|
||||
"net_bluetooth_mgmt.cpp",
|
||||
"service.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"android.hardware.bluetooth-V1-ndk",
|
||||
"libbase",
|
||||
"libbinder_ndk",
|
||||
"libhidlbase",
|
||||
"liblog",
|
||||
"libutils",
|
||||
],
|
||||
static_libs: [
|
||||
"android.hardware.bluetooth.async",
|
||||
"android.hardware.bluetooth.hci",
|
||||
],
|
||||
}
|
227
bluetooth/BluetoothHci.cpp
Normal file
227
bluetooth/BluetoothHci.cpp
Normal file
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
* Copyright (C) 2024 KonstaKANG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.bluetooth.service.rpi"
|
||||
|
||||
#include "BluetoothHci.h"
|
||||
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace ::android::hardware::bluetooth::hci;
|
||||
using namespace ::android::hardware::bluetooth::async;
|
||||
using aidl::android::hardware::bluetooth::Status;
|
||||
|
||||
namespace aidl::android::hardware::bluetooth::impl {
|
||||
|
||||
void OnDeath(void* cookie);
|
||||
|
||||
class BluetoothDeathRecipient {
|
||||
public:
|
||||
BluetoothDeathRecipient(BluetoothHci* hci) : mHci(hci) {}
|
||||
|
||||
void LinkToDeath(const std::shared_ptr<IBluetoothHciCallbacks>& cb) {
|
||||
mCb = cb;
|
||||
clientDeathRecipient_ = AIBinder_DeathRecipient_new(OnDeath);
|
||||
auto linkToDeathReturnStatus = AIBinder_linkToDeath(
|
||||
mCb->asBinder().get(), clientDeathRecipient_, this /* cookie */);
|
||||
LOG_ALWAYS_FATAL_IF(linkToDeathReturnStatus != STATUS_OK,
|
||||
"Unable to link to death recipient");
|
||||
}
|
||||
|
||||
void UnlinkToDeath(const std::shared_ptr<IBluetoothHciCallbacks>& cb) {
|
||||
LOG_ALWAYS_FATAL_IF(cb != mCb, "Unable to unlink mismatched pointers");
|
||||
}
|
||||
|
||||
void serviceDied() {
|
||||
if (mCb != nullptr && !AIBinder_isAlive(mCb->asBinder().get())) {
|
||||
ALOGE("Bluetooth remote service has died");
|
||||
} else {
|
||||
ALOGE("BluetoothDeathRecipient::serviceDied called but service not dead");
|
||||
return;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mHasDiedMutex);
|
||||
has_died_ = true;
|
||||
}
|
||||
mHci->close();
|
||||
}
|
||||
BluetoothHci* mHci;
|
||||
std::shared_ptr<IBluetoothHciCallbacks> mCb;
|
||||
AIBinder_DeathRecipient* clientDeathRecipient_;
|
||||
bool getHasDied() {
|
||||
std::lock_guard<std::mutex> guard(mHasDiedMutex);
|
||||
return has_died_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex mHasDiedMutex;
|
||||
bool has_died_{false};
|
||||
};
|
||||
|
||||
void OnDeath(void* cookie) {
|
||||
auto* death_recipient = static_cast<BluetoothDeathRecipient*>(cookie);
|
||||
death_recipient->serviceDied();
|
||||
}
|
||||
|
||||
BluetoothHci::BluetoothHci() {
|
||||
mDeathRecipient = std::make_shared<BluetoothDeathRecipient>(this);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus BluetoothHci::initialize(
|
||||
const std::shared_ptr<IBluetoothHciCallbacks>& cb) {
|
||||
ALOGI(__func__);
|
||||
|
||||
if (cb == nullptr) {
|
||||
ALOGE("cb == nullptr! -> Unable to call initializationComplete(ERR)");
|
||||
return ndk::ScopedAStatus::fromServiceSpecificError(STATUS_BAD_VALUE);
|
||||
}
|
||||
|
||||
HalState old_state = HalState::READY;
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mStateMutex);
|
||||
if (mState != HalState::READY) {
|
||||
old_state = mState;
|
||||
} else {
|
||||
mState = HalState::INITIALIZING;
|
||||
}
|
||||
}
|
||||
|
||||
if (old_state != HalState::READY) {
|
||||
ALOGE("initialize: Unexpected State %d", static_cast<int>(old_state));
|
||||
close();
|
||||
cb->initializationComplete(Status::ALREADY_INITIALIZED);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
mCb = cb;
|
||||
management_.reset(new NetBluetoothMgmt);
|
||||
mFd = management_->openHci();
|
||||
if (mFd < 0) {
|
||||
management_.reset();
|
||||
|
||||
ALOGI("Unable to open Linux interface.");
|
||||
mState = HalState::READY;
|
||||
cb->initializationComplete(Status::UNABLE_TO_OPEN_INTERFACE);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
mDeathRecipient->LinkToDeath(mCb);
|
||||
|
||||
mH4 = std::make_shared<H4Protocol>(
|
||||
mFd,
|
||||
[](const std::vector<uint8_t>& /* raw_command */) {
|
||||
LOG_ALWAYS_FATAL("Unexpected command!");
|
||||
},
|
||||
[this](const std::vector<uint8_t>& raw_acl) {
|
||||
mCb->aclDataReceived(raw_acl);
|
||||
},
|
||||
[this](const std::vector<uint8_t>& raw_sco) {
|
||||
mCb->scoDataReceived(raw_sco);
|
||||
},
|
||||
[this](const std::vector<uint8_t>& raw_event) {
|
||||
mCb->hciEventReceived(raw_event);
|
||||
},
|
||||
[this](const std::vector<uint8_t>& raw_iso) {
|
||||
mCb->isoDataReceived(raw_iso);
|
||||
},
|
||||
[this]() {
|
||||
ALOGI("HCI socket device disconnected");
|
||||
mFdWatcher.StopWatchingFileDescriptors();
|
||||
});
|
||||
mFdWatcher.WatchFdForNonBlockingReads(mFd,
|
||||
[this](int) { mH4->OnDataReady(); });
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mStateMutex);
|
||||
mState = HalState::ONE_CLIENT;
|
||||
}
|
||||
ALOGI("initialization complete");
|
||||
auto status = mCb->initializationComplete(Status::SUCCESS);
|
||||
if (!status.isOk()) {
|
||||
if (!mDeathRecipient->getHasDied()) {
|
||||
ALOGE("Error sending init callback, but no death notification");
|
||||
}
|
||||
close();
|
||||
return ndk::ScopedAStatus::fromServiceSpecificError(
|
||||
STATUS_FAILED_TRANSACTION);
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus BluetoothHci::close() {
|
||||
ALOGI(__func__);
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mStateMutex);
|
||||
if (mState != HalState::ONE_CLIENT) {
|
||||
LOG_ALWAYS_FATAL_IF(mState == HalState::INITIALIZING,
|
||||
"mState is INITIALIZING");
|
||||
ALOGI("Already closed");
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
mState = HalState::CLOSING;
|
||||
}
|
||||
|
||||
mFdWatcher.StopWatchingFileDescriptors();
|
||||
|
||||
management_->closeHci();
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mStateMutex);
|
||||
mState = HalState::READY;
|
||||
mH4 = nullptr;
|
||||
}
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus BluetoothHci::sendHciCommand(
|
||||
const std::vector<uint8_t>& packet) {
|
||||
return send(PacketType::COMMAND, packet);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus BluetoothHci::sendAclData(
|
||||
const std::vector<uint8_t>& packet) {
|
||||
return send(PacketType::ACL_DATA, packet);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus BluetoothHci::sendScoData(
|
||||
const std::vector<uint8_t>& packet) {
|
||||
return send(PacketType::SCO_DATA, packet);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus BluetoothHci::sendIsoData(
|
||||
const std::vector<uint8_t>& packet) {
|
||||
return send(PacketType::ISO_DATA, packet);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus BluetoothHci::send(PacketType type,
|
||||
const std::vector<uint8_t>& v) {
|
||||
if (v.empty()) {
|
||||
ALOGE("Packet is empty, no data was found to be sent");
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> guard(mStateMutex);
|
||||
if (mH4 == nullptr) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
|
||||
}
|
||||
|
||||
mH4->Send(type, v);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
} // namespace aidl::android::hardware::bluetooth::impl
|
75
bluetooth/BluetoothHci.h
Normal file
75
bluetooth/BluetoothHci.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
* Copyright (C) 2024 KonstaKANG
|
||||
*
|
||||
* 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 <aidl/android/hardware/bluetooth/BnBluetoothHci.h>
|
||||
#include <aidl/android/hardware/bluetooth/IBluetoothHciCallbacks.h>
|
||||
|
||||
#include "async_fd_watcher.h"
|
||||
#include "h4_protocol.h"
|
||||
#include "net_bluetooth_mgmt.h"
|
||||
|
||||
namespace aidl::android::hardware::bluetooth::impl {
|
||||
|
||||
class BluetoothDeathRecipient;
|
||||
|
||||
// This Bluetooth HAL implementation connects with a serial port at dev_path_.
|
||||
class BluetoothHci : public BnBluetoothHci {
|
||||
public:
|
||||
BluetoothHci();
|
||||
|
||||
ndk::ScopedAStatus initialize(
|
||||
const std::shared_ptr<IBluetoothHciCallbacks>& cb) override;
|
||||
|
||||
ndk::ScopedAStatus sendHciCommand(
|
||||
const std::vector<uint8_t>& packet) override;
|
||||
|
||||
ndk::ScopedAStatus sendAclData(const std::vector<uint8_t>& packet) override;
|
||||
|
||||
ndk::ScopedAStatus sendScoData(const std::vector<uint8_t>& packet) override;
|
||||
|
||||
ndk::ScopedAStatus sendIsoData(const std::vector<uint8_t>& packet) override;
|
||||
|
||||
ndk::ScopedAStatus close() override;
|
||||
|
||||
private:
|
||||
int mFd{-1};
|
||||
std::shared_ptr<IBluetoothHciCallbacks> mCb = nullptr;
|
||||
|
||||
std::shared_ptr<::android::hardware::bluetooth::hci::H4Protocol> mH4;
|
||||
|
||||
std::shared_ptr<BluetoothDeathRecipient> mDeathRecipient;
|
||||
|
||||
::android::hardware::bluetooth::async::AsyncFdWatcher mFdWatcher;
|
||||
|
||||
[[nodiscard]] ndk::ScopedAStatus send(
|
||||
::android::hardware::bluetooth::hci::PacketType type,
|
||||
const std::vector<uint8_t>& packet);
|
||||
std::unique_ptr<NetBluetoothMgmt> management_{};
|
||||
|
||||
// Don't close twice or open before close is complete
|
||||
std::mutex mStateMutex;
|
||||
enum class HalState {
|
||||
READY,
|
||||
INITIALIZING,
|
||||
ONE_CLIENT,
|
||||
CLOSING,
|
||||
} mState{HalState::READY};
|
||||
};
|
||||
|
||||
} // namespace aidl::android::hardware::bluetooth::impl
|
12
bluetooth/bdroid_buildcfg.h
Normal file
12
bluetooth/bdroid_buildcfg.h
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2022 KonstaKANG
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _BDROID_BUILDCFG_H
|
||||
#define _BDROID_BUILDCFG_H
|
||||
|
||||
#define BTM_DEF_LOCAL_NAME "Raspberry Pi 5"
|
||||
|
||||
#endif
|
6
bluetooth/bluetooth-service-rpi.rc
Normal file
6
bluetooth/bluetooth-service-rpi.rc
Normal file
@@ -0,0 +1,6 @@
|
||||
service vendor.bluetooth-default /vendor/bin/hw/android.hardware.bluetooth-service.rpi
|
||||
class hal
|
||||
capabilities BLOCK_SUSPEND NET_ADMIN SYS_NICE
|
||||
user bluetooth
|
||||
group bluetooth
|
||||
task_profiles HighPerformance
|
6
bluetooth/bluetooth-service-rpi.xml
Normal file
6
bluetooth/bluetooth-service-rpi.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<manifest version="1.0" type="device">
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.bluetooth</name>
|
||||
<fqname>IBluetoothHci/default</fqname>
|
||||
</hal>
|
||||
</manifest>
|
278
bluetooth/net_bluetooth_mgmt.cpp
Normal file
278
bluetooth/net_bluetooth_mgmt.cpp
Normal file
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
* Copyright (C) 2024 KonstaKANG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.bluetooth.service.rpi"
|
||||
|
||||
#include "net_bluetooth_mgmt.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <log/log.h>
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
// Definitions imported from <linux/net/bluetooth/bluetooth.h>
|
||||
#define BTPROTO_HCI 1
|
||||
|
||||
// Definitions imported from <linux/net/bluetooth/hci_sock.h>
|
||||
#define HCI_CHANNEL_USER 1
|
||||
#define HCI_CHANNEL_CONTROL 3
|
||||
#define HCI_DEV_NONE 0xffff
|
||||
|
||||
struct sockaddr_hci {
|
||||
sa_family_t hci_family;
|
||||
unsigned short hci_dev;
|
||||
unsigned short hci_channel;
|
||||
};
|
||||
|
||||
// Definitions imported from <linux/net/bluetooth/mgmt.h>
|
||||
#define MGMT_OP_READ_INDEX_LIST 0x0003
|
||||
#define MGMT_EV_INDEX_ADDED 0x0004
|
||||
#define MGMT_EV_CMD_COMPLETE 0x0001
|
||||
#define MGMT_PKT_SIZE_MAX 1024
|
||||
#define MGMT_INDEX_NONE 0xFFFF
|
||||
#define WRITE_NO_INTR(fn) \
|
||||
do { \
|
||||
} while ((fn) == -1 && errno == EINTR)
|
||||
|
||||
struct mgmt_pkt {
|
||||
uint16_t opcode;
|
||||
uint16_t index;
|
||||
uint16_t len;
|
||||
uint8_t data[MGMT_PKT_SIZE_MAX];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct mgmt_ev_read_index_list {
|
||||
uint16_t opcode;
|
||||
uint8_t status;
|
||||
uint16_t num_controllers;
|
||||
uint16_t index[];
|
||||
} __attribute__((packed));
|
||||
|
||||
namespace aidl::android::hardware::bluetooth::impl {
|
||||
|
||||
// Wait indefinitely for the selected HCI interface to be enabled in the
|
||||
// bluetooth driver.
|
||||
int NetBluetoothMgmt::waitHciDev(int hci_interface) {
|
||||
ALOGI("waiting for hci interface %d", hci_interface);
|
||||
|
||||
int ret = -1;
|
||||
struct mgmt_pkt cmd;
|
||||
struct pollfd pollfd;
|
||||
struct sockaddr_hci hci_addr = {
|
||||
.hci_family = AF_BLUETOOTH,
|
||||
.hci_dev = HCI_DEV_NONE,
|
||||
.hci_channel = HCI_CHANNEL_CONTROL,
|
||||
};
|
||||
|
||||
// Open and bind a socket to the bluetooth control interface in the
|
||||
// kernel driver, used to send control commands and receive control
|
||||
// events.
|
||||
int fd = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
|
||||
if (fd < 0) {
|
||||
ALOGE("unable to open raw bluetooth socket: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (bind(fd, (struct sockaddr*)&hci_addr, sizeof(hci_addr)) < 0) {
|
||||
ALOGE("unable to bind bluetooth control channel: %s", strerror(errno));
|
||||
goto end;
|
||||
}
|
||||
|
||||
// Send the control command [Read Index List].
|
||||
cmd = {
|
||||
.opcode = MGMT_OP_READ_INDEX_LIST,
|
||||
.index = MGMT_INDEX_NONE,
|
||||
.len = 0,
|
||||
};
|
||||
|
||||
if (write(fd, &cmd, 6) != 6) {
|
||||
ALOGE("error writing mgmt command: %s", strerror(errno));
|
||||
goto end;
|
||||
}
|
||||
|
||||
// Poll the control socket waiting for the command response,
|
||||
// and subsequent [Index Added] events. The loops continue without
|
||||
// timeout until the selected hci interface is detected.
|
||||
pollfd = {.fd = fd, .events = POLLIN};
|
||||
|
||||
for (;;) {
|
||||
ret = poll(&pollfd, 1, -1);
|
||||
|
||||
// Poll interrupted, try again.
|
||||
if (ret == -1 && (errno == EINTR || errno == EAGAIN)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Poll failure, abandon.
|
||||
if (ret == -1) {
|
||||
ALOGE("poll error: %s", strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
// Spurious wakeup, try again.
|
||||
if (ret == 0 || (pollfd.revents & POLLIN) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Read the next control event.
|
||||
struct mgmt_pkt ev {};
|
||||
ret = read(fd, &ev, sizeof(ev));
|
||||
if (ret < 0) {
|
||||
ALOGE("error reading mgmt event: %s", strerror(errno));
|
||||
goto end;
|
||||
}
|
||||
|
||||
// Received [Read Index List] command response.
|
||||
if (ev.opcode == MGMT_EV_CMD_COMPLETE) {
|
||||
struct mgmt_ev_read_index_list* data =
|
||||
(struct mgmt_ev_read_index_list*)ev.data;
|
||||
|
||||
// Prefer the exact hci_interface
|
||||
for (int i = 0; i < data->num_controllers; i++) {
|
||||
if (data->index[i] == hci_interface) {
|
||||
ALOGI("hci interface %d found", data->index[i]);
|
||||
ret = data->index[i];
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
// Accept a larger one if we can't find the exact one
|
||||
for (int i = 0; i < data->num_controllers; i++) {
|
||||
if (data->index[i] >= hci_interface) {
|
||||
ALOGI("hci interface %d found", data->index[i]);
|
||||
ret = data->index[i];
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Received [Index Added] event.
|
||||
if (ev.opcode == MGMT_EV_INDEX_ADDED && ev.index == hci_interface) {
|
||||
ALOGI("hci interface %d added", hci_interface);
|
||||
ret = hci_interface;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
::close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int NetBluetoothMgmt::findRfKill() {
|
||||
char rfkill_type[64];
|
||||
char type[16];
|
||||
int fd, size, i;
|
||||
for(i = 0; rfkill_state_ == NULL; i++)
|
||||
{
|
||||
snprintf(rfkill_type, sizeof(rfkill_type), "/sys/class/rfkill/rfkill%d/type", i);
|
||||
if ((fd = open(rfkill_type, O_RDONLY)) < 0)
|
||||
{
|
||||
ALOGE("open(%s) failed: %s (%d)\n", rfkill_type, strerror(errno), errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = read(fd, &type, sizeof(type));
|
||||
::close(fd);
|
||||
|
||||
if ((size >= 9) && !memcmp(type, "bluetooth", 9))
|
||||
{
|
||||
::asprintf(&rfkill_state_, "/sys/class/rfkill/rfkill%d/state", i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NetBluetoothMgmt::rfKill(int block) {
|
||||
int fd;
|
||||
char on = (block)?'1':'0';
|
||||
if (findRfKill() != 0) return 0;
|
||||
|
||||
fd = open(rfkill_state_, O_WRONLY);
|
||||
if (fd < 0) {
|
||||
ALOGE( "Unable to open /dev/rfkill");
|
||||
return -1;
|
||||
}
|
||||
ssize_t len;
|
||||
WRITE_NO_INTR(len = write(fd, &on, 1));
|
||||
if (len < 0) {
|
||||
ALOGE( "Failed to change rfkill state");
|
||||
::close(fd);
|
||||
return -1;
|
||||
}
|
||||
::close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NetBluetoothMgmt::openHci(int hci_interface) {
|
||||
ALOGI("opening hci interface %d", hci_interface);
|
||||
|
||||
// Block Bluetooth.
|
||||
rfkill_state_ = NULL;
|
||||
rfKill(1);
|
||||
|
||||
// Wait for the HCI interface to complete initialization or to come online.
|
||||
int hci = waitHciDev(hci_interface);
|
||||
if (hci < 0) {
|
||||
ALOGE("hci interface %d not found", hci_interface);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Open the raw HCI socket.
|
||||
int fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
|
||||
if (fd < 0) {
|
||||
ALOGE("unable to open raw bluetooth socket: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct sockaddr_hci hci_addr = {
|
||||
.hci_family = AF_BLUETOOTH,
|
||||
.hci_dev = static_cast<uint16_t>(hci),
|
||||
.hci_channel = HCI_CHANNEL_USER,
|
||||
};
|
||||
|
||||
// Bind the socket to the selected interface.
|
||||
if (bind(fd, (struct sockaddr*)&hci_addr, sizeof(hci_addr)) < 0) {
|
||||
ALOGE("unable to bind bluetooth user channel: %s", strerror(errno));
|
||||
::close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ALOGI("hci interface %d ready", hci);
|
||||
bt_fd_ = fd;
|
||||
return fd;
|
||||
}
|
||||
|
||||
void NetBluetoothMgmt::closeHci() {
|
||||
if (bt_fd_ != -1) {
|
||||
::close(bt_fd_);
|
||||
bt_fd_ = -1;
|
||||
}
|
||||
|
||||
// Unblock Bluetooth.
|
||||
rfKill(0);
|
||||
free(rfkill_state_);
|
||||
}
|
||||
|
||||
} // namespace aidl::android::hardware::bluetooth::impl
|
44
bluetooth/net_bluetooth_mgmt.h
Normal file
44
bluetooth/net_bluetooth_mgmt.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
* Copyright (C) 2024 KonstaKANG
|
||||
*
|
||||
* 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 <unistd.h>
|
||||
|
||||
namespace aidl::android::hardware::bluetooth::impl {
|
||||
|
||||
class NetBluetoothMgmt {
|
||||
public:
|
||||
NetBluetoothMgmt() {}
|
||||
~NetBluetoothMgmt() {
|
||||
::close(bt_fd_);
|
||||
}
|
||||
|
||||
int openHci(int hci_interface = 0);
|
||||
void closeHci();
|
||||
|
||||
private:
|
||||
int waitHciDev(int hci_interface);
|
||||
int findRfKill();
|
||||
int rfKill(int block);
|
||||
char *rfkill_state_;
|
||||
|
||||
// File descriptor opened to the bluetooth user channel.
|
||||
int bt_fd_{-1};
|
||||
};
|
||||
|
||||
} // namespace aidl::android::hardware::bluetooth::impl
|
50
bluetooth/service.cpp
Normal file
50
bluetooth/service.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
* Copyright (C) 2024 KonstaKANG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "aidl.android.hardware.bluetooth.service.rpi"
|
||||
|
||||
#include <aidl/android/hardware/bluetooth/IBluetoothHci.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
#include <hidl/HidlSupport.h>
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
|
||||
#include "BluetoothHci.h"
|
||||
|
||||
using ::aidl::android::hardware::bluetooth::impl::BluetoothHci;
|
||||
using ::android::hardware::configureRpcThreadpool;
|
||||
using ::android::hardware::joinRpcThreadpool;
|
||||
|
||||
int main(int /* argc */, char** /* argv */) {
|
||||
ALOGI("Bluetooth HAL starting");
|
||||
if (!ABinderProcess_setThreadPoolMaxThreadCount(0)) {
|
||||
ALOGI("failed to set thread pool max thread count");
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::shared_ptr<BluetoothHci> service =
|
||||
ndk::SharedRefBase::make<BluetoothHci>();
|
||||
std::string instance = std::string() + BluetoothHci::descriptor + "/default";
|
||||
auto result =
|
||||
AServiceManager_addService(service->asBinder().get(), instance.c_str());
|
||||
if (result == STATUS_OK) {
|
||||
ABinderProcess_joinThreadPool();
|
||||
} else {
|
||||
ALOGE("Could not register as a service!");
|
||||
}
|
||||
return 0;
|
||||
}
|
@@ -6,6 +6,7 @@ initramfs ramdisk.img followkernel
|
||||
|
||||
# Camera
|
||||
camera_auto_detect=1
|
||||
start_x=1
|
||||
|
||||
# Display
|
||||
disable_overscan=1
|
||||
|
@@ -8,6 +8,9 @@ cameras:
|
||||
"/base/axi/pcie@120000/rp1/i2c@88000/imx477@1a":
|
||||
location: back
|
||||
rotation: 0
|
||||
"/base/axi/pcie@120000/rp1/i2c@88000/imx500@1a":
|
||||
location: back
|
||||
rotation: 0
|
||||
"/base/axi/pcie@120000/rp1/i2c@88000/imx708@1a":
|
||||
location: back
|
||||
rotation: 0
|
||||
|
@@ -1,26 +1,17 @@
|
||||
// Copyright (C) 2021 The Android Open Source Project
|
||||
// Copyright (C) 2025 KonstaKANG
|
||||
// Copyright (C) 2019 The Android Open-Source Project
|
||||
// Copyright (C) 2021-2022 KonstaKANG
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cc_binary {
|
||||
name: "android.hardware.tv.cec@1.0-service.rpi",
|
||||
cc_library_shared {
|
||||
name: "hdmi_cec.rpi",
|
||||
relative_install_path: "hw",
|
||||
init_rc: ["android.hardware.tv.cec@1.0-service.rpi.rc"],
|
||||
vintf_fragments: ["android.hardware.tv.cec@1.0-service.rpi.xml"],
|
||||
vendor: true,
|
||||
srcs: [
|
||||
"HdmiCec.cpp",
|
||||
"HdmiCecPort.cpp",
|
||||
"service.cpp",
|
||||
],
|
||||
proprietary: true,
|
||||
srcs: ["hdmi_cec.c"],
|
||||
cflags: ["-Werror"],
|
||||
shared_libs: [
|
||||
"android.hardware.tv.cec@1.0",
|
||||
"libbase",
|
||||
"liblog",
|
||||
"libcutils",
|
||||
"libhardware",
|
||||
"libhidlbase",
|
||||
"liblog",
|
||||
"libutils",
|
||||
],
|
||||
}
|
||||
|
504
cec/HdmiCec.cpp
504
cec/HdmiCec.cpp
@@ -1,504 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
* Copyright (C) 2025 KonstaKANG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.tv.cec@1.0-service.rpi"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/properties.h>
|
||||
|
||||
#include <cutils/properties.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/ioctl.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include "HdmiCec.h"
|
||||
|
||||
#define PROPERTY_CEC_DEVICE "persist.hdmi.cec_device"
|
||||
#define PROPERTY_CEC_VERSION "ro.hdmi.cec_version"
|
||||
#define PROPERTY_VENDOR_ID "ro.hdmi.vendor_id"
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace tv {
|
||||
namespace cec {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
using android::base::GetProperty;
|
||||
using std::string;
|
||||
|
||||
HdmiCec::HdmiCec() {
|
||||
mCecEnabled = false;
|
||||
mWakeupEnabled = false;
|
||||
mCecControlEnabled = false;
|
||||
mCallback = nullptr;
|
||||
|
||||
Result result = init();
|
||||
if (result != Result::SUCCESS) {
|
||||
LOG(ERROR) << "Failed to init HDMI-CEC HAL";
|
||||
}
|
||||
}
|
||||
|
||||
HdmiCec::~HdmiCec() {
|
||||
release();
|
||||
}
|
||||
|
||||
// Methods from ::android::hardware::tv::cec::V1_0::IHdmiCec follow.
|
||||
Return<Result> HdmiCec::addLogicalAddress(CecLogicalAddress addr) {
|
||||
if (addr < CecLogicalAddress::TV || addr >= CecLogicalAddress::BROADCAST) {
|
||||
LOG(ERROR) << "Add logical address failed, Invalid address";
|
||||
return Result::FAILURE_INVALID_ARGS;
|
||||
}
|
||||
|
||||
cec_log_addrs cecLogAddrs;
|
||||
int ret = ioctl(mHdmiCecPorts[0]->mCecFd, CEC_ADAP_G_LOG_ADDRS, &cecLogAddrs);
|
||||
if (ret) {
|
||||
LOG(ERROR) << "Add logical address failed, Error = " << strerror(errno);
|
||||
return Result::FAILURE_BUSY;
|
||||
}
|
||||
|
||||
cecLogAddrs.cec_version = getCecVersion();
|
||||
cecLogAddrs.vendor_id = getVendorId();
|
||||
|
||||
unsigned int logAddrType = CEC_LOG_ADDR_TYPE_UNREGISTERED;
|
||||
unsigned int allDevTypes = 0;
|
||||
unsigned int primDevType = 0xff;
|
||||
switch (addr) {
|
||||
case CecLogicalAddress::TV:
|
||||
primDevType = CEC_OP_PRIM_DEVTYPE_TV;
|
||||
logAddrType = CEC_LOG_ADDR_TYPE_TV;
|
||||
allDevTypes = CEC_OP_ALL_DEVTYPE_TV;
|
||||
break;
|
||||
case CecLogicalAddress::RECORDER_1:
|
||||
case CecLogicalAddress::RECORDER_2:
|
||||
case CecLogicalAddress::RECORDER_3:
|
||||
primDevType = CEC_OP_PRIM_DEVTYPE_RECORD;
|
||||
logAddrType = CEC_LOG_ADDR_TYPE_RECORD;
|
||||
allDevTypes = CEC_OP_ALL_DEVTYPE_RECORD;
|
||||
break;
|
||||
case CecLogicalAddress::TUNER_1:
|
||||
case CecLogicalAddress::TUNER_2:
|
||||
case CecLogicalAddress::TUNER_3:
|
||||
case CecLogicalAddress::TUNER_4:
|
||||
primDevType = CEC_OP_PRIM_DEVTYPE_TUNER;
|
||||
logAddrType = CEC_LOG_ADDR_TYPE_TUNER;
|
||||
allDevTypes = CEC_OP_ALL_DEVTYPE_TUNER;
|
||||
break;
|
||||
case CecLogicalAddress::PLAYBACK_1:
|
||||
case CecLogicalAddress::PLAYBACK_2:
|
||||
case CecLogicalAddress::PLAYBACK_3:
|
||||
primDevType = CEC_OP_PRIM_DEVTYPE_PLAYBACK;
|
||||
logAddrType = CEC_LOG_ADDR_TYPE_PLAYBACK;
|
||||
allDevTypes = CEC_OP_ALL_DEVTYPE_PLAYBACK;
|
||||
cecLogAddrs.flags |= CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU;
|
||||
break;
|
||||
case CecLogicalAddress::AUDIO_SYSTEM:
|
||||
primDevType = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM;
|
||||
logAddrType = CEC_LOG_ADDR_TYPE_AUDIOSYSTEM;
|
||||
allDevTypes = CEC_OP_ALL_DEVTYPE_AUDIOSYSTEM;
|
||||
break;
|
||||
case CecLogicalAddress::FREE_USE:
|
||||
primDevType = CEC_OP_PRIM_DEVTYPE_PROCESSOR;
|
||||
logAddrType = CEC_LOG_ADDR_TYPE_SPECIFIC;
|
||||
allDevTypes = CEC_OP_ALL_DEVTYPE_SWITCH;
|
||||
break;
|
||||
case CecLogicalAddress::UNREGISTERED:
|
||||
cecLogAddrs.flags |= CEC_LOG_ADDRS_FL_ALLOW_UNREG_FALLBACK;
|
||||
break;
|
||||
}
|
||||
|
||||
int logAddrIndex = cecLogAddrs.num_log_addrs;
|
||||
cecLogAddrs.num_log_addrs += 1;
|
||||
cecLogAddrs.log_addr[logAddrIndex] = static_cast<cec_logical_address_t>(addr);
|
||||
cecLogAddrs.log_addr_type[logAddrIndex] = logAddrType;
|
||||
cecLogAddrs.primary_device_type[logAddrIndex] = primDevType;
|
||||
cecLogAddrs.all_device_types[logAddrIndex] = allDevTypes;
|
||||
cecLogAddrs.features[logAddrIndex][0] = 0;
|
||||
cecLogAddrs.features[logAddrIndex][1] = 0;
|
||||
|
||||
ret = ioctl(mHdmiCecPorts[0]->mCecFd, CEC_ADAP_S_LOG_ADDRS, &cecLogAddrs);
|
||||
if (ret) {
|
||||
LOG(ERROR) << "Add logical address failed for port " << mHdmiCecPorts[0]->mPortId
|
||||
<< ", Error = " << strerror(errno);
|
||||
return Result::FAILURE_BUSY;
|
||||
}
|
||||
|
||||
return Result::SUCCESS;
|
||||
}
|
||||
|
||||
Return<void> HdmiCec::clearLogicalAddress() {
|
||||
cec_log_addrs cecLogAddrs;
|
||||
memset(&cecLogAddrs, 0, sizeof(cecLogAddrs));
|
||||
|
||||
int ret = ioctl(mHdmiCecPorts[0]->mCecFd, CEC_ADAP_S_LOG_ADDRS, &cecLogAddrs);
|
||||
if (ret) {
|
||||
LOG(ERROR) << "Clear logical Address failed for port " << mHdmiCecPorts[0]->mPortId
|
||||
<< ", Error = " << strerror(errno);
|
||||
}
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> HdmiCec::getPhysicalAddress(getPhysicalAddress_cb callback) {
|
||||
uint16_t addr;
|
||||
|
||||
int ret = ioctl(mHdmiCecPorts[0]->mCecFd, CEC_ADAP_G_PHYS_ADDR, &addr);
|
||||
if (ret) {
|
||||
LOG(ERROR) << "Get physical address failed, Error = " << strerror(errno);
|
||||
callback(Result::FAILURE_INVALID_STATE, addr);
|
||||
return Void();
|
||||
}
|
||||
|
||||
callback(Result::SUCCESS, addr);
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<SendMessageResult> HdmiCec::sendMessage(const CecMessage& message) {
|
||||
if (!mCecEnabled) {
|
||||
return SendMessageResult::FAIL;
|
||||
}
|
||||
|
||||
cec_msg cecMsg;
|
||||
memset(&cecMsg, 0, sizeof(cec_msg));
|
||||
|
||||
int initiator = static_cast<cec_logical_address_t>(message.initiator);
|
||||
int destination = static_cast<cec_logical_address_t>(message.destination);
|
||||
|
||||
cecMsg.msg[0] = (initiator << 4) | destination;
|
||||
for (size_t i = 0; i < message.body.size(); ++i) {
|
||||
cecMsg.msg[i + 1] = message.body[i];
|
||||
}
|
||||
cecMsg.len = message.body.size() + 1;
|
||||
|
||||
int ret = ioctl(mHdmiCecPorts[0]->mCecFd, CEC_TRANSMIT, &cecMsg);
|
||||
if (ret) {
|
||||
LOG(ERROR) << "Send message failed, Error = " << strerror(errno);
|
||||
return SendMessageResult::FAIL;
|
||||
}
|
||||
|
||||
if (cecMsg.tx_status != CEC_TX_STATUS_OK) {
|
||||
LOG(ERROR) << "Send message tx_status = " << cecMsg.tx_status;
|
||||
}
|
||||
|
||||
return getSendMessageResult(cecMsg.tx_status);
|
||||
}
|
||||
|
||||
Return<void> HdmiCec::setCallback(const sp<IHdmiCecCallback>& callback) {
|
||||
if (mCallback != nullptr) {
|
||||
mCallback->unlinkToDeath(this);
|
||||
mCallback = nullptr;
|
||||
}
|
||||
|
||||
if (callback != nullptr) {
|
||||
mCallback = callback;
|
||||
mCallback->linkToDeath(this, 0 /*cookie*/);
|
||||
}
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<int32_t> HdmiCec::getCecVersion() {
|
||||
return property_get_int32(PROPERTY_CEC_VERSION, CEC_OP_CEC_VERSION_1_4);
|
||||
}
|
||||
|
||||
Return<uint32_t> HdmiCec::getVendorId() {
|
||||
return property_get_int32(PROPERTY_VENDOR_ID, 0x000c03 /* HDMI LLC vendor ID */);
|
||||
}
|
||||
|
||||
Return<void> HdmiCec::getPortInfo(getPortInfo_cb callback) {
|
||||
uint16_t addr = CEC_PHYS_ADDR_INVALID;
|
||||
|
||||
int ret = ioctl(mHdmiCecPorts[0]->mCecFd, CEC_ADAP_G_PHYS_ADDR, &addr);
|
||||
if (ret) {
|
||||
LOG(ERROR) << "Get port info failed for port : " << mHdmiCecPorts[0]->mPortId
|
||||
<< ", Error = " << strerror(errno);
|
||||
}
|
||||
|
||||
hidl_vec<HdmiPortInfo> portInfos {
|
||||
{.type = HdmiPortType::OUTPUT,
|
||||
.portId = mHdmiCecPorts[0]->mPortId,
|
||||
.cecSupported = true,
|
||||
.arcSupported = false,
|
||||
.physicalAddress = addr}
|
||||
};
|
||||
callback(portInfos);
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> HdmiCec::setOption(OptionKey key, bool value) {
|
||||
switch (key) {
|
||||
case OptionKey::ENABLE_CEC:
|
||||
LOG(DEBUG) << "setOption: Enable CEC: " << value;
|
||||
mCecEnabled = value;
|
||||
break;
|
||||
case OptionKey::WAKEUP:
|
||||
LOG(DEBUG) << "setOption: WAKEUP: " << value;
|
||||
mWakeupEnabled = value;
|
||||
break;
|
||||
case OptionKey::SYSTEM_CEC_CONTROL:
|
||||
LOG(DEBUG) << "setOption: SYSTEM_CEC_CONTROL: " << value;
|
||||
mCecControlEnabled = value;
|
||||
break;
|
||||
}
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> HdmiCec::setLanguage(const hidl_string& language __unused) {
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> HdmiCec::enableAudioReturnChannel(int32_t portId __unused, bool enable __unused) {
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<bool> HdmiCec::isConnected(int32_t portId __unused) {
|
||||
uint16_t addr = CEC_PHYS_ADDR_INVALID;
|
||||
|
||||
int ret = ioctl(mHdmiCecPorts[0]->mCecFd, CEC_ADAP_G_PHYS_ADDR, &addr);
|
||||
if (ret) {
|
||||
LOG(ERROR) << "Is connected failed, Error = " << strerror(errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (addr == CEC_PHYS_ADDR_INVALID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Initialise the cec file descriptor
|
||||
Return<Result> HdmiCec::init() {
|
||||
string cecDevice = GetProperty(PROPERTY_CEC_DEVICE, "cec0");
|
||||
if (cecDevice != "cec0" && cecDevice != "cec1") {
|
||||
LOG(ERROR) << "Invalid CEC device " << cecDevice;
|
||||
return Result::FAILURE_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
string devicePath = "/dev/" + cecDevice;
|
||||
int portId = stoi(cecDevice.substr(3));
|
||||
|
||||
shared_ptr<HdmiCecPort> hdmiCecPort(new HdmiCecPort(portId));
|
||||
Result result = hdmiCecPort->init(devicePath.c_str());
|
||||
if (result != Result::SUCCESS) {
|
||||
return Result::FAILURE_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
thread eventThread(&HdmiCec::event_thread, this, hdmiCecPort.get());
|
||||
mEventThreads.push_back(std::move(eventThread));
|
||||
mHdmiCecPorts.push_back(std::move(hdmiCecPort));
|
||||
LOG(INFO) << "Using CEC device " << devicePath;
|
||||
|
||||
mCecEnabled = true;
|
||||
mWakeupEnabled = true;
|
||||
mCecControlEnabled = true;
|
||||
|
||||
return Result::SUCCESS;
|
||||
}
|
||||
|
||||
Return<void> HdmiCec::release() {
|
||||
mCecEnabled = false;
|
||||
mWakeupEnabled = false;
|
||||
mCecControlEnabled = false;
|
||||
|
||||
for (thread& eventThread : mEventThreads) {
|
||||
if (eventThread.joinable()) {
|
||||
eventThread.join();
|
||||
}
|
||||
}
|
||||
setCallback(nullptr);
|
||||
mHdmiCecPorts.clear();
|
||||
mEventThreads.clear();
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
void HdmiCec::event_thread(HdmiCecPort* hdmiCecPort) {
|
||||
struct pollfd ufds[3] = {
|
||||
{hdmiCecPort->mCecFd, POLLIN, 0},
|
||||
{hdmiCecPort->mCecFd, POLLERR, 0},
|
||||
{hdmiCecPort->mExitFd, POLLIN, 0},
|
||||
};
|
||||
|
||||
while (1) {
|
||||
ufds[0].revents = 0;
|
||||
ufds[1].revents = 0;
|
||||
ufds[2].revents = 0;
|
||||
|
||||
int ret = poll(ufds, /* size(ufds) = */ 3, /* timeout = */ -1);
|
||||
|
||||
if (ret <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ufds[2].revents == POLLIN) { /* Exit */
|
||||
break;
|
||||
}
|
||||
|
||||
if (ufds[1].revents == POLLERR) { /* CEC Event */
|
||||
cec_event ev;
|
||||
ret = ioctl(hdmiCecPort->mCecFd, CEC_DQEVENT, &ev);
|
||||
|
||||
if (ret) {
|
||||
LOG(ERROR) << "CEC_DQEVENT failed, Error = " << strerror(errno);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!mCecEnabled) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ev.event == CEC_EVENT_STATE_CHANGE) {
|
||||
if (mCallback != nullptr) {
|
||||
HotplugEvent hotplugEvent{
|
||||
.connected = (ev.state_change.phys_addr != CEC_PHYS_ADDR_INVALID),
|
||||
.portId = hdmiCecPort->mPortId};
|
||||
mCallback->onHotplugEvent(hotplugEvent);
|
||||
} else {
|
||||
LOG(ERROR) << "No event callback for hotplug";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ufds[0].revents == POLLIN) { /* CEC Driver */
|
||||
cec_msg msg = {};
|
||||
ret = ioctl(hdmiCecPort->mCecFd, CEC_RECEIVE, &msg);
|
||||
|
||||
if (ret) {
|
||||
LOG(ERROR) << "CEC_RECEIVE failed, Error = " << strerror(errno);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (msg.rx_status != CEC_RX_STATUS_OK) {
|
||||
LOG(ERROR) << "msg rx_status = " << msg.rx_status;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!mCecEnabled) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!mWakeupEnabled && isWakeupMessage(msg)) {
|
||||
LOG(DEBUG) << "Filter wakeup message";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!mCecControlEnabled && !isTransferableInSleep(msg)) {
|
||||
LOG(DEBUG) << "Filter message in standby mode";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mCallback != nullptr) {
|
||||
size_t length = std::min(msg.len - 1, (uint32_t)MaxLength::MESSAGE_BODY);
|
||||
CecMessage cecMessage{
|
||||
.initiator = static_cast<CecLogicalAddress>(msg.msg[0] >> 4),
|
||||
.destination = static_cast<CecLogicalAddress>(msg.msg[0] & 0xf),
|
||||
};
|
||||
cecMessage.body.resize(length);
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
cecMessage.body[i] = static_cast<uint8_t>(msg.msg[i + 1]);
|
||||
}
|
||||
mCallback->onCecMessage(cecMessage);
|
||||
} else {
|
||||
LOG(ERROR) << "no event callback for message";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int HdmiCec::getOpcode(cec_msg message) {
|
||||
return static_cast<uint8_t>(message.msg[1]);
|
||||
}
|
||||
|
||||
bool HdmiCec::isWakeupMessage(cec_msg message) {
|
||||
int opcode = getOpcode(message);
|
||||
switch (opcode) {
|
||||
case CEC_MESSAGE_TEXT_VIEW_ON:
|
||||
case CEC_MESSAGE_IMAGE_VIEW_ON:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool HdmiCec::isTransferableInSleep(cec_msg message) {
|
||||
int opcode = getOpcode(message);
|
||||
switch (opcode) {
|
||||
case CEC_MESSAGE_ABORT:
|
||||
case CEC_MESSAGE_DEVICE_VENDOR_ID:
|
||||
case CEC_MESSAGE_GET_CEC_VERSION:
|
||||
case CEC_MESSAGE_GET_MENU_LANGUAGE:
|
||||
case CEC_MESSAGE_GIVE_DEVICE_POWER_STATUS:
|
||||
case CEC_MESSAGE_GIVE_DEVICE_VENDOR_ID:
|
||||
case CEC_MESSAGE_GIVE_OSD_NAME:
|
||||
case CEC_MESSAGE_GIVE_PHYSICAL_ADDRESS:
|
||||
case CEC_MESSAGE_REPORT_PHYSICAL_ADDRESS:
|
||||
case CEC_MESSAGE_REPORT_POWER_STATUS:
|
||||
case CEC_MESSAGE_SET_OSD_NAME:
|
||||
case CEC_MESSAGE_DECK_CONTROL:
|
||||
case CEC_MESSAGE_PLAY:
|
||||
case CEC_MESSAGE_IMAGE_VIEW_ON:
|
||||
case CEC_MESSAGE_TEXT_VIEW_ON:
|
||||
case CEC_MESSAGE_SYSTEM_AUDIO_MODE_REQUEST:
|
||||
return true;
|
||||
case CEC_MESSAGE_USER_CONTROL_PRESSED:
|
||||
return isPowerUICommand(message);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int HdmiCec::getFirstParam(cec_msg message) {
|
||||
return static_cast<uint8_t>(message.msg[2]);
|
||||
}
|
||||
|
||||
bool HdmiCec::isPowerUICommand(cec_msg message) {
|
||||
int uiCommand = getFirstParam(message);
|
||||
switch (uiCommand) {
|
||||
case CEC_OP_UI_CMD_POWER:
|
||||
case CEC_OP_UI_CMD_DEVICE_ROOT_MENU:
|
||||
case CEC_OP_UI_CMD_POWER_ON_FUNCTION:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Return<SendMessageResult> HdmiCec::getSendMessageResult(int tx_status) {
|
||||
switch (tx_status) {
|
||||
case CEC_TX_STATUS_OK:
|
||||
return SendMessageResult::SUCCESS;
|
||||
case CEC_TX_STATUS_ARB_LOST:
|
||||
return SendMessageResult::BUSY;
|
||||
case CEC_TX_STATUS_NACK:
|
||||
return SendMessageResult::NACK;
|
||||
default:
|
||||
return SendMessageResult::FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace cec
|
||||
} // namespace tv
|
||||
} // namespace hardware
|
||||
} // namespace android
|
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
* Copyright (C) 2025 KonstaKANG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <hardware/hdmi_cec.h>
|
||||
#include <linux/cec.h>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include "HdmiCecPort.h"
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace tv {
|
||||
namespace cec {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
using std::shared_ptr;
|
||||
using std::thread;
|
||||
using std::vector;
|
||||
|
||||
class HdmiCec : public IHdmiCec, public hidl_death_recipient {
|
||||
public:
|
||||
HdmiCec();
|
||||
~HdmiCec();
|
||||
// Methods from ::android::hardware::tv::cec::V1_0::IHdmiCec follow.
|
||||
Return<Result> addLogicalAddress(CecLogicalAddress addr) override;
|
||||
Return<void> clearLogicalAddress() override;
|
||||
Return<void> getPhysicalAddress(getPhysicalAddress_cb _hidl_cb) override;
|
||||
Return<SendMessageResult> sendMessage(const CecMessage& message) override;
|
||||
Return<void> setCallback(const sp<IHdmiCecCallback>& callback) override;
|
||||
Return<int32_t> getCecVersion() override;
|
||||
Return<uint32_t> getVendorId() override;
|
||||
Return<void> getPortInfo(getPortInfo_cb _hidl_cb) override;
|
||||
Return<void> setOption(OptionKey key, bool value) override;
|
||||
Return<void> setLanguage(const hidl_string& language) override;
|
||||
Return<void> enableAudioReturnChannel(int32_t portId, bool enable) override;
|
||||
Return<bool> isConnected(int32_t portId) override;
|
||||
|
||||
virtual void serviceDied(uint64_t, const wp<::android::hidl::base::V1_0::IBase>&) {
|
||||
setCallback(nullptr);
|
||||
}
|
||||
|
||||
Return<Result> init();
|
||||
Return<void> release();
|
||||
|
||||
private:
|
||||
void event_thread(HdmiCecPort* hdmiCecPort);
|
||||
static int getOpcode(cec_msg message);
|
||||
static int getFirstParam(cec_msg message);
|
||||
static bool isWakeupMessage(cec_msg message);
|
||||
static bool isTransferableInSleep(cec_msg message);
|
||||
static bool isPowerUICommand(cec_msg message);
|
||||
static Return<SendMessageResult> getSendMessageResult(int tx_status);
|
||||
|
||||
vector<thread> mEventThreads;
|
||||
vector<shared_ptr<HdmiCecPort>> mHdmiCecPorts;
|
||||
|
||||
// When set to false, all the CEC commands are discarded. True by default after initialization.
|
||||
bool mCecEnabled;
|
||||
/*
|
||||
* When set to false, HAL does not wake up the system upon receiving <Image View On> or
|
||||
* <Text View On>. True by default after initialization.
|
||||
*/
|
||||
bool mWakeupEnabled;
|
||||
/*
|
||||
* Updated when system goes into or comes out of standby mode.
|
||||
* When set to true, Android system is handling CEC commands.
|
||||
* When set to false, microprocessor is handling CEC commands.
|
||||
* True by default after initialization.
|
||||
*/
|
||||
bool mCecControlEnabled;
|
||||
|
||||
sp<IHdmiCecCallback> mCallback;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace cec
|
||||
} // namespace tv
|
||||
} // namespace hardware
|
||||
} // namespace android
|
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
* Copyright (C) 2025 KonstaKANG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.tv.cec@1.0-service.rpi"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <errno.h>
|
||||
#include <linux/cec.h>
|
||||
#include <linux/ioctl.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "HdmiCecPort.h"
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace tv {
|
||||
namespace cec {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
HdmiCecPort::HdmiCecPort(unsigned int portId) {
|
||||
mPortId = portId;
|
||||
mCecFd = -1;
|
||||
mExitFd = -1;
|
||||
}
|
||||
|
||||
HdmiCecPort::~HdmiCecPort() {
|
||||
release();
|
||||
}
|
||||
|
||||
// Initialise the cec file descriptor
|
||||
Return<Result> HdmiCecPort::init(const char* path) {
|
||||
mCecFd = open(path, O_RDWR);
|
||||
if (mCecFd < 0) {
|
||||
LOG(ERROR) << "Failed to open " << path << ", Error = " << strerror(errno);
|
||||
return Result::FAILURE_NOT_SUPPORTED;
|
||||
}
|
||||
mExitFd = eventfd(0, EFD_NONBLOCK);
|
||||
if (mExitFd < 0) {
|
||||
LOG(ERROR) << "Failed to open eventfd, Error = " << strerror(errno);
|
||||
release();
|
||||
return Result::FAILURE_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
// Ensure the CEC device supports required capabilities
|
||||
struct cec_caps caps = {};
|
||||
int ret = ioctl(mCecFd, CEC_ADAP_G_CAPS, &caps);
|
||||
if (ret) {
|
||||
LOG(ERROR) << "Unable to query cec adapter capabilities, Error = " << strerror(errno);
|
||||
release();
|
||||
return Result::FAILURE_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
if (!(caps.capabilities & (CEC_CAP_LOG_ADDRS | CEC_CAP_TRANSMIT | CEC_CAP_PASSTHROUGH))) {
|
||||
LOG(ERROR) << "Wrong cec adapter capabilities " << caps.capabilities;
|
||||
release();
|
||||
return Result::FAILURE_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
uint32_t mode = CEC_MODE_INITIATOR | CEC_MODE_EXCL_FOLLOWER_PASSTHRU;
|
||||
ret = ioctl(mCecFd, CEC_S_MODE, &mode);
|
||||
if (ret) {
|
||||
LOG(ERROR) << "Unable to set initiator mode, Error = " << strerror(errno);
|
||||
release();
|
||||
return Result::FAILURE_NOT_SUPPORTED;
|
||||
}
|
||||
return Result::SUCCESS;
|
||||
}
|
||||
|
||||
Return<void> HdmiCecPort::release() {
|
||||
if (mExitFd > 0) {
|
||||
uint64_t tmp = 1;
|
||||
write(mExitFd, &tmp, sizeof(tmp));
|
||||
}
|
||||
if (mExitFd > 0) {
|
||||
close(mExitFd);
|
||||
}
|
||||
if (mCecFd > 0) {
|
||||
close(mCecFd);
|
||||
}
|
||||
return Void();
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace cec
|
||||
} // namespace tv
|
||||
} // namespace hardware
|
||||
} // namespace android
|
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
* Copyright (C) 2025 KonstaKANG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <android/hardware/tv/cec/1.0/IHdmiCec.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace tv {
|
||||
namespace cec {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
class HdmiCecPort {
|
||||
public:
|
||||
HdmiCecPort(unsigned int portId);
|
||||
~HdmiCecPort();
|
||||
Return<Result> init(const char* path);
|
||||
Return<void> release();
|
||||
|
||||
unsigned int mPortId;
|
||||
int mCecFd;
|
||||
int mExitFd;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace cec
|
||||
} // namespace tv
|
||||
} // namespace hardware
|
||||
} // namespace android
|
@@ -1,5 +0,0 @@
|
||||
service vendor.cec-hal-1-0-rpi /vendor/bin/hw/android.hardware.tv.cec@1.0-service.rpi
|
||||
interface android.hardware.tv.cec@1.0::IHdmiCec default
|
||||
class hal
|
||||
user system
|
||||
group system
|
@@ -1,11 +0,0 @@
|
||||
<manifest version="1.0" type="device">
|
||||
<hal format="hidl">
|
||||
<name>android.hardware.tv.cec</name>
|
||||
<transport>hwbinder</transport>
|
||||
<version>1.0</version>
|
||||
<interface>
|
||||
<name>IHdmiCec</name>
|
||||
<instance>default</instance>
|
||||
</interface>
|
||||
</hal>
|
||||
</manifest>
|
616
cec/hdmi_cec.c
Normal file
616
cec/hdmi_cec.c
Normal file
@@ -0,0 +1,616 @@
|
||||
/*
|
||||
* Copyright (C) 2019 BayLibre, SAS.
|
||||
* Copyright (C) 2021-2022 KonstaKANG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "hdmi_cec"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/cec.h>
|
||||
#include <sys/eventfd.h>
|
||||
|
||||
#include <log/log.h>
|
||||
#include <cutils/properties.h>
|
||||
#include <hardware/hdmi_cec.h>
|
||||
|
||||
typedef struct hdmicec_context
|
||||
{
|
||||
hdmi_cec_device_t device; /* must be first */
|
||||
int cec_fd;
|
||||
unsigned int vendor_id;
|
||||
unsigned int type;
|
||||
unsigned int version;
|
||||
struct hdmi_port_info port_info;
|
||||
event_callback_t p_event_cb;
|
||||
void *cb_arg;
|
||||
pthread_t thread;
|
||||
int exit_fd;
|
||||
pthread_mutex_t options_lock;
|
||||
bool cec_enabled;
|
||||
bool cec_control_enabled;
|
||||
} hdmicec_context_t;
|
||||
|
||||
static int hdmicec_add_logical_address(const struct hdmi_cec_device *dev, cec_logical_address_t addr)
|
||||
{
|
||||
struct hdmicec_context *ctx = (struct hdmicec_context *)dev;
|
||||
unsigned int la_type = CEC_LOG_ADDR_TYPE_UNREGISTERED;
|
||||
unsigned int all_dev_types = 0;
|
||||
unsigned int prim_type = 0xff;
|
||||
struct cec_log_addrs laddrs;
|
||||
int ret;
|
||||
|
||||
ALOGD("%s: addr:%x\n", __func__, addr);
|
||||
|
||||
if (addr >= CEC_ADDR_BROADCAST)
|
||||
return -1;
|
||||
|
||||
ret = ioctl(ctx->cec_fd, CEC_ADAP_G_LOG_ADDRS, &laddrs);
|
||||
if (ret)
|
||||
return ret;
|
||||
memset(&laddrs, 0, sizeof(laddrs));
|
||||
|
||||
laddrs.cec_version = ctx->version;
|
||||
laddrs.vendor_id = ctx->vendor_id;
|
||||
|
||||
switch (addr) {
|
||||
case CEC_LOG_ADDR_TV:
|
||||
prim_type = CEC_OP_PRIM_DEVTYPE_TV;
|
||||
la_type = CEC_LOG_ADDR_TYPE_TV;
|
||||
all_dev_types = CEC_OP_ALL_DEVTYPE_TV;
|
||||
break;
|
||||
case CEC_LOG_ADDR_RECORD_1:
|
||||
case CEC_LOG_ADDR_RECORD_2:
|
||||
case CEC_LOG_ADDR_RECORD_3:
|
||||
prim_type = CEC_OP_PRIM_DEVTYPE_RECORD;
|
||||
la_type = CEC_LOG_ADDR_TYPE_RECORD;
|
||||
all_dev_types = CEC_OP_ALL_DEVTYPE_RECORD;
|
||||
break;
|
||||
case CEC_LOG_ADDR_TUNER_1:
|
||||
case CEC_LOG_ADDR_TUNER_2:
|
||||
case CEC_LOG_ADDR_TUNER_3:
|
||||
case CEC_LOG_ADDR_TUNER_4:
|
||||
prim_type = CEC_OP_PRIM_DEVTYPE_TUNER;
|
||||
la_type = CEC_LOG_ADDR_TYPE_TUNER;
|
||||
all_dev_types = CEC_OP_ALL_DEVTYPE_TUNER;
|
||||
break;
|
||||
case CEC_LOG_ADDR_PLAYBACK_1:
|
||||
case CEC_LOG_ADDR_PLAYBACK_2:
|
||||
case CEC_LOG_ADDR_PLAYBACK_3:
|
||||
prim_type = CEC_OP_PRIM_DEVTYPE_PLAYBACK;
|
||||
la_type = CEC_LOG_ADDR_TYPE_PLAYBACK;
|
||||
all_dev_types = CEC_OP_ALL_DEVTYPE_PLAYBACK;
|
||||
laddrs.flags = CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU;
|
||||
break;
|
||||
case CEC_LOG_ADDR_AUDIOSYSTEM:
|
||||
prim_type = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM;
|
||||
la_type = CEC_LOG_ADDR_TYPE_AUDIOSYSTEM;
|
||||
all_dev_types = CEC_OP_ALL_DEVTYPE_AUDIOSYSTEM;
|
||||
break;
|
||||
case CEC_LOG_ADDR_SPECIFIC:
|
||||
prim_type = CEC_OP_PRIM_DEVTYPE_PROCESSOR;
|
||||
la_type = CEC_LOG_ADDR_TYPE_SPECIFIC;
|
||||
all_dev_types = CEC_OP_ALL_DEVTYPE_SWITCH;
|
||||
break;
|
||||
case CEC_ADDR_RESERVED_1:
|
||||
case CEC_ADDR_RESERVED_2:
|
||||
case CEC_ADDR_UNREGISTERED:
|
||||
laddrs.flags = CEC_LOG_ADDRS_FL_ALLOW_UNREG_FALLBACK;
|
||||
break;
|
||||
}
|
||||
|
||||
laddrs.num_log_addrs = 1;
|
||||
laddrs.log_addr[0] = addr;
|
||||
laddrs.log_addr_type[0] = la_type;
|
||||
laddrs.primary_device_type[0] = prim_type;
|
||||
laddrs.all_device_types[0] = all_dev_types;
|
||||
laddrs.features[0][0] = 0;
|
||||
laddrs.features[0][1] = 0;
|
||||
|
||||
ret = ioctl(ctx->cec_fd, CEC_ADAP_S_LOG_ADDRS, &laddrs);
|
||||
if (ret) {
|
||||
ALOGD("%s: %m\n", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ALOGD("%s: log_addr_mask=%x\n", __func__, laddrs.log_addr_mask);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void hdmicec_clear_logical_address(const struct hdmi_cec_device *dev)
|
||||
{
|
||||
struct hdmicec_context *ctx = (struct hdmicec_context *)dev;
|
||||
struct cec_log_addrs laddrs;
|
||||
int ret;
|
||||
|
||||
memset(&laddrs, 0, sizeof(laddrs));
|
||||
ret = ioctl(ctx->cec_fd, CEC_ADAP_S_LOG_ADDRS, &laddrs);
|
||||
if (ret)
|
||||
ALOGD("%s: %m\n", __func__);
|
||||
}
|
||||
|
||||
static int hdmicec_get_physical_address(const struct hdmi_cec_device *dev, uint16_t *addr)
|
||||
{
|
||||
struct hdmicec_context *ctx = (struct hdmicec_context *)dev;
|
||||
int ret = ioctl(ctx->cec_fd, CEC_ADAP_G_PHYS_ADDR, addr);
|
||||
if (ret)
|
||||
ALOGD("%s: %m\n", __func__);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int hdmicec_send_message(const struct hdmi_cec_device *dev, const cec_message_t *msg)
|
||||
{
|
||||
struct hdmicec_context *ctx = (struct hdmicec_context *)dev;
|
||||
struct cec_msg cec_msg;
|
||||
int ret;
|
||||
|
||||
pthread_mutex_lock(&ctx->options_lock);
|
||||
bool cec_enabled = ctx->cec_enabled;
|
||||
pthread_mutex_unlock(&ctx->options_lock);
|
||||
if (!cec_enabled) {
|
||||
return HDMI_RESULT_FAIL;
|
||||
}
|
||||
|
||||
ALOGD("%s: len=%u\n", __func__, (unsigned int)msg->length);
|
||||
|
||||
memset(&cec_msg, 0, sizeof(cec_msg));
|
||||
cec_msg.msg[0] = (msg->initiator << 4) | msg->destination;
|
||||
|
||||
memcpy(&cec_msg.msg[1], msg->body, msg->length);
|
||||
cec_msg.len = msg->length + 1;
|
||||
|
||||
ret = ioctl(ctx->cec_fd, CEC_TRANSMIT, &cec_msg);
|
||||
if (ret) {
|
||||
ALOGD("%s: %m\n", __func__);
|
||||
return HDMI_RESULT_FAIL;
|
||||
}
|
||||
|
||||
if (cec_msg.tx_status != CEC_TX_STATUS_OK)
|
||||
ALOGD("%s: tx_status=%d\n", __func__, cec_msg.tx_status);
|
||||
|
||||
switch (cec_msg.tx_status) {
|
||||
case CEC_TX_STATUS_OK:
|
||||
return HDMI_RESULT_SUCCESS;
|
||||
case CEC_TX_STATUS_ARB_LOST:
|
||||
return HDMI_RESULT_BUSY;
|
||||
case CEC_TX_STATUS_NACK:
|
||||
return HDMI_RESULT_NACK;
|
||||
default:
|
||||
if (cec_msg.tx_status & CEC_TX_STATUS_NACK)
|
||||
return HDMI_RESULT_NACK;
|
||||
return HDMI_RESULT_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
static void hdmicec_register_event_callback(const struct hdmi_cec_device *dev,
|
||||
event_callback_t callback, void *arg)
|
||||
{
|
||||
struct hdmicec_context *ctx = (struct hdmicec_context *)dev;
|
||||
|
||||
ctx->p_event_cb = callback;
|
||||
ctx->cb_arg = arg;
|
||||
}
|
||||
|
||||
static void hdmicec_get_version(const struct hdmi_cec_device *dev, int *version)
|
||||
{
|
||||
struct hdmicec_context *ctx = (struct hdmicec_context *)dev;
|
||||
|
||||
*version = ctx->version;
|
||||
}
|
||||
|
||||
static void hdmicec_get_vendor_id(const struct hdmi_cec_device *dev, uint32_t *vendor_id)
|
||||
{
|
||||
struct hdmicec_context *ctx = (struct hdmicec_context *)dev;
|
||||
|
||||
*vendor_id = ctx->vendor_id;
|
||||
}
|
||||
|
||||
static void hdmicec_get_port_info(const struct hdmi_cec_device *dev,
|
||||
struct hdmi_port_info *list[], int *total)
|
||||
{
|
||||
struct hdmicec_context *ctx = (struct hdmicec_context *)dev;
|
||||
int ret;
|
||||
|
||||
ret = ioctl(ctx->cec_fd, CEC_ADAP_G_PHYS_ADDR, &ctx->port_info.physical_address);
|
||||
if (ret)
|
||||
ALOGD("%s: %m\n", __func__);
|
||||
|
||||
ALOGD("type:%s, id:%d, cec support:%d, arc support:%d, physical address:%x",
|
||||
ctx->port_info.type ? "output" : "input",
|
||||
ctx->port_info.port_id,
|
||||
ctx->port_info.cec_supported,
|
||||
ctx->port_info.arc_supported,
|
||||
ctx->port_info.physical_address);
|
||||
|
||||
if (ctx->port_info.physical_address != CEC_PHYS_ADDR_INVALID) {
|
||||
*list = &ctx->port_info;
|
||||
*total = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void hdmicec_set_option(const struct hdmi_cec_device *dev, int flag, int value)
|
||||
{
|
||||
struct hdmicec_context* ctx = (struct hdmicec_context*)dev;
|
||||
ALOGD("%s: flag=%d, value=%d", __func__, flag, value);
|
||||
switch (flag) {
|
||||
case HDMI_OPTION_ENABLE_CEC:
|
||||
pthread_mutex_lock(&ctx->options_lock);
|
||||
ctx->cec_enabled = (value == 1 ? true : false);
|
||||
pthread_mutex_unlock(&ctx->options_lock);
|
||||
break;
|
||||
case HDMI_OPTION_WAKEUP:
|
||||
// Not valid for playback devices
|
||||
break;
|
||||
case HDMI_OPTION_SYSTEM_CEC_CONTROL:
|
||||
pthread_mutex_lock(&ctx->options_lock);
|
||||
ctx->cec_control_enabled = (value == 1 ? true : false);
|
||||
pthread_mutex_unlock(&ctx->options_lock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int hdmicec_is_connected(const struct hdmi_cec_device *dev, int port_id)
|
||||
{
|
||||
struct hdmicec_context *ctx = (struct hdmicec_context *)dev;
|
||||
int ret;
|
||||
|
||||
(void)port_id;
|
||||
|
||||
ret = ioctl(ctx->cec_fd, CEC_ADAP_G_PHYS_ADDR,
|
||||
&ctx->port_info.physical_address);
|
||||
if (ret) {
|
||||
ALOGD("%s: %m\n", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (ctx->port_info.physical_address == CEC_PHYS_ADDR_INVALID)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int get_opcode(struct cec_msg* message) {
|
||||
return (((uint8_t)message->msg[1]) & 0xff);
|
||||
}
|
||||
|
||||
static int get_first_param(struct cec_msg* message) {
|
||||
return (((uint8_t)message->msg[2]) & 0xff);
|
||||
}
|
||||
|
||||
static bool is_power_ui_command(struct cec_msg* message) {
|
||||
int ui_command = get_first_param(message);
|
||||
switch (ui_command) {
|
||||
case CEC_OP_UI_CMD_POWER:
|
||||
case CEC_OP_UI_CMD_DEVICE_ROOT_MENU:
|
||||
case CEC_OP_UI_CMD_POWER_ON_FUNCTION:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_transferable_in_sleep(struct cec_msg* message) {
|
||||
int opcode = get_opcode(message);
|
||||
switch (opcode) {
|
||||
case CEC_MESSAGE_ABORT:
|
||||
case CEC_MESSAGE_DEVICE_VENDOR_ID:
|
||||
case CEC_MESSAGE_GET_CEC_VERSION:
|
||||
case CEC_MESSAGE_GET_MENU_LANGUAGE:
|
||||
case CEC_MESSAGE_GIVE_DEVICE_POWER_STATUS:
|
||||
case CEC_MESSAGE_GIVE_DEVICE_VENDOR_ID:
|
||||
case CEC_MESSAGE_GIVE_OSD_NAME:
|
||||
case CEC_MESSAGE_GIVE_PHYSICAL_ADDRESS:
|
||||
case CEC_MESSAGE_REPORT_PHYSICAL_ADDRESS:
|
||||
case CEC_MESSAGE_REPORT_POWER_STATUS:
|
||||
case CEC_MESSAGE_SET_OSD_NAME:
|
||||
case CEC_MESSAGE_DECK_CONTROL:
|
||||
case CEC_MESSAGE_PLAY:
|
||||
return true;
|
||||
case CEC_MESSAGE_USER_CONTROL_PRESSED:
|
||||
return is_power_ui_command(message);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void *event_thread(void *arg)
|
||||
{
|
||||
struct hdmicec_context *ctx = (struct hdmicec_context *)arg;
|
||||
int ret;
|
||||
struct pollfd ufds[3] = {
|
||||
{ ctx->cec_fd, POLLIN, 0 },
|
||||
{ ctx->cec_fd, POLLERR, 0 },
|
||||
{ ctx->exit_fd, POLLIN, 0 },
|
||||
};
|
||||
|
||||
ALOGI("%s start!", __func__);
|
||||
|
||||
while (1) {
|
||||
ufds[0].revents = 0;
|
||||
ufds[1].revents = 0;
|
||||
ufds[2].revents = 0;
|
||||
|
||||
ret = poll(ufds, 3, -1);
|
||||
|
||||
if (ret <= 0)
|
||||
continue;
|
||||
|
||||
if (ufds[2].revents == POLLIN) /* Exit */
|
||||
break;
|
||||
|
||||
if (ufds[1].revents == POLLERR) { /* CEC Event */
|
||||
hdmi_event_t event = { };
|
||||
struct cec_event ev;
|
||||
|
||||
ret = ioctl(ctx->cec_fd, CEC_DQEVENT, &ev);
|
||||
if (ret)
|
||||
continue;
|
||||
|
||||
pthread_mutex_lock(&ctx->options_lock);
|
||||
bool cec_enabled = ctx->cec_enabled;
|
||||
pthread_mutex_unlock(&ctx->options_lock);
|
||||
if (!cec_enabled) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ev.event == CEC_EVENT_STATE_CHANGE) {
|
||||
event.type = HDMI_EVENT_HOT_PLUG;
|
||||
event.dev = &ctx->device;
|
||||
event.hotplug.port_id = 1;
|
||||
if (ev.state_change.phys_addr == CEC_PHYS_ADDR_INVALID)
|
||||
event.hotplug.connected = false;
|
||||
else
|
||||
event.hotplug.connected = true;
|
||||
|
||||
if (ctx->p_event_cb != NULL) {
|
||||
ctx->p_event_cb(&event, ctx->cb_arg);
|
||||
} else {
|
||||
ALOGE("no event callback for hotplug\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ufds[0].revents == POLLIN) { /* CEC Driver */
|
||||
struct cec_msg msg = { };
|
||||
hdmi_event_t event = { };
|
||||
|
||||
ret = ioctl(ctx->cec_fd, CEC_RECEIVE, &msg);
|
||||
if (ret) {
|
||||
ALOGE("%s: CEC_RECEIVE error (%m)\n", __func__);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (msg.rx_status != CEC_RX_STATUS_OK) {
|
||||
ALOGD("%s: rx_status=%d\n", __func__, msg.rx_status);
|
||||
continue;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&ctx->options_lock);
|
||||
bool cec_enabled = ctx->cec_enabled;
|
||||
pthread_mutex_unlock(&ctx->options_lock);
|
||||
if (!cec_enabled) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&ctx->options_lock);
|
||||
bool cec_control_enabled = ctx->cec_control_enabled;
|
||||
pthread_mutex_unlock(&ctx->options_lock);
|
||||
if (!cec_control_enabled && !is_transferable_in_sleep(&msg)) {
|
||||
ALOGD("%s: filter message in standby mode\n", __func__);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ctx->p_event_cb != NULL) {
|
||||
event.type = HDMI_EVENT_CEC_MESSAGE;
|
||||
event.dev = &ctx->device;
|
||||
event.cec.initiator = msg.msg[0] >> 4;
|
||||
event.cec.destination = msg.msg[0] & 0xf;
|
||||
event.cec.length = msg.len - 1;
|
||||
memcpy(event.cec.body, &msg.msg[1], msg.len - 1);
|
||||
|
||||
ctx->p_event_cb(&event, ctx->cb_arg);
|
||||
} else {
|
||||
ALOGE("no event callback for msg\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ALOGI("%s exit!", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void hdmicec_set_arc(const struct hdmi_cec_device *dev, int port_id, int flag)
|
||||
{
|
||||
(void)dev;
|
||||
(void)port_id;
|
||||
(void)flag;
|
||||
/* Not supported */
|
||||
}
|
||||
|
||||
static int hdmicec_close(struct hdmi_cec_device *dev)
|
||||
{
|
||||
struct hdmicec_context *ctx = (struct hdmicec_context *)dev;
|
||||
uint64_t tmp = 1;
|
||||
|
||||
ALOGD("%s\n", __func__);
|
||||
|
||||
if (ctx->exit_fd > 0) {
|
||||
write(ctx->exit_fd, &tmp, sizeof(tmp));
|
||||
if (ctx->thread)
|
||||
pthread_join(ctx->thread, NULL);
|
||||
}
|
||||
|
||||
if (ctx->cec_fd > 0)
|
||||
close(ctx->cec_fd);
|
||||
if (ctx->exit_fd > 0)
|
||||
close(ctx->exit_fd);
|
||||
free(ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cec_init(struct hdmicec_context *ctx)
|
||||
{
|
||||
struct cec_log_addrs laddrs = {};
|
||||
struct cec_caps caps = {};
|
||||
uint32_t mode;
|
||||
int ret;
|
||||
|
||||
// Ensure the CEC device supports required capabilities
|
||||
ret = ioctl(ctx->cec_fd, CEC_ADAP_G_CAPS, &caps);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (!(caps.capabilities & (CEC_CAP_LOG_ADDRS |
|
||||
CEC_CAP_TRANSMIT |
|
||||
CEC_CAP_PASSTHROUGH))) {
|
||||
ALOGE("%s: wrong cec adapter capabilities %x\n",
|
||||
__func__, caps.capabilities);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// This is an exclusive follower, in addition put the CEC device into passthrough mode
|
||||
mode = CEC_MODE_INITIATOR | CEC_MODE_EXCL_FOLLOWER_PASSTHRU;
|
||||
ret = ioctl(ctx->cec_fd, CEC_S_MODE, &mode);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ctx->type = property_get_int32("ro.hdmi.device_type", CEC_DEVICE_PLAYBACK);
|
||||
|
||||
ctx->vendor_id = property_get_int32("ro.hdmi.vendor_id",
|
||||
0x000c03 /* HDMI LLC vendor ID */);
|
||||
|
||||
ctx->version = property_get_bool("ro.hdmi.cec_version",
|
||||
CEC_OP_CEC_VERSION_1_4);
|
||||
|
||||
ctx->port_info.type = ctx->type == CEC_DEVICE_TV ? HDMI_INPUT : HDMI_OUTPUT;
|
||||
ctx->port_info.port_id = 1;
|
||||
ctx->port_info.cec_supported = 1;
|
||||
ctx->port_info.arc_supported = 0;
|
||||
|
||||
ALOGD("%s: type=%d\n", __func__, ctx->type);
|
||||
ALOGD("%s: vendor_id=%04x\n", __func__, ctx->vendor_id);
|
||||
ALOGD("%s: version=%d\n", __func__, ctx->version);
|
||||
|
||||
memset(&laddrs, 0, sizeof(laddrs));
|
||||
ret = ioctl(ctx->cec_fd, CEC_ADAP_S_LOG_ADDRS, &laddrs);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
pthread_mutex_init(&ctx->options_lock, NULL);
|
||||
|
||||
ALOGD("%s: initialized CEC controller\n", __func__);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int open_hdmi_cec(const struct hw_module_t *module, const char *id,
|
||||
struct hw_device_t **device)
|
||||
{
|
||||
char path[32];
|
||||
char prop[PROPERTY_VALUE_MAX];
|
||||
hdmicec_context_t *ctx;
|
||||
int ret;
|
||||
|
||||
ALOGD("%s: id=%s\n", __func__, id);
|
||||
|
||||
ctx = malloc(sizeof(struct hdmicec_context));
|
||||
if (!ctx)
|
||||
return -ENOMEM;
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
|
||||
property_get("ro.hdmi.cec_device", prop, "cec0");
|
||||
snprintf(path, sizeof(path), "/dev/%s", prop);
|
||||
|
||||
ctx->cec_fd = open(path, O_RDWR);
|
||||
if (ctx->cec_fd < 0) {
|
||||
ALOGE("faild to open %s, ret=%s\n", path, strerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ctx->exit_fd = eventfd(0, EFD_NONBLOCK);
|
||||
if (ctx->exit_fd < 0) {
|
||||
ALOGE("faild to open eventfd, ret = %d\n", errno);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ctx->device.common.tag = HARDWARE_DEVICE_TAG;
|
||||
ctx->device.common.version = HDMI_CEC_DEVICE_API_VERSION_1_0;
|
||||
ctx->device.common.module = (struct hw_module_t *)module;
|
||||
ctx->device.common.close = (int (*)(struct hw_device_t* device))hdmicec_close;
|
||||
|
||||
ctx->device.add_logical_address = hdmicec_add_logical_address;
|
||||
ctx->device.clear_logical_address = hdmicec_clear_logical_address;
|
||||
ctx->device.get_physical_address = hdmicec_get_physical_address;
|
||||
ctx->device.send_message = hdmicec_send_message;
|
||||
ctx->device.register_event_callback = hdmicec_register_event_callback;
|
||||
ctx->device.get_version = hdmicec_get_version;
|
||||
ctx->device.get_vendor_id = hdmicec_get_vendor_id;
|
||||
ctx->device.get_port_info = hdmicec_get_port_info;
|
||||
ctx->device.set_option = hdmicec_set_option;
|
||||
ctx->device.set_audio_return_channel = hdmicec_set_arc;
|
||||
ctx->device.is_connected = hdmicec_is_connected;
|
||||
|
||||
/* init status */
|
||||
ret = cec_init(ctx);
|
||||
if (ret)
|
||||
goto fail;
|
||||
|
||||
*device = &ctx->device.common;
|
||||
|
||||
/* thread loop for receiving cec msg */
|
||||
if (pthread_create(&ctx->thread, NULL, event_thread, ctx)) {
|
||||
ALOGE("Can't create event thread: %s\n", strerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ctx->cec_enabled = true;
|
||||
ctx->cec_control_enabled = true;
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
hdmicec_close((struct hdmi_cec_device *)ctx);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
/* module method */
|
||||
static struct hw_module_methods_t hdmi_cec_module_methods = {
|
||||
.open = open_hdmi_cec,
|
||||
};
|
||||
|
||||
/* hdmi_cec module */
|
||||
struct hw_module_t HAL_MODULE_INFO_SYM = {
|
||||
.tag = HARDWARE_MODULE_TAG,
|
||||
.version_major = 1,
|
||||
.version_minor = 0,
|
||||
.id = HDMI_CEC_HARDWARE_MODULE_ID,
|
||||
.name = "Raspberry Pi HDMI CEC HAL",
|
||||
.author = "The Android Open Source Project",
|
||||
.methods = &hdmi_cec_module_methods,
|
||||
};
|
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2025 KonstaKANG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.tv.cec@1.0-service-rpi"
|
||||
|
||||
#include <android/hardware/tv/cec/1.0/IHdmiCec.h>
|
||||
#include <hidl/LegacySupport.h>
|
||||
#include "HdmiCec.h"
|
||||
|
||||
using android::hardware::configureRpcThreadpool;
|
||||
using android::hardware::joinRpcThreadpool;
|
||||
using android::hardware::tv::cec::V1_0::IHdmiCec;
|
||||
using android::hardware::tv::cec::V1_0::implementation::HdmiCec;
|
||||
|
||||
using android::OK;
|
||||
using android::status_t;
|
||||
|
||||
int main() {
|
||||
configureRpcThreadpool(1, true /* callerWillJoin */);
|
||||
|
||||
android::sp<IHdmiCec> service = new HdmiCec();
|
||||
|
||||
status_t status = service->registerAsService();
|
||||
if (status != OK) {
|
||||
ALOGE("Cannot register HDMI-CEC HAL service.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ALOGI("HDMI-CEC HAL ready.");
|
||||
joinRpcThreadpool();
|
||||
|
||||
// Under normal cases, execution will not reach this line.
|
||||
ALOGE("HDMI-CEC HAL failed to join thread pool.");
|
||||
return 1;
|
||||
}
|
21
device.mk
21
device.mk
@@ -74,7 +74,7 @@ PRODUCT_COPY_FILES += \
|
||||
|
||||
# Bluetooth
|
||||
PRODUCT_PACKAGES += \
|
||||
android.hardware.bluetooth@1.1-service.btlinux
|
||||
android.hardware.bluetooth-service.rpi
|
||||
|
||||
PRODUCT_COPY_FILES += \
|
||||
frameworks/native/data/etc/android.hardware.bluetooth.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.bluetooth.xml \
|
||||
@@ -115,6 +115,7 @@ PRODUCT_COPY_FILES += \
|
||||
external/libcamera/src/ipa/rpi/pisp/data/imx477.json:$(TARGET_COPY_OUT_VENDOR)/etc/libcamera/ipa/rpi/pisp/imx477.json \
|
||||
external/libcamera/src/ipa/rpi/pisp/data/imx477_noir.json:$(TARGET_COPY_OUT_VENDOR)/etc/libcamera/ipa/rpi/pisp/imx477_noir.json \
|
||||
external/libcamera/src/ipa/rpi/pisp/data/imx477_scientific.json:$(TARGET_COPY_OUT_VENDOR)/etc/libcamera/ipa/rpi/pisp/imx477_scientific.json \
|
||||
external/libcamera/src/ipa/rpi/pisp/data/imx500.json:$(TARGET_COPY_OUT_VENDOR)/etc/libcamera/ipa/rpi/pisp/imx500.json \
|
||||
external/libcamera/src/ipa/rpi/pisp/data/imx708.json:$(TARGET_COPY_OUT_VENDOR)/etc/libcamera/ipa/rpi/pisp/imx708.json \
|
||||
external/libcamera/src/ipa/rpi/pisp/data/imx708_noir.json:$(TARGET_COPY_OUT_VENDOR)/etc/libcamera/ipa/rpi/pisp/imx708_noir.json \
|
||||
external/libcamera/src/ipa/rpi/pisp/data/imx708_wide.json:$(TARGET_COPY_OUT_VENDOR)/etc/libcamera/ipa/rpi/pisp/imx708_wide.json \
|
||||
@@ -135,7 +136,9 @@ PRODUCT_COPY_FILES += \
|
||||
|
||||
# CEC
|
||||
PRODUCT_PACKAGES += \
|
||||
android.hardware.tv.cec@1.0-service.rpi
|
||||
android.hardware.tv.cec@1.0-impl \
|
||||
android.hardware.tv.cec@1.0-service \
|
||||
hdmi_cec.rpi
|
||||
|
||||
PRODUCT_COPY_FILES += \
|
||||
frameworks/native/data/etc/android.hardware.hdmi.cec.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.hdmi.cec.xml
|
||||
@@ -170,21 +173,21 @@ PRODUCT_PACKAGES += \
|
||||
libgbm_mesa_wrapper
|
||||
|
||||
PRODUCT_PACKAGES += \
|
||||
android.hardware.graphics.composer@2.4-service \
|
||||
hwcomposer.drm
|
||||
android.hardware.composer.hwc3-service.drm
|
||||
|
||||
PRODUCT_PACKAGES += \
|
||||
libEGL_mesa \
|
||||
libGLESv1_CM_mesa \
|
||||
libGLESv2_mesa \
|
||||
libgallium_dri
|
||||
libgallium_dri \
|
||||
libglapi
|
||||
|
||||
PRODUCT_PACKAGES += \
|
||||
dri_gbm \
|
||||
libgbm_mesa
|
||||
|
||||
PRODUCT_COPY_FILES += \
|
||||
frameworks/native/data/etc/android.software.opengles.deqp.level-2023-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml
|
||||
frameworks/native/data/etc/android.software.opengles.deqp.level-2024-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml
|
||||
|
||||
PRODUCT_PACKAGES += \
|
||||
vulkan.broadcom
|
||||
@@ -192,7 +195,7 @@ PRODUCT_PACKAGES += \
|
||||
PRODUCT_COPY_FILES += \
|
||||
frameworks/native/data/etc/android.hardware.vulkan.level-0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.level.xml \
|
||||
frameworks/native/data/etc/android.hardware.vulkan.version-1_3.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml \
|
||||
frameworks/native/data/etc/android.software.vulkan.deqp.level-2023-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml
|
||||
frameworks/native/data/etc/android.software.vulkan.deqp.level-2024-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml
|
||||
|
||||
# Health
|
||||
PRODUCT_PACKAGES += \
|
||||
@@ -249,10 +252,6 @@ PRODUCT_PACKAGES += \
|
||||
PRODUCT_PACKAGES += \
|
||||
com.android.hardware.thermal
|
||||
|
||||
# Touchscreen
|
||||
PRODUCT_COPY_FILES += \
|
||||
frameworks/native/data/etc/android.hardware.touchscreen.multitouch.jazzhand.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.touchscreen.multitouch.jazzhand.xml
|
||||
|
||||
# USB
|
||||
PRODUCT_PACKAGES += \
|
||||
android.hardware.usb-service.example \
|
||||
|
@@ -25,57 +25,13 @@ namespace aidl::android::hardware::health {
|
||||
|
||||
void HealthImpl::UpdateHealthInfo(HealthInfo* health_info) {
|
||||
health_info->chargerAcOnline = true;
|
||||
health_info->chargerUsbOnline = true;
|
||||
health_info->chargerWirelessOnline = false;
|
||||
health_info->chargerDockOnline = false;
|
||||
health_info->maxChargingCurrentMicroamps = 500000;
|
||||
health_info->maxChargingVoltageMicrovolts = 5000000;
|
||||
health_info->batteryStatus = BatteryStatus::FULL;
|
||||
health_info->batteryHealth = BatteryHealth::GOOD;
|
||||
health_info->batteryPresent = true;
|
||||
health_info->batteryLevel = 100;
|
||||
health_info->batteryVoltageMillivolts = 5000;
|
||||
health_info->batteryTemperatureTenthsCelsius = 250;
|
||||
health_info->batteryCurrentMicroamps = 500000;
|
||||
health_info->batteryCycleCount = 25;
|
||||
health_info->batteryFullChargeUah = 5000000;
|
||||
health_info->batteryChargeCounterUah = 5000000;
|
||||
health_info->batteryTechnology = "Li-ion";
|
||||
health_info->batteryCapacityLevel = BatteryCapacityLevel::FULL;
|
||||
health_info->batteryFullChargeDesignCapacityUah = 5000000;
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus HealthImpl::getChargeCounterUah(int32_t* out) {
|
||||
*out = 5000000;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus HealthImpl::getCurrentNowMicroamps(int32_t* out) {
|
||||
*out = 500000;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus HealthImpl::getCurrentAverageMicroamps(int32_t*) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus HealthImpl::getCapacity(int32_t* out) {
|
||||
*out = 100;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
health_info->batteryStatus = BatteryStatus::CHARGING;
|
||||
health_info->batteryHealth = BatteryHealth::GOOD;
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus HealthImpl::getChargeStatus(BatteryStatus* out) {
|
||||
*out = BatteryStatus::FULL;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus HealthImpl::getBatteryHealthData(BatteryHealthData* out) {
|
||||
out->batteryManufacturingDateSeconds = 1231006505;
|
||||
out->batteryFirstUsageSeconds = 1231469665;
|
||||
out->batteryStateOfHealth = 99;
|
||||
out->batterySerialNumber =
|
||||
"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f";
|
||||
out->batteryPartStatus = BatteryPartStatus::ORIGINAL;
|
||||
*out = BatteryStatus::CHARGING;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
|
@@ -28,12 +28,7 @@ public:
|
||||
using Health::Health;
|
||||
virtual ~HealthImpl() {}
|
||||
|
||||
ndk::ScopedAStatus getChargeCounterUah(int32_t* out) override;
|
||||
ndk::ScopedAStatus getCurrentNowMicroamps(int32_t* out) override;
|
||||
ndk::ScopedAStatus getCurrentAverageMicroamps(int32_t* out) override;
|
||||
ndk::ScopedAStatus getCapacity(int32_t* out) override;
|
||||
ndk::ScopedAStatus getChargeStatus(BatteryStatus* out) override;
|
||||
ndk::ScopedAStatus getBatteryHealthData(BatteryHealthData* out) override;
|
||||
|
||||
protected:
|
||||
void UpdateHealthInfo(HealthInfo* health_info) override;
|
||||
|
@@ -424,6 +424,7 @@ key 580 APP_SWITCH
|
||||
key 582 VOICE_ASSIST
|
||||
# Linux KEY_ASSISTANT
|
||||
key 583 ASSIST
|
||||
key 585 EMOJI_PICKER
|
||||
key 656 MACRO_1
|
||||
key 657 MACRO_2
|
||||
key 658 MACRO_3
|
||||
@@ -436,15 +437,22 @@ key 141 POWER
|
||||
key 174 BACK
|
||||
|
||||
# Keys defined by HID usages
|
||||
key usage 0x0c0065 SCREENSHOT FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c0067 WINDOW FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c006F BRIGHTNESS_UP FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c0070 BRIGHTNESS_DOWN FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c0079 KEYBOARD_BACKLIGHT_UP FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c007A KEYBOARD_BACKLIGHT_DOWN FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c007C KEYBOARD_BACKLIGHT_TOGGLE FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c00D9 EMOJI_PICKER FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c0173 MEDIA_AUDIO_TRACK FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c019C PROFILE_SWITCH FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c019F SETTINGS FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c01A2 ALL_APPS FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c0227 REFRESH FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c029D LANGUAGE_SWITCH FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c029F RECENT_APPS FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0c02A2 ALL_APPS FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0d0044 STYLUS_BUTTON_PRIMARY FALLBACK_USAGE_MAPPING
|
||||
key usage 0x0d005a STYLUS_BUTTON_SECONDARY FALLBACK_USAGE_MAPPING
|
||||
|
||||
|
15
manifest.xml
15
manifest.xml
@@ -17,15 +17,6 @@
|
||||
<instance>default</instance>
|
||||
</interface>
|
||||
</hal>
|
||||
<hal format="hidl">
|
||||
<name>android.hardware.bluetooth</name>
|
||||
<transport>hwbinder</transport>
|
||||
<version>1.1</version>
|
||||
<interface>
|
||||
<name>IBluetoothHci</name>
|
||||
<instance>default</instance>
|
||||
</interface>
|
||||
</hal>
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.camera.provider</name>
|
||||
<version>1</version>
|
||||
@@ -44,11 +35,11 @@
|
||||
</interface>
|
||||
</hal>
|
||||
<hal format="hidl">
|
||||
<name>android.hardware.graphics.composer</name>
|
||||
<name>android.hardware.tv.cec</name>
|
||||
<transport>hwbinder</transport>
|
||||
<version>2.4</version>
|
||||
<version>1.0</version>
|
||||
<interface>
|
||||
<name>IComposer</name>
|
||||
<name>IHdmiCec</name>
|
||||
<instance>default</instance>
|
||||
</interface>
|
||||
</hal>
|
||||
|
@@ -13,7 +13,7 @@ $(RPI_BOOT_OUT): $(INSTALLED_RAMDISK_TARGET)
|
||||
mkdir -p $(RPI_BOOT_OUT)/overlays
|
||||
cp $(DEVICE_PATH)/boot/* $(RPI_BOOT_OUT)
|
||||
cp $(KERNEL_PATH)/Image $(RPI_BOOT_OUT)
|
||||
cp $(KERNEL_PATH)/bcm2712-rpi-*.dtb $(RPI_BOOT_OUT)
|
||||
cp $(KERNEL_PATH)/bcm2712*-rpi-*.dtb $(RPI_BOOT_OUT)
|
||||
cp $(KERNEL_PATH)/overlays/* $(RPI_BOOT_OUT)/overlays
|
||||
cp $(PRODUCT_OUT)/ramdisk.img $(RPI_BOOT_OUT)
|
||||
echo $(BOARD_KERNEL_CMDLINE) > $(RPI_BOOT_OUT)/cmdline.txt
|
||||
|
54
mkimg.sh
54
mkimg.sh
@@ -6,37 +6,14 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
exit_with_error() {
|
||||
echo $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ -z ${TARGET_PRODUCT} ]; then
|
||||
exit_with_error "TARGET_PRODUCT environment variable is not set. Run lunch first."
|
||||
fi
|
||||
|
||||
if [ -z ${ANDROID_PRODUCT_OUT} ]; then
|
||||
exit_with_error "ANDROID_PRODUCT_OUT environment variable is not set. Run lunch first."
|
||||
fi
|
||||
|
||||
for PARTITION in "boot" "system" "vendor"; do
|
||||
if [ ! -f ${ANDROID_PRODUCT_OUT}/${PARTITION}.img ]; then
|
||||
exit_with_error "Partition image not found. Run 'make ${PARTITION}image' first."
|
||||
fi
|
||||
done
|
||||
|
||||
VERSION=RaspberryVanillaAOSP14
|
||||
VERSION=RaspberryVanillaAOSP15
|
||||
DATE=$(date +%Y%m%d)
|
||||
TARGET=$(echo ${TARGET_PRODUCT} | sed 's/^aosp_//')
|
||||
IMGNAME=${VERSION}-${DATE}-${TARGET}.img
|
||||
IMGSIZE=15360000000
|
||||
IMGNAME=${VERSION}-${DATE}-rpi5.img
|
||||
IMGSIZE=7
|
||||
OUTDIR=$(pwd | sed 's/\/device\/brcm\/rpi5$//')/out/target/product/rpi5
|
||||
|
||||
if [ -f ${ANDROID_PRODUCT_OUT}/${IMGNAME} ]; then
|
||||
exit_with_error "${ANDROID_PRODUCT_OUT}/${IMGNAME} already exists!"
|
||||
fi
|
||||
|
||||
echo "Creating image file ${ANDROID_PRODUCT_OUT}/${IMGNAME}..."
|
||||
sudo fallocate -l ${IMGSIZE} ${ANDROID_PRODUCT_OUT}/${IMGNAME}
|
||||
echo "Creating image file ${OUTDIR}/${IMGNAME}..."
|
||||
sudo dd if=/dev/zero of="${OUTDIR}/${IMGNAME}" bs=1M count=$(echo "${IMGSIZE}*1024" | bc)
|
||||
sync
|
||||
|
||||
echo "Creating partitions..."
|
||||
@@ -51,7 +28,7 @@ echo n
|
||||
echo p
|
||||
echo 2
|
||||
echo
|
||||
echo +2560M
|
||||
echo +2048M
|
||||
echo n
|
||||
echo p
|
||||
echo 3
|
||||
@@ -67,29 +44,28 @@ echo c
|
||||
echo a
|
||||
echo 1
|
||||
echo w
|
||||
) | sudo fdisk ${ANDROID_PRODUCT_OUT}/${IMGNAME}
|
||||
) | sudo fdisk "${OUTDIR}/${IMGNAME}"
|
||||
sync
|
||||
|
||||
LOOPDEV=$(sudo kpartx -av ${ANDROID_PRODUCT_OUT}/${IMGNAME} | awk 'NR==1{ sub(/p[0-9]$/, "", $3); print $3 }')
|
||||
LOOPDEV=$(sudo kpartx -av "${OUTDIR}/${IMGNAME}" | awk 'NR==1{ sub(/p[0-9]$/, "", $3); print $3 }')
|
||||
if [ -z ${LOOPDEV} ]; then
|
||||
exit_with_error "Unable to find loop device!"
|
||||
echo "Unable to find loop device!"
|
||||
exit 1
|
||||
fi
|
||||
echo "Image mounted as /dev/${LOOPDEV}"
|
||||
sleep 1
|
||||
|
||||
echo "Copying boot..."
|
||||
sudo dd if=${ANDROID_PRODUCT_OUT}/boot.img of=/dev/mapper/${LOOPDEV}p1 bs=1M
|
||||
sudo dd if=${OUTDIR}/boot.img of=/dev/mapper/${LOOPDEV}p1 bs=1M
|
||||
echo "Copying system..."
|
||||
sudo dd if=${ANDROID_PRODUCT_OUT}/system.img of=/dev/mapper/${LOOPDEV}p2 bs=1M
|
||||
sudo dd if=${OUTDIR}/system.img of=/dev/mapper/${LOOPDEV}p2 bs=1M
|
||||
echo "Copying vendor..."
|
||||
sudo dd if=${ANDROID_PRODUCT_OUT}/vendor.img of=/dev/mapper/${LOOPDEV}p3 bs=1M
|
||||
sudo dd if=${OUTDIR}/vendor.img of=/dev/mapper/${LOOPDEV}p3 bs=1M
|
||||
echo "Creating userdata..."
|
||||
sudo mkfs.ext4 /dev/mapper/${LOOPDEV}p4 -I 512 -L userdata
|
||||
sync
|
||||
|
||||
sudo kpartx -d "/dev/${LOOPDEV}"
|
||||
sudo losetup -d "/dev/${LOOPDEV}"
|
||||
sudo chown ${USER}:${USER} ${ANDROID_PRODUCT_OUT}/${IMGNAME}
|
||||
echo "Done, created ${OUTDIR}/${IMGNAME}!"
|
||||
|
||||
echo "Done, created ${ANDROID_PRODUCT_OUT}/${IMGNAME}!"
|
||||
exit 0
|
||||
|
@@ -6,5 +6,5 @@ runtime_resource_overlay {
|
||||
name: "AndroidRpiOverlay",
|
||||
resource_dirs: ["res"],
|
||||
sdk_version: "current",
|
||||
vendor: true,
|
||||
proprietary: true
|
||||
}
|
||||
|
@@ -6,5 +6,5 @@ runtime_resource_overlay {
|
||||
name: "AndroidTvRpiOverlay",
|
||||
resource_dirs: ["res"],
|
||||
sdk_version: "current",
|
||||
vendor: true,
|
||||
proprietary: true
|
||||
}
|
||||
|
@@ -17,6 +17,17 @@
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<!-- User activity timeout: Minimum screen off timeout in milliseconds.
|
||||
|
||||
Sets a lower bound for the {@link Settings.System#SCREEN_OFF_TIMEOUT} setting
|
||||
which determines how soon the device will go to sleep when there is no
|
||||
user activity.
|
||||
|
||||
This value must be greater than zero, otherwise the device will immediately
|
||||
fall asleep again as soon as it is awoken.
|
||||
-->
|
||||
<integer name="config_minimumScreenOffTimeout">86400000</integer>
|
||||
|
||||
<!-- Default screen brightness setting.
|
||||
Must be in the range specified by minimum and maximum. -->
|
||||
<integer name="config_screenBrightnessSettingDefault">128</integer>
|
||||
|
@@ -6,5 +6,5 @@ runtime_resource_overlay {
|
||||
name: "CarServiceRpiOverlay",
|
||||
resource_dirs: ["res"],
|
||||
sdk_version: "current",
|
||||
vendor: true,
|
||||
proprietary: true
|
||||
}
|
||||
|
@@ -6,5 +6,5 @@ runtime_resource_overlay {
|
||||
name: "SettingsProviderRpiOverlay",
|
||||
resource_dirs: ["res"],
|
||||
sdk_version: "current",
|
||||
vendor: true,
|
||||
proprietary: true
|
||||
}
|
||||
|
@@ -18,9 +18,6 @@
|
||||
|
||||
<resources>
|
||||
|
||||
<!-- Default for Settings.Global.DEVICE_NAME $1=MODEL -->
|
||||
<string name="def_device_name_simple">Raspberry Pi 5</string>
|
||||
|
||||
<!-- Default screen brightness -->
|
||||
<integer name="def_screen_brightness">128</integer>
|
||||
|
||||
|
@@ -6,5 +6,5 @@ runtime_resource_overlay {
|
||||
name: "SettingsProviderTvRpiOverlay",
|
||||
resource_dirs: ["res"],
|
||||
sdk_version: "current",
|
||||
vendor: true,
|
||||
proprietary: true
|
||||
}
|
||||
|
@@ -18,9 +18,6 @@
|
||||
|
||||
<resources>
|
||||
|
||||
<!-- Default for Settings.Global.DEVICE_NAME $1=MODEL -->
|
||||
<string name="def_device_name_simple">Raspberry Pi 5</string>
|
||||
|
||||
<!-- Default screen brightness -->
|
||||
<integer name="def_screen_brightness">128</integer>
|
||||
|
||||
|
@@ -6,5 +6,5 @@ runtime_resource_overlay {
|
||||
name: "SettingsRpiOverlay",
|
||||
resource_dirs: ["res"],
|
||||
sdk_version: "current",
|
||||
vendor: true,
|
||||
proprietary: true
|
||||
}
|
||||
|
@@ -6,5 +6,5 @@ runtime_resource_overlay {
|
||||
name: "SystemUIRpiOverlay",
|
||||
resource_dirs: ["res"],
|
||||
sdk_version: "current",
|
||||
vendor: true,
|
||||
proprietary: true
|
||||
}
|
||||
|
@@ -6,5 +6,5 @@ runtime_resource_overlay {
|
||||
name: "WifiRpiOverlay",
|
||||
resource_dirs: ["res"],
|
||||
sdk_version: "current",
|
||||
vendor: true,
|
||||
proprietary: true
|
||||
}
|
||||
|
@@ -24,13 +24,4 @@
|
||||
is no longer indicative, and a separate config now exists for each band -->
|
||||
<bool translatable="false" name ="config_wifi5ghzSupport">true</bool>
|
||||
|
||||
<!-- Boolean indicating whether the wifi chipset supports background scanning mechanism.
|
||||
This mechanism allows the host to remain in suspend state and the dongle to actively
|
||||
scan and wake the host when a configured SSID is detected by the dongle. This chipset
|
||||
capability can provide power savings when wifi needs to be always kept on. -->
|
||||
<bool translatable="false" name="config_wifi_background_scan_support">true</bool>
|
||||
|
||||
<!-- Do not translate. Default access point SSID used for tethering -->
|
||||
<string name="wifi_tether_configure_ssid_default" translatable="false">Raspberry Pi 5</string>
|
||||
|
||||
</resources>
|
||||
|
@@ -11,3 +11,12 @@ on post-fs-data
|
||||
mkdir /data/vendor/wifi 0770 wifi wifi
|
||||
mkdir /data/vendor/wifi/wpa 0770 wifi wifi
|
||||
mkdir /data/vendor/wifi/wpa/sockets 0770 wifi wifi
|
||||
|
||||
on property:sys.boot_completed=1
|
||||
# Reinit lmkd to reconfigure lmkd properties
|
||||
setprop lmkd.reinit 1
|
||||
|
||||
service suspend_blocker_rpi /vendor/bin/suspend_blocker_rpi
|
||||
class early_hal # Start together with system_suspend HAL
|
||||
group system
|
||||
user root
|
||||
|
@@ -17,5 +17,8 @@
|
||||
/dev/media2 0660 media media
|
||||
/dev/video19 0660 media media
|
||||
|
||||
# ION
|
||||
/dev/ion 0664 system system
|
||||
|
||||
# USB
|
||||
/sys/class/udc/1000480000.usb current_speed 0664 system system
|
||||
|
@@ -1,10 +1,10 @@
|
||||
# Bluetooth
|
||||
/sys/class/rfkill/rfkill[0-9]/state u:object_r:sysfs_bluetooth_writable:s0
|
||||
/vendor/bin/hw/android\.hardware\.bluetooth-service\.rpi u:object_r:hal_bluetooth_default_exec:s0
|
||||
|
||||
# CEC
|
||||
/dev/cec0 u:object_r:cec_device:s0
|
||||
/dev/cec1 u:object_r:cec_device:s0
|
||||
/vendor/bin/hw/android\.hardware\.tv\.cec@1\.0-service\.rpi u:object_r:hal_tv_cec_default_exec:s0
|
||||
|
||||
# DRM
|
||||
/vendor/bin/hw/android\.hardware\.drm-service\.clearkey u:object_r:hal_drm_clearkey_exec:s0
|
||||
@@ -17,7 +17,11 @@
|
||||
/vendor/bin/hw/android\.hardware\.gatekeeper@1\.0-service\.software u:object_r:hal_gatekeeper_default_exec:s0
|
||||
|
||||
# Graphics
|
||||
/dev/dri(/.*)? u:object_r:gpu_device:s0
|
||||
/dev/dri u:object_r:gpu_device:s0
|
||||
/dev/dri/card0 u:object_r:gpu_device:s0
|
||||
/dev/dri/card1 u:object_r:gpu_device:s0
|
||||
/dev/dri/renderD128 u:object_r:gpu_device:s0
|
||||
/vendor/bin/hw/android\.hardware\.composer\.hwc3-service\.drm u:object_r:hal_graphics_composer_default_exec:s0
|
||||
/vendor/bin/hw/android\.hardware\.graphics\.allocator@4\.0-service\.minigbm_gbm_mesa u:object_r:hal_graphics_allocator_default_exec:s0
|
||||
/vendor/lib(64)?/hw/android\.hardware\.graphics.mapper@4\.0-impl\.minigbm_gbm_mesa\.so u:object_r:same_process_hal_file:s0
|
||||
/vendor/lib(64)?/hw/vulkan\.broadcom\.so u:object_r:same_process_hal_file:s0
|
||||
@@ -25,7 +29,8 @@
|
||||
/vendor/lib(64)?/libdrm\.so u:object_r:same_process_hal_file:s0
|
||||
/vendor/lib(64)?/libgallium_dri\.so u:object_r:same_process_hal_file:s0
|
||||
/vendor/lib(64)?/libgbm_mesa\.so u:object_r:same_process_hal_file:s0
|
||||
/vendor/lib(64)?/libgbm_mesa_wrapper\.so u:object_r:same_process_hal_file:s0
|
||||
/vendor/lib{64}?/libgbm_mesa_wrapper\.so u:object_r:same_process_hal_file:s0
|
||||
/vendor/lib(64)?/libglapi\.so u:object_r:same_process_hal_file:s0
|
||||
/vendor/lib(64)?/libminigbm_gralloc_gbm_mesa\.so u:object_r:same_process_hal_file:s0
|
||||
|
||||
# Health
|
||||
|
@@ -1,6 +1,3 @@
|
||||
# Graphics
|
||||
genfscon sysfs /devices/platform/axi/1002000000.v3d u:object_r:sysfs_gpu:s0
|
||||
genfscon sysfs /devices/platform/axi/axi:gpu u:object_r:sysfs_gpu:s0
|
||||
|
||||
# Serial number
|
||||
genfscon sysfs /firmware/devicetree/base/serial-number u:object_r:sysfs_dt_firmware_android:s0
|
||||
genfscon sysfs /devices/platform/v3dbus/fec00000.v3d/uevent u:object_r:sysfs_gpu:s0
|
||||
genfscon sysfs /devices/platform/gpu/uevent u:object_r:sysfs_gpu:s0
|
||||
genfscon sysfs /firmware/devicetree/base/serial-number u:object_r:sysfs_dt_firmware_android:s0
|
||||
|
@@ -8,5 +8,7 @@ allow cameraserver device:dir r_dir_perms;
|
||||
allow cameraserver video_device:dir r_dir_perms;
|
||||
allow cameraserver video_device:chr_file rw_file_perms;
|
||||
|
||||
gpu_access(hal_camera_default)
|
||||
gpu_access(cameraserver)
|
||||
allow hal_camera_default gpu_device:dir { open read search };
|
||||
allow hal_camera_default gpu_device:chr_file { open read write ioctl map getattr };
|
||||
allow cameraserver gpu_device:dir { open read write search getattr };
|
||||
allow cameraserver gpu_device:chr_file { open read write ioctl map getattr };
|
||||
|
1
sepolicy/mediaprovider.te
Normal file
1
sepolicy/mediaprovider.te
Normal file
@@ -0,0 +1 @@
|
||||
gpu_access(surfaceflinger)
|
@@ -1 +1,2 @@
|
||||
gpu_access(mediaswcodec)
|
||||
allow mediaswcodec gpu_device:chr_file { getattr ioctl map open read write };
|
||||
|
@@ -2,8 +2,7 @@
|
||||
# gpu_access(client_domain)
|
||||
# Allow client_domain to communicate with the GPU
|
||||
define(`gpu_access', `
|
||||
allow $1 gpu_device:dir r_dir_perms;
|
||||
allow $1 gpu_device:chr_file rw_file_perms;
|
||||
allow $1 sysfs_gpu:dir r_dir_perms;
|
||||
allow $1 sysfs_gpu:file r_file_perms;
|
||||
allow $1 gpu_device:dir { open read search getattr };
|
||||
allow $1 gpu_device:chr_file { open read getattr ioctl map write };
|
||||
allow $1 sysfs_gpu:file { getattr open read };
|
||||
')
|
||||
|
@@ -5,8 +5,7 @@
|
||||
|
||||
cc_binary {
|
||||
name: "suspend_blocker_rpi",
|
||||
init_rc: ["suspend_blocker_rpi.rc"],
|
||||
vendor: true,
|
||||
srcs: ["suspend_blocker_rpi.cpp"],
|
||||
proprietary: true,
|
||||
shared_libs: ["libpower"],
|
||||
}
|
||||
|
@@ -1,4 +0,0 @@
|
||||
service suspend_blocker_rpi /vendor/bin/suspend_blocker_rpi
|
||||
class early_hal # Start together with system_suspend HAL
|
||||
group system
|
||||
user root
|
28
vendor.prop
28
vendor.prop
@@ -1,14 +1,14 @@
|
||||
|
||||
# Audio
|
||||
persist.audio.device=dac
|
||||
persist.audio.hdmi.device=vc4hdmi0
|
||||
persist.audio.pcm.card.auto=true
|
||||
persist.audio.pcm.card=0
|
||||
persist.audio.pcm.device=0
|
||||
ro.config.media_vol_default=20
|
||||
ro.config.media_vol_steps=25
|
||||
ro.hardware.audio.primary=rpi_hdmi
|
||||
|
||||
# Bluetooth
|
||||
bluetooth.device.class_of_device?=90,2,12
|
||||
bluetooth.device.default_name=Raspberry Pi 5
|
||||
bluetooth.profile.a2dp.source.enabled?=true
|
||||
bluetooth.profile.asha.central.enabled?=true
|
||||
bluetooth.profile.avrcp.target.enabled?=true
|
||||
@@ -33,16 +33,13 @@ bluetooth.profile.vcp.controller.enabled?=true
|
||||
persist.bluetooth.a2dp_aac.vbr_supported=true
|
||||
|
||||
# Camera
|
||||
media.settings.xml=/vendor/etc/media_profiles_V1_0.xml
|
||||
ro.hardware.camera=libcamera
|
||||
|
||||
# CEC
|
||||
persist.hdmi.cec_device=cec0
|
||||
ro.hdmi.cec_device=cec0
|
||||
ro.hdmi.device_type=4
|
||||
|
||||
# Chipset
|
||||
ro.soc.manufacturer=Broadcom
|
||||
ro.soc.model=BCM2712
|
||||
|
||||
# Display
|
||||
debug.drm.mode.force=1920x1080
|
||||
|
||||
@@ -53,13 +50,23 @@ persist.ffmpeg_codec2.v4l2.h265=true
|
||||
|
||||
# Graphics
|
||||
ro.hardware.egl=mesa
|
||||
ro.hardware.hwcomposer=drm
|
||||
ro.hardware.vulkan=broadcom
|
||||
ro.opengles.version=196609
|
||||
ro.vendor.hwc.drm.use_config_groups=0
|
||||
vendor.hwc.backend_override=rpi5
|
||||
vendor.hwc.drm.ctm=DRM_OR_IGNORE
|
||||
|
||||
# LMKD
|
||||
ro.lmk.critical=0
|
||||
ro.lmk.critical_upgrade=false
|
||||
ro.lmk.downgrade_pressure=100
|
||||
ro.lmk.kill_heaviest_task=true
|
||||
ro.lmk.kill_timeout_ms=100
|
||||
ro.lmk.log_stats=true
|
||||
ro.lmk.low=1001
|
||||
ro.lmk.medium=800
|
||||
ro.lmk.upgrade_pressure=100
|
||||
ro.lmk.use_minfree_levels=true
|
||||
|
||||
# Lockscreen
|
||||
ro.lockscreen.disable.default=true
|
||||
|
||||
@@ -77,3 +84,4 @@ wifi.interface=wlan0
|
||||
|
||||
# Window extensions
|
||||
persist.settings.large_screen_opt.enabled=true
|
||||
|
||||
|
136
wrimg.sh
136
wrimg.sh
@@ -1,136 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Copyright (C) 2025 KonstaKANG
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
exit_with_error() {
|
||||
echo $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
check_device() {
|
||||
for PARTITION in "1" "2" "3" "4"; do
|
||||
if [ ! -b /dev/${1}${PARTITION} ]; then
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
PARTITION1=$(lsblk -o LABEL,SIZE -b /dev/${1}1 | tail -n 1)
|
||||
PARTITION2=$(lsblk -o LABEL,SIZE -b /dev/${1}2 | tail -n 1)
|
||||
PARTITION3=$(lsblk -o LABEL,SIZE -b /dev/${1}3 | tail -n 1)
|
||||
PARTITION4=$(lsblk -o LABEL,SIZE -b /dev/${1}4 | tail -n 1)
|
||||
|
||||
if [ $(echo ${PARTITION1} | awk {'print $1'}) != "boot" ] || [ $(echo ${PARTITION1} | awk {'print $2'}) != "134217728" ]; then
|
||||
return 1
|
||||
fi
|
||||
if [ $(echo ${PARTITION2} | awk {'print $1'}) != "/" ] || [ $(echo ${PARTITION2} | awk {'print $2'}) != "2684354560" ]; then
|
||||
return 1
|
||||
fi
|
||||
if [ $(echo ${PARTITION3} | awk {'print $1'}) != "vendor" ] || [ $(echo ${PARTITION3} | awk {'print $2'}) != "268435456" ]; then
|
||||
return 1
|
||||
fi
|
||||
if [ $(echo ${PARTITION4} | awk {'print $1'}) != "userdata" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
DEVICE=${1}
|
||||
return 0
|
||||
}
|
||||
|
||||
find_device() {
|
||||
for SDX in "sda" "sdb" "sdc" "sdd" "sde" "sdf"; do
|
||||
check_device ${SDX}
|
||||
if [ $? == "0" ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z ${DEVICE} ]; then
|
||||
exit_with_error "Unable to find suitable block device!"
|
||||
fi
|
||||
}
|
||||
|
||||
confirm() {
|
||||
echo "Build target ${1}..."
|
||||
if [ "${2}" == "wipe" ]; then
|
||||
echo "Wiping userdata partition..."
|
||||
else
|
||||
echo "Writing ${2} image..."
|
||||
fi
|
||||
echo "Writing to device /dev/${DEVICE}..."
|
||||
lsblk -o NAME,LABEL,SIZE /dev/${DEVICE}
|
||||
|
||||
read -p "Continue (y/n)? " -n 1 -r RESPONSE
|
||||
echo ""
|
||||
if [[ ! ${RESPONSE} =~ ^[Yy]$ ]]; then
|
||||
exit_with_error "Exiting!"
|
||||
fi
|
||||
}
|
||||
|
||||
write_partition() {
|
||||
if [ ! -f ${ANDROID_PRODUCT_OUT}/${1}.img ]; then
|
||||
exit_with_error "Partition image not found. Run 'make ${1}image' first."
|
||||
fi
|
||||
|
||||
echo "Copying ${1}..."
|
||||
sudo umount /dev/${DEVICE}${2}
|
||||
sudo dd if=${ANDROID_PRODUCT_OUT}/${1}.img of=/dev/${DEVICE}${2} bs=1M
|
||||
}
|
||||
|
||||
wipe_userdata() {
|
||||
echo "Creating userdata..."
|
||||
sudo umount /dev/${DEVICE}4
|
||||
sudo wipefs -a /dev/${DEVICE}4
|
||||
sudo mkfs.ext4 /dev/${DEVICE}4 -I 512 -L userdata
|
||||
}
|
||||
|
||||
finish() {
|
||||
sync
|
||||
echo "Done!"
|
||||
exit 0
|
||||
}
|
||||
|
||||
if [ -z ${TARGET_PRODUCT} ]; then
|
||||
exit_with_error "TARGET_PRODUCT environment variable is not set. Run lunch first."
|
||||
fi
|
||||
|
||||
if [ -z ${ANDROID_PRODUCT_OUT} ]; then
|
||||
exit_with_error "ANDROID_PRODUCT_OUT environment variable is not set. Run lunch first."
|
||||
fi
|
||||
|
||||
TARGET=$(echo ${TARGET_PRODUCT} | sed 's/^aosp_//')
|
||||
DEVICE=
|
||||
|
||||
if [ -z $1 ]; then
|
||||
find_device
|
||||
confirm ${TARGET} "boot, system, and vendor"
|
||||
write_partition boot 1
|
||||
write_partition system 2
|
||||
write_partition vendor 3
|
||||
finish
|
||||
elif [ ! -z $1 ] && [ $1 == "boot" ]; then
|
||||
find_device
|
||||
confirm ${TARGET} "boot"
|
||||
write_partition boot 1
|
||||
finish
|
||||
elif [ ! -z $1 ] && [ $1 == "system" ]; then
|
||||
find_device
|
||||
confirm ${TARGET} "system"
|
||||
write_partition system 2
|
||||
finish
|
||||
elif [ ! -z $1 ] && [ $1 == "vendor" ]; then
|
||||
find_device
|
||||
confirm ${TARGET} "vendor"
|
||||
write_partition vendor 3
|
||||
finish
|
||||
elif [ ! -z $1 ] && [ $1 == "wipe" ]; then
|
||||
find_device
|
||||
confirm ${TARGET} "wipe"
|
||||
wipe_userdata
|
||||
finish
|
||||
else
|
||||
exit_with_error "Usage: $0 [boot|system|vendor|wipe]"
|
||||
fi
|
Reference in New Issue
Block a user