Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmacd committed Jul 21, 2018
2 parents 9647c26 + 91818cf commit 356e99e
Show file tree
Hide file tree
Showing 21 changed files with 253 additions and 213 deletions.
5 changes: 4 additions & 1 deletion app/src/full/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
</intent-filter>
</receiver>

<service android:name=".services.OnBootIntentService" />
<service
android:name=".services.OnBootService"
android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" />
<service
android:name=".services.UpdateCheckService"
android:exported="true"
Expand Down
36 changes: 29 additions & 7 deletions app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import com.topjohnwu.magisk.utils.ZipUtils;
import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.ShellUtils;
import com.topjohnwu.superuser.io.SuFile;
import com.topjohnwu.superuser.io.SuFileInputStream;
import com.topjohnwu.superuser.io.SuFileOutputStream;
import com.topjohnwu.utils.SignBoot;

import org.kamranzafar.jtar.TarInputStream;
Expand Down Expand Up @@ -214,6 +216,20 @@ private void outputBoot(File patched) throws IOException {
}
}

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
protected Boolean doInBackground(Void... voids) {
if (mode == FIX_ENV_MODE) {
Expand All @@ -240,13 +256,16 @@ protected Boolean doInBackground(Void... voids) {
mBoot = ShellUtils.fastCmd("find_boot_image", "echo \"$BOOTIMAGE\"");
break;
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");
char slot[] = ShellUtils.fastCmd("echo $SLOT").toCharArray();
if (slot[1] == 'a') slot[1] = 'b';
else slot[1] = 'a';
mBoot = ShellUtils.fastCmd("SLOT=" + String.valueOf(slot),
"find_boot_image", "echo \"$BOOTIMAGE\"");
Shell.Async.su("mount_partitions");
mBoot = ShellUtils.fastCmd(
"SLOT=" + target,
"find_boot_image",
"SLOT=" + slot,
"echo \"$BOOTIMAGE\""
);
break;
case FIX_ENV_MODE:
mBoot = "";
Expand All @@ -257,7 +276,8 @@ protected Boolean doInBackground(Void... voids) {
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);
String arch;
Expand All @@ -284,6 +304,8 @@ protected Boolean doInBackground(Void... voids) {
if (patched == null)
return false;
outputBoot(patched);
if (mode == SECOND_SLOT_MODE)
postOTA();
console.add("- All done!");
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.text.TextUtils;

import com.topjohnwu.magisk.services.OnBootIntentService;
import com.topjohnwu.magisk.services.OnBootService;

public class BootReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, OnBootIntentService.class));
} else {
context.startService(new Intent(context, OnBootIntentService.class));
}
if (TextUtils.equals(intent.getAction(), Intent.ACTION_BOOT_COMPLETED))
OnBootService.enqueueWork(context);
}

}

This file was deleted.

33 changes: 33 additions & 0 deletions app/src/full/java/com/topjohnwu/magisk/services/OnBootService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.topjohnwu.magisk.services;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.app.JobIntentService;

import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.ShowUI;
import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.ShellUtils;

public class OnBootService extends JobIntentService {

public static void enqueueWork(Context context) {
enqueueWork(context, OnBootService.class, Const.ID.ONBOOT_SERVICE_ID, new Intent());
}

@Override
protected void onHandleWork(@NonNull Intent intent) {
/* Devices with DTBO might want to patch dtbo.img.
* However, that is not possible if Magisk is installed by
* patching boot image with Magisk Manager and flashed via
* fastboot, since at that time we do not have root.
* Check for dtbo status every boot time, and prompt user
* to reboot if dtbo wasn't patched and patched by Magisk Manager.
* */
Shell shell = Shell.newInstance();
if (shell.getStatus() >= Shell.ROOT_SHELL &&
Boolean.parseBoolean(ShellUtils.fastCmd(shell, "mm_patch_dtbo")))
ShowUI.dtboPatchedNotification();
}
}
2 changes: 0 additions & 2 deletions app/src/full/java/com/topjohnwu/magisk/utils/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import com.topjohnwu.magisk.BuildConfig;

import java.util.Locale;

public class Logger {

public static void debug(String line) {
Expand Down
12 changes: 0 additions & 12 deletions app/src/full/java/com/topjohnwu/magisk/utils/RootUtils.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.topjohnwu.magisk.utils;

import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.ShellUtils;
import com.topjohnwu.superuser.io.SuFile;

public class RootUtils {
Expand All @@ -25,14 +23,4 @@ public static void init() {
public static void uninstallPkg(String pkg) {
Shell.Sync.su("db_clean " + Const.USER_ID, "pm uninstall " + pkg);
}

public static void patchDTBO() {
if (Shell.rootAccess()) {
MagiskManager mm = MagiskManager.get();
if (mm.magiskVersionCode >= Const.MAGISK_VER.DTBO_SUPPORT) {
if (Boolean.parseBoolean(ShellUtils.fastCmd("mm_patch_dtbo")))
ShowUI.dtboPatchedNotification();
}
}
}
}
5 changes: 5 additions & 0 deletions app/src/full/java/com/topjohnwu/magisk/utils/ShowUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.topjohnwu.magisk.receivers.ManagerUpdate;
import com.topjohnwu.magisk.receivers.RebootReceiver;
import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.ShellUtils;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -134,6 +135,10 @@ public static void magiskInstallDialog(Activity activity) {
if (Shell.rootAccess()) {
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)
.setTitle(R.string.select_method)
.setItems(
Expand Down
Binary file added app/src/full/res/raw/bootctl
Binary file not shown.
19 changes: 15 additions & 4 deletions app/src/full/res/raw/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ mm_patch_dtbo() {
}

restore_imgs() {
SHA1=`cat /.backup/.sha1`
[ -z $SHA1 ] && SHA1=`grep_prop #STOCKSHA1`
local SHA1=`cat /.backup/.sha1`
[ -z $SHA1 ] && local SHA1=`grep_prop #STOCKSHA1`
[ -z $SHA1 ] && return 1
STOCKBOOT=/data/stock_boot_${SHA1}.img.gz
STOCKDTBO=/data/stock_dtbo.img.gz
local STOCKBOOT=/data/stock_boot_${SHA1}.img.gz
local STOCKDTBO=/data/stock_dtbo.img.gz
[ -f $STOCKBOOT ] || return 1

find_boot_image
Expand All @@ -93,3 +93,14 @@ restore_imgs() {
fi
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 /
}
3 changes: 1 addition & 2 deletions app/src/main/java/com/topjohnwu/magisk/utils/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public static final class MAGISK_VER {
public static final int FBE_AWARE = 1410;
public static final int RESETPROP_PERSIST = 1436;
public static final int MANAGER_HIDE = 1440;
public static final int DTBO_SUPPORT = 1446;
public static final int HIDDEN_PATH = 1460;
public static final int REMOVE_LEGACY_LINK = 1630;
public static final int SEPOL_REFACTOR = 1640;
Expand All @@ -70,11 +69,11 @@ public static class ID {
public static final int UPDATE_SERVICE_ID = 1;
public static final int FETCH_ZIP = 2;
public static final int SELECT_BOOT = 3;
public static final int ONBOOT_SERVICE_ID = 6;

// notifications
public static final int MAGISK_UPDATE_NOTIFICATION_ID = 4;
public static final int APK_UPDATE_NOTIFICATION_ID = 5;
public static final int ONBOOT_NOTIFICATION_ID = 6;
public static final int DTBO_NOTIFICATION_ID = 7;
public static final String NOTIFICATION_CHANNEL = "magisk_notification";
}
Expand Down
Loading

0 comments on commit 356e99e

Please sign in to comment.