Skip to content

Commit

Permalink
[ARSC] Merge with frameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Apr 24, 2024
1 parent 28b6df5 commit 7f298c6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/reandroid/arsc/chunk/PackageBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,16 @@ private void mergeSpecStringPool(PackageBlock coming){
public int compareTo(PackageBlock pkg) {
return Integer.compare(getId(), pkg.getId());
}
public boolean isSimilarTo(PackageBlock packageBlock) {
if(packageBlock == this) {
return true;
}
if(packageBlock == null || getId() != packageBlock.getId() || !getName().equals(packageBlock.getName())) {
return false;
}
return getTypeStringPool().size() == packageBlock.getTypeStringPool().size() &&
getSpecStringPool().size() == packageBlock.getSpecStringPool().size();
}
@Override
public String toString(){
StringBuilder builder=new StringBuilder();
Expand Down
52 changes: 42 additions & 10 deletions src/main/java/com/reandroid/arsc/chunk/TableBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public TableBlock() {
TableHeader header = getHeaderBlock();
this.mTableStringPool = new TableStringPool(true);
this.mPackageArray = new PackageArray(header.getPackageCount());
this.mFrameWorks = new ArrayList<>();
this.mFrameWorks = new ArrayCollection<>();
addChild(mTableStringPool);
addChild(mPackageArray);
}
Expand Down Expand Up @@ -377,7 +377,7 @@ public boolean test(PackageBlock packageBlock){
}
public Iterator<PackageBlock> getAllPackages(PackageBlock context){
return new CombiningIterator<>(getPackages(context),
new IterableIterator<TableBlock, PackageBlock>(frameworkIterator()) {
new IterableIterator<TableBlock, PackageBlock>(frameworks()) {
@Override
public Iterator<PackageBlock> iterator(TableBlock element) {
return element.getPackages();
Expand Down Expand Up @@ -705,7 +705,7 @@ public StagedAliasEntry getStagedAlias(int stagedResId){
public List<TableBlock> getFrameWorks(){
return mFrameWorks;
}
public Iterator<TableBlock> frameworkIterator(){
public Iterator<TableBlock> frameworks(){
List<TableBlock> frameworkList = getFrameWorks();
if(frameworkList.size() == 0){
return EmptyIterator.of();
Expand All @@ -723,16 +723,30 @@ public boolean isAndroid(){
public boolean hasFramework(){
return getFrameWorks().size() != 0;
}
public void addFramework(TableBlock tableBlock){
if(tableBlock==null||tableBlock==this){
return;
public void addFrameworks(Iterator<TableBlock> iterator) {
List<TableBlock> frameworkList = CollectionUtil.toList(iterator);
for(TableBlock framework : frameworkList) {
addFramework(framework);
}
}
public void addFramework(TableBlock frameworkTable){
if(frameworkTable != null && !containsFramework(frameworkTable)){
mFrameWorks.add(frameworkTable);
}
}
public boolean containsFramework(TableBlock tableBlock) {
if(tableBlock == null){
return false;
}
for(TableBlock frm:tableBlock.getFrameWorks()){
if(frm==this || frm==tableBlock || tableBlock.equals(frm)){
return;
if(this.isSimilarTo(tableBlock)) {
return true;
}
for(TableBlock framework : mFrameWorks) {
if(framework.containsFramework(tableBlock)) {
return true;
}
}
mFrameWorks.add(tableBlock);
return false;
}
public void removeFramework(TableBlock tableBlock){
mFrameWorks.remove(tableBlock);
Expand Down Expand Up @@ -785,6 +799,24 @@ public byte[] getBytes(){
}
return outputStream.toByteArray();
}
public boolean isSimilarTo(TableBlock tableBlock) {
if(tableBlock == this) {
return true;
}
if(tableBlock == null) {
return false;
}
int size = this.size();
if(size != tableBlock.size()) {
return false;
}
for(int i = 0; i < size; i++) {
if(!get(i).isSimilarTo(tableBlock.get(i))){
return false;
}
}
return true;
}
@Override
public String toString(){
StringBuilder builder=new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,13 @@ private void initializeTable(){
TableBlock sourceTable = this.getSourceTable();
sourceTable.refresh();
TableBlock resultTable = this.getResultTable();

resultTable.addFrameworks(resultTable.frameworks());

for(PackageBlock sourcePackage : sourceTable) {
resultTable.newPackage(sourcePackage.getId(), sourcePackage.getName());
}

resultTable.getStringPool().merge(sourceTable.getStringPool());
initializePackages();
}
Expand Down

0 comments on commit 7f298c6

Please sign in to comment.