public static void firstTime(final Context context) { if (Preferences.get().isFirstTime()) { Preferences.get().setFirstTime(false); int isInstalledCorrectly = PrivilegedInstaller.isExtensionInstalledCorrectly(context); switch (isInstalledCorrectly) { case PrivilegedInstaller.IS_EXTENSION_INSTALLED_YES: Preferences.get().setPrivilegedInstallerEnabled(true); break; case PrivilegedInstaller.IS_EXTENSION_INSTALLED_NO: runFirstTime(context); break; case PrivilegedInstaller.IS_EXTENSION_INSTALLED_PERMISSIONS_PROBLEM: case PrivilegedInstaller.IS_EXTENSION_INSTALLED_SIGNATURE_PROBLEM: default: // do nothing } } }
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!"); } }
/** 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(); }