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
3b207471
Commit
3b207471
authored
Nov 23, 2016
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update progress dialog
parent
403e30fe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
65 deletions
+46
-65
ReposAdapter.java
...main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java
+31
-29
Async.java
app/src/main/java/com/topjohnwu/magisk/utils/Async.java
+14
-36
strings.xml
app/src/main/res/values/strings.xml
+1
-0
No files found.
app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java
View file @
3b207471
...
@@ -105,36 +105,38 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
...
@@ -105,36 +105,38 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
new
DownloadReceiver
()
{
new
DownloadReceiver
()
{
@Override
@Override
public
void
task
(
Uri
uri
)
{
public
void
task
(
Uri
uri
)
{
// Process and sign the zip
try
{
ByteArrayOutputStream
outBuffer
=
new
ByteArrayOutputStream
();
ByteArrayInputStream
inBuffer
;
// First remove top folder (the folder with the repo name) in Github source zip
ZipUtils
.
removeTopFolder
(
mContext
.
getContentResolver
().
openInputStream
(
uri
),
outBuffer
);
inBuffer
=
new
ByteArrayInputStream
(
outBuffer
.
toByteArray
());
outBuffer
.
reset
();
// Then sign the zip for the first time
ZipUtils
.
signZip
(
mContext
,
inBuffer
,
outBuffer
,
false
);
// Call zipadjust through JNI
inBuffer
=
new
ByteArrayInputStream
(
ZipUtils
.
zipAdjust
(
outBuffer
.
toByteArray
(),
outBuffer
.
size
()));
outBuffer
.
reset
();
// Finally, sign the whole zip file again
ZipUtils
.
signZip
(
mContext
,
inBuffer
,
outBuffer
,
true
);
// Write it back to the downloaded zip
OutputStream
out
=
mContext
.
getContentResolver
().
openOutputStream
(
uri
);
outBuffer
.
writeTo
(
out
);
out
.
close
();
}
catch
(
IOException
e
)
{
return
;
}
// Flash the zip
// Flash the zip
new
Async
.
FlashZIP
(
mContext
,
uri
,
mFilename
).
exec
();
new
Async
.
FlashZIP
(
mContext
,
uri
,
mFilename
){
@Override
protected
void
preProcessing
()
throws
Throwable
{
// Process and sign the zip
publishProgress
(
mContext
.
getString
(
R
.
string
.
zip_install_process_zip_msg
));
try
{
ByteArrayOutputStream
outBuffer
=
new
ByteArrayOutputStream
();
ByteArrayInputStream
inBuffer
;
// First remove top folder (the folder with the repo name) in Github source zip
ZipUtils
.
removeTopFolder
(
mContext
.
getContentResolver
().
openInputStream
(
mUri
),
outBuffer
);
inBuffer
=
new
ByteArrayInputStream
(
outBuffer
.
toByteArray
());
outBuffer
.
reset
();
// Then sign the zip for the first time
ZipUtils
.
signZip
(
mContext
,
inBuffer
,
outBuffer
,
false
);
// Call zipadjust through JNI
inBuffer
=
new
ByteArrayInputStream
(
ZipUtils
.
zipAdjust
(
outBuffer
.
toByteArray
(),
outBuffer
.
size
()));
outBuffer
.
reset
();
// Finally, sign the whole zip file again
ZipUtils
.
signZip
(
mContext
,
inBuffer
,
outBuffer
,
true
);
// Write it back to the downloaded zip
OutputStream
out
=
mContext
.
getContentResolver
().
openOutputStream
(
mUri
);
outBuffer
.
writeTo
(
out
);
out
.
close
();
}
catch
(
IOException
ignored
)
{}
}
}.
exec
();
}
}
},
},
repo
.
getZipUrl
(),
repo
.
getZipUrl
(),
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Async.java
View file @
3b207471
...
@@ -167,25 +167,25 @@ public class Async {
...
@@ -167,25 +167,25 @@ public class Async {
}
}
}
}
public
static
class
FlashZIP
extends
RootTask
<
Void
,
Void
,
Integer
>
{
public
static
class
FlashZIP
extends
RootTask
<
Void
,
String
,
Integer
>
{
protected
Uri
mUri
;
protected
Uri
mUri
;
protected
File
mCachedFile
,
sdFile
;
protected
File
mCachedFile
;
private
String
mFilename
;
private
String
mFilename
;
pr
ivate
ProgressDialog
progress
;
pr
otected
ProgressDialog
progress
;
private
Context
mContext
;
private
Context
mContext
;
private
boolean
copyToSD
;
public
FlashZIP
(
Context
context
,
Uri
uri
,
String
filename
)
{
public
FlashZIP
(
Context
context
,
Uri
uri
,
String
filename
)
{
mContext
=
context
;
mContext
=
context
;
mUri
=
uri
;
mUri
=
uri
;
mFilename
=
filename
;
mFilename
=
filename
;
copyToSD
=
true
;
progress
=
new
ProgressDialog
(
mContext
)
;
}
}
public
FlashZIP
(
Context
context
,
Uri
uri
)
{
public
FlashZIP
(
Context
context
,
Uri
uri
)
{
mContext
=
context
;
mContext
=
context
;
mUri
=
uri
;
mUri
=
uri
;
progress
=
new
ProgressDialog
(
mContext
);
Cursor
c
=
mContext
.
getContentResolver
().
query
(
uri
,
null
,
null
,
null
,
null
);
Cursor
c
=
mContext
.
getContentResolver
().
query
(
uri
,
null
,
null
,
null
,
null
);
if
(
c
!=
null
)
{
if
(
c
!=
null
)
{
int
nameIndex
=
c
.
getColumnIndex
(
OpenableColumns
.
DISPLAY_NAME
);
int
nameIndex
=
c
.
getColumnIndex
(
OpenableColumns
.
DISPLAY_NAME
);
...
@@ -199,7 +199,6 @@ public class Async {
...
@@ -199,7 +199,6 @@ public class Async {
int
idx
=
uri
.
getPath
().
lastIndexOf
(
'/'
);
int
idx
=
uri
.
getPath
().
lastIndexOf
(
'/'
);
mFilename
=
uri
.
getPath
().
substring
(
idx
+
1
);
mFilename
=
uri
.
getPath
().
substring
(
idx
+
1
);
}
}
copyToSD
=
false
;
}
}
private
void
createFileFromInputStream
(
InputStream
inputStream
,
File
file
)
throws
IOException
{
private
void
createFileFromInputStream
(
InputStream
inputStream
,
File
file
)
throws
IOException
{
...
@@ -240,7 +239,13 @@ public class Async {
...
@@ -240,7 +239,13 @@ public class Async {
@Override
@Override
protected
void
onPreExecute
()
{
protected
void
onPreExecute
()
{
progress
=
ProgressDialog
.
show
(
mContext
,
mContext
.
getString
(
R
.
string
.
zip_install_progress_title
),
mContext
.
getString
(
R
.
string
.
zip_install_progress_msg
,
mFilename
));
progress
.
setTitle
(
R
.
string
.
zip_install_progress_title
);
progress
.
show
();
}
@Override
protected
void
onProgressUpdate
(
String
...
values
)
{
progress
.
setMessage
(
values
[
0
]);
}
}
@Override
@Override
...
@@ -251,11 +256,10 @@ public class Async {
...
@@ -251,11 +256,10 @@ public class Async {
preProcessing
();
preProcessing
();
copyToCache
();
copyToCache
();
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
this
.
cancel
(
true
);
progress
.
cancel
();
e
.
printStackTrace
();
e
.
printStackTrace
();
return
-
1
;
return
-
1
;
}
}
publishProgress
(
mContext
.
getString
(
R
.
string
.
zip_install_progress_msg
,
mFilename
));
if
(
Shell
.
rootAccess
())
{
if
(
Shell
.
rootAccess
())
{
ret
=
Shell
.
su
(
ret
=
Shell
.
su
(
"unzip -o "
+
mCachedFile
.
getPath
()
+
" META-INF/com/google/android/* -d "
+
mCachedFile
.
getParent
(),
"unzip -o "
+
mCachedFile
.
getPath
()
+
" META-INF/com/google/android/* -d "
+
mCachedFile
.
getParent
(),
...
@@ -274,28 +278,6 @@ public class Async {
...
@@ -274,28 +278,6 @@ public class Async {
Logger
.
dev
(
line
);
Logger
.
dev
(
line
);
}
}
}
}
// Copy the file to sdcard
if
(
copyToSD
&&
mCachedFile
!=
null
)
{
String
filename
=
Utils
.
getLegalFilename
(
mFilename
.
contains
(
".zip"
)
?
mFilename
:
mFilename
+
".zip"
);
sdFile
=
new
File
(
Environment
.
getExternalStorageDirectory
()
+
"/MagiskManager/"
+
filename
);
Logger
.
dev
(
"FlashZip: Copy zip back to "
+
sdFile
.
getPath
());
if
((!
sdFile
.
getParentFile
().
exists
()
&&
!
sdFile
.
getParentFile
().
mkdirs
())
||
(
sdFile
.
exists
()
&&
!
sdFile
.
delete
()))
{
sdFile
=
null
;
}
else
{
try
{
FileInputStream
in
=
new
FileInputStream
(
mCachedFile
);
createFileFromInputStream
(
in
,
sdFile
);
in
.
close
();
}
catch
(
IOException
e
)
{
// Use the badass way :)
e
.
printStackTrace
();
Shell
.
su
(
"cp -af "
+
mCachedFile
.
getPath
()
+
" "
+
sdFile
.
getPath
());
if
(!
sdFile
.
exists
())
{
sdFile
=
null
;
}
}
}
}
if
(
mCachedFile
!=
null
&&
mCachedFile
.
exists
()
&&
!
mCachedFile
.
delete
())
{
if
(
mCachedFile
!=
null
&&
mCachedFile
.
exists
()
&&
!
mCachedFile
.
delete
())
{
Utils
.
removeItem
(
mCachedFile
.
getPath
());
Utils
.
removeItem
(
mCachedFile
.
getPath
());
}
}
...
@@ -312,11 +294,7 @@ public class Async {
...
@@ -312,11 +294,7 @@ public class Async {
progress
.
dismiss
();
progress
.
dismiss
();
switch
(
result
)
{
switch
(
result
)
{
case
-
1
:
case
-
1
:
if
(
sdFile
==
null
)
{
Toast
.
makeText
(
mContext
,
mContext
.
getString
(
R
.
string
.
manual_install
,
mUri
.
getPath
()),
Toast
.
LENGTH_LONG
).
show
();
Toast
.
makeText
(
mContext
,
mContext
.
getString
(
R
.
string
.
install_error
),
Toast
.
LENGTH_LONG
).
show
();
}
else
{
Toast
.
makeText
(
mContext
,
mContext
.
getString
(
R
.
string
.
manual_install
,
sdFile
.
getAbsolutePath
()),
Toast
.
LENGTH_LONG
).
show
();
}
break
;
break
;
case
0
:
case
0
:
Toast
.
makeText
(
mContext
,
mContext
.
getString
(
R
.
string
.
invalid_zip
),
Toast
.
LENGTH_LONG
).
show
();
Toast
.
makeText
(
mContext
,
mContext
.
getString
(
R
.
string
.
invalid_zip
),
Toast
.
LENGTH_LONG
).
show
();
...
...
app/src/main/res/values/strings.xml
View file @
3b207471
...
@@ -78,6 +78,7 @@
...
@@ -78,6 +78,7 @@
<string
name=
"reboot_msg"
>
Do you want to reboot now?
</string>
<string
name=
"reboot_msg"
>
Do you want to reboot now?
</string>
<string
name=
"reboot"
>
Reboot
</string>
<string
name=
"reboot"
>
Reboot
</string>
<string
name=
"zip_install_progress_title"
>
Installing
</string>
<string
name=
"zip_install_progress_title"
>
Installing
</string>
<string
name=
"zip_install_process_zip_msg"
>
Processing zip file ...
</string>
<string
name=
"zip_install_progress_msg"
>
"Installing %1$s …"
</string>
<string
name=
"zip_install_progress_msg"
>
"Installing %1$s …"
</string>
<string
name=
"no_magisk_title"
>
No Magisk Installed!
</string>
<string
name=
"no_magisk_title"
>
No Magisk Installed!
</string>
<string
name=
"no_magisk_msg"
>
Do you want to download and install Magisk?
</string>
<string
name=
"no_magisk_msg"
>
Do you want to download and install Magisk?
</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