Troubleshoot runtime resource overlays

Use this content to troubleshoot why a runtime resource overlay (RRO) might not be functioning as intended in an Android Automotive implementation.

To learn more about RROs in Android, see Change the value of an app's resources at runtime. Be sure to maintain a constant vigilance on logcat output, which can provide good information about what is happening throughout the process.

Step 1: List the RROs

To list the RROs:

  1. Run the following command:

    adb shell cmd overlay list --user current
    

    Output like this appears:

    com.android.systemui
    [ ] com.android.theme.icon_pack.rounded.systemui
    [ ] com.android.theme.icon_pack.filled.systemui
    [ ] com.android.theme.icon_pack.circular.systemui
    
    com.android.permissioncontroller
    --- com.android.permissioncontroller.googlecarui.rro
    
  2. Verify that your RRO appears in the list. The following indicators denote RRO status:

    Indicator RRO status
    [ ] Installed and ready to be activated.
    [X] Installed and activated.
    --- Installed but contains errors.

    If your RRO isn't listed under the package name of the target you want to overlay, your RRO isn't installed.

Step 2: Enable and disable an RRO

If an RRO is installed:

  1. Use the following command to enable (or disable) the RRO:

    adb shell cmd overlay [enable/disable] --user current [your RRO package name]
    

Step 3: Confirm RRO is installed

To confirm an RRO is installed on a device or troubleshoot why the RRO wasn't enabled:

  1. Run the following command:

    adb shell cmd overlay dump [your RRO package name]
    

    Output such as the following appears:

    com.android.car.rotaryplayground.googlecarui.rro:0 {
      mPackageName...........: com.android.car.rotaryplayground.googlecarui.rro
      mUserId................: 0
      mTargetPackageName.....: com.android.car.rotaryplayground
      mTargetOverlayableName.: car-ui-lib
      mBaseCodePath..........: /product/overlay/googlecarui-com-android-car-rotaryplayground/googlecarui-com-android-car-rotaryplayground.apk
      mState.................: STATE_MISSING_TARGET
      mIsEnabled.............: true
      mIsMutable.............: true
      mPriority..............: 10
      mCategory..............: BypassIdMapV1
    }
    com.android.car.rotaryplayground.googlecarui.rro:10 {
      mPackageName...........: com.android.car.rotaryplayground.googlecarui.rro
      mUserId................: 10
      mTargetPackageName.....: com.android.car.rotaryplayground
      mTargetOverlayableName.: car-ui-lib
      mBaseCodePath..........: /product/overlay/googlecarui-com-android-car-rotaryplayground/googlecarui-com-android-car-rotaryplayground.apk
      mState.................: STATE_MISSING_TARGET
      mIsEnabled.............: true
      mIsMutable.............: true
      mPriority..............: 10
      mCategory..............: BypassIdMapV1
    }
    
  2. Identify the user (or users) who installed the RRO. In the previous example, the RRO is available for user 0 and user10 (see the values for mUserId in the top code block).

  3. To enable (or disable) the RRO for a user, go to Step 2.

  4. To check the value of mState:

    • STATE_ENABLED and STATE_ENABLED_IMMUTABLE. The RRO is enabled and applied to your target.

    • STATE_MISSING_TARGET. Your target isn't installed.

    • STATE_NO_IDMAP. Something is wrong with the way the AndroidManifest.xml, overlays.xml, or overlayable.xml files are set up. Use adb logcat to run the logs and search for the keyword idmap to identify the error. See steps 4 & 5.

    • STATE_UNKNOWN. Something is wrong with OverlayManagerService.

Step 4: Check AndroidManifest.xml

To verify AndroidManifest.xml:

  1. Check targetName and targetPackage.

    android:targetName should have the same value of the overlayable group defined in the target app. This is required only when targeting an overlay.

    android:targetPackage is always required and should contain the package name of the target app.

  2. Check that your RRO is static (or not). Static RROs are enabled by default at boot time. Dynamic RROs aren't enabled by default at boot. Additional ways of enabling dynamic RROs are provided in Change the value of an app's resources at runtime.

  3. Check the priority of your static RRO (dynamic RRO priority is always set to Integer.MAX_VALUE and the order in which they're applied is based on when they're enabled).

    Multiple RROs can apply to the same target. RROs with a higher priority are applied last. On a scale of 0 to 10, 10 is highest and 0 is lowest.

Step 5: Check overlays.xml

  1. Check overlays.xml to confirm all resources you intend to overlay are defined in this file. For example, consider the followingoverlays.xml:

    <overlay>
        <item target="string/app_name" value="@string/overlaid_app_name" />
    </overlay>
    
  2. You must ensure that a:

    • string resource with the name app_name exists in the target app.
    • string resource with the name overlaid_app_name exists in your RRO.
  3. If your target has an overlayable.xml file, make sure app_name is contained in that file. Make sure you use the correct targetName in your AndroidManifest.xml file (Step 4).

    For example:

    <overlay>
    <item target="layout/car_ui_base_layout_toolbar" value="@layout/car_ui_base_layout_toolbar" />
    <item target="id/car_ui_toolbar_background" value="@id/car_ui_toolbar_background" />
    <item target="attr/layout_constraintTop_toBottomOf" value="@attr/layout_constraintTop_toBottomOf" />
    </overlay>
    

Step 6: Dump the idmap

At this stage, all issues with your RRO should be resolved. Next, dump the idmap of your RRO to learn how a resource is being resolved and why it's resolving to a different value than you expect.

  1. To find the path to the idmap on your device:

    adb shell
    su
    ls data/resource-cache
    
  2. To dump the contents of that file:

    adb root
    adb shell idmap2 dump --idmap-path [path to your RRO idmap file]
    

    Example:

    adb shell idmap2 dump --idmap-path data/resource-cache/system@app@CarUiPortraitLauncherReferenceRRO@CarUiPortraitLauncherReferenceRRO.apk@idmap
    

    The output appears similar to the following. The output displays which ID from your RRO is mapped to which ID in your target as well as the name of the overlaid resource.

    target apk path : /system/priv-app/CarMediaApp/CarMediaApp.apk
    overlay apk path : /product/overlay/googlecarui-com-android-car-media/googlecarui-com-android-car-media.apk
    0x7f040008 -> 0x7f010000 bool/car_ui_toolbar_logo_fills_nav_icon_space
    0x7f040009 -> 0x7f010001 bool/car_ui_toolbar_nav_icon_reserve_space
    0x7f04000b -> 0x7f010002 bool/car_ui_toolbar_tab_flexible_layout
    0x7f04000c -> 0x7f010003 bool/car_ui_toolbar_tabs_on_second_row
    0x7f09006c -> 0x7f020000 id/car_ui_base_layout_content_container
    0x7f090073 -> 0x7f020001 id/car_ui_recycler_view
    0x7f090074 -> 0x7f020002 id/car_ui_scroll_bar
    0x7f090075 -> 0x7f020003 id/car_ui_scrollbar_page_down
    0x7f090076 -> 0x7f020004 id/car_ui_scrollbar_page_up
    0x7f090077 -> 0x7f020005 id/car_ui_scrollbar_thumb
    0x7f090078 -> 0x7f020006 id/car_ui_scrollbar_track
    0x7f09007a -> 0x7f020007 id/car_ui_toolbar_background
    0x7f09007e -> 0x7f020008 id/car_ui_toolbar_logo
    0x7f090084 -> 0x7f020009 id/car_ui_toolbar_menu_items_container
    0x7f090085 -> 0x7f02000a id/car_ui_toolbar_nav_icon
    0x7f090086 -> 0x7f02000b id/car_ui_toolbar_nav_icon_container
    0x7f090087 -> 0x7f02000c id/car_ui_toolbar_progress_bar
    0x7f090089 -> 0x7f02000d id/car_ui_toolbar_row_separator_guideline
    0x7f09008d -> 0x7f02000e id/car_ui_toolbar_search_view_container
    0x7f09008f -> 0x7f02000f id/car_ui_toolbar_subtitle
    0x7f090092 -> 0x7f020010 id/car_ui_toolbar_tabs
    0x7f090093 -> 0x7f020011 id/car_ui_toolbar_title
    0x7f090094 -> 0x7f020012 id/car_ui_toolbar_title_container
    0x7f090095 -> 0x7f020013 id/car_ui_toolbar_title_logo
    0x7f090096 -> 0x7f020014 id/car_ui_toolbar_title_logo_container
    0x7f0c0024 -> 0x7f030000 layout/car_ui_base_layout_toolbar
    0x7f0c0035 -> 0x7f030001 layout/car_ui_recycler_view
    0x7f0c0038 -> 0x7f030002 layout/car_ui_toolbar
    0x7f0c003f -> 0x7f030003 layout/car_ui_toolbar_two_row
    

Use the following command to look up a specific resource to see how they're mapped:

adb shell cmd overlay lookup --verbose --user 10 com.android.car.ui.paintbooth com.android.car.ui.paintbooth:color/widget_background

The output is the final value of the resource:

#ff7986cb

You can also dump your layout files from your apks to view the resolved IDs to match the above output:

aapt2 dump xmltree $OUT/system/priv-app/sharedlibraryclient/sharedlibraryclient.apk --file res/layout/activity_main.xml

Output such as the following is returned:

N: android=http://schemas.android.com/apk/res/android (line=2)
  N: app=http://schemas.android.com/apk/res-auto (line=2)
    N: lib=http://schemas.android.com/apk/com.android.car.ui.sharedlibrary.test (line=2)
      E: androidx.constraintlayout.widget.ConstraintLayout (line=2)
        A: http://schemas.android.com/apk/res/android:layout_width(0x010100f4)=-1
        A: http://schemas.android.com/apk/res/android:layout_height(0x010100f5)=-1
          E: TextView (line=19)
            A: http://schemas.android.com/apk/res/android:layout_width(0x010100f4)=-2
            A: http://schemas.android.com/apk/res/android:layout_height(0x010100f5)=-2
            A: http://schemas.android.com/apk/res/android:text(0x0101014f)=@0x020f0000
            A: http://schemas.android.com/apk/res-auto:layout_constraintBottom_toBottomOf(0x7f0200fb)=0
            A: http://schemas.android.com/apk/res-auto:layout_constraintLeft_toLeftOf(0x7f02010e)=0
            A: http://schemas.android.com/apk/res-auto:layout_constraintRight_toRightOf(0x7f020112)=0
            A: http://schemas.android.com/apk/res-auto:layout_constraintTop_toTopOf(0x7f020118)=0
          E: com.android.car.ui.sharedlibrary.test.MyRecyclerView (line=28)
            A: http://schemas.android.com/apk/res/android:layout_width(0x010100f4)=-2
            A: http://schemas.android.com/apk/res/android:layout_height(0x010100f5)=-2
            A: http://schemas.android.com/apk/com.android.car.ui.sharedlibrary.test:implClass="HelloWorld!" (Raw: "HelloWorld!")
          E: com.android.car.ui.sharedlibraryclient.CustomView (line=34)
            A: http://schemas.android.com/apk/res/android:layout_width(0x010100f4)=-2
            A: http://schemas.android.com/apk/res/android:layout_height(0x010100f5)=-2
            A: http://schemas.android.com/apk/res-auto:implClass2(0x7f0200e8)="HelloWorld!!" (Raw: "HelloWorld!!")