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
676e9c65
Commit
676e9c65
authored
Oct 24, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide upgrade path for stubs
parent
d4598593
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
31 deletions
+44
-31
DownloadService.kt
...va/com/topjohnwu/magisk/model/download/DownloadService.kt
+1
-12
ManagerUpgrade.kt
...ava/com/topjohnwu/magisk/model/download/ManagerUpgrade.kt
+36
-16
RemoteFileService.kt
.../com/topjohnwu/magisk/model/download/RemoteFileService.kt
+1
-1
PatchAPK.kt
app/src/main/java/com/topjohnwu/magisk/utils/PatchAPK.kt
+6
-2
No files found.
app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt
View file @
676e9c65
...
@@ -7,20 +7,17 @@ import android.content.Intent
...
@@ -7,20 +7,17 @@ import android.content.Intent
import
android.os.Build
import
android.os.Build
import
android.webkit.MimeTypeMap
import
android.webkit.MimeTypeMap
import
androidx.core.app.NotificationCompat
import
androidx.core.app.NotificationCompat
import
com.topjohnwu.magisk.ProcessPhoenix
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.extensions.chooser
import
com.topjohnwu.magisk.extensions.chooser
import
com.topjohnwu.magisk.extensions.exists
import
com.topjohnwu.magisk.extensions.exists
import
com.topjohnwu.magisk.extensions.provide
import
com.topjohnwu.magisk.extensions.provide
import
com.topjohnwu.magisk.intent
import
com.topjohnwu.magisk.intent
import
com.topjohnwu.magisk.isRunningAsStub
import
com.topjohnwu.magisk.model.entity.internal.Configuration.*
import
com.topjohnwu.magisk.model.entity.internal.Configuration.*
import
com.topjohnwu.magisk.model.entity.internal.Configuration.Flash.Secondary
import
com.topjohnwu.magisk.model.entity.internal.Configuration.Flash.Secondary
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject.*
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject.*
import
com.topjohnwu.magisk.ui.flash.FlashActivity
import
com.topjohnwu.magisk.ui.flash.FlashActivity
import
com.topjohnwu.magisk.utils.APKInstall
import
com.topjohnwu.magisk.utils.APKInstall
import
com.topjohnwu.magisk.utils.DynAPK
import
org.koin.core.get
import
org.koin.core.get
import
java.io.File
import
java.io.File
import
kotlin.random.Random.Default.nextInt
import
kotlin.random.Random.Default.nextInt
...
@@ -65,15 +62,7 @@ open class DownloadService : RemoteFileService() {
...
@@ -65,15 +62,7 @@ open class DownloadService : RemoteFileService() {
)
{
)
{
remove
(
id
)
remove
(
id
)
when
(
subject
.
configuration
)
{
when
(
subject
.
configuration
)
{
is
APK
.
Upgrade
->
{
is
APK
.
Upgrade
->
APKInstall
.
install
(
this
,
subject
.
file
)
if
(
isRunningAsStub
)
{
subject
.
file
.
copyTo
(
DynAPK
.
update
(
this
),
overwrite
=
true
)
subject
.
file
.
delete
()
ProcessPhoenix
.
triggerRebirth
(
this
)
}
else
{
APKInstall
.
install
(
this
,
subject
.
file
)
}
}
is
APK
.
Restore
->
Unit
is
APK
.
Restore
->
Unit
}
}
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/model/download/ManagerUpgrade.kt
View file @
676e9c65
package
com.topjohnwu.magisk.model.download
package
com.topjohnwu.magisk.model.download
import
com.topjohnwu.magisk.BuildConfig
import
com.topjohnwu.magisk.*
import
com.topjohnwu.magisk.Config
import
com.topjohnwu.magisk.extensions.writeTo
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.isRunningAsStub
import
com.topjohnwu.magisk.model.entity.internal.Configuration.APK.Restore
import
com.topjohnwu.magisk.model.entity.internal.Configuration.APK.Restore
import
com.topjohnwu.magisk.model.entity.internal.Configuration.APK.Upgrade
import
com.topjohnwu.magisk.model.entity.internal.Configuration.APK.Upgrade
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import
com.topjohnwu.magisk.utils.DynAPK
import
com.topjohnwu.magisk.utils.PatchAPK
import
com.topjohnwu.magisk.utils.PatchAPK
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
java.io.File
import
java.io.File
private
fun
RemoteFileService
.
patchPackage
(
apk
:
File
,
id
:
Int
)
{
private
fun
RemoteFileService
.
patch
(
apk
:
File
,
id
:
Int
)
{
if
(!
isRunningAsStub
&&
packageName
!=
BuildConfig
.
APPLICATION_ID
)
{
if
(
packageName
==
BuildConfig
.
APPLICATION_ID
)
update
(
id
)
{
notification
->
return
notification
.
setProgress
(
0
,
0
,
true
)
.
setProgress
(
0
,
0
,
true
)
update
(
id
)
{
notification
->
.
setContentTitle
(
getString
(
R
.
string
.
hide_manager_title
))
notification
.
setProgress
(
0
,
0
,
true
)
.
setContentText
(
""
)
.
setProgress
(
0
,
0
,
true
)
}
.
setContentTitle
(
getString
(
R
.
string
.
hide_manager_title
))
val
patched
=
File
(
apk
.
parent
,
"patched.apk"
)
.
setContentText
(
""
)
PatchAPK
.
patch
(
apk
,
patched
,
packageName
,
applicationInfo
.
nonLocalizedLabel
.
toString
())
}
val
patched
=
File
(
apk
.
parent
,
"patched.apk"
)
PatchAPK
.
patch
(
apk
,
patched
,
packageName
,
applicationInfo
.
nonLocalizedLabel
.
toString
())
apk
.
delete
()
patched
.
renameTo
(
apk
)
}
private
fun
RemoteFileService
.
upgrade
(
apk
:
File
,
id
:
Int
)
{
if
(
isRunningAsStub
)
{
// Move to upgrade location
apk
.
copyTo
(
DynAPK
.
update
(
this
),
overwrite
=
true
)
apk
.
delete
()
apk
.
delete
()
patched
.
renameTo
(
apk
)
if
(
ClassMap
.
data
!!
.
version
<
Info
.
remote
.
stub
.
versionCode
)
{
// We also want to upgrade stub
service
.
fetchFile
(
Info
.
remote
.
stub
.
link
).
blockingGet
().
byteStream
().
use
{
it
.
writeTo
(
apk
)
}
patch
(
apk
,
id
)
}
else
{
// Simply relaunch the app
ProcessPhoenix
.
triggerRebirth
(
this
)
}
}
else
{
patch
(
apk
,
id
)
}
}
}
}
...
@@ -41,6 +61,6 @@ private fun RemoteFileService.restore(apk: File, id: Int) {
...
@@ -41,6 +61,6 @@ private fun RemoteFileService.restore(apk: File, id: Int) {
fun
RemoteFileService
.
handleAPK
(
subject
:
DownloadSubject
.
Manager
)
fun
RemoteFileService
.
handleAPK
(
subject
:
DownloadSubject
.
Manager
)
=
when
(
subject
.
configuration
)
{
=
when
(
subject
.
configuration
)
{
is
Upgrade
->
patchPackag
e
(
subject
.
file
,
subject
.
hashCode
())
is
Upgrade
->
upgrad
e
(
subject
.
file
,
subject
.
hashCode
())
is
Restore
->
restore
(
subject
.
file
,
subject
.
hashCode
())
is
Restore
->
restore
(
subject
.
file
,
subject
.
hashCode
())
}
}
app/src/main/java/com/topjohnwu/magisk/model/download/RemoteFileService.kt
View file @
676e9c65
...
@@ -22,7 +22,7 @@ import java.io.InputStream
...
@@ -22,7 +22,7 @@ import java.io.InputStream
abstract
class
RemoteFileService
:
NotificationService
()
{
abstract
class
RemoteFileService
:
NotificationService
()
{
private
val
service
:
GithubRawServices
by
inject
()
val
service
:
GithubRawServices
by
inject
()
override
val
defaultNotification
:
NotificationCompat
.
Builder
override
val
defaultNotification
:
NotificationCompat
.
Builder
get
()
=
Notifications
.
progress
(
this
,
""
)
get
()
=
Notifications
.
progress
(
this
,
""
)
...
...
app/src/main/java/com/topjohnwu/magisk/utils/PatchAPK.kt
View file @
676e9c65
...
@@ -138,6 +138,11 @@ object PatchAPK {
...
@@ -138,6 +138,11 @@ object PatchAPK {
fun
patch
(
apk
:
File
,
out
:
File
,
pkg
:
String
,
label
:
String
):
Boolean
{
fun
patch
(
apk
:
File
,
out
:
File
,
pkg
:
String
,
label
:
String
):
Boolean
{
try
{
try
{
if
(
apk
.
length
()
<
1
shl
18
)
{
// APK is smaller than 256K, must be stub
return
patch
(
apk
.
path
,
out
.
path
,
pkg
,
label
)
}
// Try using the new APK to patch itself
// Try using the new APK to patch itself
val
loader
=
DynamicClassLoader
(
apk
)
val
loader
=
DynamicClassLoader
(
apk
)
val
cls
=
loader
.
loadClass
(
"a.a"
)
val
cls
=
loader
.
loadClass
(
"a.a"
)
...
@@ -152,9 +157,8 @@ object PatchAPK {
...
@@ -152,9 +157,8 @@ object PatchAPK {
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
Timber
.
e
(
e
)
Timber
.
e
(
e
)
// Fallback to use the current implementation
// Fallback to use the current implementation
patch
(
apk
.
path
,
out
.
path
,
pkg
,
label
)
return
patch
(
apk
.
path
,
out
.
path
,
pkg
,
label
)
}
}
return
false
}
}
fun
hideManager
(
context
:
Context
,
label
:
String
)
{
fun
hideManager
(
context
:
Context
,
label
:
String
)
{
...
...
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