/\___/\
   /       \
  l  u   u  l
--l----*----l--      _   _ _                      _           _             
   \   w   /        | |_(_) |_ ____ __  __ _ _ _ ( )___  _ __| |__ _ __ ___ 
     ======         | / / |  _|_ / '  \/ _` | ' \|/(_-< | '_ \ / _` / _/ -_)
   /       \ __     |_\_\_|\__/__|_|_|_\__,_|_||_| /__/ | .__/_\__,_\__\___|
   l        l\ \                                        |_|                 
   l        l/ /
   l  l l   l /
   \ ml lm /_/
	
kitzman's place

Android for IoT

embedded linux

Introduction

So…

My previous attempt to use pmOS was not so successful… … probably due to lack of vendor libraries which would require the native Android libc, lack of set properties, and daemons I’d have to compile in order to use, let’s say, the GSM network.

So I decided to give Android a try, as a general-purpose IoT operating system ^^.

Last time I saw it in the wild, for the same usage, was for ODroid. Apparently a project called “Android Things” existed - a library/OS extension for devices - but was discontinued as of 5th Jan 2022.

				  .
     .              .   .'.     \   /
   \   /      .'. .' '.'   '  -=  o  =-
 -=  o  =-  .'   '              / | \
   / | \                          |
     |                            |
     |                            |
     |                      .=====|
     |=====.                |.---.|
     |.---.|                ||=o=||
     ||=o=||                ||   ||
     ||   ||                ||   ||
     ||   ||                ||___||
     ||___||                |[:::]|
jgs  |[:::]|                '-----'
     '-----'

   __      __    __   __         ___              __              _        __
  / /___  / /_  / /_ / /  ___   / _/__ __ ___    / /  ___  ___ _ (_)___   / /
 / // -_)/ __/ / __// _ \/ -_) / _// // // _ \  / _ \/ -_)/ _ `// // _ \ /_/ 
/_/ \__/ \__/  \__//_//_/\__/ /_/  \_,_//_//_/ /_.__/\__/ \_, //_//_//_/(_)  
							 /___/               

Motivation

Great things are gonna happen!

One of the things I want to do is to customize AOSP/LineageOS for ultra-low battery consumption. That does not only mean powering off most devices, but also suspending the system and waking it up after intervals of time. I will triangulate GSM and Radio, use it for an SIP network, etc.

Another motivation is using my knowledge to make network unlocking easier (see my other posts).

The Beginning of my Android journey

The device I’m trying to use, is an old, scarred, HTC M7.

First step was to discover an unofficial, maintained version of LineageOS. XDA Develpers to the rescue!

The LineageOS wiki is pretty well documented. Pulling the code took approximately ˜36 hours.

Everything that was left was to add the unofficial repos - the Manifest format is XML, so after skimming few times through other XMLs and the documentation, creating a local manifest was quite easy.

Building it takes ˜45 minutes, on a 12-core computer, using 50GB of ccache.

As I ran it the first time, of course I noticed some bugs™. Running adb logcat luckily worked, and I piped it through my script [1] that sends it to a syslog-ng RFC5242 port (which then sends it to Promtail, Loki and finally Grafana).

First Changes

After noticing nothing really works, and getting a lot of permission denied messages, my first instinct was to set SELinux to permissive. Which obviously worked. And after few minutes of looking around, I found where to change the CMDLINE as well. :)

Future Points

For using it an IoT device, I’ve set the following requirements:

  • disable Logcat & ADB on boot
  • don’t power on the USB
  • don’t power on most of the devices (Wifi, Bluetooth, GSM)
  • disable the LEDs/GPIOs (both during normal and recovery operation)
  • disable the screen (on power on)
  • test and set up suspending to RAM (and possibly, disk), and wake-up
  • create a service/app to read a REST MQ and handle those devices
  • remove most pre-installed apps

Appendix

[1] https://git.disroot.org/kitzman/logcat2sys