mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-26 00:27:39 +00:00
Bring back installing to second slot after OTA on A/B devices
This commit is contained in:
parent
4ffc388491
commit
07140d33a7
@ -17,7 +17,9 @@ import com.topjohnwu.magisk.utils.Utils;
|
|||||||
import com.topjohnwu.magisk.utils.ZipUtils;
|
import com.topjohnwu.magisk.utils.ZipUtils;
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
import com.topjohnwu.superuser.ShellUtils;
|
import com.topjohnwu.superuser.ShellUtils;
|
||||||
|
import com.topjohnwu.superuser.io.SuFile;
|
||||||
import com.topjohnwu.superuser.io.SuFileInputStream;
|
import com.topjohnwu.superuser.io.SuFileInputStream;
|
||||||
|
import com.topjohnwu.superuser.io.SuFileOutputStream;
|
||||||
import com.topjohnwu.utils.SignBoot;
|
import com.topjohnwu.utils.SignBoot;
|
||||||
|
|
||||||
import org.kamranzafar.jtar.TarInputStream;
|
import org.kamranzafar.jtar.TarInputStream;
|
||||||
@ -214,6 +216,20 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void postOTA() {
|
||||||
|
SuFile bootctl = new SuFile(Const.MAGISK_PATH + "/.core/bootctl");
|
||||||
|
try (InputStream in = mm.getResources().openRawResource(R.raw.bootctl);
|
||||||
|
OutputStream out = new SuFileOutputStream(bootctl)) {
|
||||||
|
ShellUtils.pump(in, out);
|
||||||
|
Shell.Sync.su("post_ota " + bootctl.getParent());
|
||||||
|
console.add("***************************************");
|
||||||
|
console.add(" Next reboot will boot to second slot!");
|
||||||
|
console.add("***************************************");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(Void... voids) {
|
protected Boolean doInBackground(Void... voids) {
|
||||||
if (mode == FIX_ENV_MODE) {
|
if (mode == FIX_ENV_MODE) {
|
||||||
@ -240,13 +256,16 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
|||||||
mBoot = ShellUtils.fastCmd("find_boot_image", "echo \"$BOOTIMAGE\"");
|
mBoot = ShellUtils.fastCmd("find_boot_image", "echo \"$BOOTIMAGE\"");
|
||||||
break;
|
break;
|
||||||
case SECOND_SLOT_MODE:
|
case SECOND_SLOT_MODE:
|
||||||
|
String slot = ShellUtils.fastCmd("echo $SLOT");
|
||||||
|
String target = (TextUtils.equals(slot, "_a") ? "_b" : "_a");
|
||||||
|
console.add("- Target slot: " + target);
|
||||||
console.add("- Detecting target image");
|
console.add("- Detecting target image");
|
||||||
char slot[] = ShellUtils.fastCmd("echo $SLOT").toCharArray();
|
mBoot = ShellUtils.fastCmd(
|
||||||
if (slot[1] == 'a') slot[1] = 'b';
|
"SLOT=" + target,
|
||||||
else slot[1] = 'a';
|
"find_boot_image",
|
||||||
mBoot = ShellUtils.fastCmd("SLOT=" + String.valueOf(slot),
|
"SLOT=" + slot,
|
||||||
"find_boot_image", "echo \"$BOOTIMAGE\"");
|
"echo \"$BOOTIMAGE\""
|
||||||
Shell.Async.su("mount_partitions");
|
);
|
||||||
break;
|
break;
|
||||||
case FIX_ENV_MODE:
|
case FIX_ENV_MODE:
|
||||||
mBoot = "";
|
mBoot = "";
|
||||||
@ -257,7 +276,8 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.add("- Target image: " + mBoot);
|
if (mode == DIRECT_MODE || mode == SECOND_SLOT_MODE)
|
||||||
|
console.add("- Target image: " + mBoot);
|
||||||
|
|
||||||
List<String> abis = Arrays.asList(Build.SUPPORTED_ABIS);
|
List<String> abis = Arrays.asList(Build.SUPPORTED_ABIS);
|
||||||
String arch;
|
String arch;
|
||||||
@ -284,6 +304,8 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
|||||||
if (patched == null)
|
if (patched == null)
|
||||||
return false;
|
return false;
|
||||||
outputBoot(patched);
|
outputBoot(patched);
|
||||||
|
if (mode == SECOND_SLOT_MODE)
|
||||||
|
postOTA();
|
||||||
console.add("- All done!");
|
console.add("- All done!");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -26,6 +26,7 @@ import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
|||||||
import com.topjohnwu.magisk.receivers.ManagerUpdate;
|
import com.topjohnwu.magisk.receivers.ManagerUpdate;
|
||||||
import com.topjohnwu.magisk.receivers.RebootReceiver;
|
import com.topjohnwu.magisk.receivers.RebootReceiver;
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
|
import com.topjohnwu.superuser.ShellUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -134,6 +135,10 @@ public class ShowUI {
|
|||||||
if (Shell.rootAccess()) {
|
if (Shell.rootAccess()) {
|
||||||
options.add(mm.getString(R.string.direct_install));
|
options.add(mm.getString(R.string.direct_install));
|
||||||
}
|
}
|
||||||
|
String s = ShellUtils.fastCmd("grep_prop ro.build.ab_update");
|
||||||
|
if (s != null && Boolean.parseBoolean(s)) {
|
||||||
|
options.add(mm.getString(R.string.install_second_slot));
|
||||||
|
}
|
||||||
new AlertDialog.Builder(activity)
|
new AlertDialog.Builder(activity)
|
||||||
.setTitle(R.string.select_method)
|
.setTitle(R.string.select_method)
|
||||||
.setItems(
|
.setItems(
|
||||||
|
BIN
app/src/full/res/raw/bootctl
Normal file
BIN
app/src/full/res/raw/bootctl
Normal file
Binary file not shown.
@ -73,11 +73,11 @@ mm_patch_dtbo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
restore_imgs() {
|
restore_imgs() {
|
||||||
SHA1=`cat /.backup/.sha1`
|
local SHA1=`cat /.backup/.sha1`
|
||||||
[ -z $SHA1 ] && SHA1=`grep_prop #STOCKSHA1`
|
[ -z $SHA1 ] && local SHA1=`grep_prop #STOCKSHA1`
|
||||||
[ -z $SHA1 ] && return 1
|
[ -z $SHA1 ] && return 1
|
||||||
STOCKBOOT=/data/stock_boot_${SHA1}.img.gz
|
local STOCKBOOT=/data/stock_boot_${SHA1}.img.gz
|
||||||
STOCKDTBO=/data/stock_dtbo.img.gz
|
local STOCKDTBO=/data/stock_dtbo.img.gz
|
||||||
[ -f $STOCKBOOT ] || return 1
|
[ -f $STOCKBOOT ] || return 1
|
||||||
|
|
||||||
find_boot_image
|
find_boot_image
|
||||||
@ -93,3 +93,14 @@ restore_imgs() {
|
|||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
post_ota() {
|
||||||
|
cd $1
|
||||||
|
chmod 755 bootctl
|
||||||
|
./bootctl hal-info || return
|
||||||
|
[ `./bootctl get-current-slot` -eq 0 ] && SLOT_NUM=1 || SLOT_NUM=0
|
||||||
|
./bootctl set-active-boot-slot $SLOT_NUM
|
||||||
|
echo '${0%/*}/../bootctl mark-boot-successful;rm -f ${0%/*}/../bootctl $0' > post-fs-data.d/post_ota.sh
|
||||||
|
chmod 755 post-fs-data.d/post_ota.sh
|
||||||
|
cd /
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user