From 48075d732e22b73b44227ac066c8d8066a9366c6 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Tue, 24 Mar 2020 07:35:07 +0100 Subject: [PATCH] #169: Allow Media Scanner to scan external sdcard and usb stick if mounted under storage --- .../java/de/k3b/android/util/OsUtils.java | 15 +++++++- .../src/main/java/de/k3b/io/OSDirectory.java | 36 +++++++++++-------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/de/k3b/android/util/OsUtils.java b/app/src/main/java/de/k3b/android/util/OsUtils.java index 48c3e24b..f0b4732f 100644 --- a/app/src/main/java/de/k3b/android/util/OsUtils.java +++ b/app/src/main/java/de/k3b/android/util/OsUtils.java @@ -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) { @@ -81,6 +93,7 @@ public static OSDirectory getRootOSDirectory(OSDirectory factory) { root = createOsDirectory(externalRoot, factory); } } + root.addChildDirs(OsUtils.getExternalStorageDirFiles()); return root; } diff --git a/fotolib2/src/main/java/de/k3b/io/OSDirectory.java b/fotolib2/src/main/java/de/k3b/io/OSDirectory.java index c0a74794..fc1d7025 100644 --- a/fotolib2/src/main/java/de/k3b/io/OSDirectory.java +++ b/fotolib2/src/main/java/de/k3b/io/OSDirectory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2019 by k3b. + * Copyright (c) 2015-2020 by k3b. * * This file is part of AndroFotoFinder / #APhotoManager * @@ -125,26 +125,32 @@ private OSDirectory getRoot() { @Override public List getChildren() { if ((mCurrent != null) && (mChilden == null)) { - mChilden = new ArrayList(); 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(); + } + 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) {