Improve system install process by killing FDroid to prevent hanging, cleanup dialog builders

This commit is contained in:
Dominik Schürmann 2015-05-20 23:56:05 +02:00
parent fc631c8781
commit 767db8a598
2 changed files with 67 additions and 62 deletions

View File

@ -67,6 +67,8 @@ abstract class InstallIntoSystem {
final void runUninstall() { final void runUninstall() {
final String[] commands = { final String[] commands = {
"am force-stop org.fdroid.fdroid",
"pm clear org.fdroid.fdroid",
"mount -o rw,remount /system", "mount -o rw,remount /system",
"pm uninstall " + context.getPackageName(), "pm uninstall " + context.getPackageName(),
"rm -f " + getInstallPath(), "rm -f " + getInstallPath(),
@ -94,6 +96,7 @@ abstract class InstallIntoSystem {
commands.add("pm install -r " + getInstallPath()); commands.add("pm install -r " + getInstallPath());
commands.add("sleep 5"); // wait until the app is really installed commands.add("sleep 5"); // wait until the app is really installed
commands.add("mount -o ro,remount /system"); commands.add("mount -o ro,remount /system");
commands.add("am force-stop org.fdroid.fdroid");
commands.addAll(getPostInstallCommands()); commands.addAll(getPostInstallCommands());
return commands; return commands;
} }

View File

@ -156,22 +156,23 @@ public class InstallIntoSystemDialogActivity extends FragmentActivity {
// hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay // hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay
ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId()); ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());
AlertDialog.Builder builder = new AlertDialog.Builder(theme);
String message = getString(R.string.system_install_first_time_message) + "<br/><br/>" + InstallIntoSystem.create(getApplicationContext()).getWarningInfo(); String message = getString(R.string.system_install_first_time_message) + "<br/><br/>" + InstallIntoSystem.create(getApplicationContext()).getWarningInfo();
builder.setMessage(Html.fromHtml(message));
builder.setPositiveButton(R.string.system_permission_install_via_root, new DialogInterface.OnClickListener() { AlertDialog.Builder builder = new AlertDialog.Builder(theme)
@Override .setMessage(Html.fromHtml(message))
public void onClick(DialogInterface dialogInterface, int i) { .setPositiveButton(R.string.system_permission_install_via_root, new DialogInterface.OnClickListener() {
installTask.execute(); @Override
} public void onClick(DialogInterface dialogInterface, int i) {
}); installTask.execute();
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { }
@Override })
public void onClick(DialogInterface dialogInterface, int i) { .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
InstallIntoSystemDialogActivity.this.setResult(Activity.RESULT_CANCELED); @Override
InstallIntoSystemDialogActivity.this.finish(); public void onClick(DialogInterface dialogInterface, int i) {
} InstallIntoSystemDialogActivity.this.setResult(Activity.RESULT_CANCELED);
}); InstallIntoSystemDialogActivity.this.finish();
}
});
builder.create().show(); builder.create().show();
} }
@ -225,16 +226,16 @@ public class InstallIntoSystemDialogActivity extends FragmentActivity {
ContextThemeWrapper theme = new ContextThemeWrapper(InstallIntoSystemDialogActivity.this, ContextThemeWrapper theme = new ContextThemeWrapper(InstallIntoSystemDialogActivity.this,
FDroidApp.getCurThemeResId()); FDroidApp.getCurThemeResId());
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(theme); AlertDialog.Builder alertBuilder = new AlertDialog.Builder(theme)
alertBuilder.setTitle(R.string.root_access_denied_title); .setTitle(R.string.root_access_denied_title)
alertBuilder.setMessage(getString(R.string.root_access_denied_body)); .setMessage(getString(R.string.root_access_denied_body))
alertBuilder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
InstallIntoSystemDialogActivity.this.setResult(Activity.RESULT_CANCELED); InstallIntoSystemDialogActivity.this.setResult(Activity.RESULT_CANCELED);
InstallIntoSystemDialogActivity.this.finish(); InstallIntoSystemDialogActivity.this.finish();
} }
}); });
alertBuilder.create().show(); alertBuilder.create().show();
} }
} }
@ -281,17 +282,18 @@ public class InstallIntoSystemDialogActivity extends FragmentActivity {
// enable system installer on installation success // enable system installer on installation success
Preferences.get().setSystemInstallerEnabled(success); Preferences.get().setSystemInstallerEnabled(success);
AlertDialog.Builder builder = new AlertDialog.Builder(theme); AlertDialog.Builder builder = new AlertDialog.Builder(theme)
builder.setTitle(success ? R.string.system_install_post_success : R.string.system_install_post_fail); .setTitle(success ? R.string.system_install_post_success : R.string.system_install_post_fail)
builder.setMessage(success ? R.string.system_install_post_success_message : R.string.system_install_post_fail_message); .setMessage(success ? R.string.system_install_post_success_message : R.string.system_install_post_fail_message)
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
InstallIntoSystemDialogActivity.this.setResult(success ? Activity.RESULT_OK : Activity.RESULT_CANCELED); InstallIntoSystemDialogActivity.this.setResult(success ? Activity.RESULT_OK : Activity.RESULT_CANCELED);
InstallIntoSystemDialogActivity.this.finish(); InstallIntoSystemDialogActivity.this.finish();
startActivity(new Intent(InstallIntoSystemDialogActivity.this, FDroid.class)); startActivity(new Intent(InstallIntoSystemDialogActivity.this, FDroid.class));
} }
}); })
.setCancelable(false);
builder.create().show(); builder.create().show();
} }
@ -302,34 +304,34 @@ public class InstallIntoSystemDialogActivity extends FragmentActivity {
final boolean systemApp = Installer.hasSystemPermissions(this, this.getPackageManager()); final boolean systemApp = Installer.hasSystemPermissions(this, this.getPackageManager());
if (systemApp) { if (systemApp) {
AlertDialog.Builder builder = new AlertDialog.Builder(theme); AlertDialog.Builder builder = new AlertDialog.Builder(theme)
builder.setTitle(R.string.system_uninstall); .setTitle(R.string.system_uninstall)
builder.setMessage(R.string.system_uninstall_message); .setMessage(R.string.system_uninstall_message)
builder.setPositiveButton(R.string.system_uninstall_button, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.system_uninstall_button, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
checkRootTask.execute(); checkRootTask.execute();
} }
}); })
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
InstallIntoSystemDialogActivity.this.setResult(Activity.RESULT_CANCELED); InstallIntoSystemDialogActivity.this.setResult(Activity.RESULT_CANCELED);
InstallIntoSystemDialogActivity.this.finish(); InstallIntoSystemDialogActivity.this.finish();
} }
}); });
builder.create().show(); builder.create().show();
} else { } else {
AlertDialog.Builder builder = new AlertDialog.Builder(theme); AlertDialog.Builder builder = new AlertDialog.Builder(theme)
builder.setTitle(R.string.system_permission_denied_title); .setTitle(R.string.system_permission_denied_title)
builder.setMessage(getString(R.string.system_permission_denied_body)); .setMessage(getString(R.string.system_permission_denied_body))
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
InstallIntoSystemDialogActivity.this.setResult(Activity.RESULT_CANCELED); InstallIntoSystemDialogActivity.this.setResult(Activity.RESULT_CANCELED);
InstallIntoSystemDialogActivity.this.finish(); InstallIntoSystemDialogActivity.this.finish();
} }
}); });
builder.create().show(); builder.create().show();
} }
} }