Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
c1fc3f37
Commit
c1fc3f37
authored
Feb 02, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proper app relaunch for stub
parent
f4cf5dc0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
26 deletions
+68
-26
PhoenixActivity.java
...d/src/main/java/com/topjohnwu/magisk/PhoenixActivity.java
+37
-0
ManagerHandler.kt
...java/com/topjohnwu/magisk/core/download/ManagerHandler.kt
+3
-16
Codegen.kt
buildSrc/src/main/java/Codegen.kt
+19
-5
ClassLoaders.java
stub/src/main/java/com/topjohnwu/magisk/ClassLoaders.java
+7
-1
DownloadActivity.java
.../src/main/java/com/topjohnwu/magisk/DownloadActivity.java
+2
-4
No files found.
app/shared/src/main/java/com/topjohnwu/magisk/PhoenixActivity.java
0 → 100644
View file @
c1fc3f37
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
);
}
}
app/src/main/java/com/topjohnwu/magisk/core/download/ManagerHandler.kt
View file @
c1fc3f37
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
())
...
...
buildSrc/src/main/java/Codegen.kt
View file @
c1fc3f37
...
...
@@ -77,7 +77,8 @@ fun genStubManifest(srcDir: File, outDir: File): String {
class
Component
(
val
real
:
String
,
val
stub
:
String
,
val
xml
:
String
val
xml
:
String
,
val
genClass
:
Boolean
=
false
)
outDir
.
deleteRecursively
()
...
...
@@ -92,13 +93,26 @@ fun genStubManifest(srcDir: File, outDir: File): String {
cmpList
.
add
(
Component
(
"androidx.core.app.CoreComponentFactory"
,
"DelegateComponentFactory"
,
""
""
,
true
))
cmpList
.
add
(
Component
(
"com.topjohnwu.magisk.core.App"
,
"DelegateApplication"
,
""
""
,
true
))
cmpList
.
add
(
Component
(
"PHOENIX"
,
"PhoenixActivity"
,
"""
|<activity
| android:name="%s"
| android:process=":%s"
| android:exported="false" />"""
.
ind
(
2
),
true
))
cmpList
.
add
(
Component
(
...
...
@@ -236,12 +250,12 @@ fun genStubManifest(srcDir: File, outDir: File): String {
maps
.
append
(
"|internalMap.put(\"$name\", com.topjohnwu.magisk.${gen.stub}.class);"
.
ind
(
2
))
maps
.
append
(
'\n'
)
}
if
(
gen
.
stub
.
startsWith
(
"Delegate"
)
)
{
if
(
gen
.
genClass
)
{
genClass
(
name
,
gen
.
stub
)
}
}
if
(
gen
.
xml
.
isNotEmpty
())
{
cmps
.
add
(
gen
.
xml
.
format
(
name
))
cmps
.
add
(
gen
.
xml
.
format
(
name
,
names
.
random
(
kRANDOM
)
))
}
}
...
...
stub/src/main/java/com/topjohnwu/magisk/ClassLoaders.java
View file @
c1fc3f37
...
...
@@ -8,13 +8,19 @@ import java.io.File;
// mapping when loading from platform (via LoadedApk.mClassLoader)
class
InjectedClassLoader
extends
ClassLoader
{
private
static
final
String
PKEY
=
"PHOENIX"
;
static
final
String
PHOENIX
=
Mapping
.
inverseMap
.
get
(
PKEY
);
InjectedClassLoader
(
File
apk
)
{
super
(
new
DynamicClassLoader
(
apk
));
}
@Override
protected
Class
<?>
loadClass
(
String
name
,
boolean
resolve
)
throws
ClassNotFoundException
{
return
super
.
loadClass
(
Mapping
.
get
(
name
),
resolve
);
String
n
=
Mapping
.
get
(
name
);
if
(
n
.
equals
(
PKEY
))
return
PhoenixActivity
.
class
;
return
super
.
loadClass
(
n
,
resolve
);
}
}
...
...
stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java
View file @
c1fc3f37
...
...
@@ -5,7 +5,6 @@ import static android.R.string.ok;
import
static
android
.
R
.
string
.
yes
;
import
static
com
.
topjohnwu
.
magisk
.
R
.
string
.
dling
;
import
static
com
.
topjohnwu
.
magisk
.
R
.
string
.
no_internet_msg
;
import
static
com
.
topjohnwu
.
magisk
.
R
.
string
.
relaunch_app
;
import
static
com
.
topjohnwu
.
magisk
.
R
.
string
.
upgrade_msg
;
import
android.app.Activity
;
...
...
@@ -17,7 +16,6 @@ import android.os.AsyncTask;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.ContextThemeWrapper
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.net.Networking
;
import
com.topjohnwu.magisk.net.Request
;
...
...
@@ -111,14 +109,14 @@ public class DownloadActivity extends Activity {
dialog
=
ProgressDialog
.
show
(
themed
,
getString
(
dling
),
getString
(
dling
)
+
" "
+
APP_NAME
,
true
);
Runnable
onSuccess
=
()
->
{
dialog
.
dismiss
();
Toast
.
makeText
(
themed
,
relaunch_app
,
Toast
.
LENGTH_LONG
).
show
(
);
PhoenixActivity
.
rebirth
(
this
,
InjectedClassLoader
.
PHOENIX
);
finish
();
};
// Download and upgrade the app
File
apk
=
dynLoad
?
StubApk
.
current
(
this
)
:
new
File
(
getCacheDir
(),
"manager.apk"
);
request
(
apkLink
).
setExecutor
(
AsyncTask
.
THREAD_POOL_EXECUTOR
).
getAsFile
(
apk
,
file
->
{
if
(
dynLoad
)
{
// TODO
runOnUiThread
(
onSuccess
);
}
else
{
var
receiver
=
APKInstall
.
register
(
this
,
BuildConfig
.
APPLICATION_ID
,
onSuccess
);
APKInstall
.
installapk
(
this
,
file
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment