import com.cyanogenmod.filemanager.R;
import com.cyanogenmod.filemanager.commands.SyncResultExecutable;
import com.cyanogenmod.filemanager.commands.shell.InvalidCommandDefinitionException;
+import com.cyanogenmod.filemanager.console.AuthenticationFailedException;
+import com.cyanogenmod.filemanager.console.CancelledOperationException;
import com.cyanogenmod.filemanager.console.CommandNotFoundException;
import com.cyanogenmod.filemanager.console.ConsoleAllocException;
import com.cyanogenmod.filemanager.console.ConsoleBuilder;
OperationTimeoutException.class,
ExecutionException.class,
ParseException.class,
- ActivityNotFoundException.class
+ ActivityNotFoundException.class,
+ AuthenticationFailedException.class
};
private static final int[] KNOWN_EXCEPTIONS_IDS = {
R.string.msgs_file_not_found,
R.string.msgs_operation_timeout,
R.string.msgs_operation_failure,
R.string.msgs_operation_failure,
- R.string.msgs_not_registered_app
+ R.string.msgs_not_registered_app,
+ 0
};
private static final boolean[] KNOWN_EXCEPTIONS_TOAST = {
false,
true,
true,
true,
- false
+ false,
+ true
};
/**
final boolean quiet, final boolean askUser,
final OnRelaunchCommandResult listener) {
+ // Is cancellable?
+ if (ex instanceof CancelledOperationException) {
+ return;
+ }
+
//Get the appropriate message for the exception
int msgResId = R.string.msgs_unknown;
boolean toast = true;
- int cc = KNOWN_EXCEPTIONS.length;
- for (int i = 0; i < cc; i++) {
- if (KNOWN_EXCEPTIONS[i].getCanonicalName().compareTo(
- ex.getClass().getCanonicalName()) == 0) {
- msgResId = KNOWN_EXCEPTIONS_IDS[i];
- toast = KNOWN_EXCEPTIONS_TOAST[i];
- break;
+
+ // If an ExecutionException has specified a resource string to use,
+ // this is a special case and should be displayed as such.
+ if ((ex instanceof ExecutionException)
+ && ((ExecutionException)ex).getDetailMessageResId() != 0) {
+ msgResId = ((ExecutionException)ex).getDetailMessageResId();
+ } else {
+ int cc = KNOWN_EXCEPTIONS.length;
+ for (int i = 0; i < cc; i++) {
+ if (KNOWN_EXCEPTIONS[i].getCanonicalName().compareTo(
+ ex.getClass().getCanonicalName()) == 0) {
+ msgResId = KNOWN_EXCEPTIONS_IDS[i];
+ toast = KNOWN_EXCEPTIONS_TOAST[i];
+ break;
+ }
}
}
}
//Audit the exception
- Log.e(context.getClass().getSimpleName(), "Error dectected", ex); //$NON-NLS-1$
+ Log.e(context.getClass().getSimpleName(), "Error detected", ex); //$NON-NLS-1$
//Build the alert
final int fMsgResId = msgResId;
@Override
public void run() {
try {
+ String msg = null;
+ if (fMsgResId > 0) {
+ msg = context.getString(fMsgResId);
+ } else {
+ msg = ex.getMessage();
+ }
if (fToast) {
- DialogHelper.showToast(context, fMsgResId, Toast.LENGTH_SHORT);
+ DialogHelper.showToast(context, msg, Toast.LENGTH_SHORT);
} else {
AlertDialog dialog =
DialogHelper.createErrorDialog(
- context, R.string.error_title, fMsgResId);
+ context, R.string.error_title, msg);
DialogHelper.delegateDialogShow(context, dialog);
}
} catch (Exception e) {
}
return;
}
+ if (relaunchable instanceof InsufficientPermissionsException &&
+ !FileManagerApplication.isDeviceRooted()) {
+ DialogHelper.showToast(context, R.string.root_not_available_msg,
+ Toast.LENGTH_SHORT);
+
+ // Operation failed. Root is not available
+ if (listener != null) {
+ listener.onFailed(relaunchable);
+ }
+ return;
+ }
//Create a yes/no dialog and ask the user
+ final DialogInterface.OnClickListener clickListener =
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (which == DialogInterface.BUTTON_POSITIVE) {
+ //Run the executable again
+ try {
+ //Prepare the system before re-launch the command
+ prepare(context, relaunchable);
+
+ //Re-execute the command
+ List<SyncResultExecutable> executables = relaunchable.getExecutables();
+ int cc = executables.size();
+ for (int i = 0; i < cc; i++) {
+ SyncResultExecutable executable = executables.get(i);
+ Object result = CommandHelper.reexecute(context, executable, null);
+ AsyncTask<Object, Integer, Boolean> task = relaunchable.getTask();
+ if (task != null && task.getStatus() != AsyncTask.Status.RUNNING) {
+ task.execute(result);
+ }
+ }
+
+ // Operation complete
+ if (listener != null) {
+ listener.onSuccess();
+ }
+
+ } catch (Throwable ex) {
+ //Capture the exception, this time in quiet mode, if the
+ //exception is the same
+ boolean ask = ex.getClass().getName().compareTo(
+ relaunchable.getClass().getName()) == 0;
+ translateException(context, ex, quiet, !ask, listener);
+
+ // Operation failed
+ if (listener != null) {
+ listener.onFailed(ex);
+ }
+ }
+ } else {
+ // Operation cancelled
+ if (listener != null) {
+ listener.onCancelled();
+ }
+ }
+ }
+ };
+
AlertDialog alert = DialogHelper.createYesNoDialog(
context,
R.string.confirm_operation,
relaunchable.getQuestionResourceId(),
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (which == DialogInterface.BUTTON_POSITIVE) {
- //Run the executable again
- try {
- //Prepare the system before re-launch the command
- prepare(context, relaunchable);
-
- //Re-execute the command
- List<SyncResultExecutable> executables =
- relaunchable.getExecutables();
- int cc = executables.size();
- for (int i = 0; i < cc; i++) {
- SyncResultExecutable executable = executables.get(i);
- Object result = CommandHelper.reexecute(
- context, executable, null);
- if (relaunchable.getTask() != null) {
- relaunchable.getTask().execute(result);
- }
- }
-
- // Operation complete
- if (listener != null) {
- listener.onSuccess();
- }
-
- } catch (Throwable ex) {
- //Capture the exception, this time in quiet mode, if the
- //exception is the same
- boolean ask =
- ex.getClass().getName().compareTo(
- relaunchable.getClass().getName()) == 0;
- translateException(
- context, ex, quiet, !ask, listener);
-
- // Operation failed
- if (listener != null) {
- listener.onFailed(ex);
- }
- }
- } else {
- // Operation cancelled
- if (listener != null) {
- listener.onCancelled();
- }
- }
- }
- });
+ clickListener);
+
+ alert.setOnDismissListener(new DialogInterface.OnDismissListener() {
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ // Operation cancelled
+ if (listener != null) {
+ listener.onCancelled();
+ }
+ }
+ });
DialogHelper.delegateDialogShow(context, alert);
}