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
7bd52d02
Commit
7bd52d02
authored
Jan 01, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update net module
parent
1df65940
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
81 additions
and
51 deletions
+81
-51
InstallMethodDialog.java
.../com/topjohnwu/magisk/components/InstallMethodDialog.java
+2
-2
UninstallDialog.java
...java/com/topjohnwu/magisk/components/UninstallDialog.java
+2
-2
DownloadApp.java
...src/full/java/com/topjohnwu/magisk/utils/DownloadApp.java
+9
-25
SafetyNet.java
core/src/main/java/com/topjohnwu/core/tasks/SafetyNet.java
+2
-2
BadRequest.java
net/src/main/java/com/topjohnwu/net/BadRequest.java
+51
-0
Networking.java
net/src/main/java/com/topjohnwu/net/Networking.java
+1
-1
ProgressInputStream.java
net/src/main/java/com/topjohnwu/net/ProgressInputStream.java
+5
-9
Request.java
net/src/main/java/com/topjohnwu/net/Request.java
+9
-10
No files found.
app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java
View file @
7bd52d02
...
...
@@ -71,12 +71,12 @@ class InstallMethodDialog extends AlertDialog.Builder {
Networking
.
get
(
Data
.
magiskLink
)
.
setDownloadProgressListener
(
progress
)
.
setErrorHandler
(((
conn
,
e
)
->
progress
.
dlFail
()))
.
getAsFile
(
f
->
{
.
getAsFile
(
zip
,
f
->
{
progress
.
dlDone
();
SnackbarMaker
.
make
(
a
,
a
.
getString
(
R
.
string
.
internal_storage
,
"/Download/"
+
filename
),
Snackbar
.
LENGTH_LONG
).
show
();
}
,
zip
);
});
});
}
...
...
app/src/full/java/com/topjohnwu/magisk/components/UninstallDialog.java
View file @
7bd52d02
...
...
@@ -46,14 +46,14 @@ public class UninstallDialog extends CustomAlertDialog {
Networking
.
get
(
Data
.
uninstallerLink
)
.
setDownloadProgressListener
(
progress
)
.
setErrorHandler
(((
conn
,
e
)
->
progress
.
dlFail
()))
.
getAsFile
(
f
->
{
.
getAsFile
(
zip
,
f
->
{
progress
.
dismiss
();
Intent
intent
=
new
Intent
(
activity
,
ClassMap
.
get
(
FlashActivity
.
class
))
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
)
.
setData
(
Uri
.
fromFile
(
f
))
.
putExtra
(
Const
.
Key
.
FLASH_ACTION
,
Const
.
Value
.
UNINSTALL
);
activity
.
startActivity
(
intent
);
}
,
zip
);
});
});
}
}
...
...
app/src/full/java/com/topjohnwu/magisk/utils/DownloadApp.java
View file @
7bd52d02
...
...
@@ -12,12 +12,8 @@ import com.topjohnwu.magisk.components.ProgressNotification;
import
com.topjohnwu.net.Networking
;
import
com.topjohnwu.net.ResponseListener
;
import
com.topjohnwu.superuser.ShellUtils
;
import
com.topjohnwu.utils.JarMap
;
import
com.topjohnwu.utils.SignAPK
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
dalvik.system.DexClassLoader
;
...
...
@@ -36,37 +32,25 @@ public class DownloadApp {
private
static
void
dlInstall
(
String
name
,
ManagerDownloadListener
listener
)
{
File
apk
=
new
File
(
App
.
self
.
getCacheDir
(),
"manager.apk"
);
ProgressNotification
progress
=
new
ProgressNotification
(
name
);
listener
.
setProgressNotification
(
progress
)
;
listener
.
progress
=
progress
;
Networking
.
get
(
Data
.
managerLink
)
.
setExecutor
(
AsyncTask
.
THREAD_POOL_EXECUTOR
)
.
setDownloadProgressListener
(
progress
)
.
setErrorHandler
((
conn
,
e
)
->
progress
.
dlFail
())
.
getAsFile
(
listener
,
apk
);
.
getAsFile
(
apk
,
listener
);
}
abstract
static
class
ManagerDownloadListener
implements
ResponseListener
<
File
>
{
private
ProgressNotification
progress
;
private
void
setProgressNotification
(
ProgressNotification
progress
)
{
this
.
progress
=
progress
;
}
public
abstract
void
onDownloadComplete
(
File
apk
,
ProgressNotification
progress
);
@Override
public
void
onResponse
(
File
apk
)
{
onDownloadComplete
(
apk
,
progress
);
}
private
abstract
static
class
ManagerDownloadListener
implements
ResponseListener
<
File
>
{
ProgressNotification
progress
;
}
static
class
PatchPackageName
extends
ManagerDownloadListener
{
private
static
class
PatchPackageName
extends
ManagerDownloadListener
{
@Override
public
void
on
DownloadComplete
(
File
apk
,
ProgressNotification
progress
)
{
public
void
on
Response
(
File
apk
)
{
File
patched
=
apk
;
App
app
=
App
.
self
;
if
(!
App
.
self
.
getPackageName
().
equals
(
BuildConfig
.
APPLICATION_ID
))
{
if
(!
app
.
getPackageName
().
equals
(
BuildConfig
.
APPLICATION_ID
))
{
progress
.
getNotificationBuilder
()
.
setProgress
(
0
,
0
,
true
)
.
setContentTitle
(
app
.
getString
(
R
.
string
.
hide_manager_title
))
...
...
@@ -91,10 +75,10 @@ public class DownloadApp {
}
}
static
class
RestoreManager
extends
ManagerDownloadListener
{
private
static
class
RestoreManager
extends
ManagerDownloadListener
{
@Override
public
void
on
DownloadComplete
(
File
apk
,
ProgressNotification
progress
)
{
public
void
on
Response
(
File
apk
)
{
App
app
=
App
.
self
;
progress
.
getNotificationBuilder
()
.
setProgress
(
0
,
0
,
true
)
...
...
core/src/main/java/com/topjohnwu/core/tasks/SafetyNet.java
View file @
7bd52d02
...
...
@@ -38,14 +38,14 @@ public class SafetyNet {
}
catch
(
Exception
ignored
)
{
Shell
.
sh
(
"rm -rf "
+
EXT_APK
.
getParent
()).
exec
();
EXT_APK
.
getParentFile
().
mkdir
();
Networking
.
get
(
Const
.
Url
.
SNET_URL
).
getAsFile
(
f
->
{
Networking
.
get
(
Const
.
Url
.
SNET_URL
).
getAsFile
(
EXT_APK
,
f
->
{
try
{
dyRun
(
activity
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
Topic
.
publish
(
false
,
Topic
.
SNET_CHECK_DONE
,
-
1
);
}
}
,
EXT_APK
);
});
}
}
}
net/src/main/java/com/topjohnwu/net/
Stub
Request.java
→
net/src/main/java/com/topjohnwu/net/
Bad
Request.java
View file @
7bd52d02
...
...
@@ -4,46 +4,48 @@ import org.json.JSONArray;
import
org.json.JSONObject
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.concurrent.Executor
;
class
Stub
Request
extends
Request
{
class
Bad
Request
extends
Request
{
StubRequest
()
{
super
(
null
);
}
private
IOException
ex
;
@Override
public
Request
addHeaders
(
String
key
,
String
value
)
{
return
this
;
}
BadRequest
(
IOException
e
)
{
super
(
null
);
ex
=
e
;
}
@Override
public
Request
setDownloadProgressListener
(
DownloadProgressListener
listener
)
{
return
this
;
}
public
Request
addHeaders
(
String
key
,
String
value
)
{
return
this
;
}
@Override
public
Re
quest
setErrorHandler
(
ErrorHandler
handler
)
{
return
this
;
}
public
Re
sult
<
InputStream
>
execForInputStream
()
{
fail
();
return
new
Result
<>()
;
}
@Override
public
Request
setExecutor
(
Executor
e
)
{
return
this
;
}
public
void
getAsFile
(
File
out
,
ResponseListener
<
File
>
rs
)
{
fail
()
;
}
@Override
public
Result
<
InputStream
>
execForInputStream
()
{
return
new
Result
<>
();
}
public
void
execForFile
(
File
out
)
{
fail
();
}
@Override
public
void
getAs
File
(
ResponseListener
<
File
>
rs
,
File
out
)
{
}
public
void
getAs
String
(
ResponseListener
<
String
>
rs
)
{
fail
();
}
@Override
public
void
getAsString
(
ResponseListener
<
String
>
rs
)
{
}
public
Result
<
String
>
execForString
()
{
fail
();
return
new
Result
<>();
}
@Override
public
Result
<
String
>
execForString
()
{
return
new
Result
<>
();
}
public
void
getAsJSONObject
(
ResponseListener
<
JSONObject
>
rs
)
{
fail
();
}
@Override
public
void
getAsJSONObject
(
ResponseListener
<
JSONObject
>
rs
){
}
public
Result
<
JSONObject
>
execForJSONObject
()
{
fail
();
return
new
Result
<>();
}
@Override
public
Result
<
JSONObject
>
execForJSONObject
()
{
return
new
Result
<>
();
}
public
void
getAsJSONArray
(
ResponseListener
<
JSONArray
>
rs
)
{
fail
();
}
@Override
public
void
getAsJSONArray
(
ResponseListener
<
JSONArray
>
rs
){
}
public
Result
<
JSONArray
>
execForJSONArray
()
{
fail
();
return
new
Result
<>();
}
@Override
public
Result
<
JSONArray
>
execForJSONArray
()
{
return
new
Result
<>();
}
private
void
fail
()
{
if
(
err
!=
null
)
err
.
onError
(
null
,
ex
);
}
}
net/src/main/java/com/topjohnwu/net/Networking.java
View file @
7bd52d02
...
...
@@ -27,7 +27,7 @@ public class Networking {
conn
.
setConnectTimeout
(
CONNECT_TIMEOUT
);
return
new
Request
(
conn
);
}
catch
(
IOException
e
)
{
return
new
StubRequest
(
);
return
new
BadRequest
(
e
);
}
}
...
...
net/src/main/java/com/topjohnwu/net/ProgressInputStream.java
View file @
7bd52d02
...
...
@@ -8,16 +8,12 @@ public class ProgressInputStream extends FilterInputStream {
private
long
totalBytes
;
private
long
bytesDownloaded
;
private
DownloadProgressListener
progress
;
public
ProgressInputStream
(
InputStream
in
,
long
total
)
{
public
ProgressInputStream
(
InputStream
in
,
long
total
,
DownloadProgressListener
listener
)
{
super
(
in
);
totalBytes
=
total
;
}
protected
void
updateProgress
(
long
bytesDownloaded
,
long
totalBytes
)
{}
private
void
update
()
{
Networking
.
mainHandler
.
post
(()
->
updateProgress
(
bytesDownloaded
,
totalBytes
));
progress
=
listener
;
}
@Override
...
...
@@ -25,7 +21,7 @@ public class ProgressInputStream extends FilterInputStream {
int
b
=
super
.
read
();
if
(
b
>=
0
)
{
bytesDownloaded
++;
update
(
);
Networking
.
mainHandler
.
post
(()
->
progress
.
onProgress
(
bytesDownloaded
,
totalBytes
)
);
}
return
b
;
}
...
...
@@ -40,7 +36,7 @@ public class ProgressInputStream extends FilterInputStream {
int
sz
=
super
.
read
(
b
,
off
,
len
);
if
(
sz
>
0
)
{
bytesDownloaded
+=
sz
;
update
(
);
Networking
.
mainHandler
.
post
(()
->
progress
.
onProgress
(
bytesDownloaded
,
totalBytes
)
);
}
return
sz
;
}
...
...
net/src/main/java/com/topjohnwu/net/Request.java
View file @
7bd52d02
...
...
@@ -23,8 +23,9 @@ public class Request {
private
HttpURLConnection
conn
;
private
Executor
executor
=
null
;
private
DownloadProgressListener
progress
=
null
;
private
ErrorHandler
err
=
null
;
private
int
code
;
private
int
code
=
-
1
;
ErrorHandler
err
=
null
;
private
interface
Requestor
<
T
>
{
T
request
()
throws
Exception
;
...
...
@@ -74,7 +75,7 @@ public class Request {
return
exec
(
this
::
getInputStream
);
}
public
void
getAsFile
(
ResponseListener
<
File
>
rs
,
File
out
)
{
public
void
getAsFile
(
File
out
,
ResponseListener
<
File
>
rs
)
{
submit
(()
->
dlFile
(
out
),
rs
);
}
...
...
@@ -110,7 +111,10 @@ public class Request {
Result
<
T
>
res
=
new
Result
<>();
try
{
res
.
result
=
req
.
request
();
}
catch
(
Exception
ignored
)
{}
}
catch
(
Exception
e
)
{
if
(
err
!=
null
)
err
.
onError
(
conn
,
e
);
}
return
res
;
}
...
...
@@ -135,12 +139,7 @@ public class Request {
code
=
conn
.
getResponseCode
();
InputStream
in
=
conn
.
getInputStream
();
if
(
progress
!=
null
)
{
in
=
new
ProgressInputStream
(
in
,
conn
.
getContentLength
())
{
@Override
protected
void
updateProgress
(
long
bytesDownloaded
,
long
totalBytes
)
{
progress
.
onProgress
(
bytesDownloaded
,
totalBytes
);
}
in
=
new
ProgressInputStream
(
in
,
conn
.
getContentLength
(),
progress
)
{
@Override
public
void
close
()
throws
IOException
{
super
.
close
();
...
...
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