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
6d037983
Commit
6d037983
authored
Oct 20, 2019
by
Viktor De Pasquale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added internal download pseudo broadcasts
parent
c954a4f7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
12 deletions
+26
-12
ApplicationModule.kt
...rc/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt
+2
-0
RemoteFileService.kt
.../com/topjohnwu/magisk/model/download/RemoteFileService.kt
+21
-9
DownloadSubject.kt
...topjohnwu/magisk/model/entity/internal/DownloadSubject.kt
+3
-3
No files found.
app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt
View file @
6d037983
...
...
@@ -6,6 +6,7 @@ import android.app.Application
import
android.content.Context
import
android.os.Build
import
android.os.Bundle
import
androidx.localbroadcastmanager.content.LocalBroadcastManager
import
androidx.preference.PreferenceManager
import
com.topjohnwu.magisk.utils.RxBus
import
org.koin.core.qualifier.named
...
...
@@ -23,6 +24,7 @@ val applicationModule = module {
single
{
PreferenceManager
.
getDefaultSharedPreferences
(
get
<
Context
>(
Protected
))
}
single
{
ActivityTracker
()
}
factory
{
get
<
ActivityTracker
>().
foreground
?:
NullActivity
}
single
{
LocalBroadcastManager
.
getInstance
(
get
())
}
}
private
fun
createDEContext
(
context
:
Context
):
Context
{
...
...
app/src/main/java/com/topjohnwu/magisk/model/download/RemoteFileService.kt
View file @
6d037983
...
...
@@ -3,6 +3,8 @@ package com.topjohnwu.magisk.model.download
import
android.app.Activity
import
android.content.Intent
import
androidx.core.app.NotificationCompat
import
androidx.lifecycle.LiveData
import
androidx.lifecycle.MutableLiveData
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.data.network.GithubRawServices
import
com.topjohnwu.magisk.di.NullActivity
...
...
@@ -17,6 +19,7 @@ import com.topjohnwu.superuser.ShellUtils
import
io.reactivex.Completable
import
okhttp3.ResponseBody
import
org.koin.android.ext.android.inject
import
org.koin.core.KoinComponent
import
timber.log.Timber
import
java.io.InputStream
...
...
@@ -41,8 +44,8 @@ abstract class RemoteFileService : NotificationService() {
Timber
.
e
(
it
)
finishNotify
(
subject
.
hashCode
())
{
notification
->
notification
.
setContentText
(
getString
(
R
.
string
.
download_file_error
))
.
setSmallIcon
(
android
.
R
.
drawable
.
stat_notify_error
)
.
setOngoing
(
false
)
.
setSmallIcon
(
android
.
R
.
drawable
.
stat_notify_error
)
.
setOngoing
(
false
)
}
})
{
val
newId
=
finishNotify
(
subject
)
...
...
@@ -62,12 +65,12 @@ abstract class RemoteFileService : NotificationService() {
}
private
fun
download
(
subject
:
DownloadSubject
)
=
service
.
fetchFile
(
subject
.
url
)
.
map
{
it
.
toStream
(
subject
.
hashCode
())
}
.
map
{
it
.
toStream
(
subject
.
hashCode
()
,
subject
)
}
.
flatMapCompletable
{
stream
->
when
(
subject
)
{
is
Module
->
service
.
fetchInstaller
()
.
doOnSuccess
{
stream
.
toModule
(
subject
.
file
,
it
.
byteStream
())
}
.
ignoreElement
()
.
doOnSuccess
{
stream
.
toModule
(
subject
.
file
,
it
.
byteStream
())
}
.
ignoreElement
()
else
->
Completable
.
fromAction
{
stream
.
writeTo
(
subject
.
file
)
}
}
}.
doOnComplete
{
...
...
@@ -75,7 +78,7 @@ abstract class RemoteFileService : NotificationService() {
handleAPK
(
subject
)
}
private
fun
ResponseBody
.
toStream
(
id
:
Int
):
InputStream
{
private
fun
ResponseBody
.
toStream
(
id
:
Int
,
subject
:
DownloadSubject
):
InputStream
{
val
maxRaw
=
contentLength
()
val
max
=
maxRaw
/
1
_000_000f
...
...
@@ -83,9 +86,10 @@ abstract class RemoteFileService : NotificationService() {
val
progress
=
it
/
1
_000_000f
update
(
id
)
{
notification
->
if
(
maxRaw
>
0
)
{
send
(
progress
/
max
,
subject
)
notification
.
setProgress
(
maxRaw
.
toInt
(),
it
.
toInt
(),
false
)
.
setContentText
(
"%.2f / %.2f MB"
.
format
(
progress
,
max
))
.
setProgress
(
maxRaw
.
toInt
(),
it
.
toInt
(),
false
)
.
setContentText
(
"%.2f / %.2f MB"
.
format
(
progress
,
max
))
}
else
{
notification
.
setContentText
(
"%.2f MB / ??"
.
format
(
progress
))
}
...
...
@@ -94,6 +98,7 @@ abstract class RemoteFileService : NotificationService() {
}
private
fun
finishNotify
(
subject
:
DownloadSubject
)
=
finishNotify
(
subject
.
hashCode
())
{
send
(
1f
,
subject
)
it
.
addActions
(
subject
)
.
setContentText
(
getString
(
R
.
string
.
download_complete
))
.
setSmallIcon
(
android
.
R
.
drawable
.
stat_sys_download_done
)
...
...
@@ -111,8 +116,15 @@ abstract class RemoteFileService : NotificationService() {
protected
abstract
fun
NotificationCompat
.
Builder
.
addActions
(
subject
:
DownloadSubject
)
:
NotificationCompat
.
Builder
companion
object
{
companion
object
:
KoinComponent
{
const
val
ARG_URL
=
"arg_url"
private
val
internalProgressBroadcast
=
MutableLiveData
<
Pair
<
Float
,
DownloadSubject
>>()
val
progressBroadcast
:
LiveData
<
Pair
<
Float
,
DownloadSubject
>>
get
()
=
internalProgressBroadcast
fun
send
(
progress
:
Float
,
subject
:
DownloadSubject
)
{
internalProgressBroadcast
.
postValue
(
progress
to
subject
)
}
}
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt
View file @
6d037983
...
...
@@ -59,7 +59,7 @@ sealed class DownloadSubject : Parcelable {
val
magisk
:
MagiskJson
=
Info
.
remote
.
magisk
@Parcelize
protected
data class
Flash
(
data class
Flash
(
override
val
configuration
:
Configuration
)
:
Magisk
()
{
override
val
url
:
String
get
()
=
magisk
.
link
...
...
@@ -72,7 +72,7 @@ sealed class DownloadSubject : Parcelable {
}
@Parcelize
protected
class
Uninstall
:
Magisk
()
{
class
Uninstall
:
Magisk
()
{
override
val
configuration
:
Configuration
get
()
=
Configuration
.
Uninstall
override
val
url
:
String
get
()
=
Info
.
remote
.
uninstaller
.
link
...
...
@@ -83,7 +83,7 @@ sealed class DownloadSubject : Parcelable {
}
@Parcelize
protected
class
Download
:
Magisk
()
{
class
Download
:
Magisk
()
{
override
val
configuration
:
Configuration
get
()
=
Configuration
.
Download
override
val
url
:
String
get
()
=
magisk
.
link
...
...
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