OSDN Git Service

CMFM: Do not use cd and pwd commands
authorJorge Ruesga <jorge@ruesga.com>
Tue, 8 Jan 2013 23:56:18 +0000 (00:56 +0100)
committerJorge Ruesga <jorge@ruesga.com>
Tue, 8 Jan 2013 23:56:18 +0000 (00:56 +0100)
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

22 files changed:
res/xml/command_list.xml
src/com/cyanogenmod/filemanager/FileManagerApplication.java
src/com/cyanogenmod/filemanager/activities/NavigationActivity.java
src/com/cyanogenmod/filemanager/commands/ChangeCurrentDirExecutable.java [deleted file]
src/com/cyanogenmod/filemanager/commands/CurrentDirExecutable.java [deleted file]
src/com/cyanogenmod/filemanager/commands/ExecutableCreator.java
src/com/cyanogenmod/filemanager/commands/java/ChangeCurrentDirCommand.java [deleted file]
src/com/cyanogenmod/filemanager/commands/java/CurrentDirCommand.java [deleted file]
src/com/cyanogenmod/filemanager/commands/java/JavaExecutableCreator.java
src/com/cyanogenmod/filemanager/commands/shell/ChangeCurrentDirCommand.java [deleted file]
src/com/cyanogenmod/filemanager/commands/shell/CurrentDirCommand.java [deleted file]
src/com/cyanogenmod/filemanager/commands/shell/ShellExecutableCreator.java
src/com/cyanogenmod/filemanager/console/ConsoleBuilder.java
src/com/cyanogenmod/filemanager/console/java/JavaConsole.java
src/com/cyanogenmod/filemanager/console/shell/NonPriviledgeConsole.java
src/com/cyanogenmod/filemanager/console/shell/PrivilegedConsole.java
src/com/cyanogenmod/filemanager/console/shell/ShellConsole.java
src/com/cyanogenmod/filemanager/util/CommandHelper.java
tests/src/com/cyanogenmod/filemanager/commands/shell/AbstractConsoleTest.java
tests/src/com/cyanogenmod/filemanager/commands/shell/ChangeCurrentDirCommandTest.java [deleted file]
tests/src/com/cyanogenmod/filemanager/commands/shell/CurrentDirCommandTest.java [deleted file]
tests/src/com/cyanogenmod/filemanager/console/ConsoleBuilderTest.java

index 343df06..1e42cdc 100644 (file)
   <command commandId="bash" commandPath="/system/bin/sh" commandArgs="" />
   <command commandId="su" commandPath="/system/xbin/su" commandArgs="" />
 
-  <!-- Directory -->
-  <command commandId="cd" commandPath="cd" commandArgs="%1$s" />
-  <command commandId="pwd" commandPath="/system/xbin/pwd" commandArgs="-P" />
-
   <!-- Console info -->
   <command commandId="groups" commandPath="/system/xbin/groups" commandArgs="" />
   <command commandId="id" commandPath="/system/bin/id" commandArgs="-Gn" />
index a25126f..0e3ac35 100644 (file)
@@ -36,7 +36,6 @@ import com.cyanogenmod.filemanager.preferences.Preferences;
 import com.cyanogenmod.filemanager.ui.ThemeManager;
 import com.cyanogenmod.filemanager.ui.ThemeManager.Theme;
 import com.cyanogenmod.filemanager.util.AIDHelper;
-import com.cyanogenmod.filemanager.util.FileHelper;
 import com.cyanogenmod.filemanager.util.MimeTypeHelper;
 
 import java.io.File;
@@ -354,13 +353,11 @@ public final class FileManagerApplication extends Application {
             if (ConsoleBuilder.isPrivileged()) {
                 sBackgroundConsole =
                         new ConsoleHolder(
-                                ConsoleBuilder.createPrivilegedConsole(
-                                        ctx, FileHelper.ROOT_DIRECTORY));
+                                ConsoleBuilder.createPrivilegedConsole(ctx));
             } else {
                 sBackgroundConsole =
                         new ConsoleHolder(
-                                ConsoleBuilder.createNonPrivilegedConsole(
-                                        ctx, FileHelper.ROOT_DIRECTORY));
+                                ConsoleBuilder.createNonPrivilegedConsole(ctx));
             }
         } catch (Exception e) {
             Log.e(TAG,
@@ -389,8 +386,7 @@ public final class FileManagerApplication extends Application {
                 sBackgroundConsole =
                         new ConsoleHolder(
                                 ConsoleBuilder.createPrivilegedConsole(
-                                        getInstance().getApplicationContext(),
-                                        FileHelper.ROOT_DIRECTORY));
+                                        getInstance().getApplicationContext()));
             } catch (Exception e) {
                 try {
                     if (sBackgroundConsole != null) {
@@ -410,6 +406,9 @@ public final class FileManagerApplication extends Application {
      * @return boolean If the access mode of the application
      */
     public static AccessMode getAccessMode() {
+        if (!sIsDeviceRooted) {
+            return AccessMode.SAFE;
+        }
         String defaultValue =
                 ((ObjectStringIdentifier)FileManagerSettings.
                             SETTINGS_ACCESS_MODE.getDefaultValue()).getId();
index 1ecd3be..5ea33c2 100644 (file)
@@ -612,6 +612,13 @@ public class NavigationActivity extends Activity
                                 StorageHelper.getStorageVolumes(NavigationActivity.this);
                         if (volumes != null && volumes.length > 0) {
                             initialDir = volumes[0].getPath();
+                        } else {
+                            // Show exception and exists
+                            DialogHelper.showToast(
+                                    NavigationActivity.this,
+                                    R.string.msgs_cant_create_console, Toast.LENGTH_LONG);
+                            exit();
+                            return;
                         }
                     }
 
diff --git a/src/com/cyanogenmod/filemanager/commands/ChangeCurrentDirExecutable.java b/src/com/cyanogenmod/filemanager/commands/ChangeCurrentDirExecutable.java
deleted file mode 100644 (file)
index 5999cfc..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2012 The CyanogenMod Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.cyanogenmod.filemanager.commands;
-
-/**
- * An interface that represents an executable for retrieve the current directory.
- */
-public interface ChangeCurrentDirExecutable extends SyncResultExecutable {
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    Boolean getResult();
-}
diff --git a/src/com/cyanogenmod/filemanager/commands/CurrentDirExecutable.java b/src/com/cyanogenmod/filemanager/commands/CurrentDirExecutable.java
deleted file mode 100644 (file)
index 1d951f8..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2012 The CyanogenMod Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.cyanogenmod.filemanager.commands;
-
-/**
- * An interface that represents an executable for retrieve the current directory.
- */
-public interface CurrentDirExecutable extends SyncResultExecutable {
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    String getResult();
-}
index a0fd6f9..5d537a9 100644 (file)
@@ -33,20 +33,6 @@ import com.cyanogenmod.filemanager.preferences.CompressionMode;
 public interface ExecutableCreator {
 
     /**
-     * Method that creates an executable for change the current directory.
-     *
-     * @param dir The absolute path of the new directory to establish as current directory
-     * @return ChangeCurrentDirExecutable A {@link ChangeCurrentDirExecutable} executable
-     * implementation reference
-     * @throws CommandNotFoundException If the executable can't be created
-     * @throws NoSuchFileOrDirectory If the file or directory was not found
-     * @throws InsufficientPermissionsException If an operation requires elevated permissions
-     */
-    ChangeCurrentDirExecutable createChangeCurrentDirExecutable(
-            String dir) throws CommandNotFoundException,
-            NoSuchFileOrDirectory, InsufficientPermissionsException;
-
-    /**
      * Method that creates an executable for change the owner of a file system object.
      *
      * @param fso The absolute path to the source file system object
@@ -119,18 +105,6 @@ public interface ExecutableCreator {
             NoSuchFileOrDirectory, InsufficientPermissionsException;
 
     /**
-     * Method that creates an executable for retrieve the current directory.
-     *
-     * @return CurrentDirExecutable A {@link CurrentDirExecutable} executable
-     * implementation reference
-     * @throws CommandNotFoundException If the executable can't be created
-     * @throws NoSuchFileOrDirectory If the file or directory was not found
-     * @throws InsufficientPermissionsException If an operation requires elevated permissions
-     */
-    CurrentDirExecutable createCurrentDirExecutable() throws CommandNotFoundException,
-            NoSuchFileOrDirectory, InsufficientPermissionsException;
-
-    /**
      * Method that creates an executable for delete a directory.
      *
      * @param dir The absolute path to the directory to be deleted
diff --git a/src/com/cyanogenmod/filemanager/commands/java/ChangeCurrentDirCommand.java b/src/com/cyanogenmod/filemanager/commands/java/ChangeCurrentDirCommand.java
deleted file mode 100644 (file)
index 476d404..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2012 The CyanogenMod Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.cyanogenmod.filemanager.commands.java;
-
-import android.util.Log;
-
-import com.cyanogenmod.filemanager.commands.ChangeCurrentDirExecutable;
-import com.cyanogenmod.filemanager.console.ExecutionException;
-import com.cyanogenmod.filemanager.console.InsufficientPermissionsException;
-import com.cyanogenmod.filemanager.console.NoSuchFileOrDirectory;
-import com.cyanogenmod.filemanager.console.java.JavaConsole;
-
-import java.io.File;
-
-
-/**
- * A class for change the current directory.
- */
-public class ChangeCurrentDirCommand extends Program implements ChangeCurrentDirExecutable {
-
-    private static final String TAG = "ChangeCurrentDirCommand"; //$NON-NLS-1$
-
-    private final JavaConsole mConsole;
-    private final String mNewDir;
-
-    /**
-     * Constructor of <code>ChangeCurrentDirCommand</code>.
-     *
-     * @param console The console
-     * @param newDir The new directory to which to change
-     */
-    public ChangeCurrentDirCommand(JavaConsole console, String newDir) {
-        super();
-        this.mNewDir = newDir;
-        this.mConsole = console;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public Boolean getResult() {
-        return Boolean.TRUE;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void execute()
-            throws InsufficientPermissionsException, NoSuchFileOrDirectory, ExecutionException {
-        if (isTrace()) {
-            Log.v(TAG,
-                    String.format("Changing current directory to %s", this.mNewDir)); //$NON-NLS-1$
-        }
-
-        // Check that the file exists and is a directory
-        File f = new File(this.mNewDir);
-        if (!f.exists() || !f.isDirectory()) {
-            if (isTrace()) {
-                Log.v(TAG, "Result: FAIL. NoSuchFileOrDirectory"); //$NON-NLS-1$
-            }
-            throw new NoSuchFileOrDirectory(this.mNewDir);
-        }
-
-        // Check that we have the access to the directory
-        if (!f.canRead() || !f.canExecute()) {
-            if (isTrace()) {
-                Log.v(TAG, "Result: FAIL. InsufficientPermissionsException"); //$NON-NLS-1$
-            }
-            throw new InsufficientPermissionsException();
-        }
-
-        // Set the new current directory
-        this.mConsole.setCurrentDir(this.mNewDir);
-
-        if (isTrace()) {
-            Log.v(TAG, "Result: OK"); //$NON-NLS-1$
-        }
-    }
-
-}
diff --git a/src/com/cyanogenmod/filemanager/commands/java/CurrentDirCommand.java b/src/com/cyanogenmod/filemanager/commands/java/CurrentDirCommand.java
deleted file mode 100644 (file)
index 8ba8dd8..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2012 The CyanogenMod Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.cyanogenmod.filemanager.commands.java;
-
-import android.util.Log;
-
-import com.cyanogenmod.filemanager.commands.CurrentDirExecutable;
-import com.cyanogenmod.filemanager.console.ExecutionException;
-import com.cyanogenmod.filemanager.console.InsufficientPermissionsException;
-import com.cyanogenmod.filemanager.console.NoSuchFileOrDirectory;
-import com.cyanogenmod.filemanager.console.java.JavaConsole;
-
-
-/**
- * A class for returns the current directory.
- */
-public class CurrentDirCommand extends Program implements CurrentDirExecutable {
-
-    private static final String TAG = "CurrentDirCommand"; //$NON-NLS-1$
-
-    private final JavaConsole mConsole;
-    private String mCurrentDir;
-
-    /**
-     * Constructor of <code>CurrentDirCommand</code>.
-     *
-     * @param console The console
-     */
-    public CurrentDirCommand(JavaConsole console) {
-        super();
-        this.mConsole = console;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public String getResult() {
-        return this.mCurrentDir;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void execute()
-            throws InsufficientPermissionsException, NoSuchFileOrDirectory, ExecutionException {
-        if (isTrace()) {
-            Log.v(TAG, "Obtaing current directory"); //$NON-NLS-1$
-        }
-
-        this.mCurrentDir = this.mConsole.getCurrentDir();
-
-        if (isTrace()) {
-            Log.v(TAG,
-                    String.format(
-                            "Result: OK. Current directory: %s", this.mCurrentDir)); //$NON-NLS-1$
-        }
-    }
-
-}
index 875544e..1186515 100644 (file)
@@ -18,14 +18,12 @@ package com.cyanogenmod.filemanager.commands.java;
 
 import com.cyanogenmod.filemanager.R;
 import com.cyanogenmod.filemanager.commands.AsyncResultListener;
-import com.cyanogenmod.filemanager.commands.ChangeCurrentDirExecutable;
 import com.cyanogenmod.filemanager.commands.ChangeOwnerExecutable;
 import com.cyanogenmod.filemanager.commands.ChangePermissionsExecutable;
 import com.cyanogenmod.filemanager.commands.CompressExecutable;
 import com.cyanogenmod.filemanager.commands.CopyExecutable;
 import com.cyanogenmod.filemanager.commands.CreateDirExecutable;
 import com.cyanogenmod.filemanager.commands.CreateFileExecutable;
-import com.cyanogenmod.filemanager.commands.CurrentDirExecutable;
 import com.cyanogenmod.filemanager.commands.DeleteDirExecutable;
 import com.cyanogenmod.filemanager.commands.DeleteFileExecutable;
 import com.cyanogenmod.filemanager.commands.DiskUsageExecutable;
@@ -81,15 +79,6 @@ public class JavaExecutableCreator implements ExecutableCreator {
      * {@inheritDoc}
      */
     @Override
-    public ChangeCurrentDirExecutable createChangeCurrentDirExecutable(String dir)
-            throws CommandNotFoundException {
-        return new ChangeCurrentDirCommand(this.mConsole, dir);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
     public ChangeOwnerExecutable createChangeOwnerExecutable(
             String fso, User newUser, Group newGroup) throws CommandNotFoundException {
         throw new CommandNotFoundException("Not implemented"); //$NON-NLS-1$
@@ -135,14 +124,6 @@ public class JavaExecutableCreator implements ExecutableCreator {
      * {@inheritDoc}
      */
     @Override
-    public CurrentDirExecutable createCurrentDirExecutable() throws CommandNotFoundException {
-        return new CurrentDirCommand(this.mConsole);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
     public DeleteDirExecutable createDeleteDirExecutable(String dir)
             throws CommandNotFoundException {
         return new DeleteDirCommand(dir);
diff --git a/src/com/cyanogenmod/filemanager/commands/shell/ChangeCurrentDirCommand.java b/src/com/cyanogenmod/filemanager/commands/shell/ChangeCurrentDirCommand.java
deleted file mode 100644 (file)
index 443e1f4..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) 2012 The CyanogenMod Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.cyanogenmod.filemanager.commands.shell;
-
-import com.cyanogenmod.filemanager.commands.ChangeCurrentDirExecutable;
-import com.cyanogenmod.filemanager.console.CommandNotFoundException;
-import com.cyanogenmod.filemanager.console.ExecutionException;
-import com.cyanogenmod.filemanager.console.InsufficientPermissionsException;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.StringReader;
-import java.text.ParseException;
-
-
-/**
- * A class for change the current directory of the shell.
- *
- * {@link "http://unixhelp.ed.ac.uk/CGI/man-cgi?cd"}
- */
-public class ChangeCurrentDirCommand
-    extends SyncResultProgram implements ChangeCurrentDirExecutable {
-
-    private static final String ID = "cd";  //$NON-NLS-1$
-    private Boolean mRet;
-
-    /**
-     * Constructor of <code>ChangeCurrentDirCommand</code>.
-     *
-     * @param newDir The new directory to which to change
-     * @throws InvalidCommandDefinitionException If the command has an invalid definition
-     */
-    public ChangeCurrentDirCommand(String newDir) throws InvalidCommandDefinitionException {
-        super(ID, newDir);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void parse(String in, String err) throws ParseException {
-        //Release the return object
-        this.mRet = Boolean.TRUE;
-
-        // Check the in and err buffer to extract information
-        BufferedReader br = null;
-        try {
-            br = new BufferedReader(new StringReader(err));
-            String szLine = br.readLine();
-            if (szLine != null) {
-                if (szLine.indexOf("No such file or directory") != -1) { //$NON-NLS-1$
-                    this.mRet = Boolean.FALSE;
-                }
-            }
-            br.close();
-            br = new BufferedReader(new StringReader(in));
-            szLine = br.readLine();
-            if (szLine != null) {
-                if (szLine.indexOf("No such file or directory") != -1) { //$NON-NLS-1$
-                    this.mRet = Boolean.FALSE;
-                }
-            }
-
-        } catch (IOException ioEx) {
-            throw new ParseException(ioEx.getMessage(), 0);
-
-        } catch (Exception ex) {
-            throw new ParseException(ex.getMessage(), 0);
-
-        } finally {
-            try {
-                if (br != null) {
-                    br.close();
-                }
-            } catch (Throwable ex) {
-                /**NON BLOCK**/
-            }
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public Boolean getResult() {
-        return this.mRet;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void checkExitCode(int exitCode)
-            throws InsufficientPermissionsException, CommandNotFoundException, ExecutionException {
-        if (exitCode != 0) {
-            throw new ExecutionException("exitcode != 0"); //$NON-NLS-1$
-        }
-    }
-}
diff --git a/src/com/cyanogenmod/filemanager/commands/shell/CurrentDirCommand.java b/src/com/cyanogenmod/filemanager/commands/shell/CurrentDirCommand.java
deleted file mode 100644 (file)
index 9c106a6..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2012 The CyanogenMod Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.cyanogenmod.filemanager.commands.shell;
-
-import com.cyanogenmod.filemanager.commands.CurrentDirExecutable;
-import com.cyanogenmod.filemanager.console.CommandNotFoundException;
-import com.cyanogenmod.filemanager.console.ExecutionException;
-import com.cyanogenmod.filemanager.console.InsufficientPermissionsException;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.StringReader;
-import java.text.ParseException;
-
-
-/**
- * A class for retrieve the current directory of the shell.
- *
- * {@link "http://unixhelp.ed.ac.uk/CGI/man-cgi?pwd"}
- */
-public class CurrentDirCommand extends SyncResultProgram implements CurrentDirExecutable {
-
-    private static final String ID = "pwd";  //$NON-NLS-1$
-    private String mPwd;
-
-    /**
-     * Constructor of <code>CurrentDirCommand</code>.
-     *
-     * @throws InvalidCommandDefinitionException If the command has an invalid definition
-     */
-    public CurrentDirCommand() throws InvalidCommandDefinitionException {
-        super(ID);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void parse(String in, String err) throws ParseException {
-        //Release the return object
-        this.mPwd = ""; //$NON-NLS-1$
-
-        // Check the in buffer to extract information
-        BufferedReader br = null;
-        try {
-            br = new BufferedReader(new StringReader(in));
-            String szLine = br.readLine();
-            if (szLine == null) {
-                throw new ParseException("no information", 0); //$NON-NLS-1$
-            }
-            this.mPwd = szLine;
-
-        } catch (IOException ioEx) {
-            throw new ParseException(ioEx.getMessage(), 0);
-
-        } catch (Exception ex) {
-            throw new ParseException(ex.getMessage(), 0);
-
-        } finally {
-            try {
-                if (br != null) {
-                    br.close();
-                }
-            } catch (Throwable ex) {
-                /**NON BLOCK**/
-            }
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public String getResult() {
-        return this.mPwd;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void checkExitCode(int exitCode)
-            throws InsufficientPermissionsException, CommandNotFoundException, ExecutionException {
-        if (exitCode != 0) {
-            throw new ExecutionException("exitcode != 0"); //$NON-NLS-1$
-        }
-    }
-}
index adc2ea6..e474184 100644 (file)
 package com.cyanogenmod.filemanager.commands.shell;
 
 import com.cyanogenmod.filemanager.commands.AsyncResultListener;
-import com.cyanogenmod.filemanager.commands.ChangeCurrentDirExecutable;
 import com.cyanogenmod.filemanager.commands.ChangeOwnerExecutable;
 import com.cyanogenmod.filemanager.commands.ChangePermissionsExecutable;
 import com.cyanogenmod.filemanager.commands.CompressExecutable;
 import com.cyanogenmod.filemanager.commands.CopyExecutable;
 import com.cyanogenmod.filemanager.commands.CreateDirExecutable;
 import com.cyanogenmod.filemanager.commands.CreateFileExecutable;
-import com.cyanogenmod.filemanager.commands.CurrentDirExecutable;
 import com.cyanogenmod.filemanager.commands.DeleteDirExecutable;
 import com.cyanogenmod.filemanager.commands.DeleteFileExecutable;
 import com.cyanogenmod.filemanager.commands.DiskUsageExecutable;
@@ -79,19 +77,6 @@ public class ShellExecutableCreator implements ExecutableCreator {
      * {@inheritDoc}
      */
     @Override
-    public ChangeCurrentDirExecutable createChangeCurrentDirExecutable(String dir)
-            throws CommandNotFoundException {
-        try {
-            return new ChangeCurrentDirCommand(dir);
-        } catch (InvalidCommandDefinitionException icdEx) {
-            throw new CommandNotFoundException("ChangeCurrentDirCommand", icdEx); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
     public ChangeOwnerExecutable createChangeOwnerExecutable(
             String fso, User newUser, Group newGroup) throws CommandNotFoundException {
         try {
@@ -157,18 +142,6 @@ public class ShellExecutableCreator implements ExecutableCreator {
      * {@inheritDoc}
      */
     @Override
-    public CurrentDirExecutable createCurrentDirExecutable() throws CommandNotFoundException {
-        try {
-            return new CurrentDirCommand();
-        } catch (InvalidCommandDefinitionException icdEx) {
-            throw new CommandNotFoundException("CurrentDirCommand", icdEx); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
     public DeleteDirExecutable createDeleteDirExecutable(String dir)
             throws CommandNotFoundException {
         try {
index 1552abd..1791469 100644 (file)
@@ -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
index df04d4a..2edb42a 100644 (file)
 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
index aec764f..7673bbf 100644 (file)
@@ -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
index 4e5d308..cc44131 100644 (file)
@@ -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
index 5f300dd..12b7fe2 100644 (file)
@@ -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;
             }
index f79cb9e..932e219 100644 (file)
@@ -19,14 +19,12 @@ package com.cyanogenmod.filemanager.util;
 import android.content.Context;
 
 import com.cyanogenmod.filemanager.commands.AsyncResultListener;
-import com.cyanogenmod.filemanager.commands.ChangeCurrentDirExecutable;
 import com.cyanogenmod.filemanager.commands.ChangeOwnerExecutable;
 import com.cyanogenmod.filemanager.commands.ChangePermissionsExecutable;
 import com.cyanogenmod.filemanager.commands.CompressExecutable;
 import com.cyanogenmod.filemanager.commands.CopyExecutable;
 import com.cyanogenmod.filemanager.commands.CreateDirExecutable;
 import com.cyanogenmod.filemanager.commands.CreateFileExecutable;
-import com.cyanogenmod.filemanager.commands.CurrentDirExecutable;
 import com.cyanogenmod.filemanager.commands.DeleteDirExecutable;
 import com.cyanogenmod.filemanager.commands.DeleteFileExecutable;
 import com.cyanogenmod.filemanager.commands.DiskUsageExecutable;
@@ -190,37 +188,6 @@ public final class CommandHelper {
     }
 
     /**
-     * Method that changes the current directory of the shell.
-     *
-     * @param context The current context (needed if console == null)
-     * @param dst The new directory
-     * @return boolean The operation result
-     * @param console The console in which execute the program. <code>null</code>
-     * to attach to the default console
-     * @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
-     * @throws NoSuchFileOrDirectory If the file or directory was not found
-     * @throws ConsoleAllocException If the console can't be allocated
-     * @throws InsufficientPermissionsException If an operation requires elevated permissions
-     * @throws CommandNotFoundException If the command was not found
-     * @throws OperationTimeoutException If the operation exceeded the maximum time of wait
-     * @throws ExecutionException If the operation returns a invalid exit code
-     * @see ChangeCurrentDirExecutable
-     */
-    public static boolean changeCurrentDir(Context context, String dst, Console console)
-            throws FileNotFoundException, IOException, ConsoleAllocException,
-            NoSuchFileOrDirectory, InsufficientPermissionsException,
-            CommandNotFoundException, OperationTimeoutException,
-            ExecutionException, InvalidCommandDefinitionException {
-        Console c = ensureConsole(context, console);
-        ChangeCurrentDirExecutable executable =
-                c.getExecutableFactory().newCreator().createChangeCurrentDirExecutable(dst);
-        execute(context, executable, c);
-        return executable.getResult().booleanValue();
-    }
-
-    /**
      * Method that changes the owner of a file system object.
      *
      * @param context The current context (needed if console == null)
@@ -451,36 +418,6 @@ public final class CommandHelper {
     }
 
     /**
-     * Method that retrieves the current directory of the shell.
-     *
-     * @param context The current context (needed if console == null)
-     * @param console The console in which execute the program. <code>null</code>
-     * to attach to the default console
-     * @return String The current directory
-     * @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
-     * @throws NoSuchFileOrDirectory If the file or directory was not found
-     * @throws ConsoleAllocException If the console can't be allocated
-     * @throws InsufficientPermissionsException If an operation requires elevated permissions
-     * @throws CommandNotFoundException If the command was not found
-     * @throws OperationTimeoutException If the operation exceeded the maximum time of wait
-     * @throws ExecutionException If the operation returns a invalid exit code
-     * @see CurrentDirExecutable
-     */
-    public static String getCurrentDir(Context context, Console console)
-            throws FileNotFoundException, IOException, ConsoleAllocException,
-            NoSuchFileOrDirectory, InsufficientPermissionsException,
-            CommandNotFoundException, OperationTimeoutException,
-            ExecutionException, InvalidCommandDefinitionException {
-        Console c = ensureConsole(context, console);
-        CurrentDirExecutable executable =
-                c.getExecutableFactory().newCreator().createCurrentDirExecutable();
-        execute(context, executable, c);
-        return executable.getResult();
-    }
-
-    /**
      * Method that retrieves the information of a file system object.
      *
      * @param context The current context (needed if console == null)
index fa1b090..202c07d 100644 (file)
@@ -20,15 +20,12 @@ import com.cyanogenmod.filemanager.FileManagerApplication;
 import com.cyanogenmod.filemanager.console.Console;
 import com.cyanogenmod.filemanager.console.ConsoleBuilder;
 import com.cyanogenmod.filemanager.console.shell.ShellConsole;
-import com.cyanogenmod.filemanager.util.FileHelper;
 
 /**
  * An abstract class that manages tests that needs a console.
  */
 public abstract class AbstractConsoleTest extends android.test.AndroidTestCase {
 
-    private static final String INITIAL_DIR = FileHelper.ROOT_DIRECTORY;
-
     private Console mConsole;
 
     /**
@@ -46,9 +43,9 @@ public abstract class AbstractConsoleTest extends android.test.AndroidTestCase {
         //Setup the console
         if (isRootConsoleNeeded()) {
             FileManagerApplication.changeBackgroundConsoleToPriviligedConsole();
-            this.mConsole = ConsoleBuilder.createPrivilegedConsole(getContext(), INITIAL_DIR);
+            this.mConsole = ConsoleBuilder.createPrivilegedConsole(getContext());
         } else {
-            this.mConsole = ConsoleBuilder.createNonPrivilegedConsole(getContext(), INITIAL_DIR);
+            this.mConsole = ConsoleBuilder.createNonPrivilegedConsole(getContext());
         }
 
         super.setUp();
diff --git a/tests/src/com/cyanogenmod/filemanager/commands/shell/ChangeCurrentDirCommandTest.java b/tests/src/com/cyanogenmod/filemanager/commands/shell/ChangeCurrentDirCommandTest.java
deleted file mode 100644 (file)
index 2ef12a4..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2012 The CyanogenMod Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.cyanogenmod.filemanager.commands.shell;
-
-import android.test.suitebuilder.annotation.SmallTest;
-
-import com.cyanogenmod.filemanager.console.NoSuchFileOrDirectory;
-import com.cyanogenmod.filemanager.util.CommandHelper;
-import com.cyanogenmod.filemanager.util.FileHelper;
-
-/**
- * A class for testing the {@link ChangeCurrentDirCommand} command.
- *
- * @see ChangeCurrentDirCommand
- */
-public class ChangeCurrentDirCommandTest extends AbstractConsoleTest {
-
-    private static final String PATH_OK = FileHelper.ROOT_DIRECTORY;
-    private static final String PATH_ERROR = "/foo/foo121212"; //$NON-NLS-1$
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isRootConsoleNeeded() {
-        return false;
-    }
-
-    /**
-     * Method that performs a test to change the directory.
-     *
-     * @throws Exception If test failed
-     */
-    @SmallTest
-    public void testChangeDirOk() throws Exception {
-        boolean ret = CommandHelper.changeCurrentDir(getContext(), PATH_OK, getConsole());
-        assertTrue("response==false", ret); //$NON-NLS-1$
-
-        //Verify that current directory is PATH_OK
-        String curDir = CommandHelper.getCurrentDir(getContext(), getConsole());
-        assertTrue(
-                String.format(
-                        "curDir!=%s", PATH_OK), curDir.compareTo(PATH_OK) == 0); //$NON-NLS-1$
-    }
-
-    /**
-     * Method that performs a test to change the fake directory.
-     *
-     * @throws Exception If test failed
-     */
-    @SmallTest
-    public void testChangeDirFail() throws Exception {
-        String oldPwd = CommandHelper.getCurrentDir(getContext(), getConsole());
-        try {
-            CommandHelper.changeCurrentDir(getContext(), PATH_ERROR, getConsole());
-            assertTrue("exit code==0", false); //$NON-NLS-1$
-        } catch (NoSuchFileOrDirectory error) {
-          //This command must failed. exit code !=0
-        }
-
-        //Verify that current directory is PATH_OK
-        String newPwd = CommandHelper.getCurrentDir(getContext(), getConsole());
-        assertTrue(
-                String.format(
-                        "curDir!=%s", oldPwd), newPwd.compareTo(oldPwd) == 0); //$NON-NLS-1$
-    }
-
-
-}
diff --git a/tests/src/com/cyanogenmod/filemanager/commands/shell/CurrentDirCommandTest.java b/tests/src/com/cyanogenmod/filemanager/commands/shell/CurrentDirCommandTest.java
deleted file mode 100644 (file)
index 5cd5f3b..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2012 The CyanogenMod Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.cyanogenmod.filemanager.commands.shell;
-
-import android.os.Environment;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import com.cyanogenmod.filemanager.util.CommandHelper;
-
-/**
- * A class for testing the {@link CurrentDirCommand} command.
- *
- * @see CurrentDirCommand
- */
-public class CurrentDirCommandTest extends AbstractConsoleTest {
-
-    private static final String PATH =
-            Environment.getExternalStorageDirectory().getAbsolutePath();
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isRootConsoleNeeded() {
-        return false;
-    }
-
-    /**
-     * Method that performs a test for retrieve current directory.
-     *
-     * @throws Exception If test failed
-     */
-    @SmallTest
-    public void testCurrentDir() throws Exception {
-        CommandHelper.changeCurrentDir(getContext(), PATH, getConsole());
-        String curDir = CommandHelper.getCurrentDir(getContext(), getConsole());
-        assertTrue(
-                String.format(
-                        "current directory!=%s; %s", PATH, curDir),  //$NON-NLS-1$
-                        curDir.compareTo(PATH) == 0);
-    }
-
-
-}
index 7d16309..6cfe481 100644 (file)
@@ -16,7 +16,6 @@
 
 package com.cyanogenmod.filemanager.console;
 
-import android.os.Environment;
 import android.test.suitebuilder.annotation.SmallTest;
 
 
@@ -27,9 +26,6 @@ import android.test.suitebuilder.annotation.SmallTest;
  */
 public class ConsoleBuilderTest extends android.test.AndroidTestCase {
 
-    private static final String PATH =
-            Environment.getExternalStorageDirectory().getAbsolutePath();
-
     /**
      * {@inheritDoc}
      */
@@ -50,11 +46,11 @@ public class ConsoleBuilderTest extends android.test.AndroidTestCase {
      * Method that performs a test over creating a privileged console.
      *
      * @throws Exception If test failed
-     * @{link {@link ConsoleBuilder#createPrivilegedConsole(android.content.Context, String)}
+     * @{link {@link ConsoleBuilder#createPrivilegedConsole(android.content.Context)}
      */
     @SmallTest
     public void testCreatePrivilegedConsole() throws Exception {
-        Console console = ConsoleBuilder.createPrivilegedConsole(getContext(), PATH);
+        Console console = ConsoleBuilder.createPrivilegedConsole(getContext());
         try {
             assertNotNull("console==null", console); //$NON-NLS-1$
         } finally {
@@ -70,11 +66,11 @@ public class ConsoleBuilderTest extends android.test.AndroidTestCase {
      * Method that performs a test over creating a non privileged console.
      *
      * @throws Exception If test failed
-     * @{link {@link ConsoleBuilder#createNonPrivilegedConsole(android.content.Context, String)}
+     * @{link {@link ConsoleBuilder#createNonPrivilegedConsole(android.content.Context)}
      */
     @SmallTest
     public void testCreateNonPrivilegedConsole() throws Exception {
-        Console console = ConsoleBuilder.createNonPrivilegedConsole(getContext(), PATH);
+        Console console = ConsoleBuilder.createNonPrivilegedConsole(getContext());
         try {
             assertNotNull("console==null", console); //$NON-NLS-1$
         } finally {