-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
|
||
|
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; | ||
|
||
/** | ||
* @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 |
---|---|---|
|
@@ -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; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
||
|
@@ -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); | ||
|
There was a problem hiding this comment.
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.