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
fa2dbe98
Commit
fa2dbe98
authored
Oct 20, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle retrofit errors
parent
ce6cceae
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
28 deletions
+48
-28
OnlineModule.kt
...va/com/topjohnwu/magisk/core/model/module/OnlineModule.kt
+6
-5
RepoUpdater.kt
.../main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt
+12
-11
NetworkService.kt
...va/com/topjohnwu/magisk/data/repository/NetworkService.kt
+30
-12
No files found.
app/src/main/java/com/topjohnwu/magisk/core/model/module/OnlineModule.kt
View file @
fa2dbe98
...
...
@@ -44,11 +44,12 @@ data class OnlineModule(
@Throws
(
IllegalRepoException
::
class
)
suspend
fun
load
()
{
val
props
=
svc
.
fetchString
(
prop_url
)
props
.
split
(
"\\n"
.
toRegex
()).
dropLastWhile
{
it
.
isEmpty
()
}.
runCatching
{
parseProps
(
this
)
}.
onFailure
{
throw
IllegalRepoException
(
"Repo [$id] parse error: "
,
it
)
try
{
val
rawProps
=
svc
.
fetchString
(
prop_url
)
val
props
=
rawProps
.
split
(
"\\n"
.
toRegex
()).
dropLastWhile
{
it
.
isEmpty
()
}
parseProps
(
props
)
}
catch
(
e
:
Exception
)
{
throw
IllegalRepoException
(
"Repo [$id] parse error:"
,
e
)
}
if
(
versionCode
<
0
)
{
...
...
app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt
View file @
fa2dbe98
...
...
@@ -20,17 +20,18 @@ class RepoUpdater(
val
cachedMap
=
HashMap
<
String
,
Date
>().
also
{
map
->
repoDB
.
getModuleStubs
().
forEach
{
map
[
it
.
id
]
=
Date
(
it
.
last_update
)
}
}.
synchronized
()
val
info
=
svc
.
fetchRepoInfo
()
coroutineScope
{
info
.
modules
.
forEach
{
launch
{
val
lastUpdated
=
cachedMap
.
remove
(
it
.
id
)
if
(
forced
||
lastUpdated
?.
before
(
Date
(
it
.
last_update
))
!=
false
)
{
try
{
val
repo
=
OnlineModule
(
it
).
apply
{
load
()
}
repoDB
.
addModule
(
repo
)
}
catch
(
e
:
OnlineModule
.
IllegalRepoException
)
{
Timber
.
e
(
e
)
svc
.
fetchRepoInfo
()
?.
also
{
info
->
coroutineScope
{
info
.
modules
.
forEach
{
launch
{
val
lastUpdated
=
cachedMap
.
remove
(
it
.
id
)
if
(
forced
||
lastUpdated
?.
before
(
Date
(
it
.
last_update
))
!=
false
)
{
try
{
val
repo
=
OnlineModule
(
it
).
apply
{
load
()
}
repoDB
.
addModule
(
repo
)
}
catch
(
e
:
OnlineModule
.
IllegalRepoException
)
{
Timber
.
e
(
e
)
}
}
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt
View file @
fa2dbe98
...
...
@@ -10,7 +10,6 @@ import com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.core.Info
import
com.topjohnwu.magisk.core.model.*
import
com.topjohnwu.magisk.data.network.*
import
okhttp3.ResponseBody
import
retrofit2.HttpException
import
timber.log.Timber
import
java.io.IOException
...
...
@@ -46,10 +45,10 @@ class NetworkService(
}
// UpdateInfo
suspend
fun
fetchStableUpdate
()
=
pages
.
fetchStableUpdate
()
suspend
fun
fetchBetaUpdate
()
=
pages
.
fetchBetaUpdate
()
suspend
fun
fetchCustomUpdate
(
url
:
String
)
=
raw
.
fetchCustomUpdate
(
url
)
suspend
fun
fetchCanaryUpdate
():
UpdateInfo
{
private
suspend
fun
fetchStableUpdate
()
=
pages
.
fetchStableUpdate
()
private
suspend
fun
fetchBetaUpdate
()
=
pages
.
fetchBetaUpdate
()
private
suspend
fun
fetchCustomUpdate
(
url
:
String
)
=
raw
.
fetchCustomUpdate
(
url
)
private
suspend
fun
fetchCanaryUpdate
():
UpdateInfo
{
val
sha
=
fetchCanaryVersion
()
val
info
=
jsd
.
fetchCanaryUpdate
(
sha
)
...
...
@@ -67,18 +66,37 @@ class NetworkService(
)
}
private
inline
fun
<
T
>
safe
(
factory
:
()
->
T
):
T
?
{
return
try
{
factory
()
}
catch
(
e
:
HttpException
)
{
Timber
.
e
(
e
)
null
}
}
private
inline
fun
<
T
>
wrap
(
factory
:
()
->
T
):
T
{
return
try
{
factory
()
}
catch
(
e
:
HttpException
)
{
throw
IOException
(
e
)
}
}
// Modules related
suspend
fun
fetchRepoInfo
(
url
:
String
=
Const
.
Url
.
OFFICIAL_REPO
)
=
raw
.
fetchRepoInfo
(
url
)
suspend
fun
fetchRepoInfo
(
url
:
String
=
Const
.
Url
.
OFFICIAL_REPO
)
=
safe
{
raw
.
fetchRepoInfo
(
url
)
}
// Fetch files
suspend
fun
fetchSafetynet
()
=
jsd
.
fetchSafetynet
()
suspend
fun
fetchBootctl
()
=
jsd
.
fetchBootctl
()
suspend
fun
fetchInstaller
()
:
ResponseBody
{
suspend
fun
fetchSafetynet
()
=
wrap
{
jsd
.
fetchSafetynet
()
}
suspend
fun
fetchBootctl
()
=
wrap
{
jsd
.
fetchBootctl
()
}
suspend
fun
fetchInstaller
()
=
wrap
{
val
sha
=
fetchMainVersion
()
return
jsd
.
fetchInstaller
(
sha
)
jsd
.
fetchInstaller
(
sha
)
}
suspend
fun
fetchFile
(
url
:
String
)
=
raw
.
fetchFile
(
url
)
suspend
fun
fetchString
(
url
:
String
)
=
raw
.
fetchString
(
url
)
suspend
fun
fetchFile
(
url
:
String
)
=
wrap
{
raw
.
fetchFile
(
url
)
}
suspend
fun
fetchString
(
url
:
String
)
=
wrap
{
raw
.
fetchString
(
url
)
}
private
suspend
fun
fetchCanaryVersion
()
=
api
.
fetchBranch
(
MAGISK_FILES
,
"canary"
).
commit
.
sha
private
suspend
fun
fetchMainVersion
()
=
api
.
fetchBranch
(
MAGISK_MAIN
,
"master"
).
commit
.
sha
...
...
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