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
6fb032b3
Commit
6fb032b3
authored
Jul 21, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean ups
parent
8ca188f4
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
66 additions
and
43 deletions
+66
-43
Config.kt
app/src/main/java/com/topjohnwu/magisk/Config.kt
+18
-12
Info.java
app/src/main/java/com/topjohnwu/magisk/Info.java
+1
-0
MagiskRepository.kt
.../com/topjohnwu/magisk/data/repository/MagiskRepository.kt
+0
-24
Patching.kt
...rc/main/java/com/topjohnwu/magisk/model/flash/Patching.kt
+1
-1
MagiskInstaller.java
...main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java
+4
-4
ProgInputStream.kt
...c/main/java/com/topjohnwu/magisk/utils/ProgInputStream.kt
+35
-0
EnvFixDialog.kt
...in/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.kt
+7
-2
No files found.
app/src/main/java/com/topjohnwu/magisk/Config.kt
View file @
6fb032b3
package
com.topjohnwu.magisk
import
android.content.Context
import
android.content.SharedPreferences
import
android.util.Xml
import
androidx.core.content.edit
import
com.topjohnwu.magisk.data.database.SettingsDao
...
...
@@ -137,6 +138,22 @@ object Config : PreferenceModel, DBConfig {
}
fun
initialize
()
=
prefs
.
edit
{
parsePrefs
(
this
)
if
(!
prefs
.
contains
(
Key
.
UPDATE_CHANNEL
))
putString
(
Key
.
UPDATE_CHANNEL
,
defaultChannel
.
toString
())
// Get actual state
putBoolean
(
Key
.
COREONLY
,
Const
.
MAGISK_DISABLE_FILE
.
exists
())
// Write database configs
putString
(
Key
.
ROOT_ACCESS
,
rootMode
.
toString
())
putString
(
Key
.
SU_MNT_NS
,
suMntNamespaceMode
.
toString
())
putString
(
Key
.
SU_MULTIUSER_MODE
,
suMultiuserMode
.
toString
())
putBoolean
(
Key
.
SU_FINGERPRINT
,
FingerprintHelper
.
useFingerprint
())
}
private
fun
parsePrefs
(
editor
:
SharedPreferences
.
Editor
)
=
editor
.
apply
{
val
config
=
SuFile
.
open
(
"/data/adb"
,
Const
.
MANAGER_CONFIGS
)
if
(
config
.
exists
())
runCatching
{
val
input
=
SuFileInputStream
(
config
).
buffered
()
...
...
@@ -184,19 +201,8 @@ object Config : PreferenceModel, DBConfig {
}
}
config
.
delete
()
remove
(
Key
.
ETAG_KEY
)
}
remove
(
Key
.
ETAG_KEY
)
if
(!
prefs
.
contains
(
Key
.
UPDATE_CHANNEL
))
putString
(
Key
.
UPDATE_CHANNEL
,
defaultChannel
.
toString
())
// Get actual state
putBoolean
(
Key
.
COREONLY
,
Const
.
MAGISK_DISABLE_FILE
.
exists
())
// Write database configs
putString
(
Key
.
ROOT_ACCESS
,
rootMode
.
toString
())
putString
(
Key
.
SU_MNT_NS
,
suMntNamespaceMode
.
toString
())
putString
(
Key
.
SU_MULTIUSER_MODE
,
suMultiuserMode
.
toString
())
putBoolean
(
Key
.
SU_FINGERPRINT
,
FingerprintHelper
.
useFingerprint
())
}
@JvmStatic
...
...
app/src/main/java/com/topjohnwu/magisk/Info.java
View file @
6fb032b3
...
...
@@ -13,6 +13,7 @@ public final class Info {
@NonNull
public
static
String
magiskVersionString
=
""
;
@NonNull
public
static
UpdateInfo
remote
=
new
UpdateInfo
();
public
static
boolean
keepVerity
=
false
;
...
...
app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt
View file @
6fb032b3
...
...
@@ -12,7 +12,6 @@ import com.topjohnwu.magisk.model.entity.HideTarget
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.inject
import
com.topjohnwu.magisk.utils.toSingle
import
com.topjohnwu.magisk.utils.writeToCachedFile
import
com.topjohnwu.superuser.Shell
import
io.reactivex.Single
...
...
@@ -22,25 +21,8 @@ class MagiskRepository(
private
val
packageManager
:
PackageManager
)
{
fun
fetchMagisk
()
=
fetchUpdate
()
.
flatMap
{
apiRaw
.
fetchFile
(
it
.
magisk
.
link
)
}
.
map
{
it
.
writeToCachedFile
(
context
,
FILE_MAGISK_ZIP
)
}
fun
fetchManager
()
=
fetchUpdate
()
.
flatMap
{
apiRaw
.
fetchFile
(
it
.
app
.
link
)
}
.
map
{
it
.
writeToCachedFile
(
context
,
FILE_MAGISK_APK
)
}
fun
fetchUninstaller
()
=
fetchUpdate
()
.
flatMap
{
apiRaw
.
fetchFile
(
it
.
uninstaller
.
link
)
}
.
map
{
it
.
writeToCachedFile
(
context
,
FILE_UNINSTALLER_ZIP
)
}
fun
fetchSafetynet
()
=
apiRaw
.
fetchSafetynet
()
fun
fetchBootctl
()
=
apiRaw
.
fetchBootctl
()
.
map
{
it
.
writeToCachedFile
(
context
,
FILE_BOOTCTL_SH
)
}
fun
fetchUpdate
()
=
when
(
Config
.
updateChannel
)
{
Config
.
Value
.
DEFAULT_CHANNEL
,
Config
.
Value
.
STABLE_CHANNEL
->
apiRaw
.
fetchStableUpdate
()
Config
.
Value
.
BETA_CHANNEL
->
apiRaw
.
fetchBetaUpdate
()
...
...
@@ -83,12 +65,6 @@ class MagiskRepository(
private
val
Boolean
.
state
get
()
=
if
(
this
)
"add"
else
"rm"
companion
object
{
const
val
FILE_MAGISK_ZIP
=
"magisk.zip"
const
val
FILE_MAGISK_APK
=
"magisk.apk"
const
val
FILE_UNINSTALLER_ZIP
=
"uninstaller.zip"
const
val
FILE_SAFETY_NET_APK
=
"safetynet.apk"
const
val
FILE_BOOTCTL_SH
=
"bootctl"
private
val
blacklist
=
listOf
(
let
{
val
app
:
App
by
inject
();
app
}.
packageName
,
"android"
,
...
...
app/src/main/java/com/topjohnwu/magisk/model/flash/Patching.kt
View file @
6fb032b3
...
...
@@ -9,7 +9,7 @@ sealed class Patching(
private
val
console
:
MutableList
<
String
>,
logs
:
MutableList
<
String
>,
private
val
resultListener
:
FlashResultListener
)
:
MagiskInstaller
(
console
,
logs
)
{
)
:
MagiskInstaller
(
file
,
console
,
logs
)
{
override
fun
onResult
(
success
:
Boolean
)
{
if
(
success
)
{
...
...
app/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java
View file @
6fb032b3
...
...
@@ -29,7 +29,6 @@ import org.kamranzafar.jtar.TarOutputStream;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
...
...
@@ -45,7 +44,7 @@ public abstract class MagiskInstaller {
protected
String
srcBoot
;
protected
File
destFile
;
protected
File
installDir
;
protected
File
zipFile
=
new
File
(
App
.
self
.
getCacheDir
(),
"magisk.zip"
)
;
protected
Uri
zipUri
;
private
final
List
<
String
>
console
;
private
final
List
<
String
>
logs
;
...
...
@@ -56,9 +55,10 @@ public abstract class MagiskInstaller {
logs
=
NOPList
.
getInstance
();
}
public
MagiskInstaller
(
List
<
String
>
out
,
List
<
String
>
err
)
{
public
MagiskInstaller
(
Uri
zip
,
List
<
String
>
out
,
List
<
String
>
err
)
{
console
=
out
;
logs
=
err
;
zipUri
=
zip
;
installDir
=
new
File
(
App
.
deContext
.
getFilesDir
().
getParent
(),
"install"
);
Shell
.
sh
(
"rm -rf "
+
installDir
).
exec
();
installDir
.
mkdirs
();
...
...
@@ -105,7 +105,7 @@ public abstract class MagiskInstaller {
try
{
ZipInputStream
zi
=
new
ZipInputStream
(
new
BufferedInputStream
(
new
FileInputStream
(
zipFile
),
(
int
)
zipFile
.
length
(
)));
App
.
self
.
getContentResolver
().
openInputStream
(
zipUri
)));
ZipEntry
ze
;
while
((
ze
=
zi
.
getNextEntry
())
!=
null
)
{
if
(
ze
.
isDirectory
())
...
...
app/src/main/java/com/topjohnwu/magisk/utils/
XNetwork
.kt
→
app/src/main/java/com/topjohnwu/magisk/utils/
ProgInputStream
.kt
View file @
6fb032b3
package
com.topjohnwu.magisk.utils
import
android.content.Context
import
com.topjohnwu.superuser.internal.UiThreadHandler
import
okhttp3.ResponseBody
import
java.io.File
import
java.io.FilterInputStream
import
java.io.InputStream
import
java.io.OutputStream
inline
fun
ResponseBody
.
writeToCachedFile
(
context
:
Context
,
fileName
:
String
,
progress
:
(
Long
)
->
Unit
=
{}
):
File
=
byteStream
().
writeToCachedFile
(
context
,
fileName
,
progress
)
class
ProgInputStream
(
base
:
InputStream
,
val
progressEmitter
:
(
Long
)
->
Unit
=
{}
)
:
FilterInputStream
(
base
)
{
inline
fun
InputStream
.
writeToCachedFile
(
context
:
Context
,
fileName
:
String
,
progress
:
(
Long
)
->
Unit
=
{}
)
=
context
.
cachedFile
(
fileName
).
apply
{
writeToFile
(
this
,
progress
)
}
inline
fun
InputStream
.
writeToFile
(
file
:
File
,
progress
:
(
Long
)
->
Unit
=
{})
=
file
.
apply
{
writeTo
(
file
.
outputStream
(),
progress
)
}
inline
fun
InputStream
.
writeTo
(
output
:
OutputStream
,
progress
:
(
Long
)
->
Unit
=
{})
{
withStreams
(
this
,
output
)
{
inStream
,
outStream
->
inStream
.
copyToWithProgress
(
outStream
,
progress
)
}
}
fun
ResponseBody
.
writeToString
()
=
string
()
inline
fun
InputStream
.
copyToWithProgress
(
out
:
OutputStream
,
progressEmitter
:
(
Long
)
->
Unit
,
bufferSize
:
Int
=
DEFAULT_BUFFER_SIZE
):
Long
{
var
bytesCopied
:
Long
=
0
val
buffer
=
ByteArray
(
bufferSize
)
var
bytes
=
read
(
buffer
)
while
(
bytes
>=
0
)
{
out
.
write
(
buffer
,
0
,
bytes
)
bytesCopied
+=
bytes
bytes
=
read
(
buffer
)
progressEmitter
(
bytesCopied
)
}
return
bytesCopied
}
class
ProgInputStream
(
base
:
InputStream
,
val
progressEmitter
:
(
Long
)
->
Unit
=
{})
:
FilterInputStream
(
base
)
{
private
var
bytesRead
:
Long
=
0
private
var
bytesRead
=
0L
override
fun
read
():
Int
{
val
b
=
read
()
...
...
app/src/main/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.kt
View file @
6fb032b3
...
...
@@ -3,16 +3,19 @@ package com.topjohnwu.magisk.view.dialogs
import
android.app.Activity
import
android.app.ProgressDialog
import
android.widget.Toast
import
androidx.core.net.toUri
import
com.topjohnwu.magisk.Info
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.tasks.MagiskInstaller
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.cachedFile
import
com.topjohnwu.magisk.utils.reboot
import
com.topjohnwu.net.Networking
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.ShellUtils
import
com.topjohnwu.superuser.internal.UiThreadHandler
import
com.topjohnwu.superuser.io.SuFile
import
java.io.File
class
EnvFixDialog
(
activity
:
Activity
)
:
CustomAlertDialog
(
activity
)
{
...
...
@@ -28,8 +31,10 @@ class EnvFixDialog(activity: Activity) : CustomAlertDialog(activity) {
override
fun
operations
():
Boolean
{
installDir
=
SuFile
(
"/data/adb/magisk"
)
Shell
.
su
(
"rm -rf /data/adb/magisk/*"
).
exec
()
if
(!
ShellUtils
.
checkSum
(
"MD5"
,
zipFile
,
Info
.
remote
.
magisk
.
hash
))
Networking
.
get
(
Info
.
remote
.
magisk
.
link
).
execForFile
(
zipFile
)
val
zip
:
File
=
activity
.
cachedFile
(
"magisk.zip"
)
if
(!
ShellUtils
.
checkSum
(
"MD5"
,
zip
,
Info
.
remote
.
magisk
.
hash
))
Networking
.
get
(
Info
.
remote
.
magisk
.
link
).
execForFile
(
zip
)
zipUri
=
zip
.
toUri
()
return
extractZip
()
&&
Shell
.
su
(
"fix_env"
).
exec
().
isSuccess
}
...
...
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