@@ -619,9 +619,21 @@ private boolean needPermission(String nativeURL, int permissionType) throws JSON
619
619
if (j .has ("externalApplicationStorageDirectory" )) {
620
620
allowedStorageDirectories .add (j .getString ("externalApplicationStorageDirectory" ));
621
621
}
622
- ArrayList <String > allowedExtraPatternStorageDirectories = new ArrayList <String >();
623
- // basic pattern for usual application storage directory, to extend the allowed list to external SD cards for example
624
- allowedExtraPatternStorageDirectories .add ("/Android/data/" + cordova .getActivity ().getPackageName () + "/" );
622
+ if (j .has ("removableExternalApplicationStorageDirectories" )) {
623
+ JSONArray array = j .getJSONArray ("removableExternalApplicationStorageDirectories" );
624
+ for (int i = 0 ; i < array .length (); i ++) {
625
+ allowedStorageDirectories .add (array .getString (i ));
626
+ }
627
+ }
628
+ if (j .has ("removableExternalMediaDirectories" )) {
629
+ JSONArray array = j .getJSONArray ("removableExternalMediaDirectories" );
630
+ for (int i = 0 ; i < array .length (); i ++) {
631
+ allowedStorageDirectories .add (array .getString (i ));
632
+ }
633
+ }
634
+ if (j .has ("externalMediaDirectory" )) {
635
+ allowedStorageDirectories .add (j .getString ("externalMediaDirectory" ));
636
+ }
625
637
626
638
if (permissionType == READ && hasReadPermission ()) {
627
639
return false ;
@@ -636,11 +648,6 @@ else if(permissionType == WRITE && hasWritePermission()) {
636
648
return false ;
637
649
}
638
650
}
639
- for (String extraPatternDirectory : allowedExtraPatternStorageDirectories ) {
640
- if (nativeURL .contains (extraPatternDirectory )) {
641
- return false ;
642
- }
643
- }
644
651
return true ;
645
652
}
646
653
@@ -1045,17 +1052,56 @@ private JSONObject requestAllPaths() throws JSONException {
1045
1052
ret .put ("applicationStorageDirectory" , toDirUrl (context .getFilesDir ().getParentFile ()));
1046
1053
ret .put ("dataDirectory" , toDirUrl (context .getFilesDir ()));
1047
1054
ret .put ("cacheDirectory" , toDirUrl (context .getCacheDir ()));
1048
- if (Environment .getExternalStorageState ().equals (Environment .MEDIA_MOUNTED )) {
1049
- try {
1050
- ret .put ("externalApplicationStorageDirectory" , toDirUrl (context .getExternalFilesDir (null ).getParentFile ()));
1051
- ret .put ("externalDataDirectory" , toDirUrl (context .getExternalFilesDir (null )));
1052
- ret .put ("externalCacheDirectory" , toDirUrl (context .getExternalCacheDir ()));
1053
- ret .put ("externalRootDirectory" , toDirUrl (Environment .getExternalStorageDirectory ()));
1054
- }
1055
- catch (NullPointerException e ) {
1055
+ try {
1056
+ if (Environment .getExternalStorageState ().equals (Environment .MEDIA_MOUNTED )) {
1057
+ ret .put ("externalApplicationStorageDirectory" , toDirUrl (context .getExternalFilesDir (null ).getParentFile ()));
1058
+ ret .put ("externalDataDirectory" , toDirUrl (context .getExternalFilesDir (null )));
1059
+ ret .put ("externalCacheDirectory" , toDirUrl (context .getExternalCacheDir ()));
1060
+ ret .put ("externalRootDirectory" , toDirUrl (Environment .getExternalStorageDirectory ()));
1061
+ }
1062
+
1063
+ JSONArray removableExternalApplicationStorageDirs = new JSONArray ();
1064
+ JSONArray removableExternalDataDirs = new JSONArray ();
1065
+ JSONArray removableExternalCacheDirs = new JSONArray ();
1066
+ JSONArray removableExternalMediaDirs = new JSONArray ();
1067
+ String externalMediaDir = null ;
1068
+ for (File filesDir : context .getExternalFilesDirs (null )) {
1069
+ if (filesDir != null ) {
1070
+ if (Environment .isExternalStorageRemovable (filesDir )) {
1071
+ removableExternalApplicationStorageDirs .put (toDirUrl (filesDir .getParentFile ()));
1072
+ removableExternalDataDirs .put (toDirUrl (filesDir ));
1073
+ }
1074
+ }
1075
+ }
1076
+ for (File cacheDir : context .getExternalCacheDirs ()) {
1077
+ if (cacheDir != null ) {
1078
+ if (Environment .isExternalStorageRemovable (cacheDir )) {
1079
+ removableExternalCacheDirs .put (toDirUrl (cacheDir ));
1080
+ }
1081
+ }
1082
+ }
1083
+ for (File mediaDir : context .getExternalMediaDirs ()) {
1084
+ if (mediaDir != null ) {
1085
+ String dirUrl = toDirUrl (mediaDir );
1086
+ if (Environment .isExternalStorageRemovable (mediaDir )) {
1087
+ removableExternalMediaDirs .put (dirUrl );
1088
+ } else {
1089
+ if (externalMediaDir != null ) {
1090
+ LOG .w (LOG_TAG , "External media directory already found ; skip other value " + dirUrl );
1091
+ continue ;
1092
+ }
1093
+ externalMediaDir = dirUrl ;
1094
+ }
1095
+ }
1096
+ }
1097
+ ret .put ("removableExternalApplicationStorageDirectories" , removableExternalApplicationStorageDirs );
1098
+ ret .put ("removableExternalDataDirectories" , removableExternalDataDirs );
1099
+ ret .put ("removableExternalCacheDirectories" , removableExternalCacheDirs );
1100
+ ret .put ("removableExternalMediaDirectories" , removableExternalMediaDirs );
1101
+ ret .put ("externalMediaDirectory" , externalMediaDir );
1102
+ } catch (NullPointerException e ) {
1056
1103
/* If external storage is unavailable, context.getExternal* returns null */
1057
- LOG .d (LOG_TAG , "Unable to access these paths, most liklely due to USB storage" );
1058
- }
1104
+ LOG .d (LOG_TAG , "Unable to access these paths, most likely due to USB storage" );
1059
1105
}
1060
1106
return ret ;
1061
1107
}
0 commit comments