Skip to content

Commit 7c5a17a

Browse files
authored
Merge pull request #986 from lianglixin/patch-1
Fix Android 11 broken obb
2 parents f5b1174 + 13e6157 commit 7c5a17a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

+15-2
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ private void startIOUniformer() {
484484
private void setupVirtualStorage(ApplicationInfo info, int userId) {
485485
VirtualStorageManager vsManager = VirtualStorageManager.get();
486486
boolean enable = vsManager.isVirtualStorageEnable(info.packageName, userId);
487-
if (!enable) {
487+
// Android 11, force enable storage redirect.
488+
if (!enable && !(Build.VERSION.SDK_INT >= 30)) {
488489
// There are lots of situation to deal, I am tired, disable it now.
489490
// such as: FileProvider.
490491
return;
@@ -507,7 +508,11 @@ private void setupVirtualStorage(ApplicationInfo info, int userId) {
507508
whiteList.add(Environment.DIRECTORY_MOVIES);
508509
whiteList.add(Environment.DIRECTORY_DOWNLOADS);
509510
whiteList.add(Environment.DIRECTORY_DCIM);
510-
whiteList.add("Android/obb");
511+
// Android 11, do not tryna fetch this directory directly or crash.
512+
// See docs below...
513+
if (Build.VERSION.SDK_INT < 30) {
514+
whiteList.add("Android/obb");
515+
}
511516
if (Build.VERSION.SDK_INT >= 19) {
512517
whiteList.add(Environment.DIRECTORY_DOCUMENTS);
513518
}
@@ -535,8 +540,13 @@ private void setupVirtualStorage(ApplicationInfo info, int userId) {
535540
NativeEngine.whitelist(whitePath, true);
536541
}
537542

543+
// Android 11 -> see https://developer.android.com/training/data-storage#scoped-storage
544+
// 安卓11 打开这个链接看看 https://developer.android.google.cn/training/data-storage#scoped-storage
545+
// see https://android-opengrok.bangnimang.net/android-11.0.0_r8/xref/frameworks/base/core/java/android/os/Environment.java
538546
// redirect xxx/Android/data/ -> /xxx/Android/data/<host>/virtual/<user>
539547
NativeEngine.redirectDirectory(new File(storageRoot, "Android/data/").getAbsolutePath(), privatePath);
548+
// redirect xxx/Android/obb/ -> /xxx/Android/data/<host>/virtual/<user>
549+
NativeEngine.redirectDirectory(new File(storageRoot, "Android/obb/").getAbsolutePath(), privatePath);
540550
// redirect /sdcard/ -> vsdcard
541551
NativeEngine.redirectDirectory(storageRoot, vsPath);
542552
}
@@ -547,6 +557,9 @@ private HashSet<String> getMountPoints() {
547557
HashSet<String> mountPoints = new HashSet<>(3);
548558
mountPoints.add("/mnt/sdcard/");
549559
mountPoints.add("/sdcard/");
560+
// Redmi 10X Pro, Pixel 5... More mount points?
561+
562+
mountPoints.add("/storage/self/primary/");
550563
String[] points = StorageManagerCompat.getAllPoints(VirtualCore.get().getContext());
551564
if (points != null) {
552565
Collections.addAll(mountPoints, points);

0 commit comments

Comments
 (0)