diff options
author | jruesga <jorge@ruesga.com> | 2012-10-06 21:45:15 +0200 |
---|---|---|
committer | jruesga <jorge@ruesga.com> | 2012-10-06 21:45:15 +0200 |
commit | ce79fe2c6f44ea1184094db3405f5d630ba1ef6a (patch) | |
tree | 0357530cab4b09cfc49a35594c9fb2bad851c3a8 /src | |
parent | 2116cc21c3e6f8249968b2e23ffd51d51c809aa7 (diff) | |
download | android_packages_apps_CMFileManager-ce79fe2c6f44ea1184094db3405f5d630ba1ef6a.tar.gz android_packages_apps_CMFileManager-ce79fe2c6f44ea1184094db3405f5d630ba1ef6a.tar.bz2 android_packages_apps_CMFileManager-ce79fe2c6f44ea1184094db3405f5d630ba1ef6a.zip |
Implemented Allow Console Selection setting
This setting allow use the menu "Select Console" or deactivate the menu
using only a privileged console, without additional privileged messages,
but require su to run the app.
By default, allow not privileged console to avoid startup problems
Diffstat (limited to 'src')
7 files changed, 95 insertions, 19 deletions
diff --git a/src/com/cyanogenmod/explorer/ExplorerApplication.java b/src/com/cyanogenmod/explorer/ExplorerApplication.java index 0c79be5e..5f5c56b9 100644 --- a/src/com/cyanogenmod/explorer/ExplorerApplication.java +++ b/src/com/cyanogenmod/explorer/ExplorerApplication.java @@ -77,6 +77,23 @@ public final class ExplorerApplication extends Application { c.reloadTrace(); } } catch (Throwable _throw) {/**NON BLOCK**/} + } else if (key != null && key.compareTo( + ExplorerSettings.SETTINGS_ALLOW_CONSOLE_SELECTION.getId()) == 0) { + // Force to change to a privileged console. + boolean allowConsoleSelection = Preferences.getSharedPreferences().getBoolean( + ExplorerSettings.SETTINGS_ALLOW_CONSOLE_SELECTION.getId(), + ((Boolean)ExplorerSettings. + SETTINGS_ALLOW_CONSOLE_SELECTION. + getDefaultValue()).booleanValue()); + if (!allowConsoleSelection) { + ConsoleBuilder.changeToPrivilegedConsole(context); + try { + Preferences.savePreference( + ExplorerSettings.SETTINGS_SUPERUSER_MODE, Boolean.TRUE, true); + } catch (Throwable ex) { + Log.w(TAG, "Can't save console preference", ex); //$NON-NLS-1$ + } + } } } } diff --git a/src/com/cyanogenmod/explorer/activities/NavigationActivity.java b/src/com/cyanogenmod/explorer/activities/NavigationActivity.java index 11c3f8df..90f858be 100644 --- a/src/com/cyanogenmod/explorer/activities/NavigationActivity.java +++ b/src/com/cyanogenmod/explorer/activities/NavigationActivity.java @@ -494,6 +494,7 @@ public class NavigationActivity extends Activity NavigationActivity.this, R.string.msgs_cant_create_console, Toast.LENGTH_LONG); finish(); + return; } //Is necessary navigate? @@ -906,6 +907,15 @@ public class NavigationActivity extends Activity } } + // Check if console selection is allowed + boolean allowConsoleSelection = Preferences.getSharedPreferences().getBoolean( + ExplorerSettings.SETTINGS_ALLOW_CONSOLE_SELECTION.getId(), + ((Boolean)ExplorerSettings. + SETTINGS_ALLOW_CONSOLE_SELECTION.getDefaultValue()).booleanValue()); + if (!allowConsoleSelection) { + menu.removeItem(R.id.mnu_console); + } + //Hide separator if (!hasActionBarMenus) { menu.removeItem(menu.getItem(this.mActionBar.getChildCount() - removed).getItemId()); diff --git a/src/com/cyanogenmod/explorer/activities/preferences/SettingsPreferences.java b/src/com/cyanogenmod/explorer/activities/preferences/SettingsPreferences.java index 1e2bbb6d..26f920ca 100644 --- a/src/com/cyanogenmod/explorer/activities/preferences/SettingsPreferences.java +++ b/src/com/cyanogenmod/explorer/activities/preferences/SettingsPreferences.java @@ -65,7 +65,7 @@ public class SettingsPreferences extends PreferenceActivity { * Method that initializes the titlebar of the activity. */ private void initTitleActionBar() { - //Configure the action bar options + //Configure the action bar options getActionBar().setBackgroundDrawable( getResources().getDrawable(R.drawable.bg_holo_titlebar)); getActionBar().setDisplayOptions( diff --git a/src/com/cyanogenmod/explorer/console/ConsoleBuilder.java b/src/com/cyanogenmod/explorer/console/ConsoleBuilder.java index f958cb77..511e564f 100644 --- a/src/com/cyanogenmod/explorer/console/ConsoleBuilder.java +++ b/src/com/cyanogenmod/explorer/console/ConsoleBuilder.java @@ -153,6 +153,7 @@ public final class ConsoleBuilder { return sHolder.getConsole() instanceof PrivilegedConsole; } catch (Throwable e) { + destroyConsole(); if (holder != null) { holder.dispose(); } @@ -184,6 +185,21 @@ public final class ConsoleBuilder { ExplorerSettings.SETTINGS_SUPERUSER_MODE.getId(), ((Boolean)ExplorerSettings.SETTINGS_SUPERUSER_MODE. getDefaultValue()).booleanValue()); + boolean allowConsoleSelection = Preferences.getSharedPreferences().getBoolean( + ExplorerSettings.SETTINGS_ALLOW_CONSOLE_SELECTION.getId(), + ((Boolean)ExplorerSettings. + SETTINGS_ALLOW_CONSOLE_SELECTION. + getDefaultValue()).booleanValue()); + if (!requiredSuConsole && !allowConsoleSelection) { + // allowConsoleSelection forces the su console + try { + Preferences.savePreference( + ExplorerSettings.SETTINGS_SUPERUSER_MODE, Boolean.TRUE, true); + } catch (Throwable ex) { + Log.w(TAG, "Can't save console preference", ex); //$NON-NLS-1$ + } + requiredSuConsole = true; + } //Check if console settings has changed if (sHolder != null) { @@ -308,21 +324,31 @@ public final class ConsoleBuilder { } } - //Save settings - try { - Editor editor = Preferences.getSharedPreferences().edit(); - editor.putBoolean(ExplorerSettings.SETTINGS_SUPERUSER_MODE.getId(), false); - editor.commit(); - } catch (Exception ex) { - Log.e(TAG, - String.format("Failed to save %s property", //$NON-NLS-1$ - ExplorerSettings.SETTINGS_SUPERUSER_MODE.getId()), ex); + boolean allowConsoleSelection = Preferences.getSharedPreferences().getBoolean( + ExplorerSettings.SETTINGS_ALLOW_CONSOLE_SELECTION.getId(), + ((Boolean)ExplorerSettings. + SETTINGS_ALLOW_CONSOLE_SELECTION. + getDefaultValue()).booleanValue()); + if (allowConsoleSelection) { + //Save settings + try { + Editor editor = Preferences.getSharedPreferences().edit(); + editor.putBoolean(ExplorerSettings.SETTINGS_SUPERUSER_MODE.getId(), false); + editor.commit(); + } catch (Exception ex) { + Log.e(TAG, + String.format("Failed to save %s property", //$NON-NLS-1$ + ExplorerSettings.SETTINGS_SUPERUSER_MODE.getId()), ex); + } + + //Create the non-privileged console + NonPriviledgeConsole console = new NonPriviledgeConsole(initialDirectory); + console.alloc(); + return console; } - //Create the non-privileged console - NonPriviledgeConsole console = new NonPriviledgeConsole(initialDirectory); - console.alloc(); - return console; + // Rethrow the exception + throw caEx; } } diff --git a/src/com/cyanogenmod/explorer/preferences/ExplorerSettings.java b/src/com/cyanogenmod/explorer/preferences/ExplorerSettings.java index 5040ce90..2926dfeb 100644 --- a/src/com/cyanogenmod/explorer/preferences/ExplorerSettings.java +++ b/src/com/cyanogenmod/explorer/preferences/ExplorerSettings.java @@ -94,7 +94,7 @@ public enum ExplorerSettings { * @hide */ SETTINGS_ALLOW_CONSOLE_SELECTION( - "cm_explorer_allow_console_selection", Boolean.FALSE), //$NON-NLS-1$ + "cm_explorer_allow_console_selection", Boolean.TRUE), //$NON-NLS-1$ /** * When to highlight the terms of the search in the search results diff --git a/src/com/cyanogenmod/explorer/ui/widgets/NavigationView.java b/src/com/cyanogenmod/explorer/ui/widgets/NavigationView.java index e67b4c0f..7e479e10 100644 --- a/src/com/cyanogenmod/explorer/ui/widgets/NavigationView.java +++ b/src/com/cyanogenmod/explorer/ui/widgets/NavigationView.java @@ -16,6 +16,7 @@ package com.cyanogenmod.explorer.ui.widgets; +import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.os.AsyncTask; @@ -25,11 +26,13 @@ import android.view.View; import android.widget.AdapterView; import android.widget.ListAdapter; import android.widget.RelativeLayout; +import android.widget.Toast; import com.cyanogenmod.explorer.R; import com.cyanogenmod.explorer.adapters.FileSystemObjectAdapter; import com.cyanogenmod.explorer.adapters.FileSystemObjectAdapter.OnRequestMenuListener; import com.cyanogenmod.explorer.adapters.FileSystemObjectAdapter.OnSelectionChangedListener; +import com.cyanogenmod.explorer.console.ConsoleAllocException; import com.cyanogenmod.explorer.listeners.OnHistoryListener; import com.cyanogenmod.explorer.listeners.OnRequestRefreshListener; import com.cyanogenmod.explorer.listeners.OnSelectionListener; @@ -47,6 +50,7 @@ import com.cyanogenmod.explorer.preferences.ObjectStringIdentifier; import com.cyanogenmod.explorer.preferences.Preferences; import com.cyanogenmod.explorer.ui.policy.ActionsPolicy; import com.cyanogenmod.explorer.util.CommandHelper; +import com.cyanogenmod.explorer.util.DialogHelper; import com.cyanogenmod.explorer.util.ExceptionUtil; import com.cyanogenmod.explorer.util.FileHelper; @@ -561,6 +565,21 @@ public class NavigationView extends RelativeLayout implements files = CommandHelper.listFiles(getContext(), newDir, null); } return files; + } catch (final ConsoleAllocException e) { + //Show exception and exists + NavigationView.this.mTitle.post(new Runnable() { + @Override + public void run() { + Context ctx = getContext(); + Log.e(TAG, ctx.getString( + R.string.msgs_cant_create_console), e); + DialogHelper.showToast(ctx, + R.string.msgs_cant_create_console, + Toast.LENGTH_LONG); + ((Activity)ctx).finish(); + } + }); + return null; } catch (Exception ex) { //End of loading data diff --git a/src/com/cyanogenmod/explorer/util/ExceptionUtil.java b/src/com/cyanogenmod/explorer/util/ExceptionUtil.java index 9f561a4e..7b516ef3 100644 --- a/src/com/cyanogenmod/explorer/util/ExceptionUtil.java +++ b/src/com/cyanogenmod/explorer/util/ExceptionUtil.java @@ -209,10 +209,14 @@ public final class ExceptionUtil { ((Activity)context).runOnUiThread(new Runnable() { @Override public void run() { - if (fToast) { - DialogHelper.showToast(context, fMsgResId, Toast.LENGTH_SHORT); - } else { - DialogHelper.createErrorDialog(context, fMsgResId).show(); + try { + if (fToast) { + DialogHelper.showToast(context, fMsgResId, Toast.LENGTH_SHORT); + } else { + DialogHelper.createErrorDialog(context, fMsgResId).show(); + } + } catch (Exception e) { + Log.e(context.getClass().getSimpleName(), "ExceptionUtil. Failed to show dialog", ex); //$NON-NLS-1$ } } }); |