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());
result.setAPKLogger(apkLogger);
result.setDisableEntryGroupMap(true);
result.setLoadDefaultFramework(false);
mergeStringPools(result);
@ -166,7 +165,6 @@ public class ApkBundle {
}
public void addModule(ApkModule apkModule){
apkModule.setLoadDefaultFramework(false);
apkModule.setDisableEntryGroupMap(true);
String name = apkModule.getModuleName();
mModulesMap.remove(name);
mModulesMap.put(name, apkModule);

View File

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

View File

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

View File

@ -50,7 +50,7 @@ public class PackageBlock extends Chunk<PackageHeader>
private final PackageBody mBody;
private final Map<Integer, EntryGroup> mEntriesGroup;
private boolean disableEntryGroupMap;
private boolean entryGroupMapLocked;
public PackageBlock() {
super(new PackageHeader(), 3);
@ -61,7 +61,8 @@ public class PackageBlock extends Chunk<PackageHeader>
this.mBody = new PackageBody();
this.mEntriesGroup=new HashMap<>();
this.mEntriesGroup = new HashMap<>();
this.entryGroupMapLocked = true;
addChild(mTypeStringPool);
addChild(mSpecStringPool);
@ -200,7 +201,7 @@ public class PackageBlock extends Chunk<PackageHeader>
return mBody.getLibraryBlock();
}
public Set<Integer> listResourceIds(){
return mEntriesGroup.keySet();
return getEntriesGroupMap().keySet();
}
public Entry getOrCreateEntry(byte typeId, short entryId, String qualifiers){
return getSpecTypePairArray().getOrCreateEntry(typeId, entryId, qualifiers);
@ -215,13 +216,30 @@ public class PackageBlock extends Chunk<PackageHeader>
return getSpecTypePairArray().getTypeBlock(typeId, qualifiers);
}
public boolean isDisableEntryGroupMap() {
return disableEntryGroupMap;
public boolean isEntryGroupMapLocked() {
return entryGroupMapLocked;
}
private void unlockEntryGroup() {
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 void setDisableEntryGroupMap(boolean disable) {
this.disableEntryGroupMap = disable;
}
public Map<Integer, EntryGroup> getEntriesGroupMap(){
unlockEntryGroup();
return mEntriesGroup;
}
public Collection<EntryGroup> listEntryGroup(){
@ -248,7 +266,7 @@ public class PackageBlock extends Chunk<PackageHeader>
return null;
}
public void updateEntry(Entry entry){
if(isDisableEntryGroupMap()){
if(isEntryGroupMapLocked()){
return;
}
if(entry == null || entry.isNull()){

View File

@ -42,7 +42,6 @@ public class TableBlock extends Chunk<TableHeader>
private final List<TableBlock> mFrameWorks;
private ApkFile mApkFile;
private ReferenceResolver referenceResolver;
private boolean disableEntryGroupMap;
public TableBlock() {
super(new TableHeader(), 2);
@ -54,15 +53,6 @@ public class TableBlock extends Chunk<TableHeader>
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){
return resolveReference(referenceId, null);
}

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2022 github.com/REAndroid
*
* 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){
if(refList==null){
if(refList == null){
return;
}
for(ReferenceItem ref:refList){
addReference(ref);
if(ref != null){
this.mReferencedList.add(ref);
}
}
}
private void reUpdateReferences(int newIndex){

View File

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