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
926c7359
Commit
926c7359
authored
Sep 03, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge download and process repo modules
parent
ec0af99a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
49 deletions
+61
-49
ReposAdapter.java
...main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java
+7
-22
ProcessRepoZip.java
...main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java
+45
-22
ZipUtils.java
app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java
+6
-4
strings.xml
app/src/main/res/values/strings.xml
+3
-1
No files found.
app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java
View file @
926c7359
...
...
@@ -3,7 +3,6 @@ package com.topjohnwu.magisk.adapters;
import
android.app.Activity
;
import
android.content.Context
;
import
android.database.Cursor
;
import
android.net.Uri
;
import
android.support.v7.widget.RecyclerView
;
import
android.text.TextUtils
;
import
android.util.Pair
;
...
...
@@ -21,7 +20,6 @@ import com.topjohnwu.magisk.components.AlertDialogBuilder;
import
com.topjohnwu.magisk.database.RepoDatabaseHelper
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.module.Repo
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
com.topjohnwu.magisk.utils.Utils
;
import
java.util.ArrayList
;
...
...
@@ -106,26 +104,13 @@ public class ReposAdapter extends SectionedAdapter<ReposAdapter.SectionHolder, R
.
setTitle
(
context
.
getString
(
R
.
string
.
repo_install_title
,
repo
.
getName
()))
.
setMessage
(
context
.
getString
(
R
.
string
.
repo_install_msg
,
filename
))
.
setCancelable
(
true
)
.
setPositiveButton
(
R
.
string
.
install
,
(
d
,
i
)
->
Utils
.
dlAndReceive
(
context
,
new
DownloadReceiver
()
{
@Override
public
void
onDownloadDone
(
Uri
uri
)
{
new
ProcessRepoZip
((
Activity
)
context
,
uri
,
true
).
exec
();
}
},
repo
.
getZipUrl
(),
Utils
.
getLegalFilename
(
filename
)))
.
setNeutralButton
(
R
.
string
.
download
,
(
d
,
i
)
->
Utils
.
dlAndReceive
(
context
,
new
DownloadReceiver
()
{
@Override
public
void
onDownloadDone
(
Uri
uri
)
{
new
ProcessRepoZip
((
Activity
)
context
,
uri
,
false
).
exec
();
}
},
repo
.
getZipUrl
(),
Utils
.
getLegalFilename
(
filename
)))
.
setPositiveButton
(
R
.
string
.
install
,
(
d
,
i
)
->
new
ProcessRepoZip
((
Activity
)
context
,
repo
.
getZipUrl
(),
Utils
.
getLegalFilename
(
filename
),
true
).
exec
()
)
.
setNeutralButton
(
R
.
string
.
download
,
(
d
,
i
)
->
new
ProcessRepoZip
((
Activity
)
context
,
repo
.
getZipUrl
(),
Utils
.
getLegalFilename
(
filename
),
false
).
exec
())
.
setNegativeButton
(
R
.
string
.
no_thanks
,
null
)
.
show
();
});
...
...
app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java
View file @
926c7359
package
com
.
topjohnwu
.
magisk
.
asyncs
;
import
android.Manifest
;
import
android.app.Activity
;
import
android.app.ProgressDialog
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Environment
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.FlashActivity
;
...
...
@@ -11,32 +13,42 @@ import com.topjohnwu.magisk.R;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.WebService
;
import
com.topjohnwu.magisk.utils.ZipUtils
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
public
class
ProcessRepoZip
extends
ParallelTask
<
Void
,
Void
,
Boolean
>
{
private
Uri
mUri
;
private
ProgressDialog
progressDialog
;
private
boolean
mInstall
;
private
String
mLink
,
mFile
;
public
ProcessRepoZip
(
Activity
context
,
Uri
uri
,
boolean
install
)
{
public
ProcessRepoZip
(
Activity
context
,
String
link
,
String
filename
,
boolean
install
)
{
super
(
context
);
mUri
=
uri
;
mLink
=
link
;
mFile
=
Environment
.
getExternalStorageDirectory
()
+
"/MagiskManager/"
+
filename
;
mInstall
=
install
;
}
@Override
protected
void
onPreExecute
()
{
Activity
activity
=
getActivity
();
if
(
activity
==
null
)
return
;
progressDialog
=
ProgressDialog
.
show
(
activity
,
activity
.
getString
(
R
.
string
.
zip_process_title
),
activity
.
getString
(
R
.
string
.
zip_process_msg
));
activity
.
getString
(
R
.
string
.
zip_download_title
),
activity
.
getString
(
R
.
string
.
zip_download_msg
));
}
@Override
protected
void
onProgressUpdate
(
Void
...
values
)
{
progressDialog
.
setTitle
(
R
.
string
.
zip_process_title
);
progressDialog
.
setMessage
(
getActivity
().
getString
(
R
.
string
.
zip_process_msg
));
}
@Override
...
...
@@ -45,15 +57,20 @@ public class ProcessRepoZip extends ParallelTask<Void, Void, Boolean> {
if
(
activity
==
null
)
return
null
;
try
{
// Create temp file
// Request zip from Internet
InputStream
in
=
WebService
.
request
(
WebService
.
GET
,
mLink
,
null
);
if
(
in
==
null
)
return
false
;
in
=
new
BufferedInputStream
(
in
);
// Temp files
File
temp1
=
new
File
(
activity
.
getCacheDir
(),
"1.zip"
);
File
temp2
=
new
File
(
activity
.
getCacheDir
(),
"2.zip"
);
activity
.
getCacheDir
().
mkdirs
();
temp1
.
createNewFile
();
temp2
.
createNewFile
();
File
temp2
=
new
File
(
temp1
.
getParentFile
(),
"2.zip"
);
temp1
.
getParentFile
().
mkdir
();
// First remove top folder in Github source zip, Uri -> temp1
ZipUtils
.
removeTopFolder
(
activity
.
getContentResolver
().
openInputStream
(
mUri
),
temp1
);
// First remove top folder in Github source zip, Web -> temp1
ZipUtils
.
removeTopFolder
(
in
,
temp1
);
publishProgress
();
// Then sign the zip for the first time, temp1 -> temp2
ZipUtils
.
signZip
(
activity
,
temp1
,
temp2
,
false
);
...
...
@@ -64,18 +81,17 @@ public class ProcessRepoZip extends ParallelTask<Void, Void, Boolean> {
// Finally, sign the whole zip file again, temp1 -> temp2
ZipUtils
.
signZip
(
activity
,
temp1
,
temp2
,
true
);
// Write it
back to the downloaded zip, temp2 -> Uri
try
(
OutputStream
out
=
activity
.
getContentResolver
().
openOutputStream
(
mUri
);
FileInputStream
in
=
new
FileInputStream
(
temp2
)
// Write it
to the target zip, temp2 -> file
try
(
OutputStream
out
=
new
BufferedOutputStream
(
new
FileOutputStream
(
mFile
)
);
InputStream
source
=
new
BufferedInputStream
(
new
FileInputStream
(
temp2
)
)
)
{
byte
[]
buffer
=
new
byte
[
4096
];
int
length
;
if
(
out
==
null
)
throw
new
FileNotFoundException
();
while
((
length
=
in
.
read
(
buffer
))
>
0
)
while
((
length
=
source
.
read
(
buffer
))
>
0
)
out
.
write
(
buffer
,
0
,
length
);
}
// Delete t
he temp file
// Delete t
emp files
temp1
.
delete
();
temp2
.
delete
();
...
...
@@ -92,17 +108,24 @@ public class ProcessRepoZip extends ParallelTask<Void, Void, Boolean> {
Activity
activity
=
getActivity
();
if
(
activity
==
null
)
return
;
progressDialog
.
dismiss
();
Uri
uri
=
Uri
.
fromFile
(
new
File
(
mFile
));
if
(
result
)
{
if
(
Shell
.
rootAccess
()
&&
mInstall
)
{
Intent
intent
=
new
Intent
(
getActivity
(),
FlashActivity
.
class
);
intent
.
setData
(
mU
ri
).
putExtra
(
FlashActivity
.
SET_ACTION
,
FlashActivity
.
FLASH_ZIP
);
intent
.
setData
(
u
ri
).
putExtra
(
FlashActivity
.
SET_ACTION
,
FlashActivity
.
FLASH_ZIP
);
activity
.
startActivity
(
intent
);
}
else
{
Utils
.
showUriSnack
(
activity
,
mU
ri
);
Utils
.
showUriSnack
(
activity
,
u
ri
);
}
}
else
{
Utils
.
getMagiskManager
(
activity
).
toast
(
R
.
string
.
process_error
,
Toast
.
LENGTH_LONG
);
}
super
.
onPostExecute
(
result
);
}
@Override
public
ParallelTask
<
Void
,
Void
,
Boolean
>
exec
(
Void
...
voids
)
{
Utils
.
runWithPermission
(
getActivity
(),
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
()
->
super
.
exec
(
voids
));
return
this
;
}
}
app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java
View file @
926c7359
...
...
@@ -22,6 +22,8 @@ import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
import
org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder
;
import
org.bouncycastle.util.encoders.Base64
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
...
...
@@ -126,7 +128,7 @@ public class ZipUtils {
public
static
void
removeTopFolder
(
InputStream
in
,
File
output
)
throws
IOException
{
try
{
JarInputStream
source
=
new
JarInputStream
(
in
);
JarOutputStream
dest
=
new
JarOutputStream
(
new
FileOutputStream
(
output
));
JarOutputStream
dest
=
new
JarOutputStream
(
new
BufferedOutputStream
(
new
FileOutputStream
(
output
)
));
JarEntry
entry
;
String
path
;
int
size
;
...
...
@@ -157,7 +159,7 @@ public class ZipUtils {
}
public
static
void
unzip
(
File
zip
,
File
folder
,
String
path
,
boolean
junkPath
)
throws
Exception
{
InputStream
in
=
new
FileInputStream
(
zip
);
InputStream
in
=
new
BufferedInputStream
(
new
FileInputStream
(
zip
)
);
unzip
(
in
,
folder
,
path
,
junkPath
);
in
.
close
();
}
...
...
@@ -198,7 +200,7 @@ public class ZipUtils {
public
static
void
signZip
(
Context
context
,
File
input
,
File
output
,
boolean
minSign
)
{
int
alignment
=
4
;
JarFile
inputJar
=
null
;
File
OutputStream
outputFile
=
null
;
Buffered
OutputStream
outputFile
=
null
;
int
hashes
=
0
;
try
{
X509Certificate
publicKey
=
readPublicKey
(
context
.
getAssets
().
open
(
PUBLIC_KEY_NAME
));
...
...
@@ -210,7 +212,7 @@ public class ZipUtils {
long
timestamp
=
publicKey
.
getNotBefore
().
getTime
()
+
3600L
*
1000
;
PrivateKey
privateKey
=
readPrivateKey
(
context
.
getAssets
().
open
(
PRIVATE_KEY_NAME
));
outputFile
=
new
FileOutputStream
(
output
);
outputFile
=
new
BufferedOutputStream
(
new
FileOutputStream
(
output
)
);
if
(
minSign
)
{
ZipUtils
.
signWholeFile
(
input
,
publicKey
,
privateKey
,
outputFile
);
}
else
{
...
...
app/src/main/res/values/strings.xml
View file @
926c7359
...
...
@@ -114,7 +114,6 @@
<string
name=
"copying_msg"
>
Copying zip to temp directory
</string>
<string
name=
"zip_install_progress_title"
>
Installing
</string>
<string
name=
"zip_unzip_msg"
>
Unzipping zip file …
</string>
<string
name=
"zip_process_msg"
>
Processing zip file …
</string>
<string
name=
"zip_install_progress_msg"
>
Installing %1$s …
</string>
<string
name=
"no_magisk_title"
>
Magisk Is Not Installed!
</string>
<string
name=
"no_magisk_msg"
>
Do you want to download and install Magisk?
</string>
...
...
@@ -130,7 +129,10 @@
<string
name=
"understand"
>
I understand
</string>
<string
name=
"process_error"
>
Process error
</string>
<string
name=
"internal_storage"
>
The zip is stored in:\n[Internal Storage]%1$s
</string>
<string
name=
"zip_download_title"
>
Downloading
</string>
<string
name=
"zip_download_msg"
>
Downloading zip file …
</string>
<string
name=
"zip_process_title"
>
Processing
</string>
<string
name=
"zip_process_msg"
>
Processing zip file …
</string>
<string
name=
"manual_boot_image"
>
Please manually select a boot image!
</string>
<string
name=
"manager_update_title"
>
New Magisk Manager Update Available!
</string>
<string
name=
"manager_download_install"
>
Press to download and install
</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