Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix / and /storage/emulated not showing any files #1034

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.os.FileObserver;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -197,6 +198,29 @@ public Object query()

ArrayList<File> files = new ArrayList<File>(Arrays.asList(readdir));
Collections.sort(files, mFileComparator);

// Hack alert: On Android >. 6.0, some of the parent directories
// of the external storage may not be readable, meaning that if
// the user browses up the tree, they may suddenly not have the
// option to go back. Think of going from /storage/emulated/0 to
// /storage/emulated and not seeing the 0 option anymore.
if (files.isEmpty()) {
File possibleChild = Environment.getExternalStorageDirectory();
while (true) {
File possibleParent = possibleChild.getParentFile();
if (possibleParent == null) {
break;
}

if (possibleParent.equals(file)) {
files.add(possibleChild);
break;
}

possibleChild = possibleChild.getParentFile();
}
}

if (!mFsRoot.equals(file))
files.add(0, new File(file, FileUtils.NAME_PARENT_FOLDER));

Expand Down Expand Up @@ -343,6 +367,7 @@ public static Limiter buildLimiter(File file)
{
if (pointsToParentFolder(file))
file = file.getParentFile().getParentFile();

String[] fields = FILE_SEPARATOR.split(file.getPath().substring(1));
return new Limiter(MediaUtils.TYPE_FILE, fields, file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@
package ch.blinkenlights.android.vanilla;

import android.content.Context;
import android.app.Activity;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.ImageView;
import android.graphics.drawable.Drawable;

import java.io.File;
import java.util.Arrays;
Expand Down Expand Up @@ -183,13 +178,26 @@ private void refresh() {
if (!mFsRoot.equals(path))
add(new FolderPickerAdapter.Item("..", null, 0));

// Hack alert: Android >= 6.0's default storage root directory
// is usually not readable. That's not a big issue but
// can be very annoying for users who browse around.
// We are therefore detecting this and will 'simulate'
// the existence of the default storage root.
if (dirs == null && mStorageDir.getParentFile().equals(path)) {
dirs = new File[] { mStorageDir };
// Hack alert: On Android >. 6.0, some of the parent directories
// of the external storage may not be readable, meaning that if
// the user browses up the tree, they may suddenly not have the
// option to go back. Think of going from /storage/emulated/0 to
// /storage/emulated and not seeing the 0 option anymore.
if (dirs == null) {
File possibleChild = mStorageDir;
while (true) {
File possibleParent = possibleChild.getParentFile();
if (possibleParent == null) {
break;
}

if (possibleParent.equals(path)) {
dirs = new File[] { possibleChild };
break;
}

possibleChild = possibleChild.getParentFile();
}
}

if (dirs != null) {
Expand Down