Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
56e788a8
Commit
56e788a8
authored
Jan 12, 2020
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix VerifyError
parent
fa0669df
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
22 deletions
+28
-22
core/src/main/java/com/github/shadowsocks/subscription/SubscriptionService.kt
...om/github/shadowsocks/subscription/SubscriptionService.kt
+28
-22
No files found.
core/src/main/java/com/github/shadowsocks/subscription/SubscriptionService.kt
View file @
56e788a8
...
...
@@ -43,6 +43,7 @@ import java.io.File
import
java.io.IOException
import
java.io.InputStream
import
java.net.HttpURLConnection
import
java.net.URL
class
SubscriptionService
:
Service
()
{
companion
object
{
...
...
@@ -74,29 +75,9 @@ class SubscriptionService : Service() {
setWhen
(
0
)
}
Core
.
notification
.
notify
(
NOTIFICATION_ID
,
notification
.
build
())
var
counter
=
0
counter
=
0
val
workers
=
urls
.
asIterable
().
map
{
url
->
async
(
Dispatchers
.
IO
)
{
val
tempFile
=
File
.
createTempFile
(
"subscription-"
,
".json"
,
cacheDir
)
try
{
(
url
.
openConnection
()
as
HttpURLConnection
).
useCancellable
{
tempFile
.
outputStream
().
use
{
out
->
inputStream
.
copyTo
(
out
)
}
}
tempFile
}
catch
(
e
:
IOException
)
{
e
.
printStackTrace
()
Toast
.
makeText
(
this
@SubscriptionService
,
e
.
readableMessage
,
Toast
.
LENGTH_LONG
).
show
()
if
(!
tempFile
.
delete
())
tempFile
.
deleteOnExit
()
null
}
finally
{
withContext
(
Dispatchers
.
Main
)
{
counter
+=
1
Core
.
notification
.
notify
(
NOTIFICATION_ID
,
notification
.
apply
{
setProgress
(
urls
.
size
(),
counter
,
false
)
}.
build
())
}
}
}
async
(
Dispatchers
.
IO
)
{
work
(
url
,
urls
.
size
(),
notification
)
}
}
try
{
val
localJsons
=
workers
.
awaitAll
()
...
...
@@ -126,6 +107,31 @@ class SubscriptionService : Service() {
return
START_NOT_STICKY
}
private
var
counter
=
0
private
suspend
fun
work
(
url
:
URL
,
max
:
Int
,
notification
:
NotificationCompat
.
Builder
):
File
?
{
val
tempFile
=
File
.
createTempFile
(
"subscription-"
,
".json"
,
cacheDir
)
try
{
(
url
.
openConnection
()
as
HttpURLConnection
).
useCancellable
{
tempFile
.
outputStream
().
use
{
out
->
inputStream
.
copyTo
(
out
)
}
}
return
tempFile
}
catch
(
e
:
IOException
)
{
e
.
printStackTrace
()
GlobalScope
.
launch
(
Dispatchers
.
Main
)
{
Toast
.
makeText
(
this
@SubscriptionService
,
e
.
readableMessage
,
Toast
.
LENGTH_LONG
).
show
()
}
if
(!
tempFile
.
delete
())
tempFile
.
deleteOnExit
()
return
null
}
finally
{
withContext
(
Dispatchers
.
Main
)
{
counter
+=
1
Core
.
notification
.
notify
(
NOTIFICATION_ID
,
notification
.
apply
{
setProgress
(
max
,
counter
,
false
)
}.
build
())
}
}
}
private
fun
createProfilesFromSubscription
(
jsons
:
Sequence
<
InputStream
>)
{
val
currentId
=
DataStore
.
profileId
val
profiles
=
ProfileManager
.
getAllProfiles
()
...
...
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