@@ -484,7 +484,8 @@ private void startIOUniformer() {
484
484
private void setupVirtualStorage (ApplicationInfo info , int userId ) {
485
485
VirtualStorageManager vsManager = VirtualStorageManager .get ();
486
486
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 )) {
488
489
// There are lots of situation to deal, I am tired, disable it now.
489
490
// such as: FileProvider.
490
491
return ;
@@ -507,7 +508,11 @@ private void setupVirtualStorage(ApplicationInfo info, int userId) {
507
508
whiteList .add (Environment .DIRECTORY_MOVIES );
508
509
whiteList .add (Environment .DIRECTORY_DOWNLOADS );
509
510
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
+ }
511
516
if (Build .VERSION .SDK_INT >= 19 ) {
512
517
whiteList .add (Environment .DIRECTORY_DOCUMENTS );
513
518
}
@@ -535,8 +540,13 @@ private void setupVirtualStorage(ApplicationInfo info, int userId) {
535
540
NativeEngine .whitelist (whitePath , true );
536
541
}
537
542
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
538
546
// redirect xxx/Android/data/ -> /xxx/Android/data/<host>/virtual/<user>
539
547
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 );
540
550
// redirect /sdcard/ -> vsdcard
541
551
NativeEngine .redirectDirectory (storageRoot , vsPath );
542
552
}
@@ -547,6 +557,9 @@ private HashSet<String> getMountPoints() {
547
557
HashSet <String > mountPoints = new HashSet <>(3 );
548
558
mountPoints .add ("/mnt/sdcard/" );
549
559
mountPoints .add ("/sdcard/" );
560
+ // Redmi 10X Pro, Pixel 5... More mount points?
561
+
562
+ mountPoints .add ("/storage/self/primary/" );
550
563
String [] points = StorageManagerCompat .getAllPoints (VirtualCore .get ().getContext ());
551
564
if (points != null ) {
552
565
Collections .addAll (mountPoints , points );
0 commit comments