Skip to content

Commit

Permalink
#169: Allow Media Scanner to scan external sdcard and usb stick if mo…
Browse files Browse the repository at this point in the history
…unted under storage
  • Loading branch information
k3b committed Mar 24, 2020
1 parent a42652e commit 48075d7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
15 changes: 14 additions & 1 deletion app/src/main/java/de/k3b/android/util/OsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,19 @@ public static File[] getExternalStorageDirFiles() {
// i.e. /mnt
File mountRoot = (extDir == null) ? null :extDir.getParentFile();

return (mountRoot != null) ? mountRoot.listFiles() : null;
File[] files = (mountRoot != null) ? mountRoot.listFiles() : null;
if (((files == null) || (files.length == 0)) && (mountRoot != null)) {
// getExternalStorageDirectory = /storage/emulated/0 ==> /storage if emulated is protected
mountRoot = mountRoot.getParentFile();
files = (mountRoot != null) ? mountRoot.listFiles() : null;
for (int i = files.length - 1; i >= 0; i--) {
if (files[i].getName().compareToIgnoreCase("emulated") == 0) {
// emulated is protected so use emulated/0 instead
files[i] = new File(mountRoot.getAbsolutePath() + "/emulated/0");
}
}
}
return files;
}

private static boolean isAllowed(File mountFile) {
Expand Down Expand Up @@ -81,6 +93,7 @@ public static OSDirectory getRootOSDirectory(OSDirectory factory) {
root = createOsDirectory(externalRoot, factory);
}
}
root.addChildDirs(OsUtils.getExternalStorageDirFiles());
return root;
}

Expand Down
36 changes: 21 additions & 15 deletions fotolib2/src/main/java/de/k3b/io/OSDirectory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2019 by k3b.
* Copyright (c) 2015-2020 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager
*
Expand Down Expand Up @@ -125,26 +125,32 @@ private OSDirectory getRoot() {
@Override
public List<IDirectory> getChildren() {
if ((mCurrent != null) && (mChilden == null)) {
mChilden = new ArrayList<IDirectory>();
File[] files = mCurrent.listFiles();
if (files != null) {
for (File file : files) {
if ((file != null)
&& !file.isHidden()
&& !file.getName().startsWith(".")
&& !FileUtils.isSymlinkDir(file,true)
// && file.canWrite() // bugfix: must be visible because writeprotected parentdir may contain writeenabled subdirs
) {
if (isDirectory(file)) {
mChilden.add(createOsDirectory(file, this, null));
}
addChildDirs(files);
}
return mChilden;
}

public void addChildDirs(File... files) {
if (mChilden == null) {
mChilden = new ArrayList<IDirectory>();
}
if (files != null) {
for (File file : files) {
if ((file != null)
&& !file.isHidden()
&& !file.getName().startsWith(".")
&& !FileUtils.isSymlinkDir(file, true)
// && file.canWrite() // bugfix: must be visible because writeprotected parentdir may contain writeenabled subdirs
) {
if (isDirectory(file)) {
mChilden.add(createOsDirectory(file, this, null));
}
// } else if (LibGlobal.debugEnabled) {
// logger.debug(FileUtils.getDebugString("OSDirectory.getChildren() rejected ", file));
}
}
}
}
return mChilden;
}

protected boolean isDirectory(File file) {
Expand Down

0 comments on commit 48075d7

Please sign in to comment.