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
a6126c5e
Commit
a6126c5e
authored
Aug 22, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cosmetic changes
parent
85d9bd91
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
67 deletions
+55
-67
DownloadService.kt
...va/com/topjohnwu/magisk/model/download/DownloadService.kt
+25
-36
ManagerUpgrade.kt
...ava/com/topjohnwu/magisk/model/download/ManagerUpgrade.kt
+3
-3
RemoteFileService.kt
.../com/topjohnwu/magisk/model/download/RemoteFileService.kt
+27
-28
No files found.
app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt
View file @
a6126c5e
...
...
@@ -30,82 +30,71 @@ open class DownloadService : RemoteFileService() {
.
getMimeTypeFromExtension
(
extension
)
?:
"resource/folder"
override
fun
onFinished
(
file
:
File
,
subject
:
DownloadSubject
,
id
:
Int
)
=
when
(
subject
)
{
is
Magisk
->
onFinishedInternal
(
file
,
subject
,
id
)
is
Module
->
onFinishedInternal
(
file
,
subject
,
id
)
is
Manager
->
onFinishedInternal
(
file
,
subject
,
id
)
override
fun
onFinished
(
subject
:
DownloadSubject
,
id
:
Int
)
=
when
(
subject
)
{
is
Magisk
->
onFinishedInternal
(
subject
,
id
)
is
Module
->
onFinishedInternal
(
subject
,
id
)
is
Manager
->
onFinishedInternal
(
subject
,
id
)
}
private
fun
onFinishedInternal
(
file
:
File
,
subject
:
Magisk
,
id
:
Int
)
=
when
(
val
conf
=
subject
.
configuration
)
{
Uninstall
->
FlashActivity
.
uninstall
(
this
,
file
,
id
)
is
Patch
->
FlashActivity
.
patch
(
this
,
file
,
conf
.
fileUri
,
id
)
is
Flash
->
FlashActivity
.
flash
(
this
,
file
,
conf
is
Secondary
,
id
)
Uninstall
->
FlashActivity
.
uninstall
(
this
,
subject
.
file
,
id
)
is
Patch
->
FlashActivity
.
patch
(
this
,
subject
.
file
,
conf
.
fileUri
,
id
)
is
Flash
->
FlashActivity
.
flash
(
this
,
subject
.
file
,
conf
is
Secondary
,
id
)
else
->
Unit
}
private
fun
onFinishedInternal
(
file
:
File
,
subject
:
Module
,
id
:
Int
)
=
when
(
subject
.
configuration
)
{
is
Flash
->
FlashActivity
.
install
(
this
,
file
,
id
)
is
Flash
->
FlashActivity
.
install
(
this
,
subject
.
file
,
id
)
else
->
Unit
}
private
fun
onFinishedInternal
(
file
:
File
,
subject
:
Manager
,
id
:
Int
)
{
remove
(
id
)
when
(
subject
.
configuration
)
{
is
APK
.
Upgrade
->
APKInstall
.
install
(
this
,
file
)
is
APK
.
Upgrade
->
APKInstall
.
install
(
this
,
subject
.
file
)
else
->
Unit
}
}
// ---
override
fun
NotificationCompat
.
Builder
.
addActions
(
file
:
File
,
subject
:
DownloadSubject
)
=
when
(
subject
)
{
is
Magisk
->
addActionsInternal
(
file
,
subject
)
is
Module
->
addActionsInternal
(
file
,
subject
)
is
Manager
->
addActionsInternal
(
file
,
subject
)
override
fun
NotificationCompat
.
Builder
.
addActions
(
subject
:
DownloadSubject
)
=
when
(
subject
)
{
is
Magisk
->
addActionsInternal
(
subject
)
is
Module
->
addActionsInternal
(
subject
)
is
Manager
->
addActionsInternal
(
subject
)
}
private
fun
NotificationCompat
.
Builder
.
addActionsInternal
(
file
:
File
,
subject
:
Magisk
)
=
when
(
val
conf
=
subject
.
configuration
)
{
private
fun
NotificationCompat
.
Builder
.
addActionsInternal
(
subject
:
Magisk
)
=
when
(
val
conf
=
subject
.
configuration
)
{
Download
->
addAction
(
0
,
R
.
string
.
download_open_parent
,
fileIntent
(
subject
.
file
.
parentFile
!!
))
.
addAction
(
0
,
R
.
string
.
download_open_self
,
fileIntent
(
subject
.
file
))
Uninstall
->
setContentIntent
(
FlashActivity
.
uninstallIntent
(
context
,
file
))
is
Flash
->
setContentIntent
(
FlashActivity
.
flashIntent
(
context
,
file
,
conf
is
Secondary
))
is
Patch
->
setContentIntent
(
FlashActivity
.
patchIntent
(
context
,
file
,
conf
.
fileUri
))
Uninstall
->
setContentIntent
(
FlashActivity
.
uninstallIntent
(
context
,
subject
.
file
))
is
Flash
->
setContentIntent
(
FlashActivity
.
flashIntent
(
context
,
subject
.
file
,
conf
is
Secondary
))
is
Patch
->
setContentIntent
(
FlashActivity
.
patchIntent
(
context
,
subject
.
file
,
conf
.
fileUri
))
else
->
this
}
private
fun
NotificationCompat
.
Builder
.
addActionsInternal
(
file
:
File
,
subject
:
Module
)
=
when
(
subject
.
configuration
)
{
private
fun
NotificationCompat
.
Builder
.
addActionsInternal
(
subject
:
Module
)
=
when
(
subject
.
configuration
)
{
Download
->
addAction
(
0
,
R
.
string
.
download_open_parent
,
fileIntent
(
subject
.
file
.
parentFile
!!
))
.
addAction
(
0
,
R
.
string
.
download_open_self
,
fileIntent
(
subject
.
file
))
is
Flash
->
setContentIntent
(
FlashActivity
.
installIntent
(
context
,
file
))
is
Flash
->
setContentIntent
(
FlashActivity
.
installIntent
(
context
,
subject
.
file
))
else
->
this
}
private
fun
NotificationCompat
.
Builder
.
addActionsInternal
(
file
:
File
,
subject
:
Manager
)
=
when
(
subject
.
configuration
)
{
APK
.
Upgrade
->
setContentIntent
(
APKInstall
.
installIntent
(
context
,
file
))
private
fun
NotificationCompat
.
Builder
.
addActionsInternal
(
subject
:
Manager
)
=
when
(
subject
.
configuration
)
{
APK
.
Upgrade
->
setContentIntent
(
APKInstall
.
installIntent
(
context
,
subject
.
file
))
else
->
this
}
...
...
app/src/main/java/com/topjohnwu/magisk/model/download/ManagerUpgrade.kt
View file @
a6126c5e
...
...
@@ -60,8 +60,8 @@ private fun RemoteFileService.restore(apk: File, id: Int): File {
return
apk
}
fun
RemoteFileService
.
handleAPK
(
apk
:
File
,
subject
:
DownloadSubject
.
Manager
)
fun
RemoteFileService
.
handleAPK
(
subject
:
DownloadSubject
.
Manager
)
=
when
(
subject
.
configuration
)
{
is
Upgrade
->
patchPackage
(
apk
,
subject
.
hashCode
())
is
Restore
->
restore
(
apk
,
subject
.
hashCode
())
is
Upgrade
->
patchPackage
(
subject
.
file
,
subject
.
hashCode
())
is
Restore
->
restore
(
subject
.
file
,
subject
.
hashCode
())
}
app/src/main/java/com/topjohnwu/magisk/model/download/RemoteFileService.kt
View file @
a6126c5e
...
...
@@ -16,7 +16,7 @@ import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.*
import
com.topjohnwu.magisk.utils.ProgressInputStream
import
com.topjohnwu.magisk.view.Notifications
import
com.topjohnwu.superuser.ShellUtils
import
io.reactivex.
Sing
le
import
io.reactivex.
Completab
le
import
okhttp3.ResponseBody
import
org.koin.android.ext.android.inject
import
timber.log.Timber
...
...
@@ -34,9 +34,7 @@ abstract class RemoteFileService : NotificationService() {
)
override
val
defaultNotification
:
NotificationCompat
.
Builder
get
()
=
Notifications
.
progress
(
this
,
""
)
.
setContentText
(
getString
(
R
.
string
.
download_local
))
get
()
=
Notifications
.
progress
(
this
,
""
)
override
fun
onStartCommand
(
intent
:
Intent
?,
flags
:
Int
,
startId
:
Int
):
Int
{
intent
?.
getParcelableExtra
<
DownloadSubject
>(
ARG_URL
)
?.
let
{
start
(
it
)
}
...
...
@@ -46,7 +44,7 @@ abstract class RemoteFileService : NotificationService() {
// ---
private
fun
start
(
subject
:
DownloadSubject
)
=
search
(
subject
)
.
onErrorResumeNext
(
download
(
subject
))
.
onErrorResumeNext
{
download
(
subject
)
}
.
doOnSubscribe
{
update
(
subject
.
hashCode
())
{
it
.
setContentTitle
(
subject
.
title
)
}
}
.
subscribeK
(
onError
=
{
Timber
.
e
(
it
)
...
...
@@ -56,13 +54,13 @@ abstract class RemoteFileService : NotificationService() {
.
setOngoing
(
false
)
}
})
{
val
newId
=
finishNotify
(
it
,
subject
)
val
newId
=
finishNotify
(
subject
)
if
(
get
<
Activity
>()
!
is
NullActivity
)
{
onFinished
(
it
,
subject
,
newId
)
onFinished
(
subject
,
newId
)
}
}
private
fun
search
(
subject
:
DownloadSubject
)
=
Single
.
fromCallable
{
private
fun
search
(
subject
:
DownloadSubject
)
=
Completable
.
fromAction
{
if
(!
Config
.
isDownloadCacheEnabled
||
subject
is
Manager
)
{
throw
IllegalStateException
(
"The download cache is disabled"
)
}
...
...
@@ -78,23 +76,22 @@ abstract class RemoteFileService : NotificationService() {
private
fun
download
(
subject
:
DownloadSubject
)
=
service
.
fetchFile
(
subject
.
url
)
.
map
{
it
.
toStream
(
subject
.
hashCode
())
}
.
flatMap
{
stream
->
.
flatMap
Completable
{
stream
->
when
(
subject
)
{
is
Module
->
service
.
fetchInstaller
()
.
map
{
stream
.
toModule
(
subject
.
file
,
it
.
byteStream
());
subject
.
file
}
else
->
Single
.
fromCallable
{
stream
.
writeTo
(
subject
.
file
);
subject
.
file
}
}
}.
map
{
when
(
subject
)
{
is
Manager
->
handleAPK
(
it
,
subject
)
else
->
it
.
doOnSuccess
{
stream
.
toModule
(
subject
.
file
,
it
.
byteStream
())
}
.
ignoreElement
()
else
->
Completable
.
fromAction
{
stream
.
writeTo
(
subject
.
file
)
}
}
}.
doOnComplete
{
if
(
subject
is
Manager
)
handleAPK
(
subject
)
}
// ---
private
fun
File
.
find
(
name
:
String
)
=
list
()
.
orEmpty
()
.
firstOrNull
{
it
==
name
}
private
fun
File
.
find
(
name
:
String
)
=
list
()
?
.
firstOrNull
{
it
==
name
}
?.
let
{
File
(
this
,
it
)
}
private
fun
ResponseBody
.
toStream
(
id
:
Int
):
InputStream
{
...
...
@@ -104,15 +101,19 @@ abstract class RemoteFileService : NotificationService() {
return
ProgressInputStream
(
byteStream
())
{
val
progress
=
it
/
1
_000_000f
update
(
id
)
{
notification
->
notification
.
setProgress
(
maxRaw
.
toInt
(),
it
.
toInt
(),
false
)
.
setContentText
(
getString
(
R
.
string
.
download_progress
,
progress
,
max
))
if
(
maxRaw
>
0
)
{
notification
.
setProgress
(
maxRaw
.
toInt
(),
it
.
toInt
(),
false
)
.
setContentText
(
"%.2f / %.2f MB"
.
format
(
progress
,
max
))
}
else
{
notification
.
setContentText
(
"%.2f MB / ??"
.
format
(
progress
))
}
}
}
}
private
fun
finishNotify
(
file
:
File
,
subject
:
DownloadSubject
)
=
finishNotify
(
subject
.
hashCode
())
{
it
.
addActions
(
file
,
subject
)
private
fun
finishNotify
(
subject
:
DownloadSubject
)
=
finishNotify
(
subject
.
hashCode
())
{
it
.
addActions
(
subject
)
.
setContentText
(
getString
(
R
.
string
.
download_complete
))
.
setSmallIcon
(
android
.
R
.
drawable
.
stat_sys_download_done
)
.
setProgress
(
0
,
0
,
false
)
...
...
@@ -124,12 +125,10 @@ abstract class RemoteFileService : NotificationService() {
@Throws
(
Throwable
::
class
)
protected
abstract
fun
onFinished
(
file
:
File
,
subject
:
DownloadSubject
,
id
:
Int
)
protected
abstract
fun
onFinished
(
subject
:
DownloadSubject
,
id
:
Int
)
protected
abstract
fun
NotificationCompat
.
Builder
.
addActions
(
file
:
File
,
subject
:
DownloadSubject
):
NotificationCompat
.
Builder
protected
abstract
fun
NotificationCompat
.
Builder
.
addActions
(
subject
:
DownloadSubject
)
:
NotificationCompat
.
Builder
companion
object
{
const
val
ARG_URL
=
"arg_url"
...
...
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