Search in sources :

Example 1 with ResXMLTree_attrExt

use of org.robolectric.res.android.ResourceTypes.ResXMLTree_attrExt in project robolectric by robolectric.

the class ResXMLParser method getAttributeValue.

public int getAttributeValue(int idx, Ref<Res_value> outValue) {
    if (mEventCode == START_TAG) {
        ResXMLTree_attrExt tag = new ResXMLTree_attrExt(mTree.mBuffer.buf, mCurExt);
        if (idx < dtohs(tag.attributeCount)) {
            // final ResXMLTree_attribute attr = (ResXMLTree_attribute)
            // (((final int8_t*)tag)
            // + dtohs(tag.attributeStart())
            // + (dtohs(tag.attributeSize())*idx));
            ResXMLTree_attribute attr = tag.attributeAt(idx);
            outValue.set(attr.typedValue);
            if (mTree.mDynamicRefTable != null && mTree.mDynamicRefTable.lookupResourceValue(outValue) != NO_ERROR) {
                return BAD_TYPE;
            }
            return ResourceTypes.Res_value.SIZEOF;
        }
    }
    return BAD_TYPE;
}
Also used : ResXMLTree_attribute(org.robolectric.res.android.ResourceTypes.ResXMLTree_attribute) ResXMLTree_attrExt(org.robolectric.res.android.ResourceTypes.ResXMLTree_attrExt)

Example 2 with ResXMLTree_attrExt

use of org.robolectric.res.android.ResourceTypes.ResXMLTree_attrExt in project robolectric by robolectric.

the class ResXMLParser method getAttributeData.

public int getAttributeData(int idx) {
    if (mEventCode == START_TAG) {
        ResXMLTree_attrExt tag = new ResXMLTree_attrExt(mTree.mBuffer.buf, mCurExt);
        if (idx < dtohs(tag.attributeCount)) {
            // final ResXMLTree_attribute attr = (ResXMLTree_attribute)
            // (((final int8_t*)tag)
            // + dtohs(tag.attributeStart)
            // + (dtohs(tag.attributeSize)*idx));
            ResXMLTree_attribute attr = tag.attributeAt(idx);
            if (attr.typedValue.dataType != DataType.DYNAMIC_REFERENCE.code() || mTree.mDynamicRefTable == null) {
                return dtohl(attr.typedValue.data);
            }
            final Ref<Integer> data = new Ref<>(dtohl(attr.typedValue.data));
            if (mTree.mDynamicRefTable.lookupResourceId(data) == NO_ERROR) {
                return data.get();
            }
        }
    }
    return 0;
}
Also used : ResXMLTree_attribute(org.robolectric.res.android.ResourceTypes.ResXMLTree_attribute) ResXMLTree_attrExt(org.robolectric.res.android.ResourceTypes.ResXMLTree_attrExt)

Example 3 with ResXMLTree_attrExt

use of org.robolectric.res.android.ResourceTypes.ResXMLTree_attrExt in project robolectric by robolectric.

the class ResXMLParser method getAttributeDataType.

public int getAttributeDataType(int idx) {
    if (mEventCode == START_TAG) {
        final ResXMLTree_attrExt tag = new ResXMLTree_attrExt(mTree.mBuffer.buf, mCurExt);
        if (idx < dtohs(tag.attributeCount)) {
            // final ResXMLTree_attribute attr = (ResXMLTree_attribute)
            // (((final int8_t*)tag)
            // + dtohs(tag.attributeStart())
            // + (dtohs(tag.attributeSize())*idx));
            ResXMLTree_attribute attr = tag.attributeAt(idx);
            int type = attr.typedValue.dataType;
            if (type != DataType.DYNAMIC_REFERENCE.code()) {
                return type;
            }
            // to regular references at this level, so lie to the caller.
            return DataType.REFERENCE.code();
        }
    }
    return DataType.NULL.code();
}
Also used : ResXMLTree_attribute(org.robolectric.res.android.ResourceTypes.ResXMLTree_attribute) ResXMLTree_attrExt(org.robolectric.res.android.ResourceTypes.ResXMLTree_attrExt)

Example 4 with ResXMLTree_attrExt

use of org.robolectric.res.android.ResourceTypes.ResXMLTree_attrExt in project robolectric by robolectric.

the class ResXMLTree method validateNode.

int validateNode(final ResXMLTree_node node) {
    final short eventCode = dtohs(node.header.type);
    int err = validate_chunk(node.header, SIZEOF_RESXMLTREE_NODE, /*sizeof(ResXMLTree_node)*/
    mDataLen, "ResXMLTree_node");
    if (err >= NO_ERROR) {
        // Only perform additional validation on START nodes
        if (eventCode != RES_XML_START_ELEMENT_TYPE) {
            return NO_ERROR;
        }
        final short headerSize = dtohs(node.header.headerSize);
        final int size = dtohl(node.header.size);
        // final ResXMLTree_attrExt attrExt = (final ResXMLTree_attrExt*)
        // (((final uint8_t*)node) + headerSize);
        ResXMLTree_attrExt attrExt = new ResXMLTree_attrExt(mBuffer.buf, node.myOffset() + headerSize);
        // check for sensical values pulled out of the stream so far...
        if ((size >= headerSize + SIZEOF_RESXMLTREE_ATTR_EXT) && (attrExt.myOffset() > node.myOffset())) {
            final int attrSize = ((int) dtohs(attrExt.attributeSize)) * dtohs(attrExt.attributeCount);
            if ((dtohs(attrExt.attributeStart) + attrSize) <= (size - headerSize)) {
                return NO_ERROR;
            }
            ALOGW("Bad XML block: node attributes use 0x%x bytes, only have 0x%x bytes\n", (int) (dtohs(attrExt.attributeStart) + attrSize), (int) (size - headerSize));
        } else {
            ALOGW("Bad XML start block: node header size 0x%x, size 0x%x\n", (int) headerSize, (int) size);
        }
        return BAD_TYPE;
    }
    return err;
// if (false) {
// final boolean isStart = dtohs(node.header().type()) == RES_XML_START_ELEMENT_TYPE;
// 
// final short headerSize = dtohs(node.header().headerSize());
// final int size = dtohl(node.header().size());
// 
// if (headerSize >= (isStart ? sizeof(ResXMLTree_attrNode) : sizeof(ResXMLTree_node))) {
// if (size >= headerSize) {
// if ((( final uint8_t*)node) <=(mDataEnd - size)){
// if (!isStart) {
// return NO_ERROR;
// }
// if ((((int) dtohs(node.attributeSize)) * dtohs(node.attributeCount))
// <= (size - headerSize)) {
// return NO_ERROR;
// }
// ALOGW("Bad XML block: node attributes use 0x%x bytes, only have 0x%x bytes\n",
// ((int) dtohs(node.attributeSize)) * dtohs(node.attributeCount),
// (int) (size - headerSize));
// return BAD_TYPE;
// }
// ALOGW("Bad XML block: node at 0x%x extends beyond data end 0x%x\n",
// (int) ((( final uint8_t*)node)-(( final uint8_t*)mHeader)),(int) mSize);
// return BAD_TYPE;
// }
// ALOGW("Bad XML block: node at 0x%x header size 0x%x smaller than total size 0x%x\n",
// (int) ((( final uint8_t*)node)-(( final uint8_t*)mHeader)),
// (int) headerSize, (int) size);
// return BAD_TYPE;
// }
// ALOGW("Bad XML block: node at 0x%x header size 0x%x too small\n",
// (int) ((( final uint8_t*)node)-(( final uint8_t*)mHeader)),
// (int) headerSize);
// return BAD_TYPE;
// }
}
Also used : ResXMLTree_attrExt(org.robolectric.res.android.ResourceTypes.ResXMLTree_attrExt)

Aggregations

ResXMLTree_attrExt (org.robolectric.res.android.ResourceTypes.ResXMLTree_attrExt)4 ResXMLTree_attribute (org.robolectric.res.android.ResourceTypes.ResXMLTree_attribute)3