Skip to content

Commit b2ecf79

Browse files
committed
Feat: support split resources
Signed-off-by: tiann <twsxtd@gmail.com>
1 parent edfb987 commit b2ecf79

8 files changed

Lines changed: 37 additions & 4 deletions

File tree

VirtualApp/app/src/main/java/io/virtualapp/home/adapters/CloneAppListAdapter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ public void onBindViewHolder(ViewHolder holder, int position) {
9898
holder.labelView.setVisibility(View.INVISIBLE);
9999
}
100100

101+
if (info.splitApk) {
102+
} else {
103+
}
101104
holder.itemView.setOnClickListener(v -> {
102105
mItemEventListener.onItemClick(info, position);
103106
});

VirtualApp/app/src/main/java/io/virtualapp/home/models/AppInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ public class AppInfo {
1515
public CharSequence version;
1616
public int cloneCount;
1717
public boolean disableMultiVersion;
18+
public boolean splitApk;
1819
}

VirtualApp/app/src/main/java/io/virtualapp/home/repo/AppRepository.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ private List<AppInfo> convertPackageInfoToAppData(Context context, List<PackageI
181181
}
182182
ApplicationInfo ai = pkg.applicationInfo;
183183
String path = ai.publicSourceDir != null ? ai.publicSourceDir : ai.sourceDir;
184+
boolean splitApk = false;
185+
if (ai.splitPublicSourceDirs != null || ai.splitSourceDirs != null) {
186+
splitApk = true;
187+
path = new File(path).getParent();
188+
}
189+
184190
if (path == null) {
185191
continue;
186192
}
@@ -191,6 +197,7 @@ private List<AppInfo> convertPackageInfoToAppData(Context context, List<PackageI
191197
info.icon = null; // Use Glide to load the icon async
192198
info.name = ai.loadLabel(pm);
193199
info.version = pkg.versionName;
200+
info.splitApk = splitApk;
194201
InstalledAppInfo installedAppInfo = VirtualCore.get().getInstalledAppInfo(pkg.packageName, 0);
195202
if (installedAppInfo != null) {
196203
info.cloneCount = installedAppInfo.getInstalledUsers().length;

VirtualApp/lib/src/main/java/com/lody/virtual/client/core/VirtualCore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,11 @@ public Resources getResources(String pkg) throws Resources.NotFoundException {
706706
if (installedAppInfo != null) {
707707
AssetManager assets = mirror.android.content.res.AssetManager.ctor.newInstance();
708708
mirror.android.content.res.AssetManager.addAssetPath.call(assets, installedAppInfo.apkPath);
709+
if (installedAppInfo.splitCodePaths != null) {
710+
for (String splitCodePath : installedAppInfo.splitCodePaths) {
711+
mirror.android.content.res.AssetManager.addAssetPath.call(assets, splitCodePath);
712+
}
713+
}
709714
Resources hostRes = context.getResources();
710715
return new Resources(assets, hostRes.getDisplayMetrics(), hostRes.getConfiguration());
711716
}

VirtualApp/lib/src/main/java/com/lody/virtual/remote/InstalledAppInfo.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ public final class InstalledAppInfo implements Parcelable {
2121
public String libPath;
2222
public boolean dependSystem;
2323
public int appId;
24+
public String[] splitCodePaths;
2425

25-
public InstalledAppInfo(String packageName, String apkPath, String libPath, boolean dependSystem, boolean skipDexOpt, int appId) {
26+
public InstalledAppInfo(String packageName, String apkPath, String libPath, boolean dependSystem, boolean skipDexOpt, int appId, String[] splitCodePaths) {
2627
this.packageName = packageName;
2728
this.apkPath = apkPath;
2829
this.libPath = libPath;
2930
this.dependSystem = dependSystem;
3031
this.appId = appId;
32+
this.splitCodePaths = splitCodePaths;
3133
}
3234

3335
public File getOdexFile() {
@@ -62,6 +64,8 @@ public void writeToParcel(Parcel dest, int flags) {
6264
dest.writeString(this.libPath);
6365
dest.writeByte(this.dependSystem ? (byte) 1 : (byte) 0);
6466
dest.writeInt(this.appId);
67+
68+
dest.writeStringArray(this.splitCodePaths);
6569
}
6670

6771
protected InstalledAppInfo(Parcel in) {
@@ -70,6 +74,8 @@ protected InstalledAppInfo(Parcel in) {
7074
this.libPath = in.readString();
7175
this.dependSystem = in.readByte() != 0;
7276
this.appId = in.readInt();
77+
78+
this.splitCodePaths = in.createStringArray();
7379
}
7480

7581
public static final Creator<InstalledAppInfo> CREATOR = new Creator<InstalledAppInfo>() {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public PackageSetting[] newArray(int size) {
3333
public int appId;
3434
public long firstInstallTime;
3535
public long lastUpdateTime;
36+
37+
public String[] splitCodePaths;
3638
private SparseArray<PackageUserState> userState = new SparseArray<>();
3739

3840
public PackageSetting() {
@@ -47,10 +49,11 @@ protected PackageSetting(Parcel in) {
4749
//noinspection unchecked
4850
this.userState = in.readSparseArray(PackageUserState.class.getClassLoader());
4951
this.skipDexOpt = in.readByte() != 0;
52+
this.splitCodePaths = in.createStringArray();
5053
}
5154

5255
public InstalledAppInfo getAppInfo() {
53-
return new InstalledAppInfo(packageName, apkPath, libPath, dependSystem, skipDexOpt, appId);
56+
return new InstalledAppInfo(packageName, apkPath, libPath, dependSystem, skipDexOpt, appId, splitCodePaths);
5457
}
5558

5659
PackageUserState modifyUserState(int userId) {
@@ -96,6 +99,7 @@ public void writeToParcel(Parcel dest, int flags) {
9699
//noinspection unchecked
97100
dest.writeSparseArray((SparseArray) this.userState);
98101
dest.writeByte(this.skipDexOpt ? (byte) 1 : (byte) 0);
102+
dest.writeStringArray(this.splitCodePaths);
99103
}
100104

101105
public boolean isLaunched(int userId) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ public synchronized InstallResult installPackage(String path, int flags, boolean
191191
dependSystem = false;
192192
}
193193

194+
String[] splitCodePaths = null;
195+
194196
if (!dependSystem) {
195197
File privatePackageFile = new File(appDir, "base.apk");
196198
File parentFolder = privatePackageFile.getParentFile();
@@ -213,6 +215,8 @@ public synchronized InstallResult installPackage(String path, int flags, boolean
213215

214216
if (pkg.splitNames != null) {
215217
int length = pkg.splitNames.length;
218+
splitCodePaths = new String[length];
219+
216220
for (int i = 0; i < length; i++) {
217221
String splitName = pkg.splitNames[i];
218222
File privateSplitFile = new File(appDir, splitName + ".apk");
@@ -225,6 +229,7 @@ public synchronized InstallResult installPackage(String path, int flags, boolean
225229
privateSplitFile.delete();
226230
return InstallResult.makeFailure("Unable to copy split: " + splitName);
227231
}
232+
splitCodePaths[i] = privateSplitFile.getPath();
228233
}
229234
}
230235
}
@@ -254,6 +259,7 @@ public synchronized InstallResult installPackage(String path, int flags, boolean
254259
ps.setUserState(userId, false/*launched*/, false/*hidden*/, installed);
255260
}
256261
}
262+
ps.splitCodePaths = splitCodePaths;
257263
PackageParserEx.savePackageCache(pkg);
258264
PackageCacheManager.put(pkg, ps);
259265
mPersistenceLayer.save();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,9 @@ public static void initApplicationInfoBase(PackageSetting ps, VPackage p) {
250250
ai.publicSourceDir = ps.apkPath;
251251
ai.sourceDir = ps.apkPath;
252252
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
253-
ai.splitSourceDirs = new String[]{ps.apkPath};
254-
ai.splitPublicSourceDirs = ai.splitSourceDirs;
253+
ai.splitSourceDirs = ps.splitCodePaths;
254+
ai.splitPublicSourceDirs = ps.splitCodePaths;
255+
255256
ApplicationInfoL.scanSourceDir.set(ai, ai.dataDir);
256257
ApplicationInfoL.scanPublicSourceDir.set(ai, ai.dataDir);
257258
String hostPrimaryCpuAbi = ApplicationInfoL.primaryCpuAbi.get(VirtualCore.get().getContext().getApplicationInfo());

0 commit comments

Comments
 (0)