Skip to content

Commit d3b1f07

Browse files
committed
Fix network error caused by apache.http.legacy.
Signed-off-by: tiann <twsxtd@gmail.com>
1 parent fe87e43 commit d3b1f07

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

VirtualApp/lib/src/main/java/android/content/pm/PackageParser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public class Package {
6868
public String codePath;
6969
public String baseCodePath;
7070
public String[] splitCodePaths;
71+
72+
public ArrayList<String> usesOptionalLibraries;
7173
}
7274

7375
public final class Service extends Component<ServiceIntentInfo> {

VirtualApp/lib/src/main/java/com/lody/virtual/client/ipc/VPackageManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ public ApplicationInfo getApplicationInfo(String packageName, int flags, int use
189189
if (!new File(APACHE_LEGACY).exists()) {
190190
APACHE_LEGACY = "/system/framework/org.apache.http.legacy.jar";
191191
}
192-
if (android.os.Build.VERSION.SDK_INT >= P && info.targetSdkVersion <= P) {
192+
List<String> sharedLibraries = getInterface().getSharedLibraries(packageName);
193+
boolean forceAdd = sharedLibraries.contains("org.apache.http.legacy");
194+
195+
// https://cs.android.com/android/platform/superproject/+/master:frameworks/base/services/core/java/com/android/server/pm/parsing/library/OrgApacheHttpLegacyUpdater.java;l=36?q=OrgApacheHttpLegacyUpdater&ss=android%2Fplatform%2Fsuperproject:frameworks%2Fbase%2Fservices%2Fcore%2Fjava%2Fcom%2Fandroid%2Fserver%2Fpm%2Fparsing%2Flibrary%2F
196+
if (android.os.Build.VERSION.SDK_INT >= P && info.targetSdkVersion < P || forceAdd) {
193197
String[] newSharedLibraryFiles;
194198
if (info.sharedLibraryFiles == null) {
195199
newSharedLibraryFiles = new String[]{APACHE_LEGACY};

VirtualApp/lib/src/main/java/com/lody/virtual/server/pm/VPackageManagerService.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,14 @@ public List<String> getSharedLibraries(String packageName) {
220220
synchronized (mPackages) {
221221
VPackage p = mPackages.get(packageName);
222222
if (p != null) {
223-
return p.usesLibraries;
223+
ArrayList<String> list = new ArrayList<>();
224+
if (p.usesLibraries != null) {
225+
list.addAll(p.usesLibraries);
226+
}
227+
if (p.usesOptionalLibraries != null) {
228+
list.addAll(p.usesOptionalLibraries);
229+
}
230+
return list;
224231
}
225232
return null;
226233
}

VirtualApp/lib/src/main/java/com/lody/virtual/server/pm/parser/PackageParserEx.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ private static VPackage buildPackageCache(PackageParser.Package p) {
233233
cache.splitCodePaths = p.splitCodePaths;
234234
}
235235

236+
cache.usesOptionalLibraries = p.usesOptionalLibraries;
237+
236238
addOwner(cache);
237239
return cache;
238240
}

VirtualApp/lib/src/main/java/com/lody/virtual/server/pm/parser/VPackage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public VPackage[] newArray(int size) {
6666
public Object mExtras;
6767

6868
public String[] splitNames;
69+
public ArrayList<String> usesOptionalLibraries;
6970

7071
/**
7172
* Path where this package was found on disk. For monolithic packages
@@ -136,6 +137,8 @@ protected VPackage(Parcel in) {
136137
this.codePath = in.readString();
137138
this.baseCodePath = in.readString();
138139
this.splitCodePaths = in.createStringArray();
140+
141+
this.usesOptionalLibraries = in.createStringArrayList();
139142
}
140143

141144
@Override
@@ -247,6 +250,8 @@ public void writeToParcel(Parcel dest, int flags) {
247250
dest.writeString(this.codePath);
248251
dest.writeString(this.baseCodePath);
249252
dest.writeStringArray(this.splitCodePaths);
253+
254+
dest.writeStringList(this.usesOptionalLibraries);
250255
}
251256

252257
public static class ActivityIntentInfo extends IntentInfo {

0 commit comments

Comments
 (0)