Skip to content

Commit dfa1862

Browse files
author
梁丽欣
authored
Fix Android 11 broken obb
Fix obb directory fetching and crash. Add a mount point.
1 parent f5b1174 commit dfa1862

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

VirtualApp/lib/src/main/java/com/lody/virtual/client/VClientImpl.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,11 @@ private void setupVirtualStorage(ApplicationInfo info, int userId) {
507507
whiteList.add(Environment.DIRECTORY_MOVIES);
508508
whiteList.add(Environment.DIRECTORY_DOWNLOADS);
509509
whiteList.add(Environment.DIRECTORY_DCIM);
510-
whiteList.add("Android/obb");
510+
// Android 11, do not tryna fetch this directory directly or crash.
511+
// See docs below...
512+
if (Build.VERSION.SDK_INT < 30) {
513+
whiteList.add("Android/obb");
514+
}
511515
if (Build.VERSION.SDK_INT >= 19) {
512516
whiteList.add(Environment.DIRECTORY_DOCUMENTS);
513517
}
@@ -535,8 +539,13 @@ private void setupVirtualStorage(ApplicationInfo info, int userId) {
535539
NativeEngine.whitelist(whitePath, true);
536540
}
537541

542+
// Android 11 -> see https://developer.android.com/training/data-storage#scoped-storage
543+
// 安卓11 打开这个链接看看 https://developer.android.google.cn/training/data-storage#scoped-storage
544+
// see https://android-opengrok.bangnimang.net/android-11.0.0_r8/xref/frameworks/base/core/java/android/os/Environment.java
538545
// redirect xxx/Android/data/ -> /xxx/Android/data/<host>/virtual/<user>
539546
NativeEngine.redirectDirectory(new File(storageRoot, "Android/data/").getAbsolutePath(), privatePath);
547+
// redirect xxx/Android/obb/ -> /xxx/Android/data/<host>/virtual/<user>
548+
NativeEngine.redirectDirectory(new File(storageRoot, "Android/obb/").getAbsolutePath(), privatePath);
540549
// redirect /sdcard/ -> vsdcard
541550
NativeEngine.redirectDirectory(storageRoot, vsPath);
542551
}
@@ -547,6 +556,9 @@ private HashSet<String> getMountPoints() {
547556
HashSet<String> mountPoints = new HashSet<>(3);
548557
mountPoints.add("/mnt/sdcard/");
549558
mountPoints.add("/sdcard/");
559+
// Redmi 10X Pro, Pixel 5... More mount points?
560+
561+
mountPoints.add("/storage/self/primary/");
550562
String[] points = StorageManagerCompat.getAllPoints(VirtualCore.get().getContext());
551563
if (points != null) {
552564
Collections.addAll(mountPoints, points);

0 commit comments

Comments
 (0)