sm6375-common: Set Bluetooth MAC address using persist property

The idea is to allow us to not depend on stock QTI Bluetooth HAL, as MAC
addresses fetched from NVRAM by nv_mac script will be saved as hex-encoded
files. We can decode back saved files to then the Bluetooth one be set using
persist property so it can be read by Bluetooth HAL.

This is loosely based on similar techniques used on Mi 9 and ZenFone Max Pro M2.

Signed-off-by: Albert I <kras@raphielgang.org>
Change-Id: I74d07c3c3125a04962c37fe8bfcc8385d1fd3398
This commit is contained in:
Albert I
2021-06-21 23:55:13 +08:00
committed by Ramii Ahmed
parent 2cd7756d93
commit 4cd824325b
6 changed files with 48 additions and 0 deletions

View File

@@ -375,6 +375,7 @@ PRODUCT_PACKAGES += \
PRODUCT_PACKAGES += \
init.batterysecret.rc \
init.class_main.sh \
init.mi.btmac.sh \
init.kernel.post_boot.sh \
init.kernel.post_boot-blair.sh \
init.kernel.post_boot-holi.sh \

View File

@@ -9,6 +9,15 @@ LOCAL_SRC_FILES := bin/init.class_main.sh
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES)
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := init.mi.btmac.sh
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
LOCAL_SRC_FILES := bin/init.mi.btmac.sh
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES)
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := init.kernel.post_boot.sh
LOCAL_MODULE_TAGS := optional

21
rootdir/bin/init.mi.btmac.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/vendor/bin/sh
# Copyright (C) 2021 KudProject Development
# SPDX-License-Identifier: GPL-3.0-or-later OR Apache-2.0
LOG_TAG="MiSetBtMac"
logi () { log -t "$LOG_TAG" -p i "$@"; }
# hex binary containing mac address
BT_MAC_HEX_PATH="/data/vendor/mac_addr/bt.mac";
if [ ! -f "$BT_MAC_HEX_PATH" ]; then
logi "bt.mac file not found, exiting"
exit
fi
# raw mac address without colons
RAW_MAC=$(xxd -p "$BT_MAC_HEX_PATH");
# convert it into format recognized by bluetooth hal
DEC_MAC=$(echo "$RAW_MAC" | sed 's!^M$!!;s!\-!!g;s!\.!!g;s!\(..\)!\1:!g;s!:$!!')
# set the mac address using persist property
setprop persist.vendor.service.bdroid.bdaddr "$DEC_MAC"
logi "bt.mac file found, setting mac addr"

View File

@@ -259,6 +259,16 @@ service svi_on /vendor/bin/ppd "svi:on"
oneshot
disabled
on property:init.svc.vendor.nv_mac=stopped
start vendor.btmac-sh
service vendor.btmac-sh /vendor/bin/init.mi.btmac.sh
class late_start
user system
group system bluetooth wifi
oneshot
disabled
on property:ro.vendor.display.svi=1 && property:sys.boot_completed=1
start svi_on

View File

@@ -9,6 +9,9 @@
/vendor/bin/batterysecret u:object_r:batterysecret_exec:s0
/mnt/vendor/persist/subsys(/.*)? u:object_r:persist_subsys_file:s0
# Bluetooth
/vendor/bin/init\.mi\.btmac\.sh u:object_r:vendor_qti_init_shell_exec:s0
# Camera
/mnt/vendor/persist/camera(/.*)? u:object_r:camera_persist_file:s0

View File

@@ -0,0 +1,4 @@
# allow init.mi.btmac.sh to read hex-encoded mac address and set it
allow vendor_qti_init_shell vendor_bluetooth_prop:property_service set;
allow vendor_qti_init_shell vendor_wifi_vendor_data_file:dir search;
allow vendor_qti_init_shell vendor_wifi_vendor_data_file:file r_file_perms;