Skip to content
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

Propagate the raw int values to callers #991

Merged
merged 1 commit into from
Jul 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
public class ResBoolValue extends ResScalarValue {
private final boolean mValue;

public ResBoolValue(boolean value, String rawValue) {
super("bool", rawValue);
public ResBoolValue(boolean value, int rawIntValue, String rawValue) {
super("bool", rawIntValue, rawValue);
this.mValue = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
/**
* @author Ryszard Wiśniewski <[email protected]>
*/
public class ResFileValue extends ResValue {
public class ResFileValue extends ResIntBasedValue {
private final String mPath;

public ResFileValue(String path) {
public ResFileValue(String path, int rawIntValue) {
super(rawIntValue);
this.mPath = path;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
public class ResFloatValue extends ResScalarValue {
private final float mValue;

public ResFloatValue(float value, String rawValue) {
super("float", rawValue);
public ResFloatValue(float value, int rawIntValue, String rawValue) {
super("float", rawIntValue, rawValue);
this.mValue = value;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2014 Ryszard Wiśniewski <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package brut.androlib.res.data.value;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you could add our license header to the top of the file.

/**
 *  Copyright 2014 Ryszard Wiśniewski <[email protected]>
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */


/**
* @author Matt Mastracci <[email protected]>
*/
public class ResIntBasedValue extends ResValue {
private int mRawIntValue;

protected ResIntBasedValue(int rawIntValue) {
mRawIntValue = rawIntValue;
}

public int getRawIntValue() {
return mRawIntValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ResIntValue(int value, String rawValue, int type) {
}

public ResIntValue(int value, String rawValue, String type) {
super(type, rawValue);
super(type, value, rawValue);
this.mValue = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
/**
* @author Ryszard Wiśniewski <[email protected]>
*/
public abstract class ResScalarValue extends ResValue implements
public abstract class ResScalarValue extends ResIntBasedValue implements
ResXmlEncodable, ResValuesXmlSerializable {
protected final String mType;
protected final String mRawValue;

protected ResScalarValue(String type, String rawValue) {
protected ResScalarValue(String type, int rawIntValue, String rawValue) {
super(rawIntValue);
mType = type;
mRawValue = rawValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
*/
public class ResStringValue extends ResScalarValue {

public ResStringValue(String value) {
this(value, "string");
public ResStringValue(String value, int rawValue) {
this(value, rawValue, "string");
}

public ResStringValue(String value, String type) {
super(type, value);
public ResStringValue(String value, int rawValue, String type) {
super(type, rawValue, value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public ResScalarValue factory(int type, int value, String rawValue)
case TypedValue.TYPE_ATTRIBUTE:
return newReference(value, rawValue, true);
case TypedValue.TYPE_STRING:
return new ResStringValue(rawValue);
return new ResStringValue(rawValue, value);
case TypedValue.TYPE_FLOAT:
return new ResFloatValue(Float.intBitsToFloat(value), rawValue);
return new ResFloatValue(Float.intBitsToFloat(value), value, rawValue);
case TypedValue.TYPE_DIMENSION:
return new ResDimenValue(value, rawValue);
case TypedValue.TYPE_FRACTION:
return new ResFractionValue(value, rawValue);
case TypedValue.TYPE_INT_BOOLEAN:
return new ResBoolValue(value != 0, rawValue);
return new ResBoolValue(value != 0, value, rawValue);
case TypedValue.TYPE_DYNAMIC_REFERENCE:
return newReference(value, rawValue);
}
Expand All @@ -66,11 +66,11 @@ public ResScalarValue factory(int type, int value, String rawValue)
throw new AndrolibException("Invalid value type: " + type);
}

public ResValue factory(String value) {
public ResIntBasedValue factory(String value, int rawValue) {
if (value.startsWith("res/")) {
return new ResFileValue(value);
return new ResFileValue(value, rawValue);
}
return new ResStringValue(value);
return new ResStringValue(value, rawValue);
}

public ResBagValue bagFactory(int parent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private void readEntry() throws IOException, AndrolibException {
ResValue value = (flags & ENTRY_FLAG_COMPLEX) == 0 ? readValue() : readComplexEntry();

if (mType.isString() && value instanceof ResFileValue) {
value = new ResStringValue(value.toString());
value = new ResStringValue(value.toString(), ((ResFileValue) value).getRawIntValue());
}
if (mConfig == null) {
return;
Expand Down Expand Up @@ -232,32 +232,32 @@ private ResBagValue readComplexEntry() throws IOException,

ResValueFactory factory = mPkg.getValueFactory();
Duo<Integer, ResScalarValue>[] items = new Duo[count];
ResValue resValue;
ResIntBasedValue resValue;
int resId;

for (int i = 0; i < count; i++) {
resId = mIn.readInt();
resValue = readValue();

try {
if (resValue instanceof ResScalarValue) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now unit tests pass, even though this was changed up which I thought would break the changes I patched in 8254764

This was just a pass through, I haven't pulled down the merge request to verify. I will do that today and check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instanceof/attempt should be equivalent to the try {} catch (ClassCastException) that was there before (it passes my local tests at least). I can revert it to the previous form to simplify the review if you like, but I figured that an internal exception like that would have some performance implications.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your version better, my local testing showed no regression with the apks that I patched the original issue for, and the non exception catch should prove to be quicker. Everything looks good on my end.

Thanks for the quick pull request. I'll get this merged into master.

items[i] = new Duo<Integer, ResScalarValue>(resId, (ResScalarValue) resValue);
} catch (ClassCastException ex) {
resValue = new ResStringValue(resValue.toString());
} else {
resValue = new ResStringValue(resValue.toString(), resValue.getRawIntValue());
items[i] = new Duo<Integer, ResScalarValue>(resId, (ResScalarValue) resValue);
}
}

return factory.bagFactory(parent, items);
}

private ResValue readValue() throws IOException, AndrolibException {
private ResIntBasedValue readValue() throws IOException, AndrolibException {
/* size */mIn.skipCheckShort((short) 8);
/* zero */mIn.skipCheckByte((byte) 0);
byte type = mIn.readByte();
int data = mIn.readInt();

return type == TypedValue.TYPE_STRING
? mPkg.getValueFactory().factory(mTableStrings.getHTML(data))
? mPkg.getValueFactory().factory(mTableStrings.getHTML(data), data)
: mPkg.getValueFactory().factory(type, data, null);
}

Expand Down Expand Up @@ -395,7 +395,7 @@ private void addMissingResSpecs() throws AndrolibException {
mConfig = mPkg.getOrCreateConfig(new ResConfigFlags());
}

ResValue value = new ResBoolValue(false, null);
ResValue value = new ResBoolValue(false, 0, null);
ResResource res = new ResResource(mConfig, spec, value);

mPkg.addResource(res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void decode(ResResource res, Directory inDir, Directory outDir)
LOGGER.log(Level.SEVERE, String.format(
"Could not decode file, replacing by FALSE value: %s",
inFileName, outFileName), ex);
res.replace(new ResBoolValue(false, null));
res.replace(new ResBoolValue(false, 0, null));
}
}

Expand Down