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
df78fd2d
Commit
df78fd2d
authored
May 23, 2019
by
Viktor De Pasquale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed setting custom channels and switching between official ones being broken
parent
dabe6267
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
90 additions
and
55 deletions
+90
-55
KConfig.kt
app/src/main/java/com/topjohnwu/magisk/KConfig.kt
+28
-20
GithubRawApiServices.kt
...com/topjohnwu/magisk/data/network/GithubRawApiServices.kt
+5
-1
MagiskRepository.kt
.../com/topjohnwu/magisk/data/repository/MagiskRepository.kt
+5
-10
ApplicationModule.kt
...rc/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt
+8
-0
BasePreferenceFragment.kt
...va/com/topjohnwu/magisk/ui/base/BasePreferenceFragment.kt
+17
-0
SettingsFragment.java
...va/com/topjohnwu/magisk/ui/settings/SettingsFragment.java
+13
-9
custom_channel_dialog.xml
app/src/main/res/layout/custom_channel_dialog.xml
+14
-15
No files found.
app/src/main/java/com/topjohnwu/magisk/KConfig.kt
View file @
df78fd2d
package
com.topjohnwu.magisk
package
com.topjohnwu.magisk
import
androidx.appcompat.app.AppCompatDelegate
import
com.chibatching.kotpref.ContextProvider
import
com.chibatching.kotpref.KotprefModel
import
com.chibatching.kotpref.KotprefModel
import
com.topjohnwu.magisk.KConfig.UpdateChannel.*
import
com.topjohnwu.magisk.KConfig.UpdateChannel.STABLE
import
com.topjohnwu.magisk.utils.get
object
KConfig
:
KotprefModel
()
{
object
KConfig
:
KotprefModel
(
get
<
ContextProvider
>()
)
{
override
val
kotprefName
:
String
=
"${context.packageName}_preferences"
override
val
kotprefName
:
String
=
"${context.packageName}_preferences"
var
darkMode
by
intPref
(
default
=
AppCompatDelegate
.
MODE_NIGHT_FOLLOW_SYSTEM
,
key
=
"darkMode"
)
private
var
internalUpdateChannel
by
intPref
(
STABLE
.
id
,
"updateChannel"
)
var
magiskChecksum
by
stringPref
(
""
,
"magiskChecksum"
)
var
forceEncrypt
by
booleanPref
(
false
,
"forceEncryption"
)
var
keepVerity
by
booleanPref
(
false
,
"keepVerity"
)
var
bootFormat
by
stringPref
(
"img"
,
"bootFormat"
)
var
suLogTimeout
by
longPref
(
0
,
"suLogTimeout"
)
private
var
internalUpdateChannel
by
stringPref
(
KConfig
.
UpdateChannel
.
STABLE
.
toString
(),
"updateChannel"
)
var
useCustomTabs
by
booleanPref
(
true
,
"useCustomTabs"
)
var
useCustomTabs
by
booleanPref
(
true
,
"useCustomTabs"
)
@JvmStatic
var
customUpdateChannel
by
stringPref
(
""
,
"custom_channel"
)
@JvmStatic
var
updateChannel
:
UpdateChannel
var
updateChannel
:
UpdateChannel
get
()
=
valueOf
(
internalUpdateChannel
)
get
()
=
UpdateChannel
.
byId
(
internalUpdateChannel
)
set
(
value
)
{
set
(
value
)
{
internalUpdateChannel
=
value
.
toString
()
internalUpdateChannel
=
value
.
id
}
}
val
isStable
get
()
=
!(
isCanary
||
isBeta
)
internal
const
val
DEFAULT_CHANNEL
=
"topjohnwu/magisk_files"
val
isCanary
get
()
=
updateChannel
==
CANARY
||
updateChannel
==
CANARY_DEBUG
val
isBeta
get
()
=
updateChannel
==
BETA
enum
class
UpdateChannel
(
val
id
:
Int
)
{
enum
class
UpdateChannel
{
STABLE
(
Config
.
Value
.
STABLE_CHANNEL
),
STABLE
,
BETA
,
CANARY
,
CANARY_DEBUG
BETA
(
Config
.
Value
.
BETA_CHANNEL
),
CANARY
(
Config
.
Value
.
CANARY_CHANNEL
),
CANARY_DEBUG
(
Config
.
Value
.
CANARY_DEBUG_CHANNEL
),
CUSTOM
(
Config
.
Value
.
CUSTOM_CHANNEL
);
companion
object
{
fun
byId
(
id
:
Int
)
=
when
(
id
)
{
Config
.
Value
.
STABLE_CHANNEL
->
STABLE
Config
.
Value
.
BETA_CHANNEL
->
BETA
Config
.
Value
.
CUSTOM_CHANNEL
->
CUSTOM
Config
.
Value
.
CANARY_CHANNEL
->
CANARY
Config
.
Value
.
CANARY_DEBUG_CHANNEL
->
CANARY_DEBUG
else
->
STABLE
}
}
}
}
}
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/data/network/GithubRawApiServices.kt
View file @
df78fd2d
package
com.topjohnwu.magisk.data.network
package
com.topjohnwu.magisk.data.network
import
com.topjohnwu.magisk.Constants
import
com.topjohnwu.magisk.Constants
import
com.topjohnwu.magisk.KConfig
import
com.topjohnwu.magisk.model.entity.MagiskConfig
import
com.topjohnwu.magisk.model.entity.MagiskConfig
import
io.reactivex.Single
import
io.reactivex.Single
import
okhttp3.ResponseBody
import
okhttp3.ResponseBody
...
@@ -26,6 +27,9 @@ interface GithubRawApiServices {
...
@@ -26,6 +27,9 @@ interface GithubRawApiServices {
@GET
(
"$MAGISK_FILES/master/canary_builds/canary.json"
)
@GET
(
"$MAGISK_FILES/master/canary_builds/canary.json"
)
fun
fetchCanaryDebugConfig
():
Single
<
MagiskConfig
>
fun
fetchCanaryDebugConfig
():
Single
<
MagiskConfig
>
@GET
fun
fetchCustomConfig
(
@Url
url
:
String
):
Single
<
MagiskConfig
>
@GET
(
"$MAGISK_FILES/{$REVISION}/snet.apk"
)
@GET
(
"$MAGISK_FILES/{$REVISION}/snet.apk"
)
@Streaming
@Streaming
fun
fetchSafetynet
(
@Path
(
REVISION
)
revision
:
String
=
Constants
.
SNET_REVISION
):
Single
<
ResponseBody
>
fun
fetchSafetynet
(
@Path
(
REVISION
)
revision
:
String
=
Constants
.
SNET_REVISION
):
Single
<
ResponseBody
>
...
@@ -67,7 +71,7 @@ interface GithubRawApiServices {
...
@@ -67,7 +71,7 @@ interface GithubRawApiServices {
private
const
val
FILE
=
"file"
private
const
val
FILE
=
"file"
private
const
val
MAGISK_FILES
=
"topjohnwu/magisk_files"
private
const
val
MAGISK_FILES
=
KConfig
.
DEFAULT_CHANNEL
private
const
val
MAGISK_MASTER
=
"topjohnwu/Magisk/master"
private
const
val
MAGISK_MASTER
=
"topjohnwu/Magisk/master"
private
const
val
MAGISK_MODULES
=
"Magisk-Modules-Repo"
private
const
val
MAGISK_MODULES
=
"Magisk-Modules-Repo"
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt
View file @
df78fd2d
...
@@ -24,12 +24,6 @@ class MagiskRepository(
...
@@ -24,12 +24,6 @@ class MagiskRepository(
private
val
packageManager
:
PackageManager
private
val
packageManager
:
PackageManager
)
{
)
{
private
val
config
=
apiRaw
.
fetchConfig
()
private
val
configBeta
=
apiRaw
.
fetchBetaConfig
()
private
val
configCanary
=
apiRaw
.
fetchCanaryConfig
()
private
val
configCanaryDebug
=
apiRaw
.
fetchCanaryDebugConfig
()
fun
fetchMagisk
()
=
fetchConfig
()
fun
fetchMagisk
()
=
fetchConfig
()
.
flatMap
{
apiRaw
.
fetchFile
(
it
.
magisk
.
link
)
}
.
flatMap
{
apiRaw
.
fetchFile
(
it
.
magisk
.
link
)
}
.
map
{
it
.
writeToFile
(
context
,
FILE_MAGISK_ZIP
)
}
.
map
{
it
.
writeToFile
(
context
,
FILE_MAGISK_ZIP
)
}
...
@@ -52,10 +46,11 @@ class MagiskRepository(
...
@@ -52,10 +46,11 @@ class MagiskRepository(
fun
fetchConfig
()
=
when
(
KConfig
.
updateChannel
)
{
fun
fetchConfig
()
=
when
(
KConfig
.
updateChannel
)
{
KConfig
.
UpdateChannel
.
STABLE
->
config
KConfig
.
UpdateChannel
.
STABLE
->
apiRaw
.
fetchConfig
()
KConfig
.
UpdateChannel
.
BETA
->
configBeta
KConfig
.
UpdateChannel
.
BETA
->
apiRaw
.
fetchBetaConfig
()
KConfig
.
UpdateChannel
.
CANARY
->
configCanary
KConfig
.
UpdateChannel
.
CANARY
->
apiRaw
.
fetchCanaryConfig
()
KConfig
.
UpdateChannel
.
CANARY_DEBUG
->
configCanaryDebug
KConfig
.
UpdateChannel
.
CANARY_DEBUG
->
apiRaw
.
fetchCanaryDebugConfig
()
KConfig
.
UpdateChannel
.
CUSTOM
->
apiRaw
.
fetchCustomConfig
(
KConfig
.
customUpdateChannel
)
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt
View file @
df78fd2d
...
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk.di
...
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk.di
import
android.content.Context
import
android.content.Context
import
androidx.preference.PreferenceManager
import
androidx.preference.PreferenceManager
import
com.chibatching.kotpref.ContextProvider
import
com.skoumal.teanity.rxbus.RxBus
import
com.skoumal.teanity.rxbus.RxBus
import
com.topjohnwu.magisk.App
import
com.topjohnwu.magisk.App
import
org.koin.dsl.module
import
org.koin.dsl.module
...
@@ -15,4 +16,11 @@ val applicationModule = module {
...
@@ -15,4 +16,11 @@ val applicationModule = module {
factory
(
Protected
)
{
get
<
App
>().
protectedContext
}
factory
(
Protected
)
{
get
<
App
>().
protectedContext
}
single
(
SUTimeout
)
{
get
<
Context
>(
Protected
).
getSharedPreferences
(
"su_timeout"
,
0
)
}
single
(
SUTimeout
)
{
get
<
Context
>(
Protected
).
getSharedPreferences
(
"su_timeout"
,
0
)
}
single
{
PreferenceManager
.
getDefaultSharedPreferences
(
get
<
Context
>(
Protected
))
}
single
{
PreferenceManager
.
getDefaultSharedPreferences
(
get
<
Context
>(
Protected
))
}
single
{
createContextProvider
(
get
(
Protected
))
as
ContextProvider
}
}
}
private
fun
createContextProvider
(
context
:
Context
)
=
object
:
ContextProvider
{
override
fun
getApplicationContext
():
Context
{
return
context
}
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/ui/base/BasePreferenceFragment.kt
View file @
df78fd2d
...
@@ -12,6 +12,8 @@ import androidx.core.view.isVisible
...
@@ -12,6 +12,8 @@ import androidx.core.view.isVisible
import
androidx.preference.*
import
androidx.preference.*
import
androidx.recyclerview.widget.RecyclerView
import
androidx.recyclerview.widget.RecyclerView
import
com.topjohnwu.magisk.App
import
com.topjohnwu.magisk.App
import
com.topjohnwu.magisk.Config
import
com.topjohnwu.magisk.KConfig
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.data.repository.ModuleRepository
import
com.topjohnwu.magisk.data.repository.ModuleRepository
import
com.topjohnwu.magisk.data.repository.SettingRepository
import
com.topjohnwu.magisk.data.repository.SettingRepository
...
@@ -64,4 +66,19 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat(),
...
@@ -64,4 +66,19 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat(),
else
else
view
.
setPadding
(
0
,
view
.
paddingTop
,
view
.
paddingRight
,
view
.
paddingBottom
)
view
.
setPadding
(
0
,
view
.
paddingTop
,
view
.
paddingRight
,
view
.
paddingBottom
)
}
}
protected
fun
setCustomUpdateChannel
(
userRepo
:
String
)
{
KConfig
.
customUpdateChannel
=
userRepo
}
protected
fun
getChannelCompat
(
channel
:
Int
):
KConfig
.
UpdateChannel
{
return
when
(
channel
)
{
Config
.
Value
.
DEFAULT_CHANNEL
->
KConfig
.
UpdateChannel
.
STABLE
Config
.
Value
.
BETA_CHANNEL
->
KConfig
.
UpdateChannel
.
BETA
Config
.
Value
.
CANARY_CHANNEL
->
KConfig
.
UpdateChannel
.
CANARY
Config
.
Value
.
CANARY_DEBUG_CHANNEL
->
KConfig
.
UpdateChannel
.
CANARY_DEBUG
Config
.
Value
.
CUSTOM_CHANNEL
->
KConfig
.
UpdateChannel
.
CUSTOM
else
->
KConfig
.
updateChannel
}
}
}
}
app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java
View file @
df78fd2d
...
@@ -12,6 +12,8 @@ import android.widget.Toast;
...
@@ -12,6 +12,8 @@ import android.widget.Toast;
import
com.topjohnwu.magisk.BuildConfig
;
import
com.topjohnwu.magisk.BuildConfig
;
import
com.topjohnwu.magisk.Config
;
import
com.topjohnwu.magisk.Config
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.KConfig
;
import
com.topjohnwu.magisk.KConfig.UpdateChannel
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.ui.base.BasePreferenceFragment
;
import
com.topjohnwu.magisk.ui.base.BasePreferenceFragment
;
import
com.topjohnwu.magisk.utils.DownloadApp
;
import
com.topjohnwu.magisk.utils.DownloadApp
;
...
@@ -130,21 +132,23 @@ public final class SettingsFragment extends BasePreferenceFragment {
...
@@ -130,21 +132,23 @@ public final class SettingsFragment extends BasePreferenceFragment {
SwitchPreferenceCompat
fingerprint
=
(
SwitchPreferenceCompat
)
findPreference
(
Config
.
Key
.
SU_FINGERPRINT
);
SwitchPreferenceCompat
fingerprint
=
(
SwitchPreferenceCompat
)
findPreference
(
Config
.
Key
.
SU_FINGERPRINT
);
updateChannel
.
setOnPreferenceChangeListener
((
p
,
o
)
->
{
updateChannel
.
setOnPreferenceChangeListener
((
p
,
o
)
->
{
int
prev
=
Config
.
get
(
Config
.
Key
.
UPDATE_CHANNEL
);
int
channel
=
Integer
.
parseInt
((
String
)
o
);
int
channel
=
Integer
.
parseInt
((
String
)
o
);
if
(
channel
==
Config
.
Value
.
CUSTOM_CHANNEL
)
{
final
UpdateChannel
previousUpdateChannel
=
KConfig
.
getUpdateChannel
();
final
UpdateChannel
updateChannel
=
getChannelCompat
(
channel
);
KConfig
.
setUpdateChannel
(
updateChannel
);
if
(
updateChannel
==
UpdateChannel
.
CUSTOM
)
{
View
v
=
LayoutInflater
.
from
(
requireActivity
()).
inflate
(
R
.
layout
.
custom_channel_dialog
,
null
);
View
v
=
LayoutInflater
.
from
(
requireActivity
()).
inflate
(
R
.
layout
.
custom_channel_dialog
,
null
);
EditText
url
=
v
.
findViewById
(
R
.
id
.
custom_url
);
EditText
url
=
v
.
findViewById
(
R
.
id
.
custom_url
);
url
.
setText
(
getPrefs
().
getString
(
Config
.
Key
.
CUSTOM_CHANNEL
,
""
));
url
.
setText
(
KConfig
.
getCustomUpdateChannel
(
));
new
AlertDialog
.
Builder
(
requireActivity
())
new
AlertDialog
.
Builder
(
requireActivity
())
.
setTitle
(
R
.
string
.
settings_update_custom
)
.
setTitle
(
R
.
string
.
settings_update_custom
)
.
setView
(
v
)
.
setView
(
v
)
.
setPositiveButton
(
R
.
string
.
ok
,
(
d
,
i
)
->
.
setPositiveButton
(
R
.
string
.
ok
,
(
d
,
i
)
->
setCustomUpdateChannel
(
url
.
getText
().
toString
()))
Config
.
set
(
Config
.
Key
.
CUSTOM_CHANNEL
,
url
.
getText
().
toString
()))
.
setNegativeButton
(
R
.
string
.
close
,
(
d
,
i
)
->
KConfig
.
setUpdateChannel
(
previousUpdateChannel
))
.
setNegativeButton
(
R
.
string
.
close
,
(
d
,
i
)
->
.
setOnCancelListener
(
d
->
KConfig
.
setUpdateChannel
(
previousUpdateChannel
))
Config
.
set
(
Config
.
Key
.
UPDATE_CHANNEL
,
prev
))
.
setOnCancelListener
(
d
->
Config
.
set
(
Config
.
Key
.
UPDATE_CHANNEL
,
prev
))
.
show
();
.
show
();
}
}
return
true
;
return
true
;
...
...
app/src/main/res/layout/custom_channel_dialog.xml
View file @
df78fd2d
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
android:orientation=
"vertical"
android:paddingStart=
"15dp"
android:padding=
"@dimen/margin_generic"
>
android:paddingTop=
"5dp"
android:paddingEnd=
"15dp"
android:paddingBottom=
"5dp"
>
<TextView
<com.google.android.material.textfield.TextInputLayout
style=
"@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_margin=
"5dp"
android:hint=
"@string/settings_update_custom_msg"
android:labelFor=
"@id/custom_url"
app:hintEnabled=
"true"
>
android:text=
"@string/settings_update_custom_msg"
android:textAppearance=
"?android:attr/textAppearanceMedium"
<com.google.android.material.textfield.TextInputEditText
android:textColor=
"?android:textColorPrimary"
/>
android:id=
"@+id/custom_url"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:inputType=
"textUri"
/>
</com.google.android.material.textfield.TextInputLayout>
<EditText
android:id=
"@+id/custom_url"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:inputType=
"textUri"
/>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
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