Ejemplo n.º 1
0
  @Override
  public void onResume() {
    super.onResume();
    resetNetworkInfo();
    setRepoSwitchChecked(FDroidApp.isLocalRepoServiceRunnig());

    LocalBroadcastManager.getInstance(this)
        .registerReceiver(onWifiChange, new IntentFilter(WifiStateChangeService.BROADCAST));
    LocalBroadcastManager.getInstance(this)
        .registerReceiver(onLocalRepoChange, new IntentFilter(LocalRepoService.STATE));
    // if no local repo exists, create one with only FDroid in it
    if (!LocalRepoManager.get(this).xmlIndex.exists())
      new UpdateAsyncTask(
              this,
              new String[] {
                getPackageName(),
              })
          .execute();

    // start repo by default
    FDroidApp.startLocalRepoService(LocalRepoActivity.this);
    // reset the timer if viewing this Activity again
    if (stopTimer != null) stopTimer.cancel();
    // automatically turn off after 15 minutes
    stopTimer = new Timer();
    stopTimer.schedule(
        new TimerTask() {

          @Override
          public void run() {
            FDroidApp.stopLocalRepoService(LocalRepoActivity.this);
          }
        },
        900000); // 15 minutes
  }
Ejemplo n.º 2
0
 @Override
 public void stopSwapping() {
   if (FDroidApp.isLocalRepoServiceRunning()) {
     if (shutdownLocalRepoTimer != null) {
       shutdownLocalRepoTimer.cancel();
     }
     FDroidApp.stopLocalRepoService(SwapActivity.this);
   }
   finish();
 }
  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();
  }
        @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();
            }
          }
        }
        @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();
        }
  /** 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();
  }
  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!");
    }
  }
Ejemplo n.º 8
0
 private void ensureLocalRepoRunning() {
   if (!FDroidApp.isLocalRepoServiceRunning()) {
     FDroidApp.startLocalRepoService(this);
     initLocalRepoTimer(900000); // 15 mins
   }
 }
  /** 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();
  }