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
64c363ce
Commit
64c363ce
authored
Nov 08, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update repo download progress report
parent
cca4347b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
27 deletions
+39
-27
ProcessRepoZip.java
...main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java
+23
-26
InputStreamWrapper.java
...va/com/topjohnwu/magisk/container/InputStreamWrapper.java
+16
-1
No files found.
app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java
View file @
64c363ce
...
...
@@ -6,6 +6,7 @@ import android.app.ProgressDialog;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Environment
;
import
android.os.Handler
;
import
android.support.annotation.NonNull
;
import
android.widget.Toast
;
...
...
@@ -39,15 +40,14 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
private
String
mLink
;
private
File
mFile
;
private
int
progress
=
0
,
total
=
-
1
;
private
static
final
int
UPDATE_DL_PROG
=
0
;
private
static
final
int
SHOW_PROCESSING
=
1
;
private
Handler
mHandler
;
public
ProcessRepoZip
(
Activity
context
,
String
link
,
String
filename
,
boolean
install
)
{
super
(
context
);
mLink
=
link
;
mFile
=
new
File
(
Environment
.
getExternalStorageDirectory
()
+
"/MagiskManager"
,
filename
);
mInstall
=
install
;
mHandler
=
new
Handler
();
}
private
void
removeTopFolder
(
InputStream
in
,
File
output
)
throws
IOException
{
...
...
@@ -81,28 +81,11 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
progressDialog
=
ProgressDialog
.
show
(
activity
,
activity
.
getString
(
R
.
string
.
zip_download_title
),
activity
.
getString
(
R
.
string
.
zip_download_msg
,
0
));
}
@Override
protected
void
onProgressUpdate
(
Object
...
values
)
{
int
mode
=
(
int
)
values
[
0
];
switch
(
mode
)
{
case
UPDATE_DL_PROG:
int
add
=
(
int
)
values
[
1
];
progress
+=
add
;
progressDialog
.
setMessage
(
getActivity
().
getString
(
R
.
string
.
zip_download_msg
,
100
*
progress
/
total
));
break
;
case
SHOW_PROCESSING:
progressDialog
.
setTitle
(
R
.
string
.
zip_process_title
);
progressDialog
.
setMessage
(
getActivity
().
getString
(
R
.
string
.
zip_process_msg
));
break
;
}
}
@Override
protected
Boolean
doInBackground
(
Void
...
params
)
{
Activity
activity
=
getActivity
();
if
(
activity
==
null
)
return
null
;
try
{
// Request zip from Internet
HttpURLConnection
conn
;
do
{
...
...
@@ -126,7 +109,10 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
removeTopFolder
(
in
,
temp1
);
conn
.
disconnect
();
publishProgress
(
SHOW_PROCESSING
);
mHandler
.
post
(()
->
{
progressDialog
.
setTitle
(
R
.
string
.
zip_process_title
);
progressDialog
.
setMessage
(
getActivity
().
getString
(
R
.
string
.
zip_process_msg
));
});
// Then sign the zip for the first time, temp1 -> temp2
ZipUtils
.
signZip
(
temp1
,
temp2
,
false
);
...
...
@@ -138,7 +124,8 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
ZipUtils
.
signZip
(
temp1
,
temp2
,
true
);
// Write it to the target zip, temp2 -> file
try
(
OutputStream
out
=
new
BufferedOutputStream
(
new
FileOutputStream
(
mFile
));
try
(
OutputStream
out
=
new
BufferedOutputStream
(
new
FileOutputStream
(
mFile
));
InputStream
source
=
new
BufferedInputStream
(
new
FileInputStream
(
temp2
))
)
{
byte
[]
buffer
=
new
byte
[
4096
];
...
...
@@ -191,10 +178,18 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
super
(
in
);
}
private
void
updateDlProgress
(
int
step
)
{
progress
+=
step
;
progressDialog
.
setMessage
(
getActivity
().
getString
(
R
.
string
.
zip_download_msg
,
100
*
progress
/
total
));
}
@Override
public
synchronized
int
read
()
throws
IOException
{
publishProgress
(
UPDATE_DL_PROG
,
1
);
return
super
.
read
();
int
b
=
super
.
read
();
if
(
b
>
0
)
{
mHandler
.
post
(()
->
updateDlProgress
(
1
));
}
return
b
;
}
@Override
...
...
@@ -205,7 +200,9 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
@Override
public
synchronized
int
read
(
@NonNull
byte
[]
b
,
int
off
,
int
len
)
throws
IOException
{
int
read
=
super
.
read
(
b
,
off
,
len
);
publishProgress
(
UPDATE_DL_PROG
,
read
);
if
(
read
>
0
)
{
mHandler
.
post
(()
->
updateDlProgress
(
read
));
}
return
read
;
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/container/InputStreamWrapper.java
View file @
64c363ce
...
...
@@ -39,7 +39,7 @@ public class InputStreamWrapper extends InputStream {
@Override
public
int
read
(
@NonNull
byte
[]
b
)
throws
IOException
{
return
read
(
b
,
0
,
b
.
length
);
return
in
.
read
(
b
);
}
@Override
...
...
@@ -56,4 +56,19 @@ public class InputStreamWrapper extends InputStream {
public
long
skip
(
long
n
)
throws
IOException
{
return
in
.
skip
(
n
);
}
@Override
public
int
hashCode
()
{
return
in
.
hashCode
();
}
@Override
public
boolean
equals
(
Object
obj
)
{
return
in
.
equals
(
obj
);
}
@Override
public
String
toString
()
{
return
in
.
toString
();
}
}
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