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
9225b475
Commit
9225b475
authored
Oct 06, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tidy up network services
Add jsdelivr CDN for several files
parent
d462873e
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
130 additions
and
125 deletions
+130
-125
Const.kt
app/src/main/java/com/topjohnwu/magisk/core/Const.kt
+4
-4
UpdateCheckService.kt
...main/java/com/topjohnwu/magisk/core/UpdateCheckService.kt
+3
-3
BaseDownloader.kt
...java/com/topjohnwu/magisk/core/download/BaseDownloader.kt
+2
-2
Repo.kt
.../main/java/com/topjohnwu/magisk/core/model/module/Repo.kt
+4
-4
MagiskInstaller.kt
...n/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt
+2
-2
PatchAPK.kt
...src/main/java/com/topjohnwu/magisk/core/tasks/PatchAPK.kt
+2
-2
RepoUpdater.kt
.../main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt
+3
-3
NetworkServices.kt
...java/com/topjohnwu/magisk/data/network/NetworkServices.kt
+22
-31
MagiskRepository.kt
.../com/topjohnwu/magisk/data/repository/MagiskRepository.kt
+0
-39
NetworkService.kt
...va/com/topjohnwu/magisk/data/repository/NetworkService.kt
+68
-0
StringRepository.kt
.../com/topjohnwu/magisk/data/repository/StringRepository.kt
+0
-16
NetworkingModule.kt
...src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt
+7
-4
RepositoryModule.kt
...src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt
+2
-4
HomeViewModel.kt
...c/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt
+3
-3
InstallViewModel.kt
.../java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt
+3
-3
CheckSafetyNetEvent.kt
.../com/topjohnwu/magisk/ui/safetynet/CheckSafetyNetEvent.kt
+2
-2
MarkDownWindow.kt
...src/main/java/com/topjohnwu/magisk/view/MarkDownWindow.kt
+3
-3
No files found.
app/src/main/java/com/topjohnwu/magisk/core/Const.kt
View file @
9225b475
...
...
@@ -12,8 +12,8 @@ object Const {
// Versions
const
val
SNET_EXT_VER
=
15
const
val
SNET_REVISION
=
"
d494bc726e86166913a13629e3b1336728ec5d7f
"
const
val
BOOTCTL_REVISION
=
"
a6c47f86f10b310358afa9dbe837037dd5d561df
"
const
val
SNET_REVISION
=
"
18ab78817087c337ae0edd1ecac38aec49217880
"
const
val
BOOTCTL_REVISION
=
"
18ab78817087c337ae0edd1ecac38aec49217880
"
// Misc
const
val
ANDROID_MANIFEST
=
"AndroidManifest.xml"
...
...
@@ -51,14 +51,14 @@ object Const {
const
val
SOURCE_CODE_URL
=
"https://github.com/topjohnwu/Magisk"
const
val
GITHUB_RAW_URL
=
"https://raw.githubusercontent.com/"
const
val
GITHUB_API_URL
=
"https://api.github.com/
users/Magisk-Modules-Repo/
"
const
val
GITHUB_API_URL
=
"https://api.github.com/"
const
val
GITHUB_PAGE_URL
=
"https://topjohnwu.github.io/magisk_files/"
const
val
JS_DELIVR_URL
=
"https://cdn.jsdelivr.net/gh/"
}
object
Key
{
// others
const
val
LINK_KEY
=
"Link"
const
val
IF_NONE_MATCH
=
"If-None-Match"
const
val
ETAG_KEY
=
"ETag"
// intents
const
val
OPEN_SECTION
=
"section"
...
...
app/src/main/java/com/topjohnwu/magisk/core/UpdateCheckService.kt
View file @
9225b475
...
...
@@ -3,7 +3,7 @@ package com.topjohnwu.magisk.core
import
android.content.Context
import
androidx.work.*
import
com.topjohnwu.magisk.BuildConfig
import
com.topjohnwu.magisk.data.repository.
MagiskRepository
import
com.topjohnwu.magisk.data.repository.
NetworkService
import
com.topjohnwu.magisk.view.Notifications
import
com.topjohnwu.superuser.Shell
import
kotlinx.coroutines.Dispatchers
...
...
@@ -15,14 +15,14 @@ import java.util.concurrent.TimeUnit
class
UpdateCheckService
(
context
:
Context
,
workerParams
:
WorkerParameters
)
:
CoroutineWorker
(
context
,
workerParams
),
KoinComponent
{
private
val
magiskRepo
:
MagiskRepository
by
inject
()
private
val
svc
:
NetworkService
by
inject
()
override
suspend
fun
doWork
():
Result
{
// Make sure shell initializer was ran
withContext
(
Dispatchers
.
IO
)
{
Shell
.
getShell
()
}
return
magiskRepo
.
fetchUpdate
()
?.
let
{
return
svc
.
fetchUpdate
()
?.
let
{
if
(
BuildConfig
.
VERSION_CODE
<
it
.
app
.
versionCode
)
Notifications
.
managerUpdate
(
applicationContext
)
else
if
(
Info
.
env
.
isActive
&&
Info
.
env
.
magiskVersionCode
<
it
.
magisk
.
versionCode
)
...
...
app/src/main/java/com/topjohnwu/magisk/core/download/BaseDownloader.kt
View file @
9225b475
...
...
@@ -11,7 +11,7 @@ import com.topjohnwu.magisk.core.base.BaseService
import
com.topjohnwu.magisk.core.utils.MediaStoreUtils.checkSum
import
com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream
import
com.topjohnwu.magisk.core.utils.ProgressInputStream
import
com.topjohnwu.magisk.data.
network.GithubRawServices
import
com.topjohnwu.magisk.data.
repository.NetworkService
import
com.topjohnwu.magisk.ktx.withStreams
import
com.topjohnwu.magisk.view.Notifications
import
kotlinx.coroutines.CoroutineScope
...
...
@@ -34,7 +34,7 @@ abstract class BaseDownloader : BaseService(), KoinComponent {
private
val
notifications
=
Collections
.
synchronizedMap
(
HashMap
<
Int
,
Notification
.
Builder
>())
private
val
coroutineScope
=
CoroutineScope
(
Dispatchers
.
IO
)
val
service
:
GithubRawServices
by
inject
()
val
service
:
NetworkService
by
inject
()
// -- Service overrides
...
...
app/src/main/java/com/topjohnwu/magisk/core/model/module/Repo.kt
View file @
9225b475
...
...
@@ -4,7 +4,7 @@ import android.os.Parcelable
import
androidx.room.Entity
import
androidx.room.PrimaryKey
import
com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.data.repository.
StringRepository
import
com.topjohnwu.magisk.data.repository.
NetworkService
import
com.topjohnwu.magisk.ktx.get
import
com.topjohnwu.magisk.ktx.legalFilename
import
kotlinx.android.parcel.Parcelize
...
...
@@ -23,7 +23,7 @@ data class Repo(
var
last_update
:
Long
)
:
BaseModule
(),
Parcelable
{
private
val
s
tringRepo
:
StringRepository
get
()
=
get
()
private
val
s
vc
:
NetworkService
get
()
=
get
()
val
lastUpdate
get
()
=
Date
(
last_update
)
...
...
@@ -31,7 +31,7 @@ data class Repo(
val
downloadFilename
:
String
get
()
=
"$name-$version($versionCode).zip"
.
legalFilename
()
suspend
fun
readme
()
=
s
tringRepo
.
get
Readme
(
this
)
suspend
fun
readme
()
=
s
vc
.
fetch
Readme
(
this
)
val
zipUrl
:
String
get
()
=
Const
.
Url
.
ZIP_URL
.
format
(
id
)
...
...
@@ -53,7 +53,7 @@ data class Repo(
@Throws
(
IllegalRepoException
::
class
)
suspend
fun
update
(
lastUpdate
:
Date
?
=
null
)
{
lastUpdate
?.
let
{
last_update
=
it
.
time
}
loadProps
(
s
tringRepo
.
get
Metadata
(
this
))
loadProps
(
s
vc
.
fetch
Metadata
(
this
))
}
class
IllegalRepoException
(
message
:
String
)
:
Exception
(
message
)
...
...
app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt
View file @
9225b475
...
...
@@ -13,7 +13,7 @@ import com.topjohnwu.magisk.core.Config
import
com.topjohnwu.magisk.core.utils.MediaStoreUtils
import
com.topjohnwu.magisk.core.utils.MediaStoreUtils.inputStream
import
com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream
import
com.topjohnwu.magisk.data.
network.GithubRawServices
import
com.topjohnwu.magisk.data.
repository.NetworkService
import
com.topjohnwu.magisk.di.Protected
import
com.topjohnwu.magisk.events.dialog.EnvFixDialog
import
com.topjohnwu.magisk.ktx.reboot
...
...
@@ -53,7 +53,7 @@ abstract class MagiskInstallImpl : KoinComponent {
private
val
logs
:
MutableList
<
String
>
private
var
tarOut
:
TarOutputStream
?
=
null
private
val
service
:
GithubRawServices
by
inject
()
private
val
service
:
NetworkService
by
inject
()
protected
val
context
:
Context
by
inject
()
protected
constructor
()
{
...
...
app/src/main/java/com/topjohnwu/magisk/core/tasks/PatchAPK.kt
View file @
9225b475
...
...
@@ -10,7 +10,7 @@ import com.topjohnwu.magisk.core.Info
import
com.topjohnwu.magisk.core.isRunningAsStub
import
com.topjohnwu.magisk.core.utils.AXML
import
com.topjohnwu.magisk.core.utils.Keygen
import
com.topjohnwu.magisk.data.
network.GithubRawServices
import
com.topjohnwu.magisk.data.
repository.NetworkService
import
com.topjohnwu.magisk.ktx.get
import
com.topjohnwu.magisk.ktx.writeTo
import
com.topjohnwu.magisk.utils.Utils
...
...
@@ -91,7 +91,7 @@ object PatchAPK {
val
dlStub
=
!
isRunningAsStub
&&
SDK_INT
>=
28
&&
Const
.
Version
.
atLeast_20_2
()
val
src
=
if
(
dlStub
)
{
val
stub
=
File
(
context
.
cacheDir
,
"stub.apk"
)
val
svc
=
get
<
GithubRawServices
>()
val
svc
=
get
<
NetworkService
>()
try
{
svc
.
fetchFile
(
Info
.
remote
.
stub
.
link
).
byteStream
().
use
{
it
.
writeTo
(
stub
)
...
...
app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt
View file @
9225b475
...
...
@@ -4,7 +4,7 @@ import com.squareup.moshi.JsonClass
import
com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.core.model.module.Repo
import
com.topjohnwu.magisk.data.database.RepoDao
import
com.topjohnwu.magisk.data.
network.GithubApiServices
import
com.topjohnwu.magisk.data.
repository.NetworkService
import
com.topjohnwu.magisk.ktx.synchronized
import
kotlinx.coroutines.*
import
timber.log.Timber
...
...
@@ -14,7 +14,7 @@ import java.util.*
import
kotlin.collections.HashSet
class
RepoUpdater
(
private
val
api
:
GithubApiServices
,
private
val
svc
:
NetworkService
,
private
val
repoDB
:
RepoDao
)
{
...
...
@@ -66,7 +66,7 @@ class RepoUpdater(
etag
:
String
=
""
):
PageResult
=
coroutineScope
{
runCatching
{
val
result
=
api
.
fetchRepos
(
page
,
etag
)
val
result
=
svc
.
fetchRepos
(
page
,
etag
)
result
.
run
{
if
(
code
()
==
HttpURLConnection
.
HTTP_NOT_MODIFIED
)
return
@coroutineScope
PageResult
.
CACHED
...
...
app/src/main/java/com/topjohnwu/magisk/data/network/
Github
Services.kt
→
app/src/main/java/com/topjohnwu/magisk/data/network/
Network
Services.kt
View file @
9225b475
...
...
@@ -7,6 +7,15 @@ import okhttp3.ResponseBody
import
retrofit2.Response
import
retrofit2.http.*
private
const
val
REVISION
=
"revision"
private
const
val
MODULE
=
"module"
private
const
val
FILE
=
"file"
private
const
val
IF_NONE_MATCH
=
"If-None-Match"
private
const
val
MAGISK_FILES
=
"topjohnwu/magisk_files"
private
const
val
MAGISK_MASTER
=
"topjohnwu/Magisk/master"
private
const
val
MAGISK_MODULES
=
"Magisk-Modules-Repo"
interface
GithubPageServices
{
@GET
(
"stable.json"
)
...
...
@@ -16,15 +25,18 @@ interface GithubPageServices {
suspend
fun
fetchBetaUpdate
():
UpdateInfo
}
interface
GithubRaw
Services
{
interface
JSDelivr
Services
{
//region topjohnwu/magisk_files
@GET
(
"$MAGISK_FILES@{$REVISION}/snet"
)
@Streaming
suspend
fun
fetchSafetynet
(
@Path
(
REVISION
)
revision
:
String
=
Const
.
SNET_REVISION
):
ResponseBody
@GET
(
"$MAGISK_FILES/master/stable.json"
)
suspend
fun
fetchStableUpdate
():
UpdateInfo
@GET
(
"$MAGISK_FILES@{$REVISION}/bootctl"
)
@Streaming
suspend
fun
fetchBootctl
(
@Path
(
REVISION
)
revision
:
String
=
Const
.
BOOTCTL_REVISION
):
ResponseBody
}
@GET
(
"$MAGISK_FILES/master/beta.json"
)
suspend
fun
fetchBetaUpdate
():
UpdateInfo
interface
GithubRawServices
{
@GET
(
"$MAGISK_FILES/canary/debug.json"
)
suspend
fun
fetchCanaryUpdate
():
UpdateInfo
...
...
@@ -32,14 +44,6 @@ interface GithubRawServices {
@GET
suspend
fun
fetchCustomUpdate
(
@Url
url
:
String
):
UpdateInfo
@GET
(
"$MAGISK_FILES/{$REVISION}/snet.jar"
)
@Streaming
suspend
fun
fetchSafetynet
(
@Path
(
REVISION
)
revision
:
String
=
Const
.
SNET_REVISION
):
ResponseBody
@GET
(
"$MAGISK_FILES/{$REVISION}/bootctl"
)
@Streaming
suspend
fun
fetchBootctl
(
@Path
(
REVISION
)
revision
:
String
=
Const
.
BOOTCTL_REVISION
):
ResponseBody
@GET
(
"$MAGISK_MASTER/scripts/module_installer.sh"
)
@Streaming
suspend
fun
fetchInstaller
():
ResponseBody
...
...
@@ -47,8 +51,6 @@ interface GithubRawServices {
@GET
(
"$MAGISK_MODULES/{$MODULE}/master/{$FILE}"
)
suspend
fun
fetchModuleFile
(
@Path
(
MODULE
)
id
:
String
,
@Path
(
FILE
)
file
:
String
):
String
//endregion
/**
* This method shall be used exclusively for fetching files from urls from previous requests.
* Him, who uses it in a wrong way, shall die in an eternal flame.
...
...
@@ -60,28 +62,17 @@ interface GithubRawServices {
@GET
suspend
fun
fetchString
(
@Url
url
:
String
):
String
companion
object
{
private
const
val
REVISION
=
"revision"
private
const
val
MODULE
=
"module"
private
const
val
FILE
=
"file"
private
const
val
MAGISK_FILES
=
"topjohnwu/magisk_files"
private
const
val
MAGISK_MASTER
=
"topjohnwu/Magisk/master"
private
const
val
MAGISK_MODULES
=
"Magisk-Modules-Repo"
}
}
interface
GithubApiServices
{
@GET
(
"repos"
)
@GET
(
"users/${MAGISK_MODULES}/repos"
)
@Headers
(
"Accept: application/vnd.github.v3+json"
)
suspend
fun
fetchRepos
(
@Query
(
"page"
)
page
:
Int
,
@Header
(
Const
.
Key
.
IF_NONE_MATCH
)
etag
:
String
,
@Header
(
IF_NONE_MATCH
)
etag
:
String
,
@Query
(
"sort"
)
sort
:
String
=
"pushed"
,
@Query
(
"per_page"
)
count
:
Int
=
100
):
Response
<
List
<
GithubRepoInfo
>>
}
app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt
deleted
100644 → 0
View file @
d462873e
package
com.topjohnwu.magisk.data.repository
import
com.topjohnwu.magisk.core.Config
import
com.topjohnwu.magisk.core.Info
import
com.topjohnwu.magisk.data.network.GithubPageServices
import
com.topjohnwu.magisk.data.network.GithubRawServices
import
retrofit2.HttpException
import
timber.log.Timber
import
java.io.IOException
class
MagiskRepository
(
private
val
rawSvc
:
GithubRawServices
,
private
val
pageSvc
:
GithubPageServices
)
{
suspend
fun
fetchUpdate
()
=
try
{
var
info
=
when
(
Config
.
updateChannel
)
{
Config
.
Value
.
DEFAULT_CHANNEL
,
Config
.
Value
.
STABLE_CHANNEL
->
pageSvc
.
fetchStableUpdate
()
Config
.
Value
.
BETA_CHANNEL
->
pageSvc
.
fetchBetaUpdate
()
Config
.
Value
.
CANARY_CHANNEL
->
rawSvc
.
fetchCanaryUpdate
()
Config
.
Value
.
CUSTOM_CHANNEL
->
rawSvc
.
fetchCustomUpdate
(
Config
.
customChannelUrl
)
else
->
throw
IllegalArgumentException
()
}
if
(
info
.
magisk
.
versionCode
<
Info
.
env
.
magiskVersionCode
&&
Config
.
updateChannel
==
Config
.
Value
.
DEFAULT_CHANNEL
)
{
Config
.
updateChannel
=
Config
.
Value
.
BETA_CHANNEL
info
=
pageSvc
.
fetchBetaUpdate
()
}
Info
.
remote
=
info
info
}
catch
(
e
:
IOException
)
{
Timber
.
e
(
e
)
null
}
catch
(
e
:
HttpException
)
{
Timber
.
e
(
e
)
null
}
}
app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt
0 → 100644
View file @
9225b475
package
com.topjohnwu.magisk.data.repository
import
com.topjohnwu.magisk.core.Config
import
com.topjohnwu.magisk.core.Config.Value.BETA_CHANNEL
import
com.topjohnwu.magisk.core.Config.Value.CANARY_CHANNEL
import
com.topjohnwu.magisk.core.Config.Value.CUSTOM_CHANNEL
import
com.topjohnwu.magisk.core.Config.Value.DEFAULT_CHANNEL
import
com.topjohnwu.magisk.core.Config.Value.STABLE_CHANNEL
import
com.topjohnwu.magisk.core.Info
import
com.topjohnwu.magisk.core.model.module.Repo
import
com.topjohnwu.magisk.data.network.GithubApiServices
import
com.topjohnwu.magisk.data.network.GithubPageServices
import
com.topjohnwu.magisk.data.network.GithubRawServices
import
com.topjohnwu.magisk.data.network.JSDelivrServices
import
retrofit2.HttpException
import
timber.log.Timber
import
java.io.IOException
class
NetworkService
(
private
val
pages
:
GithubPageServices
,
private
val
raw
:
GithubRawServices
,
private
val
jsd
:
JSDelivrServices
,
private
val
api
:
GithubApiServices
)
{
suspend
fun
fetchUpdate
()
=
try
{
var
info
=
when
(
Config
.
updateChannel
)
{
DEFAULT_CHANNEL
,
STABLE_CHANNEL
->
fetchStableUpdate
()
BETA_CHANNEL
->
fetchBetaUpdate
()
CANARY_CHANNEL
->
fetchCanaryUpdate
()
CUSTOM_CHANNEL
->
fetchCustomUpdate
(
Config
.
customChannelUrl
)
else
->
throw
IllegalArgumentException
()
}
if
(
info
.
magisk
.
versionCode
<
Info
.
env
.
magiskVersionCode
&&
Config
.
updateChannel
==
DEFAULT_CHANNEL
)
{
Config
.
updateChannel
=
BETA_CHANNEL
info
=
fetchBetaUpdate
()
}
Info
.
remote
=
info
info
}
catch
(
e
:
IOException
)
{
Timber
.
e
(
e
)
null
}
catch
(
e
:
HttpException
)
{
Timber
.
e
(
e
)
null
}
// UpdateInfo
suspend
fun
fetchStableUpdate
()
=
pages
.
fetchStableUpdate
()
suspend
fun
fetchBetaUpdate
()
=
pages
.
fetchBetaUpdate
()
suspend
fun
fetchCanaryUpdate
()
=
raw
.
fetchCanaryUpdate
()
suspend
fun
fetchCustomUpdate
(
url
:
String
)
=
raw
.
fetchCustomUpdate
(
url
)
// Byte streams
suspend
fun
fetchSafetynet
()
=
jsd
.
fetchSafetynet
()
suspend
fun
fetchBootctl
()
=
jsd
.
fetchBootctl
()
suspend
fun
fetchInstaller
()
=
raw
.
fetchInstaller
()
suspend
fun
fetchFile
(
url
:
String
)
=
raw
.
fetchFile
(
url
)
// Strings
suspend
fun
fetchMetadata
(
repo
:
Repo
)
=
raw
.
fetchModuleFile
(
repo
.
id
,
"module.prop"
)
suspend
fun
fetchReadme
(
repo
:
Repo
)
=
raw
.
fetchModuleFile
(
repo
.
id
,
"README.md"
)
suspend
fun
fetchString
(
url
:
String
)
=
raw
.
fetchString
(
url
)
// API calls
suspend
fun
fetchRepos
(
page
:
Int
,
etag
:
String
)
=
api
.
fetchRepos
(
page
,
etag
)
}
app/src/main/java/com/topjohnwu/magisk/data/repository/StringRepository.kt
deleted
100644 → 0
View file @
d462873e
package
com.topjohnwu.magisk.data.repository
import
com.topjohnwu.magisk.core.model.module.Repo
import
com.topjohnwu.magisk.data.network.GithubRawServices
class
StringRepository
(
private
val
api
:
GithubRawServices
)
{
suspend
fun
getString
(
url
:
String
)
=
api
.
fetchString
(
url
)
suspend
fun
getMetadata
(
repo
:
Repo
)
=
api
.
fetchModuleFile
(
repo
.
id
,
"module.prop"
)
suspend
fun
getReadme
(
repo
:
Repo
)
=
api
.
fetchModuleFile
(
repo
.
id
,
"README.md"
)
}
app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt
View file @
9225b475
...
...
@@ -9,6 +9,7 @@ import com.topjohnwu.magisk.core.Info
import
com.topjohnwu.magisk.data.network.GithubApiServices
import
com.topjohnwu.magisk.data.network.GithubPageServices
import
com.topjohnwu.magisk.data.network.GithubRawServices
import
com.topjohnwu.magisk.data.network.JSDelivrServices
import
com.topjohnwu.magisk.ktx.precomputedText
import
com.topjohnwu.magisk.net.Networking
import
com.topjohnwu.magisk.net.NoSSLv3SocketFactory
...
...
@@ -19,6 +20,7 @@ import okhttp3.Dns
import
okhttp3.HttpUrl
import
okhttp3.OkHttpClient
import
okhttp3.dnsoverhttps.DnsOverHttps
import
okhttp3.logging.HttpLoggingInterceptor
import
org.koin.dsl.module
import
retrofit2.Retrofit
import
retrofit2.converter.moshi.MoshiConverterFactory
...
...
@@ -32,6 +34,7 @@ val networkingModule = module {
single
{
createApiService
<
GithubRawServices
>(
get
(),
Const
.
Url
.
GITHUB_RAW_URL
)
}
single
{
createApiService
<
GithubApiServices
>(
get
(),
Const
.
Url
.
GITHUB_API_URL
)
}
single
{
createApiService
<
GithubPageServices
>(
get
(),
Const
.
Url
.
GITHUB_PAGE_URL
)
}
single
{
createApiService
<
JSDelivrServices
>(
get
(),
Const
.
Url
.
JS_DELIVR_URL
)
}
single
{
createMarkwon
(
get
(),
get
())
}
}
...
...
@@ -75,10 +78,10 @@ private class DnsResolver(client: OkHttpClient) : Dns {
fun
createOkHttpClient
(
context
:
Context
):
OkHttpClient
{
val
builder
=
OkHttpClient
.
Builder
()
//
val httpLoggingInterceptor = HttpLoggingInterceptor().apply {
//
level = HttpLoggingInterceptor.Level.HEADERS
//
}
//
builder.addInterceptor(httpLoggingInterceptor)
val
httpLoggingInterceptor
=
HttpLoggingInterceptor
().
apply
{
level
=
HttpLoggingInterceptor
.
Level
.
HEADERS
}
builder
.
addInterceptor
(
httpLoggingInterceptor
)
if
(!
Networking
.
init
(
context
))
{
Info
.
hasGMS
=
false
...
...
app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt
View file @
9225b475
package
com.topjohnwu.magisk.di
import
com.topjohnwu.magisk.data.repository.LogRepository
import
com.topjohnwu.magisk.data.repository.MagiskRepository
import
com.topjohnwu.magisk.data.repository.StringRepository
import
com.topjohnwu.magisk.data.repository.NetworkService
import
org.koin.dsl.module
val
repositoryModule
=
module
{
single
{
MagiskRepository
(
get
(),
get
())
}
single
{
LogRepository
(
get
())
}
single
{
StringRepository
(
get
())
}
single
{
NetworkService
(
get
(),
get
(),
get
(),
get
())
}
}
app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt
View file @
9225b475
...
...
@@ -12,7 +12,7 @@ import com.topjohnwu.magisk.core.download.Subject
import
com.topjohnwu.magisk.core.download.Subject.Manager
import
com.topjohnwu.magisk.core.model.MagiskJson
import
com.topjohnwu.magisk.core.model.ManagerJson
import
com.topjohnwu.magisk.data.repository.
MagiskRepository
import
com.topjohnwu.magisk.data.repository.
NetworkService
import
com.topjohnwu.magisk.events.OpenInappLinkEvent
import
com.topjohnwu.magisk.events.SnackbarEvent
import
com.topjohnwu.magisk.events.dialog.EnvFixDialog
...
...
@@ -32,7 +32,7 @@ enum class MagiskState {
}
class
HomeViewModel
(
private
val
repoMagisk
:
MagiskRepository
private
val
svc
:
NetworkService
)
:
BaseViewModel
()
{
@get
:
Bindable
...
...
@@ -84,7 +84,7 @@ class HomeViewModel(
state
=
State
.
LOADING
notifyPropertyChanged
(
BR
.
showUninstall
)
notifyPropertyChanged
(
BR
.
showSafetyNet
)
repoMagisk
.
fetchUpdate
()
?.
apply
{
svc
.
fetchUpdate
()
?.
apply
{
state
=
State
.
LOADED
stateMagisk
=
when
{
!
Info
.
env
.
isActive
->
MagiskState
.
NOT_INSTALLED
...
...
app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt
View file @
9225b475
...
...
@@ -11,7 +11,7 @@ import com.topjohnwu.magisk.core.Info
import
com.topjohnwu.magisk.core.download.Action
import
com.topjohnwu.magisk.core.download.DownloadService
import
com.topjohnwu.magisk.core.download.Subject
import
com.topjohnwu.magisk.data.repository.
StringRepository
import
com.topjohnwu.magisk.data.repository.
NetworkService
import
com.topjohnwu.magisk.events.MagiskInstallFileEvent
import
com.topjohnwu.magisk.events.dialog.SecondSlotWarningDialog
import
com.topjohnwu.magisk.utils.set
...
...
@@ -21,7 +21,7 @@ import org.koin.core.get
import
kotlin.math.roundToInt
class
InstallViewModel
(
s
tringRepo
:
StringRepository
s
vc
:
NetworkService
)
:
BaseViewModel
(
State
.
LOADED
)
{
val
isRooted
=
Shell
.
rootAccess
()
...
...
@@ -64,7 +64,7 @@ class InstallViewModel(
init
{
viewModelScope
.
launch
{
notes
=
s
tringRepo
.
get
String
(
Info
.
remote
.
magisk
.
note
)
notes
=
s
vc
.
fetch
String
(
Info
.
remote
.
magisk
.
note
)
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/ui/safetynet/CheckSafetyNetEvent.kt
View file @
9225b475
...
...
@@ -5,7 +5,7 @@ import com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.arch.ContextExecutor
import
com.topjohnwu.magisk.arch.ViewEventWithScope
import
com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.data.
network.GithubRawServices
import
com.topjohnwu.magisk.data.
repository.NetworkService
import
com.topjohnwu.magisk.ktx.DynamicClassLoader
import
com.topjohnwu.magisk.ktx.writeTo
import
com.topjohnwu.magisk.view.MagiskDialog
...
...
@@ -28,7 +28,7 @@ class CheckSafetyNetEvent(
private
val
callback
:
(
SafetyNetResult
)
->
Unit
=
{}
)
:
ViewEventWithScope
(),
ContextExecutor
,
KoinComponent
,
SafetyNetHelper
.
Callback
{
private
val
svc
by
inject
<
GithubRawServices
>()
private
val
svc
by
inject
<
NetworkService
>()
private
lateinit
var
apk
:
File
private
lateinit
var
dex
:
File
...
...
app/src/main/java/com/topjohnwu/magisk/view/MarkDownWindow.kt
View file @
9225b475
...
...
@@ -4,7 +4,7 @@ import android.content.Context
import
android.view.LayoutInflater
import
android.widget.TextView
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.data.repository.
StringRepository
import
com.topjohnwu.magisk.data.repository.
NetworkService
import
com.topjohnwu.magisk.ktx.coroutineScope
import
io.noties.markwon.Markwon
import
kotlinx.coroutines.CancellationException
...
...
@@ -18,12 +18,12 @@ import kotlin.coroutines.coroutineContext
object
MarkDownWindow
:
KoinComponent
{
private
val
repo
:
StringRepository
by
inject
()
private
val
svc
:
NetworkService
by
inject
()
private
val
markwon
:
Markwon
by
inject
()
suspend
fun
show
(
activity
:
Context
,
title
:
String
?,
url
:
String
)
{
show
(
activity
,
title
)
{
repo
.
get
String
(
url
)
svc
.
fetch
String
(
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