tags:

views:

83

answers:

3

I've been trying to figure out how to make some sense of a dumped XML layout, and it's progressing 'pretty good'. The only thing I'm currently unsure about is the following:

When I use the command:

aapt dump xmltree <pathofapk> <pathofxmlfile>

I get the following result:

   N: android=http://schemas.android.com/apk/res/android
  E: LinearLayout (line=2)
    A: android:orientation(0x010100c4)=(type 0x10)0x1
    A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
    A: android:layout_height(0x010100f5)=(type 0x10)0xffffffff
    E: LinearLayout (line=7)
      A: android:orientation(0x010100c4)=(type 0x10)0x0
      A: android:background(0x010100d4)=@0x7f020004
      A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
      A: android:layout_height(0x010100f5)=(type 0x10)0xfffffffe
      E: ImageView (line=12)
        A: android:gravity(0x010100af)=(type 0x11)0x3
        A: android:layout_gravity(0x010100b3)=(type 0x11)0x13
        A: android:id(0x010100d0)=@0x7f090021
        A: android:paddingLeft(0x010100d6)=(type 0x5)0xa01
        A: android:paddingTop(0x010100d7)=(type 0x5)0x401
        A: android:layout_width(0x010100f4)=(type 0x10)0xfffffffe
        A: android:layout_height(0x010100f5)=(type 0x10)0xfffffffe
        A: android:src(0x01010119)=@0x7f020006
    E: ScrollView (line=21)
      A: android:orientation(0x010100c4)=(type 0x10)0x1
      A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
      A: android:layout_height(0x010100f5)=(type 0x10)0xffffffff
      A: android:layout_weight(0x01010181)=(type 0x4)0x3f800000
      E: LinearLayout (line=25)
        A: android:orientation(0x010100c4)=(type 0x10)0x1
        A: android:id(0x010100d0)=@0x7f09002d
        A: android:padding(0x010100d5)=(type 0x5)0xa01
        A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
        A: android:layout_height(0x010100f5)=(type 0x10)0xffffffff
        E: EditText (line=29)
          A: android:layout_gravity(0x010100b3)=(type 0x11)0x51
          A: android:id(0x010100d0)=@0x7f09002e
          A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
          A: android:layout_height(0x010100f5)=(type 0x10)0xfffffffe
          A: android:text(0x0101014f)="" (Raw: "")
          A: android:hint(0x01010150)=@0x7f070050
        E: EditText (line=36)
          A: android:layout_gravity(0x010100b3)=(type 0x11)0x51
          A: android:id(0x010100d0)=@0x7f09002f
          A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
          A: android:layout_height(0x010100f5)=(type 0x10)0xfffffffe
          A: android:text(0x0101014f)="" (Raw: "")
          A: android:hint(0x01010150)=@0x7f070051
          A: android:password(0x0101015c)=(type 0x12)0xffffffff
        E: LinearLayout (line=44)
          A: android:orientation(0x010100c4)=(type 0x10)0x0
          A: android:padding(0x010100d5)=(type 0x5)0xa01
          A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
          A: android:layout_height(0x010100f5)=(type 0x10)0xfffffffe
          E: Button (line=48)
            A: android:id(0x010100d0)=@0x7f090030
            A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
            A: android:layout_height(0x010100f5)=(type 0x10)0xfffffffe
            A: android:text(0x0101014f)=@0x7f07000a
            A: android:layout_weight(0x01010181)=(type 0x4)0x3f800000
          E: Button (line=54)
            A: android:id(0x010100d0)=@0x7f090031
            A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
            A: android:layout_height(0x010100f5)=(type 0x10)0xfffffffe
            A: android:text(0x0101014f)=@0x7f070003
            A: android:layout_weight(0x01010181)=(type 0x4)0x3f800000

That's all good, but what I'm trying to figure out is how to convert the following code into the XML layout file:

    A: android:paddingLeft(0x010100d6)=(type 0x5)0xa01
    A: android:paddingTop(0x010100d7)=(type 0x5)0x401

Converting those values to decimal would result in:

paddingLeft:2561
paddingTop:1025

All good, but I've been trying to figure out what the (type 0x5 means). With all other types, the result is defined in the Android.util.TypedValue.class file

Decompiling that, gives the following result for 0x5:

      // Field descriptor #8 I
  public static final int TYPE_DIMENSION = 5;

Makes sense, in a way. But, I need to know what kind of value it is, so looking down, I find the following value:

  // Field descriptor #8 I
  public static final int COMPLEX_UNIT_MM = 5;

But, when I try to use 2561mm and 1025mm (It's a tad much anyway, 25cm is.. larger than my screen), The whole screen is filled with the 'parent LinearLayout'.

I have no clue what's wrong.. can anyone enlighten me on this subject?

Greetings,

Mats

A: 

If I had to guess, you are misinterpreting the values. 1025 and 2561 may be the decimal equivalents of those hex values, but there are no units of measure in Android where those would make sense -- those numbers are too big even for px, let alone mm. My guess is that they are encoded differently than you are expecting. For example, I suspect they're really floating-point values, since those are legal for dimensions.

You could test this theory by creating a scrap project, setting a handful of padding values in a layout, compiling it, then running your dump on your own APK, to see if you can reverse engineer what's happening. Or, you could try to look at the code to aapt itself, which should be in the open source tree.

CommonsWare
+1  A: 

And yes, you were right! I was messing around a bit right before this answer, and I found out the same thing.

I was always thinking about some float value, because it'd make a lot more sense, but I couldn't make anything of the value 0xa01 in float, so after a bit of snooping around, I found the following function:

public static float complexToFloat (int complex)

When I call this method with the complex variable set as 0xa01, I get the proper result, which is 10.0 (And, 4.0 for the other value).

So yeah, 10.0mm / 4.0mm did the trick!, Thanks a bunch ^_^

Mats Willemsen
+3  A: 

The data structure for these typed values is defined here:

http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=include/utils/ResourceTypes.h;hb=HEAD#l218

Inside is an enum of the type codes; after that are definitions of the bits for fraction and unit types. (What you are seeing here are unit types -- i.e., 20sp.)

hackbod
I've been there, as stated in the OP (TypedValue.class is pretty much equal to ResourceTypes. It still doesn't say that the value there is a float, and should be treated as a value that should be shifted with the COMPLEX_MANTISSA_SHIFT / COMPLEX_MANTISSA_MASK. This is a good reference for new things, though. It's far better than TypedValues, thanks for this!
Mats Willemsen
The type 0x5 says this is a dimension; a dimension is -always- a typed unit, so the lower 4 bits of the value are the unit (as defined by COMPLEX_UNIT_SHIFT and COMPLEX_UNIT_MASK). Here the lower 4 bits is 0x1, or COMPLEX_UNIT_DIP.For the value itself, the radix is in the next 4 bits, here 0x0 or COMPLEX_RADIX_23p0. The remaining bits are the actual value, 0xa for the first and 0x4 for the second, so these two attributes are 10dip and 4 dip.
hackbod
Wow, I owe you one for this. I wish I could vote for both of these answers. Hahahaha, thanks a load for this information. I couldn't be more off, I think. Thanks for the final information, I can understand why it is 10.0 now, and not just get the value. So, my MM thing was off too? I still have so much to learn :(
Mats Willemsen