* Complete removal

master
Alan SCHNEIDER 2012-04-18 17:22:24 +02:00
parent 82982ec1dd
commit 56fc980bcf
5 changed files with 53 additions and 11 deletions

View File

@ -109,4 +109,8 @@ public class MainActivity extends Activity {
public void check() {
mAdapter.check();
}
public void updateServer() {
mAdapter.updateServer();
}
}

View File

@ -117,4 +117,8 @@ public class MainAdapter extends PagerAdapter implements ViewPagerTabProvider {
public void check() {
mServerPage.check();
}
public void updateServer() {
mServerPage.update();
}
}

View File

@ -1,6 +1,10 @@
package me.shkschneider.dropbearserver.Pages;
import me.shkschneider.dropbearserver.MainActivity;
import me.shkschneider.dropbearserver.R;
import me.shkschneider.dropbearserver.Tasks.DropbearRemover;
import me.shkschneider.dropbearserver.Tasks.DropbearRemoverCallback;
import me.shkschneider.dropbearserver.Utils.RootUtils;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
@ -9,7 +13,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
public class SettingsPage implements OnClickListener {
public class SettingsPage implements OnClickListener, DialogInterface.OnClickListener, DropbearRemoverCallback<Boolean> {
private Context mContext;
private View mView;
@ -57,12 +61,11 @@ public class SettingsPage implements OnClickListener {
}
else if (v == mCompleteRemoval) {
new AlertDialog.Builder(mContext)
.setMessage("message")
.setTitle("title")
.setTitle("Confirm")
.setMessage("This will remove dropbear and all its configuration (including public keys).")
.setCancelable(true)
.setNeutralButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
})
.setPositiveButton("Okay", this)
.setNegativeButton("Cancel", this)
.show();
}
// mDropbear
@ -70,4 +73,21 @@ public class SettingsPage implements OnClickListener {
mDropbearContent.setVisibility(mDropbearContent.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
}
}
@Override
public void onClick(DialogInterface dialog, int button) {
if (button == DialogInterface.BUTTON_POSITIVE) {
// mDropbearRemover
DropbearRemover dropbearRemover = new DropbearRemover(mContext, this);
dropbearRemover.execute();
}
}
@Override
public void onDropbearRemoverComplete(Boolean result) {
if (result == true) {
RootUtils.hasDropbear = false;
((MainActivity) mContext).updateServer();
}
}
}

View File

@ -1,5 +1,6 @@
package me.shkschneider.dropbearserver.Tasks;
import me.shkschneider.dropbearserver.Utils.ShellUtils;
import me.shkschneider.dropbearserver.Utils.Utils;
import android.app.ProgressDialog;
@ -20,7 +21,7 @@ public class DropbearRemover extends AsyncTask<Void, String, Boolean>
mContext = context;
mCallback = callback;
mProgressDialog = new ProgressDialog(mContext);
mProgressDialog.setTitle("Installing Dropbear");
mProgressDialog.setTitle("Removing Dropbear");
mProgressDialog.setMessage("Please wait...");
mProgressDialog.setCancelable(false);
}
@ -35,29 +36,37 @@ public class DropbearRemover extends AsyncTask<Void, String, Boolean>
protected void onProgressUpdate(String... progress) {
super.onProgressUpdate(progress);
Float f = (Float.parseFloat(progress[0] + ".0") / Float.parseFloat(progress[1] + ".0") * 100);
mProgressDialog.setTitle("" + Math.round(f) + "%");
mProgressDialog.setTitle("Removing: " + Math.round(f) + "%");
mProgressDialog.setMessage(progress[2]);
}
@Override
protected Boolean doInBackground(Void... params) {
int step = 0;
int steps = 11;
int steps = 5;
// read-write
publishProgress("" + step++, "" + steps, "/system read-write");
Utils.remountReadWrite("/system");
if (Utils.remountReadWrite("/system") == false)
return false;
// data/dropbear
publishProgress("" + step++, "" + steps, "/data/dropbear");
if (ShellUtils.rmRecursive("/data/dropbear") == false)
return false;;
// system/xbin
publishProgress("" + step++, "" + steps, "/system/xbin/dropbear");
if (ShellUtils.rm("/system/xbin/dropbear") == false)
return false;
publishProgress("" + step++, "" + steps, "/system/xbin/dropbearkey");
if (ShellUtils.rm("/system/xbin/dropbearkey") == false)
return false;
// read-only
publishProgress("" + step++, "" + steps, "/system read-only");
Utils.remountReadOnly("/system");
if (Utils.remountReadOnly("/system") == false)
return false;
return true;
}

View File

@ -38,6 +38,11 @@ public abstract class ShellUtils
}
public static final Boolean rm(String path) {
commands.add("rm " + path);
return execute();
}
public static final Boolean rmRecursive(String path) {
commands.add("rm -r " + path);
return execute();
}