New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResAttr: Support 'enum' type #1063

Closed
zoujunhua opened this Issue Oct 15, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@zoujunhua
Contributor

zoujunhua commented Oct 15, 2015

We use the Apktool for version 2.0.2

There is a framework resource apk, define a attr with:

<attr name="mzListPreferenceMode" format="integer" >
            <enum name="MODE_DIALOG"    value="0" />
            <enum name="MODE_DROPDOWN"  value="1" />
 </attr>

the resource apk package name is flyme.

another apk, such as "TeleServices.apk" will use the attr with:

flyme:mzListPreferenceMode="MODE_DROPDOWN"

After installed the framework apks, I have confronted with the following errors when decoding TeleServices.apk:

I: Using Apktool 2.0.2 on TeleService.apk
I: Loading resource table...
I: Decoding Shared Library (flyme), pkgId: 2
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /home/zoujunhua/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Loading resource table from file: /home/zoujunhua/apktool/framework/2.apk
Exception in thread "main" java.lang.ClassCastException: brut.androlib.res.data.value.ResStyleValue cannot be cast to brut.androlib.res.data.value.ResAttr
    at brut.androlib.res.decoder.ResAttrDecoder.decode(ResAttrDecoder.java:38)
    at brut.androlib.res.decoder.AXmlResourceParser.getAttributeValue(AXmlResourceParser.java:369)
    at org.xmlpull.v1.wrapper.classic.XmlPullParserDelegate.getAttributeValue(XmlPullParserDelegate.java:69)
    at org.xmlpull.v1.wrapper.classic.StaticXmlSerializerWrapper.writeStartTag(StaticXmlSerializerWrapper.java:267)
    at org.xmlpull.v1.wrapper.classic.StaticXmlSerializerWrapper.event(StaticXmlSerializerWrapper.java:211)
    at brut.androlib.res.decoder.XmlPullStreamDecoder$1.event(XmlPullStreamDecoder.java:83)
    at brut.androlib.res.decoder.XmlPullStreamDecoder.decode(XmlPullStreamDecoder.java:141)
    at brut.androlib.res.decoder.ResStreamDecoderContainer.decode(ResStreamDecoderContainer.java:33)
    at brut.androlib.res.decoder.ResFileDecoder.decode(ResFileDecoder.java:120)
    at brut.androlib.res.decoder.ResFileDecoder.decode(ResFileDecoder.java:105)
    at brut.androlib.res.AndrolibResources.decode(AndrolibResources.java:247)
    at brut.androlib.Androlib.decodeResourcesFull(Androlib.java:135)
    at brut.androlib.ApkDecoder.decode(ApkDecoder.java:102)
    at brut.apktool.Main.cmdDecode(Main.java:165)
    at brut.apktool.Main.main(Main.java:81)

I suspect that the attr with "enum" maybe not support by apktool.

When I change the code as follows:

<attr name="mzListPreferenceMode" format="integer" />

Remove the "enum" declaration.

In the TeleService.apk, I change the code as follows:

flyme:mzListPreferenceMode="@integer/OtaShowActivationScreen"

The value of integer variable "OtaShowActivationScreen" is 1.

Then recompile

After installed the framework apks, I have confronted with the following errors when decoding TeleServices.apk:

I: Using Apktool 2.0.2 on TeleService.apk
I: Loading resource table...
I: Decoding Shared Library (flyme), pkgId: 2
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /home/zoujunhua/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Loading resource table from file: /home/zoujunhua/apktool/framework/2.apk
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...

So the decode is success.

Please tell me why.

Whether the apktool is not support for enum attr in the extended framework resource apk.

Also to be noted that the extended framework resource apk is a sharedLibrary resource apk.

@iBotPeaches iBotPeaches changed the title from java.lang.ClassCastException: brut.androlib.res.data.value.ResStyleValue cannot be cast to brut.androlib.res.data.value.ResAttr to java.lang.ClassCastException: ResStyleValue cannot be cast to ResAttr Oct 15, 2015

@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Oct 15, 2015

Owner

Thanks for the report. I see the problem. Type enum is not supported and thus is stripped during decode of apk. I don't think shared frameworks are involved.

BEFORE:

    <attr name="test_attr11" format="enum">
        <enum name="TEST_ZERO" value="0" />
        <enum name="TEST_ONE" value="1" />
    </attr>

AFTER

    <attr name="test_attr11">
        <enum name="TEST_ZERO" value="0" />
        <enum name="TEST_ONE" value="1" />
    </attr>

Stripped off.

Owner

iBotPeaches commented Oct 15, 2015

Thanks for the report. I see the problem. Type enum is not supported and thus is stripped during decode of apk. I don't think shared frameworks are involved.

BEFORE:

    <attr name="test_attr11" format="enum">
        <enum name="TEST_ZERO" value="0" />
        <enum name="TEST_ONE" value="1" />
    </attr>

AFTER

    <attr name="test_attr11">
        <enum name="TEST_ZERO" value="0" />
        <enum name="TEST_ONE" value="1" />
    </attr>

Stripped off.

@iBotPeaches iBotPeaches changed the title from java.lang.ClassCastException: ResStyleValue cannot be cast to ResAttr to ResAttr: Support 'enum' type Oct 15, 2015

iBotPeaches added a commit that referenced this issue Oct 15, 2015

@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Oct 15, 2015

Owner

Actually. TypedValue does not have a definition for Enum. In the entirety of the res/values/attrs.xml file there is only one reference to Enum type - https://android.googlesource.com/platform/frameworks/base/+/2888524e03896831f487e5dee63f18f1c33c0115/core/res/res/values/attrs.xml

The attrs that declare enum as its type have a value of 0. As you can imagine, that is the same ID that an attribute has if it declares no type. This means we can't determine enum vs not defined type. Assuming enum every time the type is 0 would be wrong.

The first error you had (ClassCast Exception). I believe I fixed earlier today here - 3dea579

Otherwise I can't do anything about the striping of format="enum".

Owner

iBotPeaches commented Oct 15, 2015

Actually. TypedValue does not have a definition for Enum. In the entirety of the res/values/attrs.xml file there is only one reference to Enum type - https://android.googlesource.com/platform/frameworks/base/+/2888524e03896831f487e5dee63f18f1c33c0115/core/res/res/values/attrs.xml

The attrs that declare enum as its type have a value of 0. As you can imagine, that is the same ID that an attribute has if it declares no type. This means we can't determine enum vs not defined type. Assuming enum every time the type is 0 would be wrong.

The first error you had (ClassCast Exception). I believe I fixed earlier today here - 3dea579

Otherwise I can't do anything about the striping of format="enum".

@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Oct 16, 2015

Owner

Closing per above comment.

Owner

iBotPeaches commented Oct 16, 2015

Closing per above comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment