From 4db2fc7e429424e5ec9eb1ac42ecbeb5410e9157 Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Mon, 7 Jan 2013 22:41:26 +0100 Subject: [PATCH 01/10] CMFM: Fix AsyncResultProgram deadlock Change-Id: Idd32ef7902eaf86e573728f7e442c281a47249fc Signed-off-by: jruesga --- .../commands/shell/AsyncResultProgram.java | 15 +++----- .../commands/shell/WriteCommand.java | 10 +++--- .../console/shell/ShellConsole.java | 36 ++++++++++--------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/com/cyanogenmod/filemanager/commands/shell/AsyncResultProgram.java b/src/com/cyanogenmod/filemanager/commands/shell/AsyncResultProgram.java index 94d0498ff..9d00002b4 100644 --- a/src/com/cyanogenmod/filemanager/commands/shell/AsyncResultProgram.java +++ b/src/com/cyanogenmod/filemanager/commands/shell/AsyncResultProgram.java @@ -131,17 +131,12 @@ public final void onRequestEndParsePartialResult(boolean cancelled) { this.mSync.notify(); } synchronized (this.mTerminateSync) { - try { - this.mTerminateSync.wait(); - } catch (Exception e) { - /**NON BLOCK**/ - } - try { - if (this.mWorkerThread.isAlive()) { - this.mWorkerThread.interrupt(); + if (this.mWorkerThread.isAlive()) { + try { + this.mTerminateSync.wait(); + } catch (Exception e) { + /**NON BLOCK**/ } - } catch (Exception e) { - /**NON BLOCK**/ } } diff --git a/src/com/cyanogenmod/filemanager/commands/shell/WriteCommand.java b/src/com/cyanogenmod/filemanager/commands/shell/WriteCommand.java index 08968305d..51c0800cd 100644 --- a/src/com/cyanogenmod/filemanager/commands/shell/WriteCommand.java +++ b/src/com/cyanogenmod/filemanager/commands/shell/WriteCommand.java @@ -44,7 +44,7 @@ public class WriteCommand extends AsyncResultProgram implements WriteExecutable /** * @hide */ - final Object mSync = new Object(); + final Object mWriteSync = new Object(); private boolean mReady; /** * @hide @@ -81,10 +81,10 @@ public boolean isExpectEnd() { public OutputStream createOutputStream() throws IOException { // Wait until command is ready - synchronized (this.mSync) { + synchronized (this.mWriteSync) { if (!this.mReady) { try { - this.mSync.wait(TIMEOUT); + this.mWriteSync.wait(TIMEOUT); } catch (Exception e) {/**NON BLOCK**/} } } @@ -96,9 +96,9 @@ public OutputStream createOutputStream() throws IOException { */ @Override public void onStartParsePartialResult() { - synchronized (this.mSync) { + synchronized (this.mWriteSync) { this.mReady = true; - this.mSync.notify(); + this.mWriteSync.notify(); } } diff --git a/src/com/cyanogenmod/filemanager/console/shell/ShellConsole.java b/src/com/cyanogenmod/filemanager/console/shell/ShellConsole.java index e7de2fbf0..5f300dd17 100644 --- a/src/com/cyanogenmod/filemanager/console/shell/ShellConsole.java +++ b/src/com/cyanogenmod/filemanager/console/shell/ShellConsole.java @@ -1135,28 +1135,32 @@ private boolean killCurrentCommand() { if (program.getCommand() != null) { try { if (program.isCancellable()) { - //Get the PID in background - Integer pid = - CommandHelper.getProcessId( + try { + //Get the PID in background + Integer pid = + CommandHelper.getProcessId( + null, + this.mShell.getPid(), + program.getCommand(), + FileManagerApplication.getBackgroundConsole()); + if (pid != null) { + CommandHelper.sendSignal( null, - this.mShell.getPid(), - program.getCommand(), + pid.intValue(), FileManagerApplication.getBackgroundConsole()); - if (pid != null) { - CommandHelper.sendSignal( - null, - pid.intValue(), - FileManagerApplication.getBackgroundConsole()); - try { - //Wait for process kill - Thread.sleep(100L); - } catch (Throwable ex) { - /**NON BLOCK**/ + try { + //Wait for process kill + Thread.sleep(100L); + } catch (Throwable ex) { + /**NON BLOCK**/ + } + return true; } + } finally { + // It's finished this.mCancelled = true; notifyProcessFinished(); this.mSync.notify(); - return this.mCancelled; } } } catch (Throwable ex) { From f2a9335b58e7922d79ff6744cc65ab98a4f551de Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Mon, 7 Jan 2013 22:45:27 +0100 Subject: [PATCH 02/10] CMFM: Fix FC caused by accessing ui outside of UI thread Patchset 2: Formatting Change-Id: I1323b4f92a64dd23afe4aa28d3569ce01d72c039 Signed-off-by: jruesga --- .../ui/widgets/NavigationView.java | 22 ++++++++++++------- .../filemanager/util/ExceptionUtil.java | 1 + 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java b/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java index afcf45701..69746693c 100644 --- a/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java +++ b/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java @@ -906,14 +906,20 @@ protected void onPostExecute(List files) { * * @param out Fade out (true); Fade in (false) */ - void fadeEfect(boolean out) { - Animation fadeAnim = out ? - new AlphaAnimation(1, 0) : - new AlphaAnimation(0, 1); - fadeAnim.setDuration(50L); - fadeAnim.setFillAfter(true); - fadeAnim.setInterpolator(new AccelerateInterpolator()); - NavigationView.this.startAnimation(fadeAnim); + void fadeEfect(final boolean out) { + Activity activity = (Activity)getContext(); + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + Animation fadeAnim = out ? + new AlphaAnimation(1, 0) : + new AlphaAnimation(0, 1); + fadeAnim.setDuration(50L); + fadeAnim.setFillAfter(true); + fadeAnim.setInterpolator(new AccelerateInterpolator()); + NavigationView.this.startAnimation(fadeAnim); + } + }); } }; task.execute(fNewDir); diff --git a/src/com/cyanogenmod/filemanager/util/ExceptionUtil.java b/src/com/cyanogenmod/filemanager/util/ExceptionUtil.java index 658a28ccf..e7d6074d0 100644 --- a/src/com/cyanogenmod/filemanager/util/ExceptionUtil.java +++ b/src/com/cyanogenmod/filemanager/util/ExceptionUtil.java @@ -293,6 +293,7 @@ public void onClick(DialogInterface dialog, int which) { Object result = CommandHelper.reexecute( context, executable, null); if (relaunchable.getTask() != null) { + relaunchable.getTask().cancel(true); relaunchable.getTask().execute(result); } } From 5b4a6b62faa0c75cccaf6cb551cfcf9bf4ba2fda Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Mon, 7 Jan 2013 23:41:36 +0100 Subject: [PATCH 03/10] CMFM: Read hidden files with new stat listing method Change-Id: I421586d8deb4e59b6b2abb80ed7c846479f3bd2d Signed-off-by: jruesga --- res/xml/command_list.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/xml/command_list.xml b/res/xml/command_list.xml index 5d27be545..3d7ca439b 100644 --- a/res/xml/command_list.xml +++ b/res/xml/command_list.xml @@ -52,7 +52,7 @@ - + From e5751bc8aad4b6c0c6ac22acf4b750cffa86845b Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Tue, 8 Jan 2013 22:52:25 +0100 Subject: [PATCH 04/10] CMFM: Fix race condition Change-Id: I3ed0d38665b12aa39313c55f7daaa63bd80875a0 Signed-off-by: jruesga --- .../filemanager/commands/shell/AsyncResultProgram.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/com/cyanogenmod/filemanager/commands/shell/AsyncResultProgram.java b/src/com/cyanogenmod/filemanager/commands/shell/AsyncResultProgram.java index 9d00002b4..922de7b0b 100644 --- a/src/com/cyanogenmod/filemanager/commands/shell/AsyncResultProgram.java +++ b/src/com/cyanogenmod/filemanager/commands/shell/AsyncResultProgram.java @@ -367,9 +367,6 @@ public void run() { synchronized (AsyncResultProgram.this.mSync) { AsyncResultProgram.this.mSync.wait(); while (AsyncResultProgram.this.mPartialData.size() > 0) { - if (!this.mAlive) { - return; - } Byte type = AsyncResultProgram.this.mPartialDataType.remove(0); String data = AsyncResultProgram.this.mPartialData.remove(0); try { From c5298c6f2f5e49fb801a9146cadc3750dec7d3d6 Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Tue, 8 Jan 2013 23:19:21 +0100 Subject: [PATCH 05/10] CMFM: Ignore stderr from stat list command We don't need "No such file or directory" from path/.* or path/* because is previously checked by ls, and it is only returned when no matches were found, which indeed it is not an error. Signed-off-by: jruesga Change-Id: I4fa0ef947a30e42a4cccd0c95855c4953a34e874 --- res/xml/command_list.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/xml/command_list.xml b/res/xml/command_list.xml index 3d7ca439b..343df0614 100644 --- a/res/xml/command_list.xml +++ b/res/xml/command_list.xml @@ -52,7 +52,7 @@ - + From 3bf048a2ab6e0393055c4991dfaab6c84f0ecae7 Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Wed, 9 Jan 2013 00:56:18 +0100 Subject: [PATCH 06/10] 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 Change-Id: I772866c00233351f505b61f53d43bac5de02a5e4 --- res/xml/command_list.xml | 4 - .../filemanager/FileManagerApplication.java | 13 +- .../activities/NavigationActivity.java | 7 ++ .../commands/ChangeCurrentDirExecutable.java | 29 ----- .../commands/CurrentDirExecutable.java | 29 ----- .../commands/ExecutableCreator.java | 26 ---- .../java/ChangeCurrentDirCommand.java | 96 --------------- .../commands/java/CurrentDirCommand.java | 75 ------------ .../commands/java/JavaExecutableCreator.java | 19 --- .../shell/ChangeCurrentDirCommand.java | 113 ------------------ .../commands/shell/CurrentDirCommand.java | 102 ---------------- .../shell/ShellExecutableCreator.java | 27 ----- .../filemanager/console/ConsoleBuilder.java | 36 +++--- .../filemanager/console/java/JavaConsole.java | 41 +------ .../console/shell/NonPriviledgeConsole.java | 13 -- .../console/shell/PrivilegedConsole.java | 13 -- .../console/shell/ShellConsole.java | 31 +---- .../filemanager/util/CommandHelper.java | 63 ---------- .../commands/shell/AbstractConsoleTest.java | 7 +- .../shell/ChangeCurrentDirCommandTest.java | 83 ------------- .../commands/shell/CurrentDirCommandTest.java | 58 --------- .../console/ConsoleBuilderTest.java | 12 +- 22 files changed, 36 insertions(+), 861 deletions(-) delete mode 100644 src/com/cyanogenmod/filemanager/commands/ChangeCurrentDirExecutable.java delete mode 100644 src/com/cyanogenmod/filemanager/commands/CurrentDirExecutable.java delete mode 100644 src/com/cyanogenmod/filemanager/commands/java/ChangeCurrentDirCommand.java delete mode 100644 src/com/cyanogenmod/filemanager/commands/java/CurrentDirCommand.java delete mode 100644 src/com/cyanogenmod/filemanager/commands/shell/ChangeCurrentDirCommand.java delete mode 100644 src/com/cyanogenmod/filemanager/commands/shell/CurrentDirCommand.java delete mode 100644 tests/src/com/cyanogenmod/filemanager/commands/shell/ChangeCurrentDirCommandTest.java delete mode 100644 tests/src/com/cyanogenmod/filemanager/commands/shell/CurrentDirCommandTest.java diff --git a/res/xml/command_list.xml b/res/xml/command_list.xml index 343df0614..1e42cdc79 100644 --- a/res/xml/command_list.xml +++ b/res/xml/command_list.xml @@ -39,10 +39,6 @@ - - - - diff --git a/src/com/cyanogenmod/filemanager/FileManagerApplication.java b/src/com/cyanogenmod/filemanager/FileManagerApplication.java index a25126fb3..0e3ac357b 100644 --- a/src/com/cyanogenmod/filemanager/FileManagerApplication.java +++ b/src/com/cyanogenmod/filemanager/FileManagerApplication.java @@ -36,7 +36,6 @@ 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 @@ private static synchronized void allocBackgroundConsole(Context ctx) { 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 static void changeBackgroundConsoleToPriviligedConsole() sBackgroundConsole = new ConsoleHolder( ConsoleBuilder.createPrivilegedConsole( - getInstance().getApplicationContext(), - FileHelper.ROOT_DIRECTORY)); + getInstance().getApplicationContext())); } catch (Exception e) { try { if (sBackgroundConsole != null) { @@ -410,6 +406,9 @@ public static void changeBackgroundConsoleToPriviligedConsole() * @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(); diff --git a/src/com/cyanogenmod/filemanager/activities/NavigationActivity.java b/src/com/cyanogenmod/filemanager/activities/NavigationActivity.java index 1ecd3be56..5ea33c26e 100644 --- a/src/com/cyanogenmod/filemanager/activities/NavigationActivity.java +++ b/src/com/cyanogenmod/filemanager/activities/NavigationActivity.java @@ -612,6 +612,13 @@ public void run() { 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 index 5999cfc7b..000000000 --- a/src/com/cyanogenmod/filemanager/commands/ChangeCurrentDirExecutable.java +++ /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 index 1d951f88f..000000000 --- a/src/com/cyanogenmod/filemanager/commands/CurrentDirExecutable.java +++ /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(); -} diff --git a/src/com/cyanogenmod/filemanager/commands/ExecutableCreator.java b/src/com/cyanogenmod/filemanager/commands/ExecutableCreator.java index a0fd6f94b..5d537a9b0 100644 --- a/src/com/cyanogenmod/filemanager/commands/ExecutableCreator.java +++ b/src/com/cyanogenmod/filemanager/commands/ExecutableCreator.java @@ -32,20 +32,6 @@ */ 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. * @@ -118,18 +104,6 @@ CreateDirExecutable createCreateDirectoryExecutable(String dir) CreateFileExecutable createCreateFileExecutable(String file) throws CommandNotFoundException, 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. * diff --git a/src/com/cyanogenmod/filemanager/commands/java/ChangeCurrentDirCommand.java b/src/com/cyanogenmod/filemanager/commands/java/ChangeCurrentDirCommand.java deleted file mode 100644 index 476d40412..000000000 --- a/src/com/cyanogenmod/filemanager/commands/java/ChangeCurrentDirCommand.java +++ /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 ChangeCurrentDirCommand. - * - * @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 index 8ba8dd8f5..000000000 --- a/src/com/cyanogenmod/filemanager/commands/java/CurrentDirCommand.java +++ /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 CurrentDirCommand. - * - * @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$ - } - } - -} diff --git a/src/com/cyanogenmod/filemanager/commands/java/JavaExecutableCreator.java b/src/com/cyanogenmod/filemanager/commands/java/JavaExecutableCreator.java index 875544efe..1186515d0 100644 --- a/src/com/cyanogenmod/filemanager/commands/java/JavaExecutableCreator.java +++ b/src/com/cyanogenmod/filemanager/commands/java/JavaExecutableCreator.java @@ -18,14 +18,12 @@ 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; @@ -77,15 +75,6 @@ public class JavaExecutableCreator implements ExecutableCreator { this.mConsole = console; } - /** - * {@inheritDoc} - */ - @Override - public ChangeCurrentDirExecutable createChangeCurrentDirExecutable(String dir) - throws CommandNotFoundException { - return new ChangeCurrentDirCommand(this.mConsole, dir); - } - /** * {@inheritDoc} */ @@ -131,14 +120,6 @@ public CreateFileExecutable createCreateFileExecutable(String file) return new CreateFileCommand(file); } - /** - * {@inheritDoc} - */ - @Override - public CurrentDirExecutable createCurrentDirExecutable() throws CommandNotFoundException { - return new CurrentDirCommand(this.mConsole); - } - /** * {@inheritDoc} */ diff --git a/src/com/cyanogenmod/filemanager/commands/shell/ChangeCurrentDirCommand.java b/src/com/cyanogenmod/filemanager/commands/shell/ChangeCurrentDirCommand.java deleted file mode 100644 index 443e1f446..000000000 --- a/src/com/cyanogenmod/filemanager/commands/shell/ChangeCurrentDirCommand.java +++ /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 ChangeCurrentDirCommand. - * - * @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 index 9c106a682..000000000 --- a/src/com/cyanogenmod/filemanager/commands/shell/CurrentDirCommand.java +++ /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 CurrentDirCommand. - * - * @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$ - } - } -} diff --git a/src/com/cyanogenmod/filemanager/commands/shell/ShellExecutableCreator.java b/src/com/cyanogenmod/filemanager/commands/shell/ShellExecutableCreator.java index adc2ea68b..e47418455 100644 --- a/src/com/cyanogenmod/filemanager/commands/shell/ShellExecutableCreator.java +++ b/src/com/cyanogenmod/filemanager/commands/shell/ShellExecutableCreator.java @@ -17,14 +17,12 @@ 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; @@ -75,19 +73,6 @@ public class ShellExecutableCreator implements ExecutableCreator { this.mConsole = console; } - /** - * {@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} */ @@ -153,18 +138,6 @@ public CreateFileExecutable createCreateFileExecutable(String file) } } - /** - * {@inheritDoc} - */ - @Override - public CurrentDirExecutable createCurrentDirExecutable() throws CommandNotFoundException { - try { - return new CurrentDirCommand(); - } catch (InvalidCommandDefinitionException icdEx) { - throw new CommandNotFoundException("CurrentDirCommand", icdEx); //$NON-NLS-1$ - } - } - /** * {@inheritDoc} */ diff --git a/src/com/cyanogenmod/filemanager/console/ConsoleBuilder.java b/src/com/cyanogenmod/filemanager/console/ConsoleBuilder.java index 1552abd95..179146932 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.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 static boolean changeToNonPrivilegedConsole(Context context) { 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 static boolean changeToPrivilegedConsole(Context context) { 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 static Console createDefaultConsole(Context context, //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 static void destroyConsole() { * 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 static void destroyConsole() { * @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 static Console createNonPrivilegedConsole(Context context, String initial // 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 static Console createNonPrivilegedConsole(Context context, String initial * 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 static Console createNonPrivilegedConsole(Context context, String initial * @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 static Console createPrivilegedConsole(Context context, String initialDir * 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 static Console createPrivilegedConsole(Context context, String initialDir * @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 static Console createAndCheckPrivilegedConsole(Context context, String in * 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 static Console createAndCheckPrivilegedConsole(Context context, String in * @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 static Console createAndCheckPrivilegedConsole( } //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 df04d4a5f..2edb42a9c 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.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.
@@ -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 JavaConsole * * @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 void alloc() throws ConsoleAllocException { 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$ @@ -150,24 +129,6 @@ public boolean isActive() { return this.mActive; } - /** - * 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 * diff --git a/src/com/cyanogenmod/filemanager/console/shell/NonPriviledgeConsole.java b/src/com/cyanogenmod/filemanager/console/shell/NonPriviledgeConsole.java index aec764f81..7673bbf06 100644 --- a/src/com/cyanogenmod/filemanager/console/shell/NonPriviledgeConsole.java +++ b/src/com/cyanogenmod/filemanager/console/shell/NonPriviledgeConsole.java @@ -30,19 +30,6 @@ */ public class NonPriviledgeConsole extends ShellConsole { - /** - * Constructor of NonPriviledgeConsole. - * - * @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 NonPriviledgeConsole. * diff --git a/src/com/cyanogenmod/filemanager/console/shell/PrivilegedConsole.java b/src/com/cyanogenmod/filemanager/console/shell/PrivilegedConsole.java index 4e5d30889..cc4413147 100644 --- a/src/com/cyanogenmod/filemanager/console/shell/PrivilegedConsole.java +++ b/src/com/cyanogenmod/filemanager/console/shell/PrivilegedConsole.java @@ -31,19 +31,6 @@ */ public class PrivilegedConsole extends ShellConsole { - /** - * Constructor of PrivilegedConsole. - * - * @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 PrivilegedConsole. * diff --git a/src/com/cyanogenmod/filemanager/console/shell/ShellConsole.java b/src/com/cyanogenmod/filemanager/console/shell/ShellConsole.java index 5f300dd17..12b7fe262 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.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 ShellConsole. * * @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 ShellConsole. - * - * @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 ShellConsole(Shell shell, String initialDirectory) 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 final void alloc() throws ConsoleAllocException { 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; } diff --git a/src/com/cyanogenmod/filemanager/util/CommandHelper.java b/src/com/cyanogenmod/filemanager/util/CommandHelper.java index f79cb9e99..932e219c9 100644 --- a/src/com/cyanogenmod/filemanager/util/CommandHelper.java +++ b/src/com/cyanogenmod/filemanager/util/CommandHelper.java @@ -19,14 +19,12 @@ 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; @@ -189,37 +187,6 @@ private CommandHelper() { super(); } - /** - * 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. null - * 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. * @@ -450,36 +417,6 @@ public static FileSystemObject resolveSymlink(Context context, String symlink, C return executable.getResult(); } - /** - * 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. null - * 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. * diff --git a/tests/src/com/cyanogenmod/filemanager/commands/shell/AbstractConsoleTest.java b/tests/src/com/cyanogenmod/filemanager/commands/shell/AbstractConsoleTest.java index fa1b09089..202c07d7d 100644 --- a/tests/src/com/cyanogenmod/filemanager/commands/shell/AbstractConsoleTest.java +++ b/tests/src/com/cyanogenmod/filemanager/commands/shell/AbstractConsoleTest.java @@ -20,15 +20,12 @@ 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 @@ protected void setUp() throws Exception { //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 index 2ef12a474..000000000 --- a/tests/src/com/cyanogenmod/filemanager/commands/shell/ChangeCurrentDirCommandTest.java +++ /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 index 5cd5f3ba2..000000000 --- a/tests/src/com/cyanogenmod/filemanager/commands/shell/CurrentDirCommandTest.java +++ /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); - } - - -} diff --git a/tests/src/com/cyanogenmod/filemanager/console/ConsoleBuilderTest.java b/tests/src/com/cyanogenmod/filemanager/console/ConsoleBuilderTest.java index 7d1630953..6cfe481a5 100644 --- a/tests/src/com/cyanogenmod/filemanager/console/ConsoleBuilderTest.java +++ b/tests/src/com/cyanogenmod/filemanager/console/ConsoleBuilderTest.java @@ -16,7 +16,6 @@ package com.cyanogenmod.filemanager.console; -import android.os.Environment; import android.test.suitebuilder.annotation.SmallTest; @@ -27,9 +26,6 @@ */ public class ConsoleBuilderTest extends android.test.AndroidTestCase { - private static final String PATH = - Environment.getExternalStorageDirectory().getAbsolutePath(); - /** * {@inheritDoc} */ @@ -50,11 +46,11 @@ protected void tearDown() throws Exception { * 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 void testCreatePrivilegedConsole() throws Exception { * 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 { From 32dc158fb9f13a4e1844bf6db8ee51c6c437d9c1 Mon Sep 17 00:00:00 2001 From: Marco Brohet Date: Mon, 7 Jan 2013 12:32:56 +0100 Subject: [PATCH 07/10] CMFileManager: Dutch translations Change-Id: I2ac748fd2678d7634741c0209b8887c1f73ca0b9 --- res/values-nl/strings.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/res/values-nl/strings.xml b/res/values-nl/strings.xml index 6309451ea..7b345bb38 100644 --- a/res/values-nl/strings.xml +++ b/res/values-nl/strings.xml @@ -242,6 +242,12 @@ Grootte: Inhoud: + + Geopend: + + Bewerkt: + + Gewijzigd: Eigenaar: From a364e00e56ee226044231955dc86a677db47d157 Mon Sep 17 00:00:00 2001 From: igoriok Date: Wed, 9 Jan 2013 22:13:35 +0200 Subject: [PATCH 08/10] CMFileManager: fixed typo in romanian translation Change-Id: I031a4306a6f07a84c0772414564d8f05e74e1f4e Signed-off-by: igoriok --- res/values-ro/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/values-ro/strings.xml b/res/values-ro/strings.xml index 9a52a18f9..058a11378 100644 --- a/res/values-ro/strings.xml +++ b/res/values-ro/strings.xml @@ -269,7 +269,7 @@ Mod interogare Mod interogare\n\nAplicaţia se execută cu acces total la fişierele de sistem, dar va solicita permisiuni pentru a efectua operaţiuni privelegiate Mod acces Root - Mod cccess Root\n\nAvertizare! Acest mod permite operaţiuni ce pot duce la defectarea dispozitivului Dvs. Este responsabilitatea Dvs. să vă asigurați ce operațiune este sigură + Mod acces Root\n\nAvertizare! Acest mod permite operaţiuni ce pot duce la defectarea dispozitivului Dvs. Este responsabilitatea Dvs. să vă asigurați ce operațiune este sigură Rezultate Afişare widget relevanţă Evidenţiere termeni de căutare From 7cc707c2dd8d73ea756fd9029d466528e37fc274 Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Wed, 9 Jan 2013 23:50:37 +0100 Subject: [PATCH 09/10] CMFM: Fix typo Change-Id: Ib42a83bde4611ba4bdd661a45b1dda6d25c58cdb Signed-off-by: jruesga --- .../filemanager/activities/NavigationActivity.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/com/cyanogenmod/filemanager/activities/NavigationActivity.java b/src/com/cyanogenmod/filemanager/activities/NavigationActivity.java index 5ea33c26e..3221002e0 100644 --- a/src/com/cyanogenmod/filemanager/activities/NavigationActivity.java +++ b/src/com/cyanogenmod/filemanager/activities/NavigationActivity.java @@ -580,10 +580,10 @@ public void run() { } } catch (Throwable ex) { if (!NavigationActivity.this.mChRooted) { - //Show exception and exists + //Show exception and exit Log.e(TAG, getString(R.string.msgs_cant_create_console), ex); // We don't have any console - // Show exception and exists + // Show exception and exit DialogHelper.showToast( NavigationActivity.this, R.string.msgs_cant_create_console, Toast.LENGTH_LONG); @@ -613,7 +613,7 @@ public void run() { if (volumes != null && volumes.length > 0) { initialDir = volumes[0].getPath(); } else { - // Show exception and exists + // Show exception and exit DialogHelper.showToast( NavigationActivity.this, R.string.msgs_cant_create_console, Toast.LENGTH_LONG); @@ -1427,7 +1427,7 @@ void askOrExit() { public void onClick(DialogInterface alertDialog, int which) { if (which == DialogInterface.BUTTON_NEGATIVE) { // We don't have any console - // Show exception and exists + // Show exception and exit DialogHelper.showToast( NavigationActivity.this, R.string.msgs_cant_create_console, Toast.LENGTH_LONG); From 0228f31024a758afbf48c7ff85a561b98ea2c3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20T=C3=B3th?= Date: Thu, 10 Jan 2013 13:24:47 +0100 Subject: [PATCH 10/10] Added missing hungarian translation Change-Id: I5afacd2975c5396122c3cd8b763f20a61f42b36f --- res/values-hu/strings.xml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/res/values-hu/strings.xml b/res/values-hu/strings.xml index b45cbb25b..365c5d350 100644 --- a/res/values-hu/strings.xml +++ b/res/values-hu/strings.xml @@ -100,7 +100,7 @@ A művelet nem engedélyezett, mert következetlenséget okozna. - A művelet nem engedélyezett a jelenlegi mappában. + A művelet nem engedélyezett a jelenlegi mappában.\n\nA célmappa nem lehet azonos a forrásmappával, és nem lehet annak almappája. Nyomja meg mégegyszer a kilépéshez. @@ -237,6 +237,12 @@ Méret: Tartalmaz: + + Elérés ideje: + + Módosítás ideje: + + Adatváltozás ideje: Tulajdonos: @@ -331,7 +337,7 @@ Kezdőkönyvtár - Válasszon kezdőkonyvtárat: + Válasszon kezdőkönyvtárat: Relatív útvonalak nem használhatóak. @@ -401,9 +407,9 @@ Elvet - Kijelöltek beillesztése + Kijelöltek beillesztése ide - Kijelöltek mozgatása + Kijelöltek mozgatása ide Kijelöltek törlése