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
0ec47319
Commit
0ec47319
authored
Sep 02, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update install Magisk method
parent
0bf09256
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
119 additions
and
49 deletions
+119
-49
FlashActivity.java
app/src/main/java/com/topjohnwu/magisk/FlashActivity.java
+30
-3
MagiskFragment.java
app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java
+15
-10
InstallMagisk.java
.../main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java
+72
-35
ZipUtils.java
app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java
+1
-1
strings.xml
app/src/main/res/values/strings.xml
+1
-0
No files found.
app/src/main/java/com/topjohnwu/magisk/FlashActivity.java
View file @
0ec47319
...
@@ -14,7 +14,7 @@ import android.widget.LinearLayout;
...
@@ -14,7 +14,7 @@ import android.widget.LinearLayout;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
com.topjohnwu.magisk.asyncs.FlashZip
;
import
com.topjohnwu.magisk.asyncs.FlashZip
;
import
com.topjohnwu.magisk.asyncs.
PatchBootImage
;
import
com.topjohnwu.magisk.asyncs.
InstallMagisk
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.utils.AdaptiveList
;
import
com.topjohnwu.magisk.utils.AdaptiveList
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Shell
;
...
@@ -28,9 +28,13 @@ import butterknife.OnClick;
...
@@ -28,9 +28,13 @@ import butterknife.OnClick;
public
class
FlashActivity
extends
Activity
{
public
class
FlashActivity
extends
Activity
{
public
static
final
String
SET_ACTION
=
"action"
;
public
static
final
String
SET_ACTION
=
"action"
;
public
static
final
String
SET_BOOT_URI
=
"boot_uri"
;
public
static
final
String
SET_BOOT
=
"boot"
;
public
static
final
String
SET_ENC
=
"enc"
;
public
static
final
String
SET_VERITY
=
"verity"
;
public
static
final
String
FLASH_ZIP
=
"flash"
;
public
static
final
String
FLASH_ZIP
=
"flash"
;
public
static
final
String
PATCH_BOOT
=
"patch"
;
public
static
final
String
PATCH_BOOT
=
"patch"
;
public
static
final
String
FLASH_MAGISK
=
"magisk"
;
@BindView
(
R
.
id
.
toolbar
)
Toolbar
toolbar
;
@BindView
(
R
.
id
.
toolbar
)
Toolbar
toolbar
;
@BindView
(
R
.
id
.
flash_logs
)
RecyclerView
flashLogs
;
@BindView
(
R
.
id
.
flash_logs
)
RecyclerView
flashLogs
;
...
@@ -68,6 +72,9 @@ public class FlashActivity extends Activity {
...
@@ -68,6 +72,9 @@ public class FlashActivity extends Activity {
Intent
intent
=
getIntent
();
Intent
intent
=
getIntent
();
Uri
uri
=
intent
.
getData
();
Uri
uri
=
intent
.
getData
();
boolean
keepEnc
=
intent
.
getBooleanExtra
(
SET_ENC
,
false
);
boolean
keepVerity
=
intent
.
getBooleanExtra
(
SET_VERITY
,
false
);
switch
(
getIntent
().
getStringExtra
(
SET_ACTION
))
{
switch
(
getIntent
().
getStringExtra
(
SET_ACTION
))
{
case
FLASH_ZIP:
case
FLASH_ZIP:
new
FlashZip
(
this
,
uri
,
rootShellOutput
)
new
FlashZip
(
this
,
uri
,
rootShellOutput
)
...
@@ -75,9 +82,29 @@ public class FlashActivity extends Activity {
...
@@ -75,9 +82,29 @@ public class FlashActivity extends Activity {
.
exec
();
.
exec
();
break
;
break
;
case
PATCH_BOOT:
case
PATCH_BOOT:
new
PatchBootImage
(
this
,
uri
,
intent
.
getParcelableExtra
(
SET_BOOT_URI
),
rootShellOutput
)
new
InstallMagisk
(
this
,
rootShellOutput
,
uri
,
keepEnc
,
keepVerity
,
(
Uri
)
intent
.
getParcelableExtra
(
SET_BOOT
)
)
.
setCallBack
(()
->
buttonPanel
.
setVisibility
(
View
.
VISIBLE
))
.
setCallBack
(()
->
buttonPanel
.
setVisibility
(
View
.
VISIBLE
))
.
exec
();
.
exec
();
break
;
case
FLASH_MAGISK:
String
boot
=
intent
.
getStringExtra
(
SET_BOOT
);
if
(
getApplicationContext
().
remoteMagiskVersionCode
<
1370
)
{
// Use legacy installation method
getShell
().
su_raw
(
"echo \"BOOTIMAGE="
+
boot
+
"\" > /dev/.magisk"
,
"echo \"KEEPFORCEENCRYPT="
+
keepEnc
+
"\" >> /dev/.magisk"
,
"echo \"KEEPVERITY="
+
keepVerity
+
"\" >> /dev/.magisk"
);
new
FlashZip
(
this
,
uri
,
rootShellOutput
)
.
setCallBack
(()
->
buttonPanel
.
setVisibility
(
View
.
VISIBLE
))
.
exec
();
}
else
{
// Use new installation method
new
InstallMagisk
(
this
,
rootShellOutput
,
uri
,
keepEnc
,
keepVerity
,
boot
)
.
setCallBack
(()
->
buttonPanel
.
setVisibility
(
View
.
VISIBLE
))
.
exec
();
}
break
;
}
}
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java
View file @
0ec47319
...
@@ -24,6 +24,7 @@ import android.widget.LinearLayout;
...
@@ -24,6 +24,7 @@ import android.widget.LinearLayout;
import
android.widget.ProgressBar
;
import
android.widget.ProgressBar
;
import
android.widget.Spinner
;
import
android.widget.Spinner
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.asyncs.CheckUpdates
;
import
com.topjohnwu.magisk.asyncs.CheckUpdates
;
import
com.topjohnwu.magisk.components.AlertDialogBuilder
;
import
com.topjohnwu.magisk.components.AlertDialogBuilder
;
...
@@ -150,6 +151,10 @@ public class MagiskFragment extends Fragment
...
@@ -150,6 +151,10 @@ public class MagiskFragment extends Fragment
DownloadReceiver
receiver
=
null
;
DownloadReceiver
receiver
=
null
;
switch
(
idx
)
{
switch
(
idx
)
{
case
1
:
case
1
:
if
(
magiskManager
.
remoteMagiskVersionCode
<
1370
)
{
magiskManager
.
toast
(
R
.
string
.
no_boot_file_patch_support
,
Toast
.
LENGTH_LONG
);
return
;
}
Intent
intent
=
new
Intent
(
Intent
.
ACTION_GET_CONTENT
);
Intent
intent
=
new
Intent
(
Intent
.
ACTION_GET_CONTENT
);
intent
.
setType
(
"*/*"
);
intent
.
setType
(
"*/*"
);
startActivityForResult
(
intent
,
SELECT_BOOT_IMG
);
startActivityForResult
(
intent
,
SELECT_BOOT_IMG
);
...
@@ -166,13 +171,12 @@ public class MagiskFragment extends Fragment
...
@@ -166,13 +171,12 @@ public class MagiskFragment extends Fragment
receiver
=
new
DownloadReceiver
()
{
receiver
=
new
DownloadReceiver
()
{
@Override
@Override
public
void
onDownloadDone
(
Uri
uri
)
{
public
void
onDownloadDone
(
Uri
uri
)
{
getShell
().
su_raw
(
"echo \"BOOTIMAGE="
+
boot
+
"\" > /dev/.magisk"
,
"echo \"KEEPFORCEENCRYPT="
+
keepEncChkbox
.
isChecked
()
+
"\" >> /dev/.magisk"
,
"echo \"KEEPVERITY="
+
keepVerityChkbox
.
isChecked
()
+
"\" >> /dev/.magisk"
);
Intent
intent
=
new
Intent
(
getActivity
(),
FlashActivity
.
class
);
Intent
intent
=
new
Intent
(
getActivity
(),
FlashActivity
.
class
);
intent
.
setData
(
uri
).
putExtra
(
FlashActivity
.
SET_ACTION
,
FlashActivity
.
FLASH_ZIP
);
intent
.
setData
(
uri
)
.
putExtra
(
FlashActivity
.
SET_BOOT
,
boot
)
.
putExtra
(
FlashActivity
.
SET_ENC
,
keepEncChkbox
.
isChecked
())
.
putExtra
(
FlashActivity
.
SET_VERITY
,
keepVerityChkbox
.
isChecked
())
.
putExtra
(
FlashActivity
.
SET_ACTION
,
FlashActivity
.
FLASH_MAGISK
);
startActivity
(
intent
);
startActivity
(
intent
);
}
}
};
};
...
@@ -304,10 +308,11 @@ public class MagiskFragment extends Fragment
...
@@ -304,10 +308,11 @@ public class MagiskFragment extends Fragment
new
DownloadReceiver
()
{
new
DownloadReceiver
()
{
@Override
@Override
public
void
onDownloadDone
(
Uri
uri
)
{
public
void
onDownloadDone
(
Uri
uri
)
{
// Get the URI of the selected file
Intent
intent
=
new
Intent
(
getActivity
(),
FlashActivity
.
class
);
Intent
intent
=
new
Intent
(
getActivity
(),
FlashActivity
.
class
);
intent
.
setData
(
uri
)
intent
.
setData
(
uri
)
.
putExtra
(
FlashActivity
.
SET_BOOT_URI
,
data
.
getData
())
.
putExtra
(
FlashActivity
.
SET_BOOT
,
data
.
getData
())
.
putExtra
(
FlashActivity
.
SET_ENC
,
keepEncChkbox
.
isChecked
())
.
putExtra
(
FlashActivity
.
SET_VERITY
,
keepVerityChkbox
.
isChecked
())
.
putExtra
(
FlashActivity
.
SET_ACTION
,
FlashActivity
.
PATCH_BOOT
);
.
putExtra
(
FlashActivity
.
SET_ACTION
,
FlashActivity
.
PATCH_BOOT
);
startActivity
(
intent
);
startActivity
(
intent
);
}
}
...
@@ -350,11 +355,11 @@ public class MagiskFragment extends Fragment
...
@@ -350,11 +355,11 @@ public class MagiskFragment extends Fragment
int
status
=
0
;
int
status
=
0
;
status
|=
Shell
.
rootAccess
()
?
ROOT
:
0
;
status
|=
Shell
.
rootAccess
()
?
ROOT
:
0
;
status
|=
Utils
.
checkNetworkStatus
(
magiskManager
)
?
NETWORK
:
0
;
status
|=
Utils
.
checkNetworkStatus
(
magiskManager
)
?
NETWORK
:
0
;
status
|=
magiskManager
.
magiskVersionCode
>=
130
?
UPTODATE
:
0
;
status
|=
magiskManager
.
magiskVersionCode
>=
130
0
?
UPTODATE
:
0
;
magiskUpdateCard
.
setVisibility
(
Utils
.
checkBits
(
status
,
NETWORK
)
?
View
.
VISIBLE
:
View
.
GONE
);
magiskUpdateCard
.
setVisibility
(
Utils
.
checkBits
(
status
,
NETWORK
)
?
View
.
VISIBLE
:
View
.
GONE
);
safetyNetCard
.
setVisibility
(
Utils
.
checkBits
(
status
,
NETWORK
)
?
View
.
VISIBLE
:
View
.
GONE
);
safetyNetCard
.
setVisibility
(
Utils
.
checkBits
(
status
,
NETWORK
)
?
View
.
VISIBLE
:
View
.
GONE
);
bootImageCard
.
setVisibility
(
Utils
.
checkBits
(
status
,
NETWORK
,
ROOT
)
?
View
.
VISIBLE
:
View
.
GONE
);
bootImageCard
.
setVisibility
(
Utils
.
checkBits
(
status
,
NETWORK
,
ROOT
)
?
View
.
VISIBLE
:
View
.
GONE
);
installOptionCard
.
setVisibility
(
Utils
.
checkBits
(
status
,
NETWORK
,
ROOT
)
?
View
.
VISIBLE
:
View
.
GONE
);
installOptionCard
.
setVisibility
(
Utils
.
checkBits
(
status
,
NETWORK
)
?
View
.
VISIBLE
:
View
.
GONE
);
installButton
.
setVisibility
(
Utils
.
checkBits
(
status
,
NETWORK
)
?
View
.
VISIBLE
:
View
.
GONE
);
installButton
.
setVisibility
(
Utils
.
checkBits
(
status
,
NETWORK
)
?
View
.
VISIBLE
:
View
.
GONE
);
uninstallButton
.
setVisibility
(
Utils
.
checkBits
(
status
,
UPTODATE
,
ROOT
)
?
View
.
VISIBLE
:
View
.
GONE
);
uninstallButton
.
setVisibility
(
Utils
.
checkBits
(
status
,
UPTODATE
,
ROOT
)
?
View
.
VISIBLE
:
View
.
GONE
);
...
...
app/src/main/java/com/topjohnwu/magisk/asyncs/
PatchBootImage
.java
→
app/src/main/java/com/topjohnwu/magisk/asyncs/
InstallMagisk
.java
View file @
0ec47319
...
@@ -20,18 +20,35 @@ import java.io.OutputStream;
...
@@ -20,18 +20,35 @@ import java.io.OutputStream;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
public
class
PatchBootImage
extends
ParallelTask
<
Void
,
Void
,
Boolean
>
{
public
class
InstallMagisk
extends
ParallelTask
<
Void
,
Void
,
Boolean
>
{
private
static
final
int
PATCH_MODE
=
0
;
private
static
final
int
DIRECT_MODE
=
1
;
private
Uri
mBootImg
,
mZip
;
private
Uri
mBootImg
,
mZip
;
private
AdaptiveList
<
String
>
mList
;
private
AdaptiveList
<
String
>
mList
;
private
File
dest
;
private
String
mBootLocation
;
private
boolean
mKeepEnc
,
mKeepVerity
;
private
int
mode
;
p
ublic
PatchBootImage
(
Activity
context
,
Uri
zip
,
Uri
boot
,
AdaptiveList
<
String
>
list
)
{
p
rivate
InstallMagisk
(
Activity
context
,
AdaptiveList
<
String
>
list
,
Uri
zip
,
boolean
enc
,
boolean
verity
)
{
super
(
context
);
super
(
context
);
mBootImg
=
boot
;
mList
=
list
;
mList
=
list
;
mZip
=
zip
;
mZip
=
zip
;
dest
=
new
File
(
Environment
.
getExternalStorageDirectory
()
+
"/MagiskManager/"
+
"patched_boot.img"
);
mKeepEnc
=
enc
;
mKeepVerity
=
verity
;
}
public
InstallMagisk
(
Activity
context
,
AdaptiveList
<
String
>
list
,
Uri
zip
,
boolean
enc
,
boolean
verity
,
Uri
boot
)
{
this
(
context
,
list
,
zip
,
enc
,
verity
);
mBootImg
=
boot
;
mode
=
PATCH_MODE
;
}
public
InstallMagisk
(
Activity
context
,
AdaptiveList
<
String
>
list
,
Uri
zip
,
boolean
enc
,
boolean
verity
,
String
boot
)
{
this
(
context
,
list
,
zip
,
enc
,
verity
);
mBootLocation
=
boot
;
mode
=
DIRECT_MODE
;
}
}
@Override
@Override
...
@@ -83,42 +100,69 @@ public class PatchBootImage extends ParallelTask<Void, Void, Boolean> {
...
@@ -83,42 +100,69 @@ public class PatchBootImage extends ParallelTask<Void, Void, Boolean> {
throw
e
;
throw
e
;
}
}
// Copy boot image
File
boot
;
File
boot
=
new
File
(
install
,
"boot.img"
);
switch
(
mode
)
{
try
(
case
PATCH_MODE:
InputStream
in
=
magiskManager
.
getContentResolver
().
openInputStream
(
mBootImg
);
boot
=
new
File
(
install
,
"boot.img"
);
OutputStream
out
=
new
FileOutputStream
(
boot
);
// Copy boot image to local
)
{
try
(
if
(
in
==
null
)
throw
new
FileNotFoundException
();
InputStream
in
=
magiskManager
.
getContentResolver
().
openInputStream
(
mBootImg
);
byte
buffer
[]
=
new
byte
[
1024
];
OutputStream
out
=
new
FileOutputStream
(
boot
);
int
length
;
)
{
while
((
length
=
in
.
read
(
buffer
))
>
0
)
if
(
in
==
null
)
throw
new
FileNotFoundException
();
out
.
write
(
buffer
,
0
,
length
);
byte
buffer
[]
=
new
byte
[
1024
];
}
catch
(
FileNotFoundException
e
)
{
int
length
;
mList
.
add
(
"! Invalid Uri"
);
while
((
length
=
in
.
read
(
buffer
))
>
0
)
throw
e
;
out
.
write
(
buffer
,
0
,
length
);
}
catch
(
IOException
e
)
{
}
catch
(
FileNotFoundException
e
)
{
mList
.
add
(
"! Copy failed"
);
mList
.
add
(
"! Invalid Uri"
);
throw
e
;
throw
e
;
}
catch
(
IOException
e
)
{
mList
.
add
(
"! Copy failed"
);
throw
e
;
}
break
;
case
DIRECT_MODE:
boot
=
new
File
(
mBootLocation
);
break
;
default
:
return
false
;
}
}
mList
.
add
(
"- Use boot image: "
+
boot
);
mList
.
add
(
"- Use boot image: "
+
boot
);
// Patch boot image
// Patch boot image
getShell
().
sh
(
mList
,
getShell
().
sh
(
mList
,
"chmod -R 755 "
+
install
,
"cd "
+
install
,
"cd "
+
install
,
"sh update-binary indep boot_patch.sh "
+
boot
+
"KEEPFORCEENCRYPT="
+
mKeepEnc
+
" KEEPVERITY="
+
mKeepVerity
+
" sh "
+
"update-binary indep boot_patch.sh "
+
boot
+
" 2>&1"
+
" && echo 'Success!' || echo 'Failed!'"
" && echo 'Success!' || echo 'Failed!'"
);
);
if
(!
TextUtils
.
equals
(
mList
.
get
(
mList
.
size
()
-
1
),
"Success!"
))
if
(!
TextUtils
.
equals
(
mList
.
get
(
mList
.
size
()
-
1
),
"Success!"
))
return
false
;
return
false
;
// Move boot image
File
patched_boot
=
new
File
(
install
,
"new-boot.img"
);
File
source
=
new
File
(
install
,
"new-boot.img"
);
mList
.
add
(
""
);
dest
.
getParentFile
().
mkdirs
();
switch
(
mode
)
{
getShell
().
sh_raw
(
"mv "
+
source
+
" "
+
dest
);
case
PATCH_MODE:
// Move boot image
File
dest
=
new
File
(
Environment
.
getExternalStorageDirectory
()
+
"/MagiskManager/"
+
"patched_boot.img"
);
dest
.
getParentFile
().
mkdirs
();
getShell
().
sh_raw
(
"cp "
+
patched_boot
+
" "
+
dest
);
mList
.
add
(
"*********************************"
);
mList
.
add
(
" Patched Boot Image is placed in "
);
mList
.
add
(
" "
+
dest
+
" "
);
mList
.
add
(
"*********************************"
);
break
;
case
DIRECT_MODE:
// Direct flash boot image
getShell
().
su_raw
(
"cat "
+
patched_boot
+
" /dev/zero | dd of="
+
mBootLocation
+
" bs=4096"
);
mList
.
add
(
"Flashing patched boot to "
+
mBootLocation
);
break
;
default
:
return
false
;
}
// Finals
// Finals
getShell
().
sh_raw
(
getShell
().
sh_raw
(
...
@@ -133,13 +177,6 @@ public class PatchBootImage extends ParallelTask<Void, Void, Boolean> {
...
@@ -133,13 +177,6 @@ public class PatchBootImage extends ParallelTask<Void, Void, Boolean> {
@Override
@Override
protected
void
onPostExecute
(
Boolean
result
)
{
protected
void
onPostExecute
(
Boolean
result
)
{
if
(
result
)
{
mList
.
add
(
""
);
mList
.
add
(
"*********************************"
);
mList
.
add
(
" Patched Boot Image is placed in "
);
mList
.
add
(
" "
+
dest
+
" "
);
mList
.
add
(
"*********************************"
);
}
super
.
onPostExecute
(
result
);
super
.
onPostExecute
(
result
);
}
}
}
}
app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java
View file @
0ec47319
...
@@ -157,7 +157,7 @@ public class ZipUtils {
...
@@ -157,7 +157,7 @@ public class ZipUtils {
}
}
public
static
void
unzip
(
File
zip
,
File
folder
,
String
path
,
boolean
junkPath
)
throws
Exception
{
public
static
void
unzip
(
File
zip
,
File
folder
,
String
path
,
boolean
junkPath
)
throws
Exception
{
JarInputStream
in
=
new
JarInputStream
(
new
FileInputStream
(
zip
)
);
InputStream
in
=
new
FileInputStream
(
zip
);
unzip
(
in
,
folder
,
path
,
junkPath
);
unzip
(
in
,
folder
,
path
,
junkPath
);
in
.
close
();
in
.
close
();
}
}
...
...
app/src/main/res/values/strings.xml
View file @
0ec47319
...
@@ -142,6 +142,7 @@
...
@@ -142,6 +142,7 @@
<string
name=
"patch_boot_file"
>
Patch Boot Image File
</string>
<string
name=
"patch_boot_file"
>
Patch Boot Image File
</string>
<string
name=
"direct_install"
>
Direct Install (Recommend)
</string>
<string
name=
"direct_install"
>
Direct Install (Recommend)
</string>
<string
name=
"select_method"
>
Select Method
</string>
<string
name=
"select_method"
>
Select Method
</string>
<string
name=
"no_boot_file_patch_support"
>
Target Magisk version doesn\'t support boot image file patching
</string>
<!--Settings Activity -->
<!--Settings Activity -->
<string
name=
"settings_general_category"
>
General
</string>
<string
name=
"settings_general_category"
>
General
</string>
...
...
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