2018-07-28 22:52:40 +08:00
|
|
|
package com.topjohnwu.magisk.components;
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-12-02 04:47:57 -05:00
|
|
|
import com.androidnetworking.AndroidNetworking;
|
|
|
|
import com.androidnetworking.error.ANError;
|
|
|
|
import com.androidnetworking.interfaces.DownloadListener;
|
2018-07-31 17:42:35 +08:00
|
|
|
import com.topjohnwu.magisk.Const;
|
2018-07-31 17:41:54 +08:00
|
|
|
import com.topjohnwu.magisk.Data;
|
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;
|
2018-08-02 00:41:10 +08:00
|
|
|
import com.topjohnwu.magisk.utils.Utils;
|
|
|
|
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-09-10 02:27:45 -04:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2018-07-31 17:41:54 +08:00
|
|
|
if (!TextUtils.isEmpty(Data.uninstallerLink)) {
|
2018-12-02 04:47:57 -05:00
|
|
|
setPositiveButton(R.string.complete_uninstall, (d, i) -> {
|
|
|
|
File zip = new File(activity.getFilesDir(), "uninstaller.zip");
|
|
|
|
NotificationProgress progress = new NotificationProgress(zip.getName());
|
|
|
|
AndroidNetworking.download(Data.uninstallerLink, zip.getParent(), zip.getName())
|
|
|
|
.build()
|
|
|
|
.setDownloadProgressListener(progress)
|
|
|
|
.startDownload(new DownloadListener() {
|
2018-07-28 22:52:40 +08:00
|
|
|
@Override
|
2018-12-02 04:47:57 -05:00
|
|
|
public void onDownloadComplete() {
|
2018-12-02 05:33:53 -05:00
|
|
|
progress.dismiss();
|
2018-12-02 04:47:57 -05:00
|
|
|
Intent intent = new Intent(activity, Data.classMap.get(FlashActivity.class))
|
2018-07-28 22:52:40 +08:00
|
|
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
2018-12-02 04:47:57 -05:00
|
|
|
.setData(Uri.fromFile(zip))
|
2018-07-28 22:52:40 +08:00
|
|
|
.putExtra(Const.Key.FLASH_ACTION, Const.Value.UNINSTALL);
|
2018-12-02 04:47:57 -05:00
|
|
|
activity.startActivity(intent);
|
2018-07-28 22:52:40 +08:00
|
|
|
}
|
2018-12-02 04:47:57 -05:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(ANError anError) {}
|
|
|
|
});
|
|
|
|
});
|
2018-07-28 22:52:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|