2017-09-05 17:43:13 +08:00
|
|
|
package com.topjohnwu.magisk.asyncs;
|
|
|
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2017-10-16 00:54:48 +08:00
|
|
|
import com.topjohnwu.magisk.MagiskManager;
|
2017-09-05 17:43:13 +08:00
|
|
|
import com.topjohnwu.magisk.R;
|
|
|
|
import com.topjohnwu.magisk.utils.Utils;
|
2018-01-21 06:07:24 +08:00
|
|
|
import com.topjohnwu.superuser.Shell;
|
2017-09-05 17:43:13 +08:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2017-12-12 02:35:00 +08:00
|
|
|
public class RestoreImages extends ParallelTask<Void, Void, Boolean> {
|
2017-09-05 17:43:13 +08:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Boolean doInBackground(Void... voids) {
|
2017-11-03 05:02:14 +08:00
|
|
|
String sha1;
|
|
|
|
List<String> ret = Utils.readFile("/.backup/.sha1");
|
2017-11-15 04:39:05 +08:00
|
|
|
if (Utils.isValidShellResponse(ret)) {
|
|
|
|
sha1 = ret.get(0);
|
|
|
|
} else {
|
2017-11-03 05:02:14 +08:00
|
|
|
ret = Shell.su("cat /init.magisk.rc | grep STOCKSHA1");
|
|
|
|
if (!Utils.isValidShellResponse(ret))
|
|
|
|
return false;
|
|
|
|
sha1 = ret.get(0).substring(ret.get(0).indexOf('=') + 1);
|
|
|
|
}
|
|
|
|
|
2017-11-15 04:39:05 +08:00
|
|
|
ret = Shell.su("restore_imgs " + sha1 + " && echo true || echo false");
|
|
|
|
|
|
|
|
return Utils.isValidShellResponse(ret) && Boolean.parseBoolean(ret.get(ret.size() - 1));
|
2017-09-05 17:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Boolean result) {
|
|
|
|
if (result) {
|
2017-10-16 00:54:48 +08:00
|
|
|
MagiskManager.toast(R.string.restore_done, Toast.LENGTH_SHORT);
|
2017-09-05 17:43:13 +08:00
|
|
|
} else {
|
2017-10-16 00:54:48 +08:00
|
|
|
MagiskManager.toast(R.string.restore_fail, Toast.LENGTH_LONG);
|
2017-09-05 17:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|