mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-27 08:47:38 +00:00
Fix crash on Android O
This commit is contained in:
parent
1daf5a611c
commit
789fef34ba
@ -70,7 +70,7 @@
|
|||||||
|
|
||||||
<receiver android:name=".receivers.ManagerUpdate" />
|
<receiver android:name=".receivers.ManagerUpdate" />
|
||||||
|
|
||||||
<service android:name=".services.BootupIntentService" />
|
<service android:name=".services.OnBootIntentService" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".services.UpdateCheckService"
|
android:name=".services.UpdateCheckService"
|
||||||
|
@ -3,14 +3,28 @@ package com.topjohnwu.magisk.receivers;
|
|||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.services.BootupIntentService;
|
import com.topjohnwu.magisk.services.OnBootIntentService;
|
||||||
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
public class BootReceiver extends BroadcastReceiver {
|
public class BootReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
private void startIntentService(Context context) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
context.startForegroundService(new Intent(context, OnBootIntentService.class));
|
||||||
|
} else {
|
||||||
|
context.startService(new Intent(context, OnBootIntentService.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
context.startService(new Intent(context, BootupIntentService.class));
|
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
||||||
|
Utils.getMagiskManager(context).initSU();
|
||||||
|
// There is currently no need to start an IntentService onBoot
|
||||||
|
// startIntentService(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.services;
|
|
||||||
|
|
||||||
import android.app.IntentService;
|
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
|
||||||
|
|
||||||
public class BootupIntentService extends IntentService {
|
|
||||||
|
|
||||||
public BootupIntentService() {
|
|
||||||
super("BootupIntentService");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onHandleIntent(Intent intent) {
|
|
||||||
((MagiskManager) getApplication()).initSU();
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.topjohnwu.magisk.services;
|
||||||
|
|
||||||
|
import android.app.IntentService;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.support.v7.app.NotificationCompat;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.R;
|
||||||
|
|
||||||
|
public class OnBootIntentService extends IntentService {
|
||||||
|
|
||||||
|
private static final int ONBOOT_NOTIFICATION_ID = 3;
|
||||||
|
|
||||||
|
public OnBootIntentService() {
|
||||||
|
super("OnBootIntentService");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
super.onCreate();
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
|
||||||
|
builder.setSmallIcon(R.drawable.ic_magisk)
|
||||||
|
.setContentTitle("onBoot")
|
||||||
|
.setContentText("Running onBoot operations...");
|
||||||
|
startForeground(ONBOOT_NOTIFICATION_ID, builder.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onHandleIntent(Intent intent) {
|
||||||
|
// Currently nothing to do
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user