2019-01-30 23:23:49 -05:00
|
|
|
package com.topjohnwu.magisk.dialogs;
|
2018-07-28 22:52:40 +08:00
|
|
|
|
|
|
|
import android.app.Activity;
|
2018-08-02 00:41:10 +08:00
|
|
|
import android.app.ProgressDialog;
|
2018-07-28 22:52:40 +08:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.text.TextUtils;
|
2018-08-02 00:41:10 +08:00
|
|
|
import android.widget.Toast;
|
2018-07-28 22:52:40 +08:00
|
|
|
|
2019-03-07 03:41:24 -05:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
2018-12-13 04:35:50 -05:00
|
|
|
import com.topjohnwu.magisk.ClassMap;
|
2019-01-30 03:10:12 -05:00
|
|
|
import com.topjohnwu.magisk.Config;
|
|
|
|
import com.topjohnwu.magisk.Const;
|
2018-09-16 00:08:13 -04:00
|
|
|
import com.topjohnwu.magisk.FlashActivity;
|
2018-07-28 22:52:40 +08:00
|
|
|
import com.topjohnwu.magisk.R;
|
2019-01-30 23:23:49 -05:00
|
|
|
import com.topjohnwu.magisk.uicomponents.ProgressNotification;
|
2019-01-30 03:10:12 -05:00
|
|
|
import com.topjohnwu.magisk.utils.Utils;
|
2018-12-12 05:51:45 -05:00
|
|
|
import com.topjohnwu.net.Networking;
|
2018-08-02 00:41:10 +08:00
|
|
|
import com.topjohnwu.superuser.Shell;
|
2018-07-28 22:52:40 +08:00
|
|
|
|
2018-12-02 04:47:57 -05:00
|
|
|
import java.io.File;
|
|
|
|
|
2018-07-28 22:52:40 +08:00
|
|
|
public class UninstallDialog extends CustomAlertDialog {
|
|
|
|
|
|
|
|
public UninstallDialog(@NonNull Activity activity) {
|
|
|
|
super(activity);
|
|
|
|
setTitle(R.string.uninstall_magisk_title);
|
|
|
|
setMessage(R.string.uninstall_magisk_msg);
|
2018-08-02 00:41:10 +08:00
|
|
|
setNeutralButton(R.string.restore_img, (d, i) -> {
|
|
|
|
ProgressDialog dialog = ProgressDialog.show(activity,
|
|
|
|
activity.getString(R.string.restore_img),
|
|
|
|
activity.getString(R.string.restore_img_msg));
|
|
|
|
Shell.su("restore_imgs").submit(result -> {
|
|
|
|
dialog.cancel();
|
|
|
|
if (result.isSuccess()) {
|
|
|
|
Utils.toast(R.string.restore_done, Toast.LENGTH_SHORT);
|
|
|
|
} else {
|
|
|
|
Utils.toast(R.string.restore_fail, Toast.LENGTH_LONG);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2019-01-21 15:49:03 -05:00
|
|
|
if (!TextUtils.isEmpty(Config.uninstallerLink)) {
|
2018-12-02 04:47:57 -05:00
|
|
|
setPositiveButton(R.string.complete_uninstall, (d, i) -> {
|
|
|
|
File zip = new File(activity.getFilesDir(), "uninstaller.zip");
|
2018-12-03 01:44:13 -05:00
|
|
|
ProgressNotification progress = new ProgressNotification(zip.getName());
|
2019-01-21 15:49:03 -05:00
|
|
|
Networking.get(Config.uninstallerLink)
|
2018-12-02 04:47:57 -05:00
|
|
|
.setDownloadProgressListener(progress)
|
2018-12-12 05:51:45 -05:00
|
|
|
.setErrorHandler(((conn, e) -> progress.dlFail()))
|
2019-01-01 18:45:48 +08:00
|
|
|
.getAsFile(zip, f -> {
|
2018-12-12 05:51:45 -05:00
|
|
|
progress.dismiss();
|
2018-12-13 04:35:50 -05:00
|
|
|
Intent intent = new Intent(activity, ClassMap.get(FlashActivity.class))
|
2018-12-12 05:51:45 -05:00
|
|
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
|
.setData(Uri.fromFile(f))
|
|
|
|
.putExtra(Const.Key.FLASH_ACTION, Const.Value.UNINSTALL);
|
|
|
|
activity.startActivity(intent);
|
2019-01-01 18:45:48 +08:00
|
|
|
});
|
2018-12-02 04:47:57 -05:00
|
|
|
});
|
2018-07-28 22:52:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|