Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ce79fe2c authored by jruesga's avatar jruesga
Browse files

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
parent 2116cc21
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@
        android:summaryOn="@string/pref_allow_console_selection_on"
        android:summaryOff="@string/pref_allow_console_selection_off"
        android:persistent="true"
        android:defaultValue="false" />
        android:defaultValue="true" />

    </PreferenceCategory>
</PreferenceScreen>
 No newline at end of file
+17 −0
Original line number Diff line number Diff line
@@ -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$
                        }
                    }
                }
            }
        }
+10 −0
Original line number Diff line number Diff line
@@ -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());
+39 −13
Original line number Diff line number Diff line
@@ -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,6 +324,12 @@ public final class ConsoleBuilder {
                }
            }

            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();
@@ -325,6 +347,10 @@ public final class ConsoleBuilder {
                return console;
            }

            // Rethrow the exception
            throw caEx;
        }

    }

}
+1 −1
Original line number Diff line number Diff line
@@ -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
Loading