コード例 #1
0
  public void askBeforeInstall() {
    // hack to get theme applied (which is not automatically applied due to activity's
    // Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(theme);
    alertBuilder.setTitle(R.string.system_install_question);
    String message = InstallExtension.create(getApplicationContext()).getWarningString();
    alertBuilder.setMessage(Html.fromHtml(message));
    alertBuilder.setPositiveButton(
        R.string.system_install_button_install,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            checkRootTask.execute();
          }
        });
    alertBuilder.setNegativeButton(
        R.string.cancel,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED);
            InstallExtensionDialogActivity.this.finish();
          }
        });
    alertBuilder.create().show();
  }
コード例 #2
0
        @Override
        protected void onPostExecute(Boolean rootGranted) {
          super.onPostExecute(rootGranted);

          mProgressDialog.dismiss();

          if (rootGranted) {
            // root access granted

            switch (getIntent().getAction()) {
              case ACTION_UNINSTALL:
                uninstallTask.execute();
                break;
              case ACTION_INSTALL:
                installTask.execute();
                break;
              case ACTION_FIRST_TIME:
                firstTime();
                break;
            }
          } else {
            // root access denied

            if (!ACTION_FIRST_TIME.equals(getIntent().getAction())) {
              // hack to get theme applied (which is not automatically applied due to activity's
              // Theme.NoDisplay
              ContextThemeWrapper theme =
                  new ContextThemeWrapper(
                      InstallExtensionDialogActivity.this, FDroidApp.getCurThemeResId());

              AlertDialog.Builder alertBuilder =
                  new AlertDialog.Builder(theme)
                      .setTitle(R.string.root_access_denied_title)
                      .setMessage(getString(R.string.root_access_denied_body))
                      .setNeutralButton(
                          android.R.string.ok,
                          new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                              InstallExtensionDialogActivity.this.setResult(
                                  Activity.RESULT_CANCELED);
                              InstallExtensionDialogActivity.this.finish();
                            }
                          });
              alertBuilder.create().show();
            }
          }
        }
コード例 #3
0
        @Override
        protected void onPreExecute() {
          super.onPreExecute();

          // hack to get theme applied (which is not automatically applied due to activity's
          // Theme.NoDisplay
          ContextThemeWrapper theme =
              new ContextThemeWrapper(
                  InstallExtensionDialogActivity.this, FDroidApp.getCurThemeResId());

          mProgressDialog = new ProgressDialog(theme);
          mProgressDialog.setMessage(getString(R.string.system_install_uninstalling));
          mProgressDialog.setIndeterminate(true);
          mProgressDialog.setCancelable(false);
          mProgressDialog.show();
        }
コード例 #4
0
  /** first time */
  private void firstTime() {
    // hack to get theme applied (which is not automatically applied due to activity's
    // Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    String message =
        getString(R.string.system_install_first_time_message)
            + "<br/><br/>"
            + getString(R.string.system_install_question);

    AlertDialog.Builder builder =
        new AlertDialog.Builder(theme)
            .setMessage(Html.fromHtml(message))
            .setPositiveButton(
                R.string.system_install_button_open,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialogInterface, int i) {
                    // Open details of F-Droid Privileged
                    Intent intent =
                        new Intent(InstallExtensionDialogActivity.this, AppDetails.class);
                    intent.putExtra(
                        AppDetails.EXTRA_APPID,
                        PrivilegedInstaller.PRIVILEGED_EXTENSION_PACKAGE_NAME);
                    startActivity(intent);
                  }
                })
            .setNegativeButton(
                R.string.cancel,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialogInterface, int i) {
                    InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED);
                    InstallExtensionDialogActivity.this.finish();
                  }
                });
    builder.create().show();
  }
コード例 #5
0
  private void uninstall() {
    // hack to get theme applied (which is not automatically applied due to activity's
    // Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    final boolean isInstalled = PrivilegedInstaller.isExtensionInstalled(this);

    if (isInstalled) {
      String message = InstallExtension.create(getApplicationContext()).getWarningString();

      AlertDialog.Builder builder =
          new AlertDialog.Builder(theme)
              .setTitle(R.string.system_uninstall)
              .setMessage(Html.fromHtml(message))
              .setPositiveButton(
                  R.string.system_uninstall_button,
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                      checkRootTask.execute();
                    }
                  })
              .setNegativeButton(
                  R.string.cancel,
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED);
                      InstallExtensionDialogActivity.this.finish();
                    }
                  });
      builder.create().show();
    } else {
      throw new RuntimeException("Uninstall invoked, but extension is not installed!");
    }
  }
コード例 #6
0
  /** 3. Verify that install worked */
  private void postInstall() {
    // hack to get theme applied (which is not automatically applied due to activity's
    // Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    int isInstalledCorrectly = PrivilegedInstaller.isExtensionInstalledCorrectly(this);

    String title;
    String message;
    final int result;
    switch (isInstalledCorrectly) {
      case PrivilegedInstaller.IS_EXTENSION_INSTALLED_YES:
        title = getString(R.string.system_install_post_success);
        message = getString(R.string.system_install_post_success_message);
        result = Activity.RESULT_OK;

        // enable system installer on installation success
        Preferences.get().setPrivilegedInstallerEnabled(true);
        break;
      case PrivilegedInstaller.IS_EXTENSION_INSTALLED_NO:
        title = getString(R.string.system_install_post_fail);
        message = getString(R.string.system_install_post_fail_message);
        result = Activity.RESULT_CANCELED;
        break;
      case PrivilegedInstaller.IS_EXTENSION_INSTALLED_SIGNATURE_PROBLEM:
        title = getString(R.string.system_install_post_fail);
        message =
            getString(R.string.system_install_post_fail_message)
                + "\n\n"
                + getString(R.string.system_install_denied_signature);
        result = Activity.RESULT_CANCELED;
        break;
      case PrivilegedInstaller.IS_EXTENSION_INSTALLED_PERMISSIONS_PROBLEM:
        title = getString(R.string.system_install_post_fail);
        message =
            getString(R.string.system_install_post_fail_message)
                + "\n\n"
                + getString(R.string.system_install_denied_permissions);
        result = Activity.RESULT_CANCELED;
        break;
      default:
        throw new RuntimeException("unhandled return");
    }

    AlertDialog.Builder builder =
        new AlertDialog.Builder(theme)
            .setTitle(title)
            .setMessage(message)
            .setPositiveButton(
                R.string.ok,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialogInterface, int i) {
                    InstallExtensionDialogActivity.this.setResult(result);
                    InstallExtensionDialogActivity.this.finish();
                    startActivity(new Intent(InstallExtensionDialogActivity.this, FDroid.class));
                  }
                })
            .setCancelable(false);
    builder.create().show();
  }