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
55aaa421
Commit
55aaa421
authored
Jul 23, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Directly download to target location
parent
a8932706
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
46 deletions
+34
-46
DownloadService.kt
...va/com/topjohnwu/magisk/model/download/DownloadService.kt
+5
-36
RemoteFileService.kt
.../com/topjohnwu/magisk/model/download/RemoteFileService.kt
+3
-4
DownloadSubject.kt
...topjohnwu/magisk/model/entity/internal/DownloadSubject.kt
+26
-6
No files found.
app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt
View file @
55aaa421
...
...
@@ -6,13 +6,10 @@ import android.app.PendingIntent
import
android.content.Context
import
android.content.Intent
import
android.os.Build
import
android.os.Environment
import
android.webkit.MimeTypeMap
import
android.widget.Toast
import
androidx.annotation.RequiresPermission
import
androidx.core.app.NotificationCompat
import
com.topjohnwu.magisk.ClassMap
import
com.topjohnwu.magisk.Config
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.model.entity.internal.Configuration.*
import
com.topjohnwu.magisk.model.entity.internal.Configuration.Flash.Secondary
...
...
@@ -20,7 +17,6 @@ import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Magisk
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Module
import
com.topjohnwu.magisk.ui.flash.FlashActivity
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.chooser
import
com.topjohnwu.magisk.utils.provide
import
java.io.File
...
...
@@ -31,7 +27,6 @@ import kotlin.random.Random.Default.nextInt
open
class
DownloadService
:
RemoteFileService
()
{
private
val
context
get
()
=
this
private
val
String
.
downloadsFile
get
()
=
File
(
Config
.
downloadDirectory
,
this
)
private
val
File
.
type
get
()
=
MimeTypeMap
.
getSingleton
()
.
getMimeTypeFromExtension
(
extension
)
...
...
@@ -46,17 +41,16 @@ open class DownloadService : RemoteFileService() {
file
:
File
,
subject
:
Magisk
)
=
when
(
val
conf
=
subject
.
configuration
)
{
Download
->
moveToDownloads
(
file
)
Uninstall
->
FlashActivity
.
uninstall
(
this
,
file
)
is
Patch
->
FlashActivity
.
patch
(
this
,
file
,
conf
.
fileUri
)
is
Flash
->
FlashActivity
.
flash
(
this
,
file
,
conf
is
Secondary
)
else
->
Unit
}
private
fun
onFinishedInternal
(
file
:
File
,
subject
:
Module
)
=
when
(
subject
.
configuration
)
{
Download
->
moveToDownloads
(
file
)
is
Flash
->
FlashActivity
.
install
(
this
,
file
)
else
->
Unit
}
...
...
@@ -75,8 +69,8 @@ open class DownloadService : RemoteFileService() {
file
:
File
,
subject
:
Magisk
)
=
when
(
val
conf
=
subject
.
configuration
)
{
Download
->
addAction
(
0
,
R
.
string
.
download_open_parent
,
file
ParentIntent
(
subject
.
fileName
))
.
addAction
(
0
,
R
.
string
.
download_open_self
,
fileIntent
(
subject
.
file
Name
))
Download
->
addAction
(
0
,
R
.
string
.
download_open_parent
,
file
Intent
(
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
))
...
...
@@ -87,8 +81,8 @@ open class DownloadService : RemoteFileService() {
file
:
File
,
subject
:
Module
)
=
when
(
subject
.
configuration
)
{
Download
->
addAction
(
0
,
R
.
string
.
download_open_parent
,
file
ParentIntent
(
subject
.
fileName
))
.
addAction
(
0
,
R
.
string
.
download_open_self
,
fileIntent
(
subject
.
file
Name
))
Download
->
addAction
(
0
,
R
.
string
.
download_open_parent
,
file
Intent
(
subject
.
file
.
parentFile
!!
))
.
addAction
(
0
,
R
.
string
.
download_open_self
,
fileIntent
(
subject
.
file
))
is
Flash
->
setContentIntent
(
FlashActivity
.
installIntent
(
context
,
file
))
else
->
this
}
...
...
@@ -105,31 +99,6 @@ open class DownloadService : RemoteFileService() {
// ---
private
fun
moveToDownloads
(
file
:
File
)
{
val
destination
=
file
.
name
.
downloadsFile
if
(
file
!=
destination
)
{
destination
.
deleteRecursively
()
file
.
copyTo
(
destination
)
}
Utils
.
toast
(
getString
(
R
.
string
.
internal_storage
,
"/"
+
destination
.
toRelativeString
(
Environment
.
getExternalStorageDirectory
())
),
Toast
.
LENGTH_LONG
)
}
private
fun
fileIntent
(
fileName
:
String
):
Intent
{
return
fileIntent
(
fileName
.
downloadsFile
)
}
private
fun
fileParentIntent
(
fileName
:
String
):
Intent
{
return
fileIntent
(
fileName
.
downloadsFile
.
parentFile
!!
)
}
private
fun
fileIntent
(
file
:
File
):
Intent
{
return
Intent
(
Intent
.
ACTION_VIEW
)
.
setDataAndType
(
file
.
provide
(
this
),
file
.
type
)
...
...
app/src/main/java/com/topjohnwu/magisk/model/download/RemoteFileService.kt
View file @
55aaa421
...
...
@@ -11,7 +11,6 @@ import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Magisk
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Module
import
com.topjohnwu.magisk.utils.ProgInputStream
import
com.topjohnwu.magisk.utils.cachedFile
import
com.topjohnwu.magisk.utils.firstMap
import
com.topjohnwu.magisk.utils.writeTo
import
com.topjohnwu.magisk.view.Notifications
...
...
@@ -48,7 +47,7 @@ abstract class RemoteFileService : NotificationService() {
private
fun
start
(
subject
:
DownloadSubject
)
=
search
(
subject
)
.
onErrorResumeNext
(
download
(
subject
))
.
doOnSubscribe
{
update
(
subject
.
hashCode
())
{
it
.
setContentTitle
(
subject
.
fileNam
e
)
}
}
.
doOnSubscribe
{
update
(
subject
.
hashCode
())
{
it
.
setContentTitle
(
subject
.
titl
e
)
}
}
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
doOnSuccess
{
runCatching
{
onFinished
(
it
,
subject
)
}.
onFailure
{
Timber
.
e
(
it
)
}
...
...
@@ -60,7 +59,7 @@ abstract class RemoteFileService : NotificationService() {
throw
IllegalStateException
(
"The download cache is disabled"
)
}
supportedFolders
.
firstMap
{
it
.
find
(
subject
.
file
N
ame
)
}.
also
{
supportedFolders
.
firstMap
{
it
.
find
(
subject
.
file
.
n
ame
)
}.
also
{
if
(
subject
is
Magisk
)
{
if
(!
ShellUtils
.
checkSum
(
"MD5"
,
it
,
subject
.
magisk
.
hash
))
{
throw
IllegalStateException
(
"The given file doesn't match the hash"
)
...
...
@@ -72,7 +71,7 @@ abstract class RemoteFileService : NotificationService() {
private
fun
download
(
subject
:
DownloadSubject
)
=
repo
.
downloadFile
(
subject
.
url
)
.
map
{
it
.
toStream
(
subject
.
hashCode
())
}
.
map
{
cachedFile
(
subject
.
fileName
)
.
apply
{
subject
.
file
.
apply
{
when
(
subject
)
{
is
Module
->
it
.
toModule
(
this
,
repo
.
downloadFile
(
Const
.
Url
.
MODULE_INSTALLER
).
blockingGet
().
byteStream
())
...
...
app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt
View file @
55aaa421
package
com.topjohnwu.magisk.model.entity.internal
import
android.content.Context
import
android.os.Parcelable
import
com.topjohnwu.magisk.Config
import
com.topjohnwu.magisk.Info
import
com.topjohnwu.magisk.model.entity.MagiskJson
import
com.topjohnwu.magisk.model.entity.Repo
import
com.topjohnwu.magisk.utils.cachedFile
import
com.topjohnwu.magisk.utils.get
import
kotlinx.android.parcel.IgnoredOnParcel
import
kotlinx.android.parcel.Parcelize
import
java.io.File
sealed
class
DownloadSubject
:
Parcelable
{
abstract
val
fileName
:
String
abstract
val
url
:
String
abstract
val
file
:
File
open
val
title
:
String
get
()
=
file
.
name
@Parcelize
data class
Module
(
...
...
@@ -17,7 +24,11 @@ sealed class DownloadSubject : Parcelable {
val
configuration
:
Configuration
)
:
DownloadSubject
()
{
override
val
url
:
String
get
()
=
module
.
zipUrl
override
val
fileName
:
String
get
()
=
"${module.name}-v${module.version}(${module.versionCode}).zip"
@IgnoredOnParcel
override
val
file
by
lazy
{
File
(
Config
.
downloadDirectory
,
"${module.name}-v${module.version}(${module.versionCode}).zip"
)
}
}
sealed
class
Magisk
:
DownloadSubject
()
{
...
...
@@ -30,19 +41,28 @@ sealed class DownloadSubject : Parcelable {
override
val
configuration
:
Configuration
)
:
Magisk
()
{
override
val
url
:
String
get
()
=
magisk
.
link
override
val
fileName
get
()
=
"magisk.zip"
override
val
title
:
String
get
()
=
"Magisk-v${magisk.version}(${magisk.versionCode})"
@IgnoredOnParcel
override
val
file
by
lazy
{
get
<
Context
>().
cachedFile
(
"magisk.zip"
)
}
}
@Parcelize
protected
object
Download
:
Magisk
()
{
protected
class
Download
:
Magisk
()
{
override
val
configuration
:
Configuration
get
()
=
Configuration
.
Download
override
val
url
:
String
get
()
=
magisk
.
link
override
val
fileName
get
()
=
"Magisk-v${magisk.version}(${magisk.versionCode}).zip"
@IgnoredOnParcel
override
val
file
by
lazy
{
File
(
Config
.
downloadDirectory
,
"Magisk-v${magisk.version}(${magisk.versionCode}).zip"
)
}
}
companion
object
{
operator
fun
invoke
(
configuration
:
Configuration
)
=
when
(
configuration
)
{
Configuration
.
Download
->
Download
Configuration
.
Download
->
Download
()
else
->
Flash
(
configuration
)
}
}
...
...
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