Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Android interprets @null keyword in layouts?

Tags:

java

android

I was digging in sources of Android by looking for an answer of how system recognizes @null keyword that mentioned in a layout. For instance,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:background="@null"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/>

So far I followed this route:

  1. TypedArray#getDrawable(int index)
  2. ResourcesImpl#getValue(@AnyRes int id, TypedValue outValue, boolean resolveRefs)
  3. AssetManager#getResourceValue(@AnyRes int resId, int densityDpi, @NonNull TypedValue outValue,boolean resolveRefs)
  4. AssetManager#loadResourceValue(int ident, short density, TypedValue outValue,boolean resolve)

I tried to find in source code of JNI implementation of AssetManager loadResourceValue method, but I have not succeeded.

I would appreciate if anyone can point out how Android resolves @null tag.

Thanks in advance!

like image 231
Tom Koptel Avatar asked Sep 20 '16 09:09

Tom Koptel


1 Answers

You were searching in AssetManager frontend that is exposed via NDK. There are no JNI functions at all. JNI wrapper for android.util.AssetManager is here.

ResTable class is used for actual parsing and resolving. If you dig a bit deeper - you can find lines where @null is handled.

like image 133
Sergio Avatar answered Oct 20 '22 19:10

Sergio