Skip to content

Commit cb7d575

Browse files
committed
cache frameworks for faster usage
1 parent 2266cfc commit cb7d575

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/main/java/com/reandroid/apk/AndroidFrameworks.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (C) 2022 github.com/REAndroid
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -53,7 +53,11 @@ public static FrameworkApk getLatest() throws IOException {
5353
if(path == null){
5454
throw new IOException("Could not get latest framework");
5555
}
56-
return loadResource(latest);
56+
FrameworkApk frameworkApk = loadResource(latest);
57+
if(current == null){
58+
setCurrent(frameworkApk);
59+
}
60+
return frameworkApk;
5761
}
5862
}
5963
public static FrameworkApk getBestMatch(int version) throws IOException {
@@ -145,14 +149,16 @@ private static Map<Integer, String> getResourcePaths(){
145149
}
146150
private static Map<Integer, String> scanAvailableResourcePaths(){
147151
Map<Integer, String> results = new HashMap<>();
148-
int maxSearch = 50;
149-
for(int version=20; version<maxSearch; version++){
152+
int maxSearch = 33;
153+
for(int version = 21; version < maxSearch; version++){
150154
String path = toResourcePath(version);
151155
if(!isAvailable(path)){
152156
continue;
153157
}
154158
results.put(version, path);
155-
maxSearch = version + 20;
159+
if((version + 1) == maxSearch){
160+
maxSearch++;
161+
}
156162
}
157163
return results;
158164
}

src/main/java/com/reandroid/apk/ApkModule.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ public String getSplit(){
123123
}
124124
return getAndroidManifestBlock().getSplit();
125125
}
126+
public FrameworkApk initializeAndroidFramework(Integer version) throws IOException {
127+
TableBlock tableBlock = getTableBlock(false);
128+
return initializeAndroidFramework(tableBlock, version);
129+
}
126130
public FrameworkApk initializeAndroidFramework(TableBlock tableBlock, Integer version) throws IOException {
127131
if(tableBlock == null || isAndroid(tableBlock)){
128132
return null;
@@ -131,10 +135,13 @@ public FrameworkApk initializeAndroidFramework(TableBlock tableBlock, Integer ve
131135
for(TableBlock frameWork:frameWorkList){
132136
if(isAndroid(frameWork)){
133137
ApkFile apkFile = frameWork.getApkFile();
134-
if(apkFile instanceof FrameworkApk){
135-
return (FrameworkApk) apkFile;
138+
if(!(apkFile instanceof FrameworkApk)){
139+
continue;
140+
}
141+
FrameworkApk frameworkApk = (FrameworkApk) apkFile;
142+
if(frameworkApk.getVersionCode() == version){
143+
return frameworkApk;
136144
}
137-
return null;
138145
}
139146
}
140147
logMessage("Initializing android framework ...");
@@ -148,7 +155,8 @@ public FrameworkApk initializeAndroidFramework(TableBlock tableBlock, Integer ve
148155
}
149156
FrameworkTable frameworkTable = frameworkApk.getTableBlock();
150157
tableBlock.addFramework(frameworkTable);
151-
logMessage("Initialized framework: "+frameworkApk.getName());
158+
logMessage("Initialized framework: " + frameworkApk.getName()
159+
+ " (" + frameworkApk.getVersionName() + ")");
152160
return frameworkApk;
153161
}
154162
private boolean isAndroid(TableBlock tableBlock){

0 commit comments

Comments
 (0)