Introduction: Diving Deep into Android Things Customization
Android Things, Google’s embedded operating system for IoT devices, brought the familiarity of Android development to a new frontier of hardware. While Google officially wound down support, countless existing devices and custom projects continue to leverage its robust framework. For developers and enthusiasts looking to truly own their device’s behavior, the ability to unpack, modify, and repackage pre-built Android Things system images is an indispensable skill. This guide will walk you through the advanced techniques required to achieve expert-level customization, transforming a closed system into an open canvas.
From adjusting system properties to injecting custom applications or services, understanding the anatomy of an Android Things system image empowers you to adapt devices for highly specific industrial IoT, automotive, or smart home applications. We’ll cover the tools, the process, and the critical steps to ensure your modifications are successful and your custom images are flashable.
Prerequisites and Essential Tools
Before embarking on this reverse engineering journey, ensure you have the following:
- Linux Environment: A Linux distribution (Ubuntu, Debian, Fedora, etc.) is highly recommended, as many tools are native to or function best within this environment.
- ADB and Fastboot: Android Debug Bridge and Fastboot tools are crucial for interacting with your Android Things device and flashing images. Ensure they are installed and in your system’s PATH.
- Image Conversion Utilities: Tools like
simg2img(for sparse to raw image conversion) andimg2simg(for raw to sparse) are vital. These are often found in Android AOSP build tools or can be compiled from source. - Filesystem Utilities:
mount,mkfs.ext4, ande2fsckare standard Linux utilities for managing filesystems. - Text Editor: A capable text editor (e.g., Vim, Nano, VS Code) for modifying configuration files.
Setting Up Your Environment
Ensure ADB and Fastboot are installed. On Ubuntu, you can install them via:
sudo apt update
sudo apt install android-sdk-platform-tools
For simg2img and img2simg, you might need to build them from AOSP source or find pre-compiled binaries. If building, navigate to the AOSP source root and run:
source build/envsetup.sh
mmm system/core/libsparse/simg2img
mmm system/core/libsparse/img2simg
The binaries will be found in out/host/linux-x86/bin/.
Step 1: Acquiring and Preparing the System Image
The first step is to obtain the Android Things system image you wish to modify. This typically comes as a zipped archive containing several .img files (e.g., boot.img, system.img, vendor.img, userdata.img). These images are often in a ‘sparse’ format, optimized for storage and flashing, but not directly mountable.
Converting Sparse to Raw Image
We’ll focus on modifying system.img, which contains the core Android OS. First, convert it from sparse to a raw, mountable image:
simg2img system.img system.raw.img
This command creates a new file, system.raw.img, which is a full, non-sparse image of the system partition.
Step 2: Mounting and Exploring the File System
With system.raw.img, we can now mount it to a temporary directory to explore and modify its contents. Create a mount point:
mkdir -p ~/android_things_root/system
Now, mount the raw image:
sudo mount -o loop system.raw.img ~/android_things_root/system
You can now navigate into ~/android_things_root/system and browse the complete file structure of the Android Things system partition. You’ll find directories like app, priv-app, bin, etc, lib, and more.
Important Note: While you can modify files directly within this mounted image, it’s safer and more flexible to copy the contents to a new directory, modify them there, and then rebuild the image from scratch. This allows for size adjustments without complex filesystem resizing.
mkdir -p ~/android_things_modified_root/system
sudo cp -a ~/android_things_root/system/* ~/android_things_modified_root/system/
Once copied, unmount the original image:
sudo umount ~/android_things_root/system
Step 3: Performing Modifications
Now, all your modifications will happen within ~/android_things_modified_root/system. Here are some common and powerful modifications:
1. Modifying System Properties (build.prop)
The build.prop file (located at ~/android_things_modified_root/system/build.prop) contains critical system properties. You can edit this file to change device name, default settings, and more. For example, to enable ADB over Wi-Fi by default:
sudo nano ~/android_things_modified_root/system/build.prop
Add or modify lines like:
# Enable ADB over Wi-Fi
persist.adb.tcp_enable=1
service.adb.tcp.port=5555
Be cautious when modifying build.prop, as incorrect entries can lead to boot loops.
2. Adding or Removing Applications (APKs)
Pre-installing applications is a common requirement for custom devices. You can add your own APKs or remove unwanted ones. Standard user apps go into /system/app, while privileged system apps (requiring system permissions) go into /system/priv-app.
To add an APK:
sudo cp /path/to/your_app.apk ~/android_things_modified_root/system/app/your_app/
sudo chmod 644 ~/android_things_modified_root/system/app/your_app/your_app.apk
Remember to create a subdirectory for the APK (e.g., your_app/) and set appropriate permissions.
3. Injecting Custom Scripts or Services
You can add custom shell scripts or init services. For scripts, place them in /system/bin or /system/etc/init.d (if your system supports init.d scripts) and ensure they are executable:
sudo cp /path/to/my_custom_script.sh ~/android_things_modified_root/system/bin/
sudo chmod 755 ~/android_things_modified_root/system/bin/my_custom_script.sh
For more complex services, you might need to create or modify an .rc file in /system/etc/init. This requires a deeper understanding of Android’s init process.
Step 4: Repackaging the System Image
Once all modifications are complete, you need to rebuild the system.img from your modified directory.
Calculating Image Size and Rebuilding
First, determine the size of your modified system directory. This will help you decide the minimum size for your new image.
du -sh ~/android_things_modified_root/system
Now, use make_ext4fs (often found in AOSP build tools or pre-compiled) to create a new raw system.img. You’ll need to specify a size slightly larger than your current usage to allow for future updates or small additions. For example, if your directory is 800MB, specify 1GB (1073741824 bytes).
make_ext4fs -s -l 1073741824 -a system -L system ~/android_things_modified_root/system_new.img ~/android_things_modified_root/system
-s: Create a sparse image (though we’ll make it raw first).-l: Specify the size of the image in bytes.-a system: Specifies the mount point name (/system) within the image.-L system: Specifies the filesystem label.~/android_things_modified_root/system_new.img: The output path for the new raw image.~/android_things_modified_root/system: The source directory containing your modified files.
Note: If make_ext4fs isn’t readily available, you can create an empty ext4 filesystem and then copy files into it, but make_ext4fs is more direct for creating a system image from a directory.
Converting Back to Sparse (if required)
Many flashing tools prefer sparse images. If your newly created system_new.img is raw, you might need to convert it:
img2simg ~/android_things_modified_root/system_new.img ~/android_things_modified_root/system.img
This creates the final flashable sparse image: system.img.
Step 5: Flashing and Testing Your Custom Image
With your custom system.img ready, you can now flash it to your Android Things device using Fastboot. Ensure your device is in Fastboot mode.
fastboot flash system ~/android_things_modified_root/system.img
fastboot reboot
After flashing, the device will reboot. Monitor its boot process and verify your modifications. Connect via ADB to check logs (adb logcat) or explore the filesystem (adb shell) to confirm your changes are present and functional.
Conclusion
Reverse engineering and customizing Android Things system images is a powerful technique that unlocks the full potential of your IoT devices. By understanding how to unpack, modify, and repackage these images, you gain granular control over the operating system, allowing for deep integration, specialized functionalities, and a truly tailored user experience. While the official journey for Android Things may have ended, your ability to innovate and adapt with it has just begun.
Android Mobile Specs & Compare Directory
Are you researching mobile hardware properties, processor SoCs, GPU chipsets, or RAM configurations? Access our complete specs catalog to compare up to 5 devices side-by-side!
Compare Devices Specs →