diff --git a/Backbone/src/main/AndroidManifest.xml b/Backbone/src/main/AndroidManifest.xml index 9394059fb..5b6a0d129 100644 --- a/Backbone/src/main/AndroidManifest.xml +++ b/Backbone/src/main/AndroidManifest.xml @@ -196,7 +196,7 @@ + android:value="me.toolify.backbone.dashclock.DashSettings" /> mDisksUsage; + private final Hashtable mDisksUsage = new Hashtable(); /** * Constructor of DiskUsageCommand. @@ -60,7 +62,6 @@ public DiskUsageCommand(String mountsFile, String dir) { super(); this.mMountsFile = mountsFile; this.mSrc = null; - this.mDisksUsage = new ArrayList(); } /** @@ -68,7 +69,10 @@ public DiskUsageCommand(String mountsFile, String dir) { */ @Override public List getResult() { - return this.mDisksUsage; + List ret = new ArrayList(); + for(DiskUsage du : mDisksUsage.values()) + ret.add(du); + return ret; } /** @@ -94,11 +98,12 @@ public void execute() // Get every disk usage for (int i = 0; i < mp.size(); i++) { - File root = new File(mp.get(i).getMountPoint()); - this.mDisksUsage.add(createDiskUsuage(root)); + String mpp = mp.get(i).getMountPoint(); + File root = new File(mpp); + mDisksUsage.put(mpp, createDiskUsage(root)); } } else { - this.mDisksUsage.add(createDiskUsuage(new File(this.mSrc))); + mDisksUsage.put(mSrc, createDiskUsage(new File(this.mSrc))); } if (isTrace()) { @@ -112,12 +117,14 @@ public void execute() * @param root The root file * @return DiskUsage The disk usage */ - private DiskUsage createDiskUsuage(File file) { + private DiskUsage createDiskUsage(File root) { + long total = root.getTotalSpace(); + long free = root.getFreeSpace(); DiskUsage du = new DiskUsage( - file.getAbsolutePath(), - file.getTotalSpace(), - file.getTotalSpace() - file.getFreeSpace(), - file.getFreeSpace()); + root.getAbsolutePath(), + total, + total - free, + free); if (isTrace()) { Log.v(TAG, du.toString()); } diff --git a/Backbone/src/main/java/me/toolify/backbone/dashclock/DashSettings.java b/Backbone/src/main/java/me/toolify/backbone/dashclock/DashSettings.java index ea30064e2..66a01a00d 100644 --- a/Backbone/src/main/java/me/toolify/backbone/dashclock/DashSettings.java +++ b/Backbone/src/main/java/me/toolify/backbone/dashclock/DashSettings.java @@ -78,14 +78,19 @@ public boolean onPreferenceClick(Preference preference) { for(Object storage : StorageHelper.getStorageVolumes(this)) { final String path = StorageHelper.getStoragePath(storage); - final String desc = StorageHelper.getStorageVolumeDescription(this, storage); + String desc = StorageHelper.getStorageVolumeDescription(this, storage); final CheckBoxPreference p = new CheckBoxPreference(this); int storeIcon = DashExtension.getIcon(desc); + if(desc.equals(getString(R.string.external_storage))|| + desc.equals(getString(R.string.internal_storage))) + storeIcon = R.drawable.dashclock_sd; p.setIcon(storeIcon); boolean useMe = true; MountPoint mp = MountPointHelper.getMountPointFromDirectory(path); if(mp.getOptions().indexOf("mode=0")>-1) useMe = false; // Cyanogenmod USB workaround if(!MountPointHelper.isReadWrite(mp)) useMe = false; + if(desc.equals(getString(R.string.bookmarks_system_folder))) + desc = path; p.setTitle(desc); p.setChecked(prefs.getBoolean("storage_" + path, useMe)); p.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { diff --git a/Backbone/src/main/java/me/toolify/backbone/model/Bookmark.java b/Backbone/src/main/java/me/toolify/backbone/model/Bookmark.java index e4f2212da..ab2217c8c 100644 --- a/Backbone/src/main/java/me/toolify/backbone/model/Bookmark.java +++ b/Backbone/src/main/java/me/toolify/backbone/model/Bookmark.java @@ -22,11 +22,11 @@ import android.os.Parcelable; import android.provider.BaseColumns; -import me.toolify.backbone.providers.BookmarksContentProvider; - import java.io.File; import java.io.Serializable; +import me.toolify.backbone.providers.BookmarksContentProvider; + /** * A class that represent a bookmark. */ @@ -190,7 +190,7 @@ public boolean equals(Object obj) { if (obj == null) { return false; } - if (getClass() != obj.getClass()) { + if (!(obj instanceof Bookmark)) { return false; } Bookmark other = (Bookmark) obj; @@ -268,6 +268,10 @@ public int compareTo(Bookmark another) { return this.mPath.compareTo(another.mPath); } + public BOOKMARK_TYPE getType() { + return mType; + } + /** * {@inheritDoc} */ diff --git a/Backbone/src/main/java/me/toolify/backbone/model/MountPoint.java b/Backbone/src/main/java/me/toolify/backbone/model/MountPoint.java index 956422cda..a3da94ba0 100644 --- a/Backbone/src/main/java/me/toolify/backbone/model/MountPoint.java +++ b/Backbone/src/main/java/me/toolify/backbone/model/MountPoint.java @@ -135,7 +135,7 @@ public boolean equals(Object obj) { if (obj == null) { return false; } - if (getClass() != obj.getClass()) { + if (!(obj instanceof MountPoint)) { return false; } MountPoint other = (MountPoint) obj; diff --git a/Backbone/src/main/java/me/toolify/backbone/tasks/FilesystemAsyncTask.java b/Backbone/src/main/java/me/toolify/backbone/tasks/FilesystemAsyncTask.java index 9c3024c2f..f2bd76560 100644 --- a/Backbone/src/main/java/me/toolify/backbone/tasks/FilesystemAsyncTask.java +++ b/Backbone/src/main/java/me/toolify/backbone/tasks/FilesystemAsyncTask.java @@ -95,7 +95,10 @@ protected Boolean doInBackground(String... params) { if (isCancelled()) { return Boolean.TRUE; } - final MountPoint mp = MountPointHelper.getMountPointFromDirectory(dir); + MountPoint mp1 = MountPointHelper.getMountPointFromDirectory(dir); + if(mp1.getMountPoint().equals("/") && dir.equals("/storage/emulated/0")) // AOSP 4.3 bug + mp1 = MountPointHelper.getMountPointFromDirectory("/mnt/shell/emulated"); + final MountPoint mp = mp1; if (mp == null) { //There is no information about if (isCancelled()) { diff --git a/Backbone/src/main/java/me/toolify/backbone/util/CommandHelper.java b/Backbone/src/main/java/me/toolify/backbone/util/CommandHelper.java index 72e434411..0c90206be 100644 --- a/Backbone/src/main/java/me/toolify/backbone/util/CommandHelper.java +++ b/Backbone/src/main/java/me/toolify/backbone/util/CommandHelper.java @@ -17,7 +17,13 @@ package me.toolify.backbone.util; import android.content.Context; +import android.util.Log; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; + +import me.toolify.backbone.BuildConfig; import me.toolify.backbone.commands.AsyncResultListener; import me.toolify.backbone.commands.ChangeOwnerExecutable; import me.toolify.backbone.commands.ChangePermissionsExecutable; @@ -74,10 +80,6 @@ import me.toolify.backbone.model.User; import me.toolify.backbone.preferences.CompressionMode; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.List; - /** * A helper class with useful methods for deal with commands. @@ -909,9 +911,16 @@ public static DiskUsage getDiskUsage(Context context, String dir, Console consol DiskUsageExecutable executable = c.getExecutableFactory().newCreator().createDiskUsageExecutable(dir); execute(context, executable, c); - List du = executable.getResult(); - if (du != null && du.size() > 0) { - return du.get(0); + List dus = executable.getResult(); + if (dus != null && dus.size() > 0) { + for(DiskUsage du : dus) + { + if(!du.getMountPoint().equals(dir)) continue; + return du; + } + if(BuildConfig.DEBUG) + Log.w("CommandHelper", "Unable to find correct DiskUsage for " + dir); + return dus.get(0); // return first if none match } return null; } diff --git a/Backbone/src/main/java/me/toolify/backbone/util/StorageHelper.java b/Backbone/src/main/java/me/toolify/backbone/util/StorageHelper.java index 055e24d99..08476c2c1 100644 --- a/Backbone/src/main/java/me/toolify/backbone/util/StorageHelper.java +++ b/Backbone/src/main/java/me/toolify/backbone/util/StorageHelper.java @@ -19,16 +19,19 @@ import android.os.storage.StorageManager; import android.util.Log; +import java.io.File; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + import me.toolify.backbone.FileManagerApplication; import me.toolify.backbone.R; +import me.toolify.backbone.model.DiskUsage; import me.toolify.backbone.model.FileSystemObject; import me.toolify.backbone.model.MountPoint; import me.toolify.backbone.model.StorageVolume; -import java.io.File; -import java.lang.reflect.Method; -import java.util.HashMap; - /** * A helper class with useful methods for deal with storages. @@ -50,12 +53,22 @@ public final class StorageHelper { @SuppressWarnings("boxing") public static synchronized Object[] getStorageVolumes(Context ctx) { if (sStorageVolumes == null) { + //IMP!! Android SDK doesn't have a "getVolumeList" but is supported by CM10. //Use reflect to get this value (if possible) try { StorageManager sm = (StorageManager) ctx.getSystemService(Context.STORAGE_SERVICE); Method method = sm.getClass().getMethod("getVolumeList"); //$NON-NLS-1$ - sStorageVolumes = (Object[])method.invoke(sm); + List volumes = new ArrayList(); + for(Object o : (Object[])method.invoke(sm)) + { + String path = getStoragePath(o); + DiskUsage du = CommandHelper.getDiskUsage(ctx, path, null); + if(du.getTotal() <= 0) continue; // Ensure validity by checking for disk space + volumes.add(o); + } + if(volumes.size() == 0) throw new Exception("No valid volumes"); + return volumes.toArray(); } catch (Exception ex) { //Ignore. Android SDK StorageManager class doesn't have this method @@ -68,12 +81,12 @@ public static synchronized Object[] getStorageVolumes(Context ctx) { if(!MountPointHelper.isReadWrite(mp)) continue; String path = mp.getMountPoint(); if(!mp.getDevice().startsWith("/")) continue; - if(path.matches("^\\/(dev|persist|cache|proc|efs|data)")) - continue; + if(path.matches("^\\/(dev|persist|cache|proc|efs|data|acct|sys)\\/")) + continue; + if(path.matches("^\\/(dev|persist|cache|proc|efs|data|acct|sys)$")) + continue; StorageVolume sv = null; try { - if(MountPointHelper.getMountPointDiskUsage(mp).getTotal() < 5000000) - continue; FileSystemObject fso = CommandHelper.getFileInfo(ctx, path, null); sv = convertToStorageVolume(fso); } catch(Exception e3) { } @@ -149,7 +162,7 @@ public static boolean isPathInStorageVolume(String path) { /** * Method that determines the mount path of a {@link StorageVolume} object. * - * @param volume Object returned from {@link StorageHelper.getStorageVolumes()} + * @param volume Object returned from StorageHelper.getStorageVolumes() * @return Mounted path */ public static String getStoragePath(Object volume) @@ -167,7 +180,7 @@ public static String getStoragePath(Object volume) /** * Method that determines whether a path returned from - * {@link StorageHelper.getStorageVolumes()} is a valid, mounted, path. + * getStorageVolumes is a valid, mounted, path. * @param path Path to root of mount * @return boolean Whether path is mounted & valid */