load entry group map when necessary

This commit is contained in:
REAndroid 2023-04-28 15:16:46 +02:00
parent 6fce5ad5ed
commit 1fcf5a507e
7 changed files with 32 additions and 45 deletions

View File

@ -40,7 +40,6 @@ public class ApkBundle {
} }
ApkModule result = new ApkModule(generateMergedModuleName(), new APKArchive()); ApkModule result = new ApkModule(generateMergedModuleName(), new APKArchive());
result.setAPKLogger(apkLogger); result.setAPKLogger(apkLogger);
result.setDisableEntryGroupMap(true);
result.setLoadDefaultFramework(false); result.setLoadDefaultFramework(false);
mergeStringPools(result); mergeStringPools(result);
@ -166,7 +165,6 @@ public class ApkBundle {
} }
public void addModule(ApkModule apkModule){ public void addModule(ApkModule apkModule){
apkModule.setLoadDefaultFramework(false); apkModule.setLoadDefaultFramework(false);
apkModule.setDisableEntryGroupMap(true);
String name = apkModule.getModuleName(); String name = apkModule.getModuleName();
mModulesMap.remove(name); mModulesMap.remove(name);
mModulesMap.put(name, apkModule); mModulesMap.put(name, apkModule);

View File

@ -57,7 +57,6 @@ public class ApkModule implements ApkFile {
private Decoder mDecoder; private Decoder mDecoder;
private ApkType mApkType; private ApkType mApkType;
private ApkSignatureBlock apkSignatureBlock; private ApkSignatureBlock apkSignatureBlock;
private boolean disableEntryGroupMap;
public ApkModule(String moduleName, APKArchive apkArchive){ public ApkModule(String moduleName, APKArchive apkArchive){
this.moduleName=moduleName; this.moduleName=moduleName;
@ -66,16 +65,6 @@ public class ApkModule implements ApkFile {
this.mUncompressedFiles.addPath(apkArchive); this.mUncompressedFiles.addPath(apkArchive);
} }
public boolean isDisableEntryGroupMap() {
return disableEntryGroupMap;
}
public void setDisableEntryGroupMap(boolean disable) {
this.disableEntryGroupMap = disable;
TableBlock tableBlock = this.mTableBlock;
if(tableBlock != null){
tableBlock.setDisableEntryGroupMap(disable);
}
}
public ApkSignatureBlock getApkSignatureBlock() { public ApkSignatureBlock getApkSignatureBlock() {
return apkSignatureBlock; return apkSignatureBlock;
} }
@ -537,7 +526,6 @@ public class ApkModule implements ApkFile {
new BlockInputSource<>(TableBlock.FILE_NAME, tableBlock); new BlockInputSource<>(TableBlock.FILE_NAME, tableBlock);
archive.add(source); archive.add(source);
mTableBlock = tableBlock; mTableBlock = tableBlock;
tableBlock.setDisableEntryGroupMap(isDisableEntryGroupMap());
} }
@Override @Override
public AndroidManifestBlock getAndroidManifestBlock() { public AndroidManifestBlock getAndroidManifestBlock() {
@ -576,7 +564,6 @@ public class ApkModule implements ApkFile {
} }
try { try {
mTableBlock = loadTableBlock(); mTableBlock = loadTableBlock();
mTableBlock.setDisableEntryGroupMap(isDisableEntryGroupMap());
if(initFramework && loadDefaultFramework){ if(initFramework && loadDefaultFramework){
Integer version = getAndroidFrameworkVersion(); Integer version = getAndroidFrameworkVersion();
initializeAndroidFramework(mTableBlock, version); initializeAndroidFramework(mTableBlock, version);

View File

@ -92,10 +92,6 @@ public class PackageArray extends BlockArray<PackageBlock>
packageBlock = createNext(); packageBlock = createNext();
packageBlock.setId(pkgId); packageBlock.setId(pkgId);
packageBlock.setName("PACKAGE NAME"); packageBlock.setName("PACKAGE NAME");
TableBlock tableBlock = getParentInstance(TableBlock.class);
if(tableBlock != null){
packageBlock.setDisableEntryGroupMap(tableBlock.isDisableEntryGroupMap());
}
return packageBlock; return packageBlock;
} }
public PackageBlock getPackageBlockById(byte pkgId){ public PackageBlock getPackageBlockById(byte pkgId){
@ -135,10 +131,6 @@ public class PackageArray extends BlockArray<PackageBlock>
return; return;
} }
setChildesCount(mPackageCount.get()); setChildesCount(mPackageCount.get());
TableBlock tableBlock = getParentInstance(TableBlock.class);
if(tableBlock != null){
tableBlock.setDisableEntryGroupMap(tableBlock.isDisableEntryGroupMap());
}
} }
@Override @Override
public JSONArray toJson() { public JSONArray toJson() {

View File

@ -50,7 +50,7 @@ public class PackageBlock extends Chunk<PackageHeader>
private final PackageBody mBody; private final PackageBody mBody;
private final Map<Integer, EntryGroup> mEntriesGroup; private final Map<Integer, EntryGroup> mEntriesGroup;
private boolean disableEntryGroupMap; private boolean entryGroupMapLocked;
public PackageBlock() { public PackageBlock() {
super(new PackageHeader(), 3); super(new PackageHeader(), 3);
@ -61,7 +61,8 @@ public class PackageBlock extends Chunk<PackageHeader>
this.mBody = new PackageBody(); this.mBody = new PackageBody();
this.mEntriesGroup=new HashMap<>(); this.mEntriesGroup = new HashMap<>();
this.entryGroupMapLocked = true;
addChild(mTypeStringPool); addChild(mTypeStringPool);
addChild(mSpecStringPool); addChild(mSpecStringPool);
@ -200,7 +201,7 @@ public class PackageBlock extends Chunk<PackageHeader>
return mBody.getLibraryBlock(); return mBody.getLibraryBlock();
} }
public Set<Integer> listResourceIds(){ public Set<Integer> listResourceIds(){
return mEntriesGroup.keySet(); return getEntriesGroupMap().keySet();
} }
public Entry getOrCreateEntry(byte typeId, short entryId, String qualifiers){ public Entry getOrCreateEntry(byte typeId, short entryId, String qualifiers){
return getSpecTypePairArray().getOrCreateEntry(typeId, entryId, qualifiers); return getSpecTypePairArray().getOrCreateEntry(typeId, entryId, qualifiers);
@ -215,13 +216,30 @@ public class PackageBlock extends Chunk<PackageHeader>
return getSpecTypePairArray().getTypeBlock(typeId, qualifiers); return getSpecTypePairArray().getTypeBlock(typeId, qualifiers);
} }
public boolean isDisableEntryGroupMap() { public boolean isEntryGroupMapLocked() {
return disableEntryGroupMap; return entryGroupMapLocked;
} }
public void setDisableEntryGroupMap(boolean disable) { private void unlockEntryGroup() {
this.disableEntryGroupMap = disable; synchronized (this){
if(!this.entryGroupMapLocked){
return;
}
System.err.println("\nUnlocking EntryGroupMap ...");
this.entryGroupMapLocked = false;
Map<Integer, EntryGroup> map = this.mEntriesGroup;
map.clear();
createEntryGroupMap(map);
System.err.println("\nEntryGroupMap unlocked!");
}
}
private void createEntryGroupMap(Map<Integer, EntryGroup> map){
map.clear();
for(SpecTypePair specTypePair:listAllSpecTypePair()){
map.putAll(specTypePair.createEntryGroups());
}
} }
public Map<Integer, EntryGroup> getEntriesGroupMap(){ public Map<Integer, EntryGroup> getEntriesGroupMap(){
unlockEntryGroup();
return mEntriesGroup; return mEntriesGroup;
} }
public Collection<EntryGroup> listEntryGroup(){ public Collection<EntryGroup> listEntryGroup(){
@ -248,7 +266,7 @@ public class PackageBlock extends Chunk<PackageHeader>
return null; return null;
} }
public void updateEntry(Entry entry){ public void updateEntry(Entry entry){
if(isDisableEntryGroupMap()){ if(isEntryGroupMapLocked()){
return; return;
} }
if(entry == null || entry.isNull()){ if(entry == null || entry.isNull()){

View File

@ -42,7 +42,6 @@ public class TableBlock extends Chunk<TableHeader>
private final List<TableBlock> mFrameWorks; private final List<TableBlock> mFrameWorks;
private ApkFile mApkFile; private ApkFile mApkFile;
private ReferenceResolver referenceResolver; private ReferenceResolver referenceResolver;
private boolean disableEntryGroupMap;
public TableBlock() { public TableBlock() {
super(new TableHeader(), 2); super(new TableHeader(), 2);
@ -54,15 +53,6 @@ public class TableBlock extends Chunk<TableHeader>
addChild(mPackageArray); addChild(mPackageArray);
} }
public boolean isDisableEntryGroupMap() {
return disableEntryGroupMap;
}
public void setDisableEntryGroupMap(boolean disable) {
this.disableEntryGroupMap = disable;
for(PackageBlock packageBlock : listPackages()){
packageBlock.setDisableEntryGroupMap(disable);
}
}
public List<Entry> resolveReference(int referenceId){ public List<Entry> resolveReference(int referenceId){
return resolveReference(referenceId, null); return resolveReference(referenceId, null);
} }

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -65,11 +65,13 @@ public class StringItem extends BlockItem implements JSONConvert<JSONObject> {
} }
} }
public void addReference(Collection<ReferenceItem> refList){ public void addReference(Collection<ReferenceItem> refList){
if(refList==null){ if(refList == null){
return; return;
} }
for(ReferenceItem ref:refList){ for(ReferenceItem ref:refList){
addReference(ref); if(ref != null){
this.mReferencedList.add(ref);
}
} }
} }
private void reUpdateReferences(int newIndex){ private void reUpdateReferences(int newIndex){

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");