SlideShare a Scribd company logo
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

젠킨스 설치 및 설정
젠킨스 설치 및 설정젠킨스 설치 및 설정
젠킨스 설치 및 설정
중선 곽
 
Exploring Next Generation Buildpacks - Anand Rao & Scott Deeg
Exploring Next Generation Buildpacks - Anand Rao & Scott DeegExploring Next Generation Buildpacks - Anand Rao & Scott Deeg
Exploring Next Generation Buildpacks - Anand Rao & Scott Deeg
VMware Tanzu
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
Houcheng Lin
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
National Cheng Kung University
 
ADB(Android Debug Bridge): How it works?
ADB(Android Debug Bridge): How it works?ADB(Android Debug Bridge): How it works?
ADB(Android Debug Bridge): How it works?
Tetsuyuki Kobayashi
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting Sequence
Jayanta Ghoshal
 
Root file system
Root file systemRoot file system
Root file system
Bindu U
 
Android crash debugging
Android crash debuggingAndroid crash debugging
Android crash debugging
Ashish Agrawal
 
Android Automotive
Android AutomotiveAndroid Automotive
Android Automotive
Opersys inc.
 
Customizing AOSP For Different Embedded Devices And Integration at Applicatio...
Customizing AOSP For Different Embedded Devices And Integration at Applicatio...Customizing AOSP For Different Embedded Devices And Integration at Applicatio...
Customizing AOSP For Different Embedded Devices And Integration at Applicatio...
ijafrc
 
Linux Porting to a Custom Board
Linux Porting to a Custom BoardLinux Porting to a Custom Board
Linux Porting to a Custom Board
Patrick Bellasi
 
Jenkins CI presentation
Jenkins CI presentationJenkins CI presentation
Jenkins CI presentation
Jonathan Holloway
 
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
Chris Simmonds
 
Improve Android System Component Performance
Improve Android System Component PerformanceImprove Android System Component Performance
Improve Android System Component Performance
National Cheng Kung University
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Bin Chen
 
淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道 淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道
National Cheng Kung University
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
Utkarsh Mankad
 
Android internals 07 - Android graphics (rev_1.1)
Android internals 07 - Android graphics (rev_1.1)Android internals 07 - Android graphics (rev_1.1)
Android internals 07 - Android graphics (rev_1.1)
Egor Elizarov
 
Android Binder IPC for Linux
Android Binder IPC for LinuxAndroid Binder IPC for Linux
Android Binder IPC for Linux
Yu-Hsin Hung
 
How Jenkins Builds the Netflix Global Streaming Service
How Jenkins Builds the Netflix Global Streaming ServiceHow Jenkins Builds the Netflix Global Streaming Service
How Jenkins Builds the Netflix Global Streaming Service
Gareth Bowles
 

What's hot (20)

젠킨스 설치 및 설정
젠킨스 설치 및 설정젠킨스 설치 및 설정
젠킨스 설치 및 설정
 
Exploring Next Generation Buildpacks - Anand Rao & Scott Deeg
Exploring Next Generation Buildpacks - Anand Rao & Scott DeegExploring Next Generation Buildpacks - Anand Rao & Scott Deeg
Exploring Next Generation Buildpacks - Anand Rao & Scott Deeg
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
ADB(Android Debug Bridge): How it works?
ADB(Android Debug Bridge): How it works?ADB(Android Debug Bridge): How it works?
ADB(Android Debug Bridge): How it works?
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting Sequence
 
Root file system
Root file systemRoot file system
Root file system
 
Android crash debugging
Android crash debuggingAndroid crash debugging
Android crash debugging
 
Android Automotive
Android AutomotiveAndroid Automotive
Android Automotive
 
Customizing AOSP For Different Embedded Devices And Integration at Applicatio...
Customizing AOSP For Different Embedded Devices And Integration at Applicatio...Customizing AOSP For Different Embedded Devices And Integration at Applicatio...
Customizing AOSP For Different Embedded Devices And Integration at Applicatio...
 
Linux Porting to a Custom Board
Linux Porting to a Custom BoardLinux Porting to a Custom Board
Linux Porting to a Custom Board
 
Jenkins CI presentation
Jenkins CI presentationJenkins CI presentation
Jenkins CI presentation
 
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
 
Improve Android System Component Performance
Improve Android System Component PerformanceImprove Android System Component Performance
Improve Android System Component Performance
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
 
淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道 淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
 
Android internals 07 - Android graphics (rev_1.1)
Android internals 07 - Android graphics (rev_1.1)Android internals 07 - Android graphics (rev_1.1)
Android internals 07 - Android graphics (rev_1.1)
 
Android Binder IPC for Linux
Android Binder IPC for LinuxAndroid Binder IPC for Linux
Android Binder IPC for Linux
 
How Jenkins Builds the Netflix Global Streaming Service
How Jenkins Builds the Netflix Global Streaming ServiceHow Jenkins Builds the Netflix Global Streaming Service
How Jenkins Builds the Netflix Global Streaming Service
 

Similar to Implementing a LED LightBar solution on Android system

Embedded system
Embedded systemEmbedded system
Embedded system
VishwasJangra
 
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
IRJET Journal
 
summer training report (2)
summer training report (2)summer training report (2)
summer training report (2)
Kavya Gupta
 
Bidirect visitor counter
Bidirect visitor counterBidirect visitor counter
Bidirect visitor counter
Electric&elctronics&engineeering
 
Lab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docxLab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docx
RashidFaridChishti
 
Android ndk: Entering the native world
Android ndk: Entering the native worldAndroid ndk: Entering the native world
Android ndk: Entering the native world
Eduardo Carrara de Araujo
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-one
DefconRussia
 
Android NDK: Entrando no Mundo Nativo
Android NDK: Entrando no Mundo NativoAndroid NDK: Entrando no Mundo Nativo
Android NDK: Entrando no Mundo Nativo
Eduardo Carrara de Araujo
 
Android Things in action
Android Things in actionAndroid Things in action
Android Things in action
Stefano Sanna
 
Arduino IDE
Arduino IDE Arduino IDE
Arduino IDE
Mrunal Deshkar
 
Robot controlled car using Wireless Module
 Robot controlled car using Wireless Module Robot controlled car using Wireless Module
Robot controlled car using Wireless Module
shreyaseksambe
 
3D Mapping with LiDAR - Report
3D Mapping with LiDAR - Report3D Mapping with LiDAR - Report
3D Mapping with LiDAR - Report
Eric Feldman
 
Introducing the Sun SPOTs
Introducing the Sun SPOTsIntroducing the Sun SPOTs
Introducing the Sun SPOTs
Stefano 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 CANToolz
Alexey Sintsov
 
dual axis solar tracker.pptx
dual axis solar tracker.pptxdual axis solar tracker.pptx
dual axis solar tracker.pptx
raashidnik
 
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
infogdgmi
 
Arduino & NodeMcu
Arduino & NodeMcuArduino & NodeMcu
Arduino & NodeMcu
Guhan Ganesan
 
[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 Systems
HiroshiMisawa
 

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
 
Lab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docxLab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docx
 
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
 

Recently uploaded

E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 

Recently uploaded (20)

E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 

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