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
debaec32
Commit
debaec32
authored
Jul 29, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove old download progress update system
parent
0e9b71e7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
10 additions
and
149 deletions
+10
-149
RemoteFileService.kt
.../com/topjohnwu/magisk/model/download/RemoteFileService.kt
+2
-2
ProgressInputStream.kt
...in/java/com/topjohnwu/magisk/utils/ProgressInputStream.kt
+1
-1
ProgressNotification.kt
...in/java/com/topjohnwu/magisk/view/ProgressNotification.kt
+0
-73
DownloadProgressListener.java
...main/java/com/topjohnwu/net/DownloadProgressListener.java
+0
-5
Networking.java
net/src/main/java/com/topjohnwu/net/Networking.java
+0
-1
ProgressInputStream.java
net/src/main/java/com/topjohnwu/net/ProgressInputStream.java
+0
-43
Request.java
net/src/main/java/com/topjohnwu/net/Request.java
+7
-24
No files found.
app/src/main/java/com/topjohnwu/magisk/model/download/RemoteFileService.kt
View file @
debaec32
...
...
@@ -12,7 +12,7 @@ import com.topjohnwu.magisk.extensions.get
import
com.topjohnwu.magisk.extensions.writeTo
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject.*
import
com.topjohnwu.magisk.utils.ProgInputStream
import
com.topjohnwu.magisk.utils.Prog
ress
InputStream
import
com.topjohnwu.magisk.view.Notifications
import
com.topjohnwu.superuser.ShellUtils
import
io.reactivex.Single
...
...
@@ -100,7 +100,7 @@ abstract class RemoteFileService : NotificationService() {
val
maxRaw
=
contentLength
()
val
max
=
maxRaw
/
1
_000_000f
return
ProgInputStream
(
byteStream
())
{
return
Prog
ress
InputStream
(
byteStream
())
{
val
progress
=
it
/
1
_000_000f
update
(
id
)
{
notification
->
notification
...
...
app/src/main/java/com/topjohnwu/magisk/utils/ProgInputStream.kt
→
app/src/main/java/com/topjohnwu/magisk/utils/Prog
ress
InputStream.kt
View file @
debaec32
...
...
@@ -4,7 +4,7 @@ import com.topjohnwu.superuser.internal.UiThreadHandler
import
java.io.FilterInputStream
import
java.io.InputStream
class
ProgInputStream
(
class
Prog
ress
InputStream
(
base
:
InputStream
,
val
progressEmitter
:
(
Long
)
->
Unit
=
{}
)
:
FilterInputStream
(
base
)
{
...
...
app/src/main/java/com/topjohnwu/magisk/view/ProgressNotification.kt
deleted
100644 → 0
View file @
0e9b71e7
package
com.topjohnwu.magisk.view
import
android.app.Notification
import
android.app.PendingIntent
import
android.content.Intent
import
android.widget.Toast
import
androidx.core.app.NotificationCompat
import
com.topjohnwu.magisk.App
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.net.DownloadProgressListener
class
ProgressNotification
(
title
:
String
)
:
DownloadProgressListener
{
val
notificationBuilder
:
NotificationCompat
.
Builder
=
Notifications
.
progress
(
title
)
lateinit
var
notification
:
Notification
private
set
private
var
prevTime
:
Long
=
0
init
{
prevTime
=
System
.
currentTimeMillis
()
update
()
Utils
.
toast
(
App
.
self
.
getString
(
R
.
string
.
downloading_toast
,
title
),
Toast
.
LENGTH_SHORT
)
}
override
fun
onProgress
(
bytesDownloaded
:
Long
,
totalBytes
:
Long
)
{
val
cur
=
System
.
currentTimeMillis
()
if
(
cur
-
prevTime
>=
1000
)
{
prevTime
=
cur
val
progress
=
(
bytesDownloaded
*
100
/
totalBytes
).
toInt
()
notificationBuilder
.
setProgress
(
100
,
progress
,
false
)
notificationBuilder
.
setContentText
(
"$progress%"
)
update
()
}
}
fun
update
()
{
notification
=
notificationBuilder
.
build
()
Notifications
.
mgr
.
notify
(
hashCode
(),
notification
)
}
private
fun
lastUpdate
()
{
Notifications
.
mgr
.
cancel
(
hashCode
())
notification
=
notificationBuilder
.
build
().
apply
{
Notifications
.
mgr
.
notify
(
hashCode
(),
this
)
}
}
fun
dlDone
(
intent
:
PendingIntent
=
PendingIntent
.
getActivity
(
App
.
self
,
hashCode
(),
Intent
(),
PendingIntent
.
FLAG_UPDATE_CURRENT
))
{
notificationBuilder
.
setProgress
(
0
,
0
,
false
)
.
setContentText
(
App
.
self
.
getString
(
R
.
string
.
download_complete
))
.
setSmallIcon
(
android
.
R
.
drawable
.
stat_sys_download_done
)
.
setContentIntent
(
intent
)
.
setOngoing
(
false
)
.
setAutoCancel
(
true
)
lastUpdate
()
}
fun
dlFail
()
{
notificationBuilder
.
setProgress
(
0
,
0
,
false
)
.
setContentText
(
App
.
self
.
getString
(
R
.
string
.
download_file_error
))
.
setSmallIcon
(
android
.
R
.
drawable
.
stat_notify_error
)
.
setOngoing
(
false
)
lastUpdate
()
}
fun
dismiss
()
{
Notifications
.
mgr
.
cancel
(
hashCode
())
}
}
net/src/main/java/com/topjohnwu/net/DownloadProgressListener.java
deleted
100644 → 0
View file @
0e9b71e7
package
com
.
topjohnwu
.
net
;
public
interface
DownloadProgressListener
{
void
onProgress
(
long
bytesDownloaded
,
long
totalBytes
);
}
net/src/main/java/com/topjohnwu/net/Networking.java
View file @
debaec32
...
...
@@ -13,7 +13,6 @@ import java.net.URL;
import
javax.net.ssl.HttpsURLConnection
;
@Deprecated
public
class
Networking
{
private
static
final
int
READ_TIMEOUT
=
15000
;
...
...
net/src/main/java/com/topjohnwu/net/ProgressInputStream.java
deleted
100644 → 0
View file @
0e9b71e7
package
com
.
topjohnwu
.
net
;
import
java.io.FilterInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
public
class
ProgressInputStream
extends
FilterInputStream
{
private
long
totalBytes
;
private
long
bytesDownloaded
;
private
DownloadProgressListener
progress
;
public
ProgressInputStream
(
InputStream
in
,
long
total
,
DownloadProgressListener
listener
)
{
super
(
in
);
totalBytes
=
total
;
progress
=
listener
;
}
@Override
public
int
read
()
throws
IOException
{
int
b
=
super
.
read
();
if
(
totalBytes
>
0
&&
b
>=
0
)
{
bytesDownloaded
++;
Networking
.
mainHandler
.
post
(()
->
progress
.
onProgress
(
bytesDownloaded
,
totalBytes
));
}
return
b
;
}
@Override
public
int
read
(
byte
[]
b
)
throws
IOException
{
return
read
(
b
,
0
,
b
.
length
);
}
@Override
public
int
read
(
byte
[]
b
,
int
off
,
int
len
)
throws
IOException
{
int
sz
=
super
.
read
(
b
,
off
,
len
);
if
(
totalBytes
>
0
&&
sz
>
0
)
{
bytesDownloaded
+=
sz
;
Networking
.
mainHandler
.
post
(()
->
progress
.
onProgress
(
bytesDownloaded
,
totalBytes
));
}
return
sz
;
}
}
net/src/main/java/com/topjohnwu/net/Request.java
View file @
debaec32
...
...
@@ -23,7 +23,6 @@ import java.util.concurrent.Executor;
public
class
Request
implements
Closeable
{
private
HttpURLConnection
conn
;
private
Executor
executor
=
null
;
private
DownloadProgressListener
progress
=
null
;
private
int
code
=
-
1
;
ErrorHandler
err
=
null
;
...
...
@@ -66,11 +65,6 @@ public class Request implements Closeable {
return
this
;
}
public
Request
setDownloadProgressListener
(
DownloadProgressListener
listener
)
{
progress
=
listener
;
return
this
;
}
public
Request
setErrorHandler
(
ErrorHandler
handler
)
{
err
=
handler
;
return
this
;
...
...
@@ -169,24 +163,13 @@ public class Request implements Closeable {
private
BufferedInputStream
getInputStream
()
throws
IOException
{
connect0
();
InputStream
in
=
conn
.
getInputStream
();
if
(
progress
!=
null
)
{
in
=
new
ProgressInputStream
(
in
,
conn
.
getContentLength
(),
progress
)
{
@Override
public
void
close
()
throws
IOException
{
super
.
close
();
conn
.
disconnect
();
}
};
}
else
{
in
=
new
FilterInputStream
(
in
)
{
@Override
public
void
close
()
throws
IOException
{
super
.
close
();
conn
.
disconnect
();
}
};
}
InputStream
in
=
new
FilterInputStream
(
conn
.
getInputStream
())
{
@Override
public
void
close
()
throws
IOException
{
super
.
close
();
conn
.
disconnect
();
}
};
return
new
BufferedInputStream
(
in
);
}
...
...
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