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

Commit 962e7492 authored by jruesga's avatar jruesga
Browse files

When no console available, ask the user prior to exit

When advanced console selection is disabled and a can't create a
console, the only way is restore to non-privileged console, which
includes reverts the superuser and advanced selection modes.
parent b03fde58
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -70,7 +70,13 @@
  <!-- Error message -->
  <string name="error_message">Error.</string>

  <!-- A console can't not be create. Without a console the application can't continue -->
  <!-- A console can't not be created. Ask the user to change to advanced model -->
  <string name="msgs_change_to_advanced_console_selection">
    The application is not capable of create a console. The only way to run the application
    is to change to advanced console selection and to a non-privileged console.\n\n
    Apply this changes?</string>

  <!-- A console can't not be created. Without a console the application can't continue -->
  <string name="msgs_cant_create_console">The application is not capable of create a console. The
    application can\'t work without a console.</string>
  <!-- The message show when a allocation of a privileged console fails, and a non
+71 −6
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.app.AlertDialog;
import android.app.SearchManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
@@ -428,8 +429,16 @@ public class NavigationActivity extends Activity
                        throw new ConsoleAllocException("console == null"); //$NON-NLS-1$
                    }
                } catch (Throwable ex) {
                    boolean allowConsoleSelection = Preferences.getSharedPreferences().getBoolean(
                            ExplorerSettings.SETTINGS_ALLOW_CONSOLE_SELECTION.getId(),
                            ((Boolean)ExplorerSettings.
                                    SETTINGS_ALLOW_CONSOLE_SELECTION.
                                        getDefaultValue()).booleanValue());
                    if (allowConsoleSelection) {
                        //Show exception and exists
                        Log.e(TAG, getString(R.string.msgs_cant_create_console), ex);
                        // We don't have any console
                        // Show exception and exists
                        DialogHelper.showToast(
                                NavigationActivity.this,
                                R.string.msgs_cant_create_console, Toast.LENGTH_LONG);
@@ -437,6 +446,13 @@ public class NavigationActivity extends Activity
                        return;
                    }

                    // We are in a trouble (something is not allowing su console)
                    // Ask the user to return to Advanced Console Selection with
                    // Non-privileged console prior to make crash the application
                    askOrExit();
                    return;
                }

                //Is necessary navigate?
                if (!restore) {
                    //Load the preference initial directory
@@ -1212,4 +1228,53 @@ public class NavigationActivity extends Activity
        }
    }

    /**
     * Method that ask the user to change to to advanced console
     * @hide
     */
    void askOrExit() {
        //Show a dialog asking the user
        AlertDialog dialog =
            DialogHelper.createYesNoDialog(
                this, R.string.msgs_change_to_advanced_console_selection,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface alertDialog, int which) {
                        if (which == DialogInterface.BUTTON_NEGATIVE) {
                            // We don't have any console
                            // Show exception and exists
                            DialogHelper.showToast(
                                    NavigationActivity.this,
                                    R.string.msgs_cant_create_console, Toast.LENGTH_LONG);
                            finish();
                            return;
                        }

                        // Ok. Now try to change to advanced selection console. Any crash
                        // here is a fatal error. We don't have any console
                        try {
                            // Change console
                            ConsoleBuilder.changeToNonPrivilegedConsole(NavigationActivity.this);

                            // Save preferences
                            Preferences.savePreference(
                                    ExplorerSettings.SETTINGS_ALLOW_CONSOLE_SELECTION,
                                    Boolean.TRUE, true);
                            Preferences.savePreference(
                                    ExplorerSettings.SETTINGS_SUPERUSER_MODE,
                                    Boolean.FALSE, true);

                        } catch (Exception e) {
                            //Show exception and exists
                            Log.e(TAG, getString(R.string.msgs_cant_create_console), e);
                            DialogHelper.showToast(
                                    NavigationActivity.this,
                                    R.string.msgs_cant_create_console, Toast.LENGTH_LONG);
                            finish();
                        }
                    }
               });
        dialog.show();
    }

}