92 lines
3.8 KiB
Java
Raw Normal View History

2018-12-02 16:53:00 -05:00
package com.topjohnwu.magisk.receivers;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
2018-12-29 14:14:29 +08:00
import android.os.AsyncTask;
2018-12-02 16:53:00 -05:00
2019-01-30 03:10:12 -05:00
import com.topjohnwu.magisk.App;
import com.topjohnwu.magisk.ClassMap;
2019-01-30 03:10:12 -05:00
import com.topjohnwu.magisk.Config;
import com.topjohnwu.magisk.Const;
2018-12-02 16:53:00 -05:00
import com.topjohnwu.magisk.SuRequestActivity;
2018-12-29 14:14:29 +08:00
import com.topjohnwu.magisk.components.Notifications;
2019-01-30 17:54:25 -05:00
import com.topjohnwu.magisk.components.Shortcuts;
import com.topjohnwu.magisk.utils.DownloadApp;
2018-12-02 16:53:00 -05:00
import com.topjohnwu.magisk.utils.SuConnector;
import com.topjohnwu.superuser.Shell;
2018-12-29 14:14:29 +08:00
import com.topjohnwu.superuser.ShellUtils;
2018-12-02 16:53:00 -05:00
public class GeneralReceiver extends BroadcastReceiver {
private String getPkg(Intent i) {
return i.getData() == null ? "" : i.getData().getEncodedSchemeSpecificPart();
}
@Override
public void onReceive(Context context, Intent intent) {
App app = App.self;
2018-12-02 16:53:00 -05:00
if (intent == null)
return;
String action = intent.getAction();
if (action == null)
return;
switch (action) {
case Intent.ACTION_BOOT_COMPLETED:
String bootAction = intent.getStringExtra("action");
if (bootAction == null)
bootAction = "boot";
switch (bootAction) {
case "request":
Intent i = new Intent(app, ClassMap.get(SuRequestActivity.class))
2018-12-02 16:53:00 -05:00
.putExtra("socket", intent.getStringExtra("socket"))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
app.startActivity(i);
2018-12-02 16:53:00 -05:00
break;
case "log":
SuConnector.handleLogs(intent);
2018-12-02 16:53:00 -05:00
break;
case "notify":
SuConnector.handleNotify(intent);
break;
case "boot":
default:
2018-12-29 14:14:29 +08:00
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
/* 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.
* */
if (Shell.rootAccess() && ShellUtils.fastCmdResult("mm_patch_dtbo"))
Notifications.dtboPatched();
});
2018-12-02 16:53:00 -05:00
break;
}
break;
case Intent.ACTION_PACKAGE_REPLACED:
// This will only work pre-O
2019-01-21 15:49:03 -05:00
if (Config.get(Config.Key.SU_REAUTH)) {
app.mDB.deletePolicy(getPkg(intent));
2018-12-02 16:53:00 -05:00
}
break;
case Intent.ACTION_PACKAGE_FULLY_REMOVED:
String pkg = getPkg(intent);
app.mDB.deletePolicy(pkg);
2018-12-02 16:53:00 -05:00
Shell.su("magiskhide --rm " + pkg).submit();
break;
2019-01-30 17:54:25 -05:00
case Intent.ACTION_LOCALE_CHANGED:
Shortcuts.setup(context);
break;
2018-12-02 16:53:00 -05:00
case Const.Key.BROADCAST_MANAGER_UPDATE:
2019-01-21 15:49:03 -05:00
Config.managerLink = intent.getStringExtra(Const.Key.INTENT_SET_LINK);
DownloadApp.upgrade(intent.getStringExtra(Const.Key.INTENT_SET_NAME));
2018-12-02 16:53:00 -05:00
break;
case Const.Key.BROADCAST_REBOOT:
Shell.su("/system/bin/reboot").submit();
break;
}
}
}