SlideShare a Scribd company logo
1 of 38
Download to read offline
Implementing a LED Light Bar
Solution on Android System
LC Wang, Wig Cheng
30 July 2023
OUTLINE
• PART I. System Part (Presented by Wig Cheng)
Implementing JNI function in system
• PART II. APK Part (Presented by LC Wang)
Implementing a demo APK using JNI library
PART I.
• Me
• Motivation
• System architecture
• AOSP Kernel driver tweaking
• LIBUBOOTENV porting
• JNI implementation
• Summary
ME
• Name: Wig
• Job: IEIWorld - Android OS team
• Work
#> Embedded Linux platforms
#> Industrial Android BSP
• GITHUB: https://github.com/wigcheng
CLASSICANDROID PORDUCTS
Refer from google search
OTHERANDROIDAPPLICATIONS
Refer from google search
MOTIVATION
• In healthcare use case which need LED color for a patient’s
health status. In this case, we'll show you a LED light-bar
solution using Android OS.
MOTIVATION (CONT'D)
Power on APP Sleep (Suspend) Power off
System Status Power on Power on Sleep Power off
Power LED Off Off
Color Blinking
default: Blue
On/off (Red)
default: On
User LED Off
1. LED control
2. Wave/Breath mode
3. Sleep/Power off setting
Off Off
blinking
blinking
Specifications
MOTIVATION (CONT'D)
Specifications
LED light bar
LED light bar
Power LED
User LED User LED
Power LED
Platform:
- NXP ARM Cortex-A53 IMX8MM
Supported OS:
- Android 12, Kernel 5.10.72
- Android 13, Kernel 5.15.74
SYSTEM ARCHITECTURE
Hardware
U-boot
AOSP Kernel
ART
JNI Layer
APP Layer
1. Enabling LightBar driver with device tree
2. Tweaking driver
AOSP
1. libubootenv library porting
2. Checking LED nodes
3. SELINUX
1. Add LightBar related boot argument
1. DesignAPIs for APK
1. Design demo APK
 TI TLC59116 LED driver IC
 16 channels
 via I2C bus
 PWM control method
 Linux upstream driver
 Enable driver in defconfig
 Add to device tree
 Tweaking driver (later)
AOSP KERNEL DRIVER
• Normal defconfig
<source>/vendor/nxp-opensource /kernel_imx /arch
/arm64/configs/iei_imx_android_defconfig
• GKI (Google Kernel Image) defconfig
<source>/vendor/nxp-opensource
/kernel_imx /arch /arm64/configs/imx8mm_gki.fragment
CONFIG_LEDS_TLC591XX=m (build as kernel module)
master SDA
SCL
slave 1 slave 2
lightbar1: tlc59116_left@60 {
#address-cells = <1>;
#size-cells = <0>;
compatible = "ti,tlc59116";
reg = <0x60>;
status = "okay";
out0@0 {
label = "i2c2_led_red_00";
reg = <0x0>;
};
….....
….....
out14@e {
label = "i2c2_led_blue_04";
reg = <0xe>;
};
};
I2C device address 0x60
Driver name
Link to <kernel source>/drivers/leds/leds-tlc591xx.c
static const struct of_device_id of_tlc591xx_leds_match[] = {
{ .compatible = "ti,tlc59116",
.data = &tlc59116 },
{},
};
MODULE_DEVICE_TABLE(of, of_tlc591xx_leds_match);
LED-0 node: id = 0x0, node name = "i2c2_led_red_00"
device node path:
/sys/bus/i2c/drivers/tlc591xx/1-0060/leds/i2c2_led_red_00/brightness
LED1 ~ LED13 definition
/sys/bus/i2c/drivers/tlc591xx/1-0060/leds/i2c2_led_red_01/brightness
/sys/bus/i2c/drivers/tlc591xx/1-0060/leds/i2c2_led_red_02/brightness
….
/sys/bus/i2c/drivers/tlc591xx/1-0060/leds/i2c2_led_blue_03/brightness
LED-14
/sys/bus/i2c/drivers/tlc591xx/1-0060/leds/i2c2_led_blue_04/brightness
Modify device tree
AOSP KERNEL DRIVER (CONT.D)
 CONFIG_LEDS_TLC591XX → drivers/leds/leds-tlc591xx.c
static struct i2c_driver tlc591xx_driver = {
.driver = {
.name = "tlc591xx",
.of_match_table = of_match_ptr(of_tlc591xx_leds_match),
.pm = &tlc591xx_pm_ops,
},
.probe = tlc591xx_probe,
.shutdown = tlc591xx_shutdown,
.id_table = tlc591xx_id,
};
Add to driver for suspend/resume function
add LED blinking behavior to suspend function
add clear LED state behavior to resume function
static SIMPLE_DEV_PM_OPS(tlc591xx_pm_ops,
tlc591xx_suspend, tlc591xx_resume);
Add to driver for power-off function
add turn on red color for LED to shutdown function
Modify driver
LIBUBOOTENV PORTING
 New tool in 2021 (DENX)
 Feature – modify bootargs in rootfs of Linux OS
 Port to AOSP
 Source path: <source>/external/libubootenv
 Add Android.bp (Makefile)
 Output file
 /vendor/lib64/libubootenv.so (library)
 /vendor/bin/fw_printenv (utility)
 /vendor/bin/fw_setenv (utility)
 /vendor/etc/fw_env.config (config)
eMMC address:
/dev/block/mmcblk2 0x400000 0x4000
device name offset address env size
Tracing U-boot defconfig
<u-boot source>/configs/xxx_android_defconfig
CONFIG_ENV_SIZE=0x4000
CONFIG_ENV_OFFSET=0x400000
JNI IMPLEMENTATION
 Implement via C/C++ -> LightBar.cpp
 Bridge using CMAKE configuration
 API definition
 setLightBarUserLED
 clearLightBarLED
 setLightBarBreathMode
 setLightBarWaveMode
 setLightBarPowerLedSuspendColor
 setLightBarPowerLedPoweroffState
 getLightBarPowerLedStatus
JAVA Base
Kotlin Base
LightBar.cpp
JniMethod.java
MainActivity.java
JniMethod.kt
MainActivity.kt
JNI IMPLEMENTATION (CONT.D)
 Implementation flow
 User LED controlling
 Power LED controlling
Open specific LED
brightness node
/sys/bus/i2c/drivers/tlc591xx/1-0060/leds/i2c<bus>_led_<color>_<number>/brightness
/sys/bus/i2c/drivers/tlc591xx/3-0060/leds/i2c<bus>_led_<color>_<number>/brightness
read/write brightness node close brightness node
Adapt fw_setenv command
popenAPI pclose
Adapt fw_printenv command
Suspend argument: leds.suspend_color="<color>"
support color list: red, green, blue (default), yellow, cyan, magenta, white
Power-off argument: leds.poweroff_state="<status>"
support state list: on, off
U-boot environment arguments
1. Save to eMMC specific
address
2. Add power LED relate
argument
SUMMARY
Kernel driver (as a module)
1. Load power LED arguemnt
from u-boot arguments
2. Initial drivers with specific
functions
libubootenv
1. Load power LED arguemnt
from u-boot arguments in
ART stage
2. Set power LED argument to
u-boot environment (need
reboot)
Implement JNIAPI to APK
development
PART II.
 Me
 App architecture
 App java design
 App JNI design
 SELinux
 Troubleshooting
ME
• Name: LC
• Job: IEIWorld - Android software engineer
• GITHUB: https://github.com/lc-wang
APP ARCHITECTURE
UI
JNI
Build Setting
APP JAVA DESIGN
APP JAVA DESIGN
APP JAVA DESIGN
BreathMode WaveMode
APP JNI DESIGN
APP JNI DESIGN
package name_Java file_name_function name
APP JNI DESIGN
APP POWER LED
Power Suspend
Power Off
SELINUX
Linux DAC
DAC: Discretionary Access Control
directory
read
write
execute
Owner Group Other
uid gid
SELINUX
User process makes a system call
system call
DAC check
LSM check
User space
Kernel space
LSM: Linux Security Module
SELINUX
Command: ls –lZ / ps -lZ
drwxr-xr-x 15 root root u:object_r:system_file:s0 330 2023-07-13 10:01 system
SELinux user
role
domain
Multi-Level Security
SELINUX
allow system_app system_app_data_file:notdevfile_class_set rw_file_perms;
File: system_app.te
rule source type
(domain)
target type
(domain)
class perm_set
SELINUX
Ligtbar fw_setenv /dev/block/mmcblk2
system app vendor_file block_device_file
process/file
domain
SELINUX
Ligtbar fw_setenv /dev/block/mmcblk2
system_app vendor_file block_device_file
allow system_app system_app_data_file:notdevfile_class_set rw_file_perms;
allow system_app cache_recovery_file:dir { search write add_name };
…
allow system_app vendor_file:file {read write};
allow vendor_file block_device_file:blk_file {read write};
SELINUX
Ligtbar fw_setenv /dev/block/mmcblk2
File: {AOSP root}/system/sepolicy/public/domain.te
neverallow neverallow
system_app vendor_file block_device_file
SELINUX
File: system_app.te
allow system_app system_app_data_file:notdevfile_class_set rw_file_perms;
allow system_app cache_recovery_file:dir { search write add_name };
…
permissive system_app;
Ligtbar fw_setenv /dev/block/mmcblk2
system_app vendor_file block_device_file
TROUBLESHOOTING
allow system_app system_app_data_file:notdevfile_class_set rw_file_perms;
allow system_app cache_recovery_file:dir { search write add_name };
…
permissive system_app;
Breaking the Android rule, it causes CTS/VTS cases fail
! ! !
SUMMARY
• App UI
• App JNI
• How to solve SELINUX Issue
OPEN SOURCE
 Light bar JNI SDK instruction
https://github.com/ieiARMCommunity/lightbar_sdk_aosp
 Light bar demo APK source code
https://github.com/QNAP-android-internal/IEI-AndroidLightBar

More Related Content

What's hot

Automotive Grade Linux on Raspberry Pi: How Does It Work?
Automotive Grade Linux on Raspberry Pi: How Does It Work?Automotive Grade Linux on Raspberry Pi: How Does It Work?
Automotive Grade Linux on Raspberry Pi: How Does It Work?Leon Anavi
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
 
Deeper dive in Docker Overlay Networks
Deeper dive in Docker Overlay NetworksDeeper dive in Docker Overlay Networks
Deeper dive in Docker Overlay NetworksLaurent Bernaille
 
Implementing generic JNI hardware control for Kotlin based app on AOSP
Implementing generic JNI hardware control for Kotlin based app on AOSPImplementing generic JNI hardware control for Kotlin based app on AOSP
Implementing generic JNI hardware control for Kotlin based app on AOSPCheng Wig
 
Singularity: The Inner Workings of Securely Running User Containers on HPC Sy...
Singularity: The Inner Workings of Securely Running User Containers on HPC Sy...Singularity: The Inner Workings of Securely Running User Containers on HPC Sy...
Singularity: The Inner Workings of Securely Running User Containers on HPC Sy...inside-BigData.com
 
Architecture diagram of jvm
Architecture diagram of jvmArchitecture diagram of jvm
Architecture diagram of jvmhome
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation ToolIzzet Mustafaiev
 
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...Edureka!
 
Migrating to Java 11
Migrating to Java 11Migrating to Java 11
Migrating to Java 11Arto Santala
 
Hacking Jenkins
Hacking JenkinsHacking Jenkins
Hacking JenkinsMiro Cupak
 
XPDDS18: A dive into kbuild - Cao jin, Fujitsu
XPDDS18: A dive into kbuild - Cao jin, FujitsuXPDDS18: A dive into kbuild - Cao jin, Fujitsu
XPDDS18: A dive into kbuild - Cao jin, FujitsuThe Linux Foundation
 
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiRunning Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiChris Simmonds
 

What's hot (20)

Automotive Grade Linux on Raspberry Pi: How Does It Work?
Automotive Grade Linux on Raspberry Pi: How Does It Work?Automotive Grade Linux on Raspberry Pi: How Does It Work?
Automotive Grade Linux on Raspberry Pi: How Does It Work?
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Deeper dive in Docker Overlay Networks
Deeper dive in Docker Overlay NetworksDeeper dive in Docker Overlay Networks
Deeper dive in Docker Overlay Networks
 
Implementing generic JNI hardware control for Kotlin based app on AOSP
Implementing generic JNI hardware control for Kotlin based app on AOSPImplementing generic JNI hardware control for Kotlin based app on AOSP
Implementing generic JNI hardware control for Kotlin based app on AOSP
 
Singularity: The Inner Workings of Securely Running User Containers on HPC Sy...
Singularity: The Inner Workings of Securely Running User Containers on HPC Sy...Singularity: The Inner Workings of Securely Running User Containers on HPC Sy...
Singularity: The Inner Workings of Securely Running User Containers on HPC Sy...
 
Architecture diagram of jvm
Architecture diagram of jvmArchitecture diagram of jvm
Architecture diagram of jvm
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
 
Spring boot
Spring bootSpring boot
Spring boot
 
Java Spring
Java SpringJava Spring
Java Spring
 
Docker, LinuX Container
Docker, LinuX ContainerDocker, LinuX Container
Docker, LinuX Container
 
Migrating to Java 11
Migrating to Java 11Migrating to Java 11
Migrating to Java 11
 
Hacking Jenkins
Hacking JenkinsHacking Jenkins
Hacking Jenkins
 
XPDDS18: A dive into kbuild - Cao jin, Fujitsu
XPDDS18: A dive into kbuild - Cao jin, FujitsuXPDDS18: A dive into kbuild - Cao jin, Fujitsu
XPDDS18: A dive into kbuild - Cao jin, Fujitsu
 
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiRunning Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
 
Kubernetes
KubernetesKubernetes
Kubernetes
 

Similar to Implementing a LED LightBar solution on Android system

IRJET - Automatic Mechanism for LED Parameters Testing & Checking
IRJET -  	  Automatic Mechanism for LED Parameters Testing & CheckingIRJET -  	  Automatic Mechanism for LED Parameters Testing & Checking
IRJET - Automatic Mechanism for LED Parameters Testing & CheckingIRJET Journal
 
summer training report (2)
summer training report (2)summer training report (2)
summer training report (2)Kavya Gupta
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneDefconRussia
 
Android Things in action
Android Things in actionAndroid Things in action
Android Things in actionStefano Sanna
 
Robot controlled car using Wireless Module
 Robot controlled car using Wireless Module Robot controlled car using Wireless Module
Robot controlled car using Wireless Moduleshreyaseksambe
 
3D Mapping with LiDAR - Report
3D Mapping with LiDAR - Report3D Mapping with LiDAR - Report
3D Mapping with LiDAR - ReportEric Feldman
 
Introducing the Sun SPOTs
Introducing the Sun SPOTsIntroducing the Sun SPOTs
Introducing the Sun SPOTsStefano Sanna
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation Jiann-Fuh Liaw
 
Testing CAN network with help of CANToolz
Testing CAN network with help of CANToolzTesting CAN network with help of CANToolz
Testing CAN network with help of CANToolzAlexey Sintsov
 
dual axis solar tracker.pptx
dual axis solar tracker.pptxdual axis solar tracker.pptx
dual axis solar tracker.pptxraashidnik
 
Da Arduino ad Android_ illumina il Natale con il BLE
Da Arduino ad Android_ illumina il Natale con il BLEDa Arduino ad Android_ illumina il Natale con il BLE
Da Arduino ad Android_ illumina il Natale con il BLEinfogdgmi
 
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹GangSeok Lee
 
Introduction to Test Execution Automation Framework for Embedded Systems
Introduction to Test Execution Automation Framework for Embedded SystemsIntroduction to Test Execution Automation Framework for Embedded Systems
Introduction to Test Execution Automation Framework for Embedded SystemsHiroshiMisawa
 

Similar to Implementing a LED LightBar solution on Android system (20)

Embedded system
Embedded systemEmbedded system
Embedded system
 
IRJET - Automatic Mechanism for LED Parameters Testing & Checking
IRJET -  	  Automatic Mechanism for LED Parameters Testing & CheckingIRJET -  	  Automatic Mechanism for LED Parameters Testing & Checking
IRJET - Automatic Mechanism for LED Parameters Testing & Checking
 
summer training report (2)
summer training report (2)summer training report (2)
summer training report (2)
 
Bidirect visitor counter
Bidirect visitor counterBidirect visitor counter
Bidirect visitor counter
 
Android ndk: Entering the native world
Android ndk: Entering the native worldAndroid ndk: Entering the native world
Android ndk: Entering the native world
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-one
 
Android NDK: Entrando no Mundo Nativo
Android NDK: Entrando no Mundo NativoAndroid NDK: Entrando no Mundo Nativo
Android NDK: Entrando no Mundo Nativo
 
Android Things in action
Android Things in actionAndroid Things in action
Android Things in action
 
Arduino IDE
Arduino IDE Arduino IDE
Arduino IDE
 
Robot controlled car using Wireless Module
 Robot controlled car using Wireless Module Robot controlled car using Wireless Module
Robot controlled car using Wireless Module
 
3D Mapping with LiDAR - Report
3D Mapping with LiDAR - Report3D Mapping with LiDAR - Report
3D Mapping with LiDAR - Report
 
Introducing the Sun SPOTs
Introducing the Sun SPOTsIntroducing the Sun SPOTs
Introducing the Sun SPOTs
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation
 
Testing CAN network with help of CANToolz
Testing CAN network with help of CANToolzTesting CAN network with help of CANToolz
Testing CAN network with help of CANToolz
 
dual axis solar tracker.pptx
dual axis solar tracker.pptxdual axis solar tracker.pptx
dual axis solar tracker.pptx
 
Da Arduino ad Android_ illumina il Natale con il BLE
Da Arduino ad Android_ illumina il Natale con il BLEDa Arduino ad Android_ illumina il Natale con il BLE
Da Arduino ad Android_ illumina il Natale con il BLE
 
Arduino & NodeMcu
Arduino & NodeMcuArduino & NodeMcu
Arduino & NodeMcu
 
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹
 
Introduction to Test Execution Automation Framework for Embedded Systems
Introduction to Test Execution Automation Framework for Embedded SystemsIntroduction to Test Execution Automation Framework for Embedded Systems
Introduction to Test Execution Automation Framework for Embedded Systems
 
Microcontroller project
Microcontroller projectMicrocontroller project
Microcontroller project
 

Recently uploaded

WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 

Recently uploaded (20)

WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 

Implementing a LED LightBar solution on Android system

  • 1. Implementing a LED Light Bar Solution on Android System LC Wang, Wig Cheng 30 July 2023
  • 2. OUTLINE • PART I. System Part (Presented by Wig Cheng) Implementing JNI function in system • PART II. APK Part (Presented by LC Wang) Implementing a demo APK using JNI library
  • 3. PART I. • Me • Motivation • System architecture • AOSP Kernel driver tweaking • LIBUBOOTENV porting • JNI implementation • Summary
  • 4. ME • Name: Wig • Job: IEIWorld - Android OS team • Work #> Embedded Linux platforms #> Industrial Android BSP • GITHUB: https://github.com/wigcheng
  • 7. MOTIVATION • In healthcare use case which need LED color for a patient’s health status. In this case, we'll show you a LED light-bar solution using Android OS.
  • 8. MOTIVATION (CONT'D) Power on APP Sleep (Suspend) Power off System Status Power on Power on Sleep Power off Power LED Off Off Color Blinking default: Blue On/off (Red) default: On User LED Off 1. LED control 2. Wave/Breath mode 3. Sleep/Power off setting Off Off blinking blinking Specifications
  • 9. MOTIVATION (CONT'D) Specifications LED light bar LED light bar Power LED User LED User LED Power LED Platform: - NXP ARM Cortex-A53 IMX8MM Supported OS: - Android 12, Kernel 5.10.72 - Android 13, Kernel 5.15.74
  • 10. SYSTEM ARCHITECTURE Hardware U-boot AOSP Kernel ART JNI Layer APP Layer 1. Enabling LightBar driver with device tree 2. Tweaking driver AOSP 1. libubootenv library porting 2. Checking LED nodes 3. SELINUX 1. Add LightBar related boot argument 1. DesignAPIs for APK 1. Design demo APK
  • 11.  TI TLC59116 LED driver IC  16 channels  via I2C bus  PWM control method  Linux upstream driver  Enable driver in defconfig  Add to device tree  Tweaking driver (later) AOSP KERNEL DRIVER • Normal defconfig <source>/vendor/nxp-opensource /kernel_imx /arch /arm64/configs/iei_imx_android_defconfig • GKI (Google Kernel Image) defconfig <source>/vendor/nxp-opensource /kernel_imx /arch /arm64/configs/imx8mm_gki.fragment CONFIG_LEDS_TLC591XX=m (build as kernel module) master SDA SCL slave 1 slave 2
  • 12. lightbar1: tlc59116_left@60 { #address-cells = <1>; #size-cells = <0>; compatible = "ti,tlc59116"; reg = <0x60>; status = "okay"; out0@0 { label = "i2c2_led_red_00"; reg = <0x0>; }; …..... …..... out14@e { label = "i2c2_led_blue_04"; reg = <0xe>; }; }; I2C device address 0x60 Driver name Link to <kernel source>/drivers/leds/leds-tlc591xx.c static const struct of_device_id of_tlc591xx_leds_match[] = { { .compatible = "ti,tlc59116", .data = &tlc59116 }, {}, }; MODULE_DEVICE_TABLE(of, of_tlc591xx_leds_match); LED-0 node: id = 0x0, node name = "i2c2_led_red_00" device node path: /sys/bus/i2c/drivers/tlc591xx/1-0060/leds/i2c2_led_red_00/brightness LED1 ~ LED13 definition /sys/bus/i2c/drivers/tlc591xx/1-0060/leds/i2c2_led_red_01/brightness /sys/bus/i2c/drivers/tlc591xx/1-0060/leds/i2c2_led_red_02/brightness …. /sys/bus/i2c/drivers/tlc591xx/1-0060/leds/i2c2_led_blue_03/brightness LED-14 /sys/bus/i2c/drivers/tlc591xx/1-0060/leds/i2c2_led_blue_04/brightness Modify device tree
  • 13. AOSP KERNEL DRIVER (CONT.D)  CONFIG_LEDS_TLC591XX → drivers/leds/leds-tlc591xx.c static struct i2c_driver tlc591xx_driver = { .driver = { .name = "tlc591xx", .of_match_table = of_match_ptr(of_tlc591xx_leds_match), .pm = &tlc591xx_pm_ops, }, .probe = tlc591xx_probe, .shutdown = tlc591xx_shutdown, .id_table = tlc591xx_id, }; Add to driver for suspend/resume function add LED blinking behavior to suspend function add clear LED state behavior to resume function static SIMPLE_DEV_PM_OPS(tlc591xx_pm_ops, tlc591xx_suspend, tlc591xx_resume); Add to driver for power-off function add turn on red color for LED to shutdown function Modify driver
  • 14. LIBUBOOTENV PORTING  New tool in 2021 (DENX)  Feature – modify bootargs in rootfs of Linux OS  Port to AOSP  Source path: <source>/external/libubootenv  Add Android.bp (Makefile)  Output file  /vendor/lib64/libubootenv.so (library)  /vendor/bin/fw_printenv (utility)  /vendor/bin/fw_setenv (utility)  /vendor/etc/fw_env.config (config) eMMC address: /dev/block/mmcblk2 0x400000 0x4000 device name offset address env size Tracing U-boot defconfig <u-boot source>/configs/xxx_android_defconfig CONFIG_ENV_SIZE=0x4000 CONFIG_ENV_OFFSET=0x400000
  • 15. JNI IMPLEMENTATION  Implement via C/C++ -> LightBar.cpp  Bridge using CMAKE configuration  API definition  setLightBarUserLED  clearLightBarLED  setLightBarBreathMode  setLightBarWaveMode  setLightBarPowerLedSuspendColor  setLightBarPowerLedPoweroffState  getLightBarPowerLedStatus JAVA Base Kotlin Base LightBar.cpp JniMethod.java MainActivity.java JniMethod.kt MainActivity.kt
  • 16. JNI IMPLEMENTATION (CONT.D)  Implementation flow  User LED controlling  Power LED controlling Open specific LED brightness node /sys/bus/i2c/drivers/tlc591xx/1-0060/leds/i2c<bus>_led_<color>_<number>/brightness /sys/bus/i2c/drivers/tlc591xx/3-0060/leds/i2c<bus>_led_<color>_<number>/brightness read/write brightness node close brightness node Adapt fw_setenv command popenAPI pclose Adapt fw_printenv command Suspend argument: leds.suspend_color="<color>" support color list: red, green, blue (default), yellow, cyan, magenta, white Power-off argument: leds.poweroff_state="<status>" support state list: on, off
  • 17. U-boot environment arguments 1. Save to eMMC specific address 2. Add power LED relate argument SUMMARY Kernel driver (as a module) 1. Load power LED arguemnt from u-boot arguments 2. Initial drivers with specific functions libubootenv 1. Load power LED arguemnt from u-boot arguments in ART stage 2. Set power LED argument to u-boot environment (need reboot) Implement JNIAPI to APK development
  • 18. PART II.  Me  App architecture  App java design  App JNI design  SELinux  Troubleshooting
  • 19. ME • Name: LC • Job: IEIWorld - Android software engineer • GITHUB: https://github.com/lc-wang
  • 25. APP JNI DESIGN package name_Java file_name_function name
  • 27. APP POWER LED Power Suspend Power Off
  • 28. SELINUX Linux DAC DAC: Discretionary Access Control directory read write execute Owner Group Other uid gid
  • 29. SELINUX User process makes a system call system call DAC check LSM check User space Kernel space LSM: Linux Security Module
  • 30. SELINUX Command: ls –lZ / ps -lZ drwxr-xr-x 15 root root u:object_r:system_file:s0 330 2023-07-13 10:01 system SELinux user role domain Multi-Level Security
  • 31. SELINUX allow system_app system_app_data_file:notdevfile_class_set rw_file_perms; File: system_app.te rule source type (domain) target type (domain) class perm_set
  • 32. SELINUX Ligtbar fw_setenv /dev/block/mmcblk2 system app vendor_file block_device_file process/file domain
  • 33. SELINUX Ligtbar fw_setenv /dev/block/mmcblk2 system_app vendor_file block_device_file allow system_app system_app_data_file:notdevfile_class_set rw_file_perms; allow system_app cache_recovery_file:dir { search write add_name }; … allow system_app vendor_file:file {read write}; allow vendor_file block_device_file:blk_file {read write};
  • 34. SELINUX Ligtbar fw_setenv /dev/block/mmcblk2 File: {AOSP root}/system/sepolicy/public/domain.te neverallow neverallow system_app vendor_file block_device_file
  • 35. SELINUX File: system_app.te allow system_app system_app_data_file:notdevfile_class_set rw_file_perms; allow system_app cache_recovery_file:dir { search write add_name }; … permissive system_app; Ligtbar fw_setenv /dev/block/mmcblk2 system_app vendor_file block_device_file
  • 36. TROUBLESHOOTING allow system_app system_app_data_file:notdevfile_class_set rw_file_perms; allow system_app cache_recovery_file:dir { search write add_name }; … permissive system_app; Breaking the Android rule, it causes CTS/VTS cases fail ! ! !
  • 37. SUMMARY • App UI • App JNI • How to solve SELINUX Issue
  • 38. OPEN SOURCE  Light bar JNI SDK instruction https://github.com/ieiARMCommunity/lightbar_sdk_aosp  Light bar demo APK source code https://github.com/QNAP-android-internal/IEI-AndroidLightBar