Android IoT, Automotive, & Smart TV Customizations

Hacking AAOS Settings: Adding Custom Preference Categories and Screens to System UI

Google AdSense Native Placement - Horizontal Top-Post banner

Introduction: Customizing AAOS Settings for Automotive Excellence

Android Automotive OS (AAOS) provides a powerful, flexible platform for in-vehicle infotainment systems. For automotive OEMs and Tier 1 suppliers, the ability to deeply customize the system UI and integrate vehicle-specific settings is paramount. This guide delves into the advanced topic of extending the core AAOS Settings application, demonstrating how to add your own custom preference categories and screens. By the end, you’ll understand the underlying architecture and gain the practical knowledge to tailor the in-car user experience to your exact specifications.

While AOSP provides a robust foundation, integrating unique vehicle features, diagnostic tools, or brand-specific configurations often requires modifying the system settings. This tutorial assumes you have a working AAOS AOSP build environment and familiarity with Android development concepts.

Understanding the AAOS Settings Application Structure

The AAOS Settings application, located primarily in packages/apps/Settings within the AOSP tree, is built upon the standard Android Preference framework. It leverages PreferenceFragmentCompat to display hierarchical settings, defined primarily through XML resources. Key components include:

  • SettingsActivity.java: The main entry point, responsible for displaying top-level preference headers.
  • PreferenceFragmentCompat: Base class for fragments that display a preference hierarchy from XML. Each settings screen typically corresponds to one of these fragments.
  • res/xml/: Directory containing XML files that define the structure and content of preference screens. Examples include settings_headers.xml (for top-level categories) and various specific preference screen definitions (e.g., security_settings.xml).
  • AndroidManifest.xml: Defines the activities, services, and permissions for the Settings application. Crucially, it declares the fragments and their associated metadata.

Step 1: Setting Up Your Development Environment

Before proceeding, ensure your AAOS AOSP build environment is correctly set up. You’ll need to sync the AOSP source code, build it successfully, and be able to flash it to a compatible device or emulator. Navigate to the Settings application directory:

cd <AOSP_ROOT>/packages/apps/Settings

Step 2: Creating a New Custom Preference Fragment

The first step is to define the actual screen containing your custom preferences. This involves creating both a Java class for the fragment and an XML layout for its preferences.

2.1 Define the Preference XML

Create a new XML file in res/xml/, for example, my_custom_settings.xml. This file will contain your specific settings. For demonstration, we’ll add a simple checkbox preference and a static text preference.

<?xml version="1.0" encoding="utf-8"?><PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"    android:title="My Custom Settings">    <SwitchPreferenceCompat        android:key="enable_custom_feature"        android:title="Enable Awesome Feature"        android:summary="Toggle to enable or disable my custom feature"        android:defaultValue="false" />    <Preference        android:key="feature_info"        android:title="Feature Information"        android:summary="This is a read-only setting providing details.">        <intent android:action="android.intent.action.VIEW"                android:data="https://www.example.com/custom_info" />    </Preference></PreferenceScreen>

2.2 Implement the Preference Fragment

Next, create a Java class that extends PreferenceFragmentCompat. This class will inflate your XML and handle any logic for the preferences.

Create a new file, e.g., src/com/android/settings/mycustom/MyCustomSettingsFragment.java.

package com.android.settings.mycustom;import android.os.Bundle;import com.android.settings.R;import com.android.settings.SettingsPreferenceFragment;import com.android.settingslib.core.AbstractPreferenceController;import java.util.ArrayList;import java.util.List;public class MyCustomSettingsFragment extends SettingsPreferenceFragment {    private static final String TAG = "MyCustomSettingsFragment";    @Override    public int getMetricsCategory() {        return com.android.settings.dashboard.DashboardFragment.METRICS_CATEGORY_UNKNOWN; // Or define your own    }    @Override    protected int getPreferenceScreenResId() {        return R.xml.my_custom_settings;    }    @Override    protected List<AbstractPreferenceController> createPreferenceControllers(android.content.Context context) {        return new ArrayList<>(); // No custom controllers for this simple example    }    @Override    public void onCreate(Bundle icicle) {        super.onCreate(icicle);        // Any additional setup or logic for your preferences can go here        // Example: Find a preference and set a listener        // SwitchPreferenceCompat mySwitch = findPreference("enable_custom_feature");        // if (mySwitch != null) {        //     mySwitch.setOnPreferenceChangeListener((preference, newValue) -> {        //         Log.d(TAG, "Custom feature enabled: " + (Boolean) newValue);        //         return true;        //     });        // }    }}

Step 3: Integrating the New Fragment into a Category

Now that you have your fragment, you need to make it accessible from the Settings UI. The simplest way is to add it as an item within an existing preference category.

3.1 Modifying settings_headers.xml

The top-level categories in AAOS Settings are defined in res/xml/settings_headers.xml. To add your custom screen as a new top-level entry, you’d add a <header> element. For example, to add it under the ‘Connected Devices’ section, you might find the relevant XML for that section, or more generally, add it to the main headers file:

<!-- In packages/apps/Settings/res/xml/settings_headers.xml --><header    android:id="@id/my_custom_settings_header"    android:fragment="com.android.settings.mycustom.MyCustomSettingsFragment"    android:icon="@drawable/ic_settings_bluetooth" <!-- Use an existing icon or create your own -->    android:title="@string/my_custom_settings_title"    android:summary="@string/my_custom_settings_summary" />

You’ll also need to define the string resources my_custom_settings_title and my_custom_settings_summary in res/values/strings.xml:

<!-- In packages/apps/Settings/res/values/strings.xml --><string name="my_custom_settings_title">My Vehicle Settings</string><string name="my_custom_settings_summary">Configure vehicle-specific features and functions</string>

Alternative: Adding to an Existing Sub-Category

If you want to place your custom screen deeper, say within the ‘Display’ settings, you’d modify display_settings.xml (or the relevant XML for that sub-category) to include a <Preference> tag with an intent pointing to your fragment.

<!-- Example: In display_settings.xml or similar --><Preference    android:key="my_feature_entry"    android:title="My Advanced Display Feature"    android:summary="Adjust specific display settings">    <intent android:action="android.intent.action.MAIN"            android:targetPackage="com.android.settings"            android:targetClass="com.android.settings.Settings$MyCustomSettingsFragmentActivity" /></Preference>

Note that if you use targetClass directly, you’d need to define a host activity for your fragment, or directly target SettingsActivity with EXTRA_SHOW_FRAGMENT. The android:fragment attribute in settings_headers.xml is the simpler approach for top-level entries.

Step 4: Building and Deploying Your Changes

After making these modifications, you need to rebuild the Settings application and deploy it to your AAOS device or emulator.

4.1 Rebuild Settings

From your AOSP root directory, run:

source build/envsetup.shlunch <your_product_name>-userdebug # e.g., car_x86_64-userdebugm Settings # Build only the Settings app

4.2 Push to Device

Once the build is complete, you’ll find the new Settings.apk in out/target/product/<your_product_name>/system/priv-app/Settings/. You can push it to your device using ADB:

adb rootadb remountadb push out/target/product/<your_product_name>/system/priv-app/Settings/Settings.apk /system/priv-app/Settings/Settings.apkadb reboot # Or restart the Settings process

After the device reboots, navigate to the Settings application, and you should see your new

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 →
Google AdSense Inline Placement - Content Footer banner