mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-02 21:11:50 +00:00
Proper app relaunch for stub
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
|
||||
import io.michaelrocks.paranoid.Obfuscate;
|
||||
|
||||
// Inspired by https://github.com/JakeWharton/ProcessPhoenix
|
||||
|
||||
@Obfuscate
|
||||
public class PhoenixActivity extends Activity {
|
||||
|
||||
private static final String PID_KEY = "pid";
|
||||
|
||||
public static void rebirth(Context context, String clzName) {
|
||||
var intent = new Intent();
|
||||
intent.setComponent(new ComponentName(context, clzName));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra(PID_KEY, Process.myPid());
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Process.killProcess(getIntent().getIntExtra(PID_KEY, -1));
|
||||
var intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
Runtime.getRuntime().exit(0);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,9 @@
|
||||
package com.topjohnwu.magisk.core.download
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Intent
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.net.toFile
|
||||
import com.topjohnwu.magisk.PhoenixActivity
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.StubApk
|
||||
import com.topjohnwu.magisk.core.ActivityTracker
|
||||
import com.topjohnwu.magisk.core.Info
|
||||
import com.topjohnwu.magisk.core.isRunningAsStub
|
||||
import com.topjohnwu.magisk.core.tasks.HideAPK
|
||||
@@ -59,17 +55,8 @@ suspend fun DownloadService.handleAPK(subject: Subject.Manager, stream: InputStr
|
||||
apk.delete()
|
||||
patched.renameTo(apk)
|
||||
} else {
|
||||
val intent = packageManager.getLaunchIntentForPackage(packageName)
|
||||
intent!!.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
//noinspection InlinedApi
|
||||
val flag = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
||||
val pending = PendingIntent.getActivity(this, id, intent, flag)
|
||||
if (ActivityTracker.hasForeground) {
|
||||
val alarm = getSystemService<AlarmManager>()
|
||||
alarm!!.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, pending)
|
||||
}
|
||||
stopSelf()
|
||||
Runtime.getRuntime().exit(0)
|
||||
val clz = Info.stub!!.classToComponent["PHOENIX"]!!
|
||||
PhoenixActivity.rebirth(this, clz)
|
||||
}
|
||||
} else {
|
||||
write(subject.file.outputStream())
|
||||
|
||||
Reference in New Issue
Block a user