Migrate to JobIntentService to prevent boot notification

This commit is contained in:
topjohnwu
2018-07-21 02:59:36 +08:00
parent 07140d33a7
commit 6263d684d9
7 changed files with 42 additions and 68 deletions
@@ -1,44 +0,0 @@
package com.topjohnwu.magisk.services;
import android.app.IntentService;
import android.content.Intent;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.RootUtils;
public class OnBootIntentService extends IntentService {
public OnBootIntentService() {
super("OnBootIntentService");
}
@Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForeground(Const.ID.ONBOOT_NOTIFICATION_ID,
new NotificationCompat.Builder(this, Const.ID.NOTIFICATION_CHANNEL)
.setSmallIcon(R.drawable.ic_magisk_outline)
.setContentTitle("Startup Operations")
.setContentText("Running startup operations...")
.build());
}
}
@Override
protected void onHandleIntent(Intent intent) {
/* Pixel 2 (XL) devices will need to patch dtbo.img.
* However, that is not possible if Magisk is installed by
* patching boot image with Magisk Manager and fastboot flash
* the boot image, 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.
* */
MagiskManager.get().loadMagiskInfo();
RootUtils.patchDTBO();
}
}
@@ -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();
}
}