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
<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" />
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;
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,
sBackgroundConsole =
new ConsoleHolder(
ConsoleBuilder.createPrivilegedConsole(
- getInstance().getApplicationContext(),
- FileHelper.ROOT_DIRECTORY));
+ getInstance().getApplicationContext()));
} catch (Exception e) {
try {
if (sBackgroundConsole != null) {
* @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();
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;
}
}
+++ /dev/null
-/*
- * 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();
-}
+++ /dev/null
-/*
- * 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();
-}
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
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
+++ /dev/null
-/*
- * 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$
- }
- }
-
-}
+++ /dev/null
-/*
- * 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$
- }
- }
-
-}
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;
* {@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$
* {@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);
+++ /dev/null
-/*
- * 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$
- }
- }
-}
+++ /dev/null
-/*
- * 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$
- }
- }
-}
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;
* {@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 {
* {@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 {
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;
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;
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;
//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();
* 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
* @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 {
// 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;
}
* 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
* @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) {
* 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
* @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);
}
/**
* 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
* @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?
}
//Create the non-privileged console
- return createNonPrivilegedConsole(context, initialDirectory);
+ return createNonPrivilegedConsole(context);
}
// Rethrow the exception
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;
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/>
private static final String TAG = "JavaConsole"; //$NON-NLS-1$
private boolean mActive;
- private String mCurrentDir;
private final Context mCtx;
private final int mBufferSize;
* 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;
}
/**
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$
}
/**
- * 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
/**
* 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
/**
* 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
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;
//Shell References
private final Shell mShell;
- private final String mInitialDirectory;
private Identity mIdentity;
//Process References
* 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;
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();
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;
}
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;
}
/**
- * 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)
}
/**
- * 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)
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;
/**
//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();
+++ /dev/null
-/*
- * 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$
- }
-
-
-}
+++ /dev/null
-/*
- * 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);
- }
-
-
-}
package com.cyanogenmod.filemanager.console;
-import android.os.Environment;
import android.test.suitebuilder.annotation.SmallTest;
*/
public class ConsoleBuilderTest extends android.test.AndroidTestCase {
- private static final String PATH =
- Environment.getExternalStorageDirectory().getAbsolutePath();
-
/**
* {@inheritDoc}
*/
* 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 {
* 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 {