diff options
author | Jorge Ruesga <jorge@ruesga.com> | 2013-01-09 00:56:18 +0100 |
---|---|---|
committer | Jorge Ruesga <jorge@ruesga.com> | 2013-01-09 00:56:18 +0100 |
commit | 3bf048a2ab6e0393055c4991dfaab6c84f0ecae7 (patch) | |
tree | c7dc0b9f2647328cb139abcd1d3839f84d437128 /src/com/cyanogenmod/filemanager/console | |
parent | 1530ad9a8b23fd1a599ad71057e029d2ada3e4a5 (diff) | |
download | android_packages_apps_CMFileManager-3bf048a2ab6e0393055c4991dfaab6c84f0ecae7.tar.gz android_packages_apps_CMFileManager-3bf048a2ab6e0393055c4991dfaab6c84f0ecae7.tar.bz2 android_packages_apps_CMFileManager-3bf048a2ab6e0393055c4991dfaab6c84f0ecae7.zip |
CMFM: Do not use cd and pwd commands
Remove cd and pwd commands and use / as working directory for shell process (this commands
are not used). This prevents that storage volumes from get busy on unmount file systems.
Signed-off-by: jruesga <jorge@ruesga.com>
Change-Id: I772866c00233351f505b61f53d43bac5de02a5e4
Diffstat (limited to 'src/com/cyanogenmod/filemanager/console')
5 files changed, 17 insertions, 117 deletions
diff --git a/src/com/cyanogenmod/filemanager/console/ConsoleBuilder.java b/src/com/cyanogenmod/filemanager/console/ConsoleBuilder.java index 1552abd9..17914693 100644 --- a/src/com/cyanogenmod/filemanager/console/ConsoleBuilder.java +++ b/src/com/cyanogenmod/filemanager/console/ConsoleBuilder.java @@ -30,7 +30,6 @@ import com.cyanogenmod.filemanager.preferences.AccessMode; import com.cyanogenmod.filemanager.preferences.FileManagerSettings; import com.cyanogenmod.filemanager.preferences.Preferences; import com.cyanogenmod.filemanager.util.DialogHelper; -import com.cyanogenmod.filemanager.util.FileHelper; import java.io.FileNotFoundException; import java.io.IOException; @@ -125,7 +124,7 @@ public final class ConsoleBuilder { try { //Create the console, destroy the current console, and marks as current holder = new ConsoleHolder( - createNonPrivilegedConsole(context, FileHelper.ROOT_DIRECTORY)); + createNonPrivilegedConsole(context)); destroyConsole(); sHolder = holder; return true; @@ -157,7 +156,7 @@ public final class ConsoleBuilder { try { //Create the console, destroy the current console, and marks as current holder = new ConsoleHolder( - createAndCheckPrivilegedConsole(context, FileHelper.ROOT_DIRECTORY)); + createAndCheckPrivilegedConsole(context)); destroyConsole(); sHolder = holder; @@ -243,11 +242,8 @@ public final class ConsoleBuilder { //Is there a console allocated if (sHolder == null) { sHolder = (superuserMode) - ? new ConsoleHolder( - createAndCheckPrivilegedConsole( - context, FileHelper.ROOT_DIRECTORY)) - : new ConsoleHolder( - createNonPrivilegedConsole(context, FileHelper.ROOT_DIRECTORY)); + ? new ConsoleHolder(createAndCheckPrivilegedConsole(context)) + : new ConsoleHolder(createNonPrivilegedConsole(context)); if (superuserMode) { // Change also the background console to privileged FileManagerApplication.changeBackgroundConsoleToPriviligedConsole(); @@ -275,7 +271,6 @@ public final class ConsoleBuilder { * Method that creates a new non privileged console. * * @param context The current context - * @param initialDirectory The initial directory of the console * @return Console The non privileged console * @throws FileNotFoundException If the initial directory not exists * @throws IOException If initial directory couldn't be checked @@ -283,7 +278,7 @@ public final class ConsoleBuilder { * @throws ConsoleAllocException If the console can't be allocated * @see NonPriviledgeConsole */ - public static Console createNonPrivilegedConsole(Context context, String initialDirectory) + public static Console createNonPrivilegedConsole(Context context) throws FileNotFoundException, IOException, InvalidCommandDefinitionException, ConsoleAllocException { @@ -291,14 +286,14 @@ public final class ConsoleBuilder { // Is rooted? Then create a shell console if (FileManagerApplication.isDeviceRooted()) { - NonPriviledgeConsole console = new NonPriviledgeConsole(initialDirectory); + NonPriviledgeConsole console = new NonPriviledgeConsole(); console.setBufferSize(bufferSize); console.alloc(); return console; } // No rooted. Then create a java console - JavaConsole console = new JavaConsole(context, initialDirectory, bufferSize); + JavaConsole console = new JavaConsole(context, bufferSize); console.alloc(); return console; } @@ -308,7 +303,6 @@ public final class ConsoleBuilder { * privileged console fails, the a non privileged console * * @param context The current context - * @param initialDirectory The initial directory of the console * @return Console The privileged console * @throws FileNotFoundException If the initial directory not exists * @throws IOException If initial directory couldn't be checked @@ -317,10 +311,10 @@ public final class ConsoleBuilder { * @throws InsufficientPermissionsException If the console created is not a privileged console * @see PrivilegedConsole */ - public static Console createPrivilegedConsole(Context context, String initialDirectory) + public static Console createPrivilegedConsole(Context context) throws FileNotFoundException, IOException, InvalidCommandDefinitionException, ConsoleAllocException, InsufficientPermissionsException { - PrivilegedConsole console = new PrivilegedConsole(initialDirectory); + PrivilegedConsole console = new PrivilegedConsole(); console.setBufferSize(context.getResources().getInteger(R.integer.buffer_size)); console.alloc(); if (console.getIdentity().getUser().getId() != ROOT_UID) { @@ -340,7 +334,6 @@ public final class ConsoleBuilder { * privileged console fails, the a non privileged console * * @param context The current context - * @param initialDirectory The initial directory of the console * @return Console The privileged console * @throws FileNotFoundException If the initial directory not exists * @throws IOException If initial directory couldn't be checked @@ -349,10 +342,10 @@ public final class ConsoleBuilder { * @throws InsufficientPermissionsException If the console created is not a privileged console * @see PrivilegedConsole */ - public static Console createAndCheckPrivilegedConsole(Context context, String initialDirectory) + public static Console createAndCheckPrivilegedConsole(Context context) throws FileNotFoundException, IOException, InvalidCommandDefinitionException, ConsoleAllocException, InsufficientPermissionsException { - return createAndCheckPrivilegedConsole(context, initialDirectory, true); + return createAndCheckPrivilegedConsole(context, true); } /** @@ -360,7 +353,6 @@ public final class ConsoleBuilder { * privileged console fails, the a non privileged console * * @param context The current context - * @param initialDirectory The initial directory of the console * @param silent Indicates that no message have to be displayed * @return Console The privileged console * @throws FileNotFoundException If the initial directory not exists @@ -371,12 +363,12 @@ public final class ConsoleBuilder { * @see PrivilegedConsole */ public static Console createAndCheckPrivilegedConsole( - Context context, String initialDirectory, boolean silent) + Context context, boolean silent) throws FileNotFoundException, IOException, InvalidCommandDefinitionException, ConsoleAllocException, InsufficientPermissionsException { try { // Create the privileged console - return createPrivilegedConsole(context, initialDirectory); + return createPrivilegedConsole(context); } catch (ConsoleAllocException caEx) { //Show a message with the problem? @@ -404,7 +396,7 @@ public final class ConsoleBuilder { } //Create the non-privileged console - return createNonPrivilegedConsole(context, initialDirectory); + return createNonPrivilegedConsole(context); } // Rethrow the exception diff --git a/src/com/cyanogenmod/filemanager/console/java/JavaConsole.java b/src/com/cyanogenmod/filemanager/console/java/JavaConsole.java index df04d4a5..2edb42a9 100644 --- a/src/com/cyanogenmod/filemanager/console/java/JavaConsole.java +++ b/src/com/cyanogenmod/filemanager/console/java/JavaConsole.java @@ -17,10 +17,8 @@ package com.cyanogenmod.filemanager.console.java; import android.content.Context; -import android.os.storage.StorageVolume; import android.util.Log; -import com.cyanogenmod.filemanager.commands.ChangeCurrentDirExecutable; import com.cyanogenmod.filemanager.commands.Executable; import com.cyanogenmod.filemanager.commands.ExecutableFactory; import com.cyanogenmod.filemanager.commands.SIGNAL; @@ -35,7 +33,6 @@ import com.cyanogenmod.filemanager.console.NoSuchFileOrDirectory; import com.cyanogenmod.filemanager.console.OperationTimeoutException; import com.cyanogenmod.filemanager.console.ReadOnlyFilesystemException; import com.cyanogenmod.filemanager.model.Identity; -import com.cyanogenmod.filemanager.util.StorageHelper; /** * An implementation of a {@link Console} based on a java implementation.<br/> @@ -48,7 +45,6 @@ public final class JavaConsole extends Console { private static final String TAG = "JavaConsole"; //$NON-NLS-1$ private boolean mActive; - private String mCurrentDir; private final Context mCtx; private final int mBufferSize; @@ -57,14 +53,12 @@ public final class JavaConsole extends Console { * Constructor of <code>JavaConsole</code> * * @param ctx The current context - * @param initialDir The initial directory * @param bufferSize The buffer size */ - public JavaConsole(Context ctx, String initialDir, int bufferSize) { + public JavaConsole(Context ctx, int bufferSize) { super(); this.mCtx = ctx; this.mBufferSize = bufferSize; - this.mCurrentDir = initialDir; } /** @@ -76,21 +70,6 @@ public final class JavaConsole extends Console { if (isTrace()) { Log.v(TAG, "Allocating Java console"); //$NON-NLS-1$ } - - //Retrieve the current directory from the first storage volume - StorageVolume[] vols = StorageHelper.getStorageVolumes(this.mCtx); - if (vols == null || vols.length == 0) { - throw new ConsoleAllocException("Can't stat any directory"); //$NON-NLS-1$ - } - - // Test to change to current directory - ChangeCurrentDirExecutable currentDirCmd = - getExecutableFactory(). - newCreator().createChangeCurrentDirExecutable(this.mCurrentDir); - execute(currentDirCmd); - - // Tested. Is not active - this.mCurrentDir = vols[0].getPath(); this.mActive = true; } catch (Exception e) { Log.e(TAG, "Failed to allocate Java console", e); //$NON-NLS-1$ @@ -151,24 +130,6 @@ public final class JavaConsole extends Console { } /** - * Method that returns the current directory of the console - * - * @return String The current directory - */ - public String getCurrentDir() { - return this.mCurrentDir; - } - - /** - * Method that sets the current directory of the console - * - * @param currentDir The current directory - */ - public void setCurrentDir(String currentDir) { - this.mCurrentDir = currentDir; - } - - /** * Method that returns the current context * * @return Context The current context diff --git a/src/com/cyanogenmod/filemanager/console/shell/NonPriviledgeConsole.java b/src/com/cyanogenmod/filemanager/console/shell/NonPriviledgeConsole.java index aec764f8..7673bbf0 100644 --- a/src/com/cyanogenmod/filemanager/console/shell/NonPriviledgeConsole.java +++ b/src/com/cyanogenmod/filemanager/console/shell/NonPriviledgeConsole.java @@ -33,19 +33,6 @@ public class NonPriviledgeConsole extends ShellConsole { /** * Constructor of <code>NonPriviledgeConsole</code>. * - * @param initialDirectory The initial directory of the shell - * @throws FileNotFoundException If the initial directory not exists - * @throws IOException If initial directory couldn't be checked - * @throws InvalidCommandDefinitionException If the command has an invalid definition - */ - public NonPriviledgeConsole(String initialDirectory) - throws FileNotFoundException, IOException, InvalidCommandDefinitionException { - super(new BashShell(), initialDirectory); - } - - /** - * Constructor of <code>NonPriviledgeConsole</code>. - * * @throws FileNotFoundException If the default initial directory not exists * @throws IOException If initial directory couldn't be checked * @throws InvalidCommandDefinitionException If the command has an invalid definition diff --git a/src/com/cyanogenmod/filemanager/console/shell/PrivilegedConsole.java b/src/com/cyanogenmod/filemanager/console/shell/PrivilegedConsole.java index 4e5d3088..cc441314 100644 --- a/src/com/cyanogenmod/filemanager/console/shell/PrivilegedConsole.java +++ b/src/com/cyanogenmod/filemanager/console/shell/PrivilegedConsole.java @@ -34,19 +34,6 @@ public class PrivilegedConsole extends ShellConsole { /** * Constructor of <code>PrivilegedConsole</code>. * - * @param initialDirectory The initial directory of the shell - * @throws FileNotFoundException If the initial directory not exists - * @throws IOException If initial directory couldn't be checked - * @throws InvalidCommandDefinitionException If the command has an invalid definition - */ - public PrivilegedConsole(String initialDirectory) - throws FileNotFoundException, IOException, InvalidCommandDefinitionException { - super(new SuperuserShell(), initialDirectory); - } - - /** - * Constructor of <code>PrivilegedConsole</code>. - * * @throws FileNotFoundException If the default initial directory not exists * @throws IOException If initial directory couldn't be checked * @throws InvalidCommandDefinitionException If the command has an invalid definition diff --git a/src/com/cyanogenmod/filemanager/console/shell/ShellConsole.java b/src/com/cyanogenmod/filemanager/console/shell/ShellConsole.java index 5f300dd1..12b7fe26 100644 --- a/src/com/cyanogenmod/filemanager/console/shell/ShellConsole.java +++ b/src/com/cyanogenmod/filemanager/console/shell/ShellConsole.java @@ -42,8 +42,6 @@ import com.cyanogenmod.filemanager.console.NoSuchFileOrDirectory; import com.cyanogenmod.filemanager.console.OperationTimeoutException; import com.cyanogenmod.filemanager.console.ReadOnlyFilesystemException; import com.cyanogenmod.filemanager.model.Identity; -import com.cyanogenmod.filemanager.preferences.FileManagerSettings; -import com.cyanogenmod.filemanager.preferences.Preferences; import com.cyanogenmod.filemanager.util.CommandHelper; import com.cyanogenmod.filemanager.util.FileHelper; @@ -78,7 +76,6 @@ public abstract class ShellConsole extends Console implements Program.ProgramLis //Shell References private final Shell mShell; - private final String mInitialDirectory; private Identity mIdentity; //Process References @@ -134,24 +131,10 @@ public abstract class ShellConsole extends Console implements Program.ProgramLis * Constructor of <code>ShellConsole</code>. * * @param shell The shell used to execute commands - * @throws FileNotFoundException If the default initial directory not exists - * @throws IOException If initial directory couldn't be resolved - */ - public ShellConsole(Shell shell) throws FileNotFoundException, IOException { - this(shell, Preferences.getSharedPreferences().getString( - FileManagerSettings.SETTINGS_INITIAL_DIR.getId(), - (String)FileManagerSettings.SETTINGS_INITIAL_DIR.getDefaultValue())); - } - - /** - * Constructor of <code>ShellConsole</code>. - * - * @param shell The shell used to execute commands - * @param initialDirectory The initial directory of the shell * @throws FileNotFoundException If the initial directory not exists * @throws IOException If initial directory couldn't be resolved */ - public ShellConsole(Shell shell, String initialDirectory) + public ShellConsole(Shell shell) throws FileNotFoundException, IOException { super(); this.mShell = shell; @@ -159,16 +142,6 @@ public abstract class ShellConsole extends Console implements Program.ProgramLis this.mBufferSize = DEFAULT_BUFFER; - //Resolve and checks the initial directory - File f = new File(initialDirectory); - while (FileHelper.isSymlink(f)) { - f = FileHelper.resolveSymlink(f); - } - if (!f.exists() || !f.isDirectory()) { - throw new FileNotFoundException(f.toString()); - } - this.mInitialDirectory = initialDirectory; - //Restart the buffers this.mSbIn = new StringBuffer(); this.mSbErr = new StringBuffer(); @@ -242,7 +215,7 @@ public abstract class ShellConsole extends Console implements Program.ProgramLis rt.exec( cmd.toArray(new String[cmd.size()]), null, - new File(this.mInitialDirectory)); + new File(FileHelper.ROOT_DIRECTORY).getCanonicalFile()); synchronized (this.mSync) { this.mActive = true; } |