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
e67d0678
Commit
e67d0678
authored
Mar 24, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use viewModelScope instead of GlobalScope
parent
b1faa5ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
13 deletions
+12
-13
SuRequestHandler.kt
...ain/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt
+7
-10
SuRequestViewModel.kt
...a/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt
+5
-3
No files found.
app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt
View file @
e67d0678
...
...
@@ -7,11 +7,8 @@ import com.topjohnwu.magisk.core.Config
import
com.topjohnwu.magisk.core.magiskdb.PolicyDao
import
com.topjohnwu.magisk.core.model.su.SuPolicy
import
com.topjohnwu.magisk.core.model.su.toPolicy
import
com.topjohnwu.magisk.ktx.now
import
com.topjohnwu.superuser.Shell
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
import
timber.log.Timber
import
java.io.Closeable
...
...
@@ -54,10 +51,9 @@ class SuRequestHandler(
return
true
}
@Throws
(
IOException
::
class
)
override
fun
close
()
{
if
(
::
output
.
isInitialized
)
output
.
close
()
runCatching
{
output
.
close
()
}
}
private
class
SuRequestError
:
IOException
()
...
...
@@ -73,7 +69,7 @@ class SuRequestHandler(
when
(
e
)
{
is
IOException
,
is
PackageManager
.
NameNotFoundException
->
{
Timber
.
e
(
e
)
runCatching
{
close
()
}
close
()
false
}
else
->
throw
e
// Unexpected error
...
...
@@ -81,23 +77,24 @@ class SuRequestHandler(
}
}
fun
respond
(
action
:
Int
,
time
:
Int
)
{
suspend
fun
respond
(
action
:
Int
,
time
:
Int
)
{
val
until
=
if
(
time
>
0
)
TimeUnit
.
MILLISECONDS
.
toSeconds
(
now
)
+
TimeUnit
.
MINUTES
.
toSeconds
(
time
.
toLong
())
TimeUnit
.
MILLISECONDS
.
toSeconds
(
System
.
currentTimeMillis
())
+
TimeUnit
.
MINUTES
.
toSeconds
(
time
.
toLong
())
else
time
.
toLong
()
policy
.
policy
=
action
policy
.
until
=
until
GlobalScope
.
launch
(
Dispatchers
.
IO
)
{
withContext
(
Dispatchers
.
IO
)
{
try
{
output
.
writeInt
(
policy
.
policy
)
output
.
flush
()
}
catch
(
e
:
IOException
)
{
Timber
.
e
(
e
)
}
finally
{
runCatching
{
close
()
}
close
()
if
(
until
>=
0
)
policyDB
.
update
(
policy
)
}
...
...
app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt
View file @
e67d0678
...
...
@@ -125,10 +125,12 @@ class SuRequestViewModel(
val
pos
=
selectedItemPosition
timeoutPrefs
.
edit
().
putInt
(
handler
.
policy
.
packageName
,
pos
).
apply
()
handler
.
respond
(
action
,
Config
.
Value
.
TIMEOUT_LIST
[
pos
])
// Kill activity after response
DieEvent
().
publish
()
viewModelScope
.
launch
{
handler
.
respond
(
action
,
Config
.
Value
.
TIMEOUT_LIST
[
pos
])
// Kill activity after response
DieEvent
().
publish
()
}
}
private
fun
cancelTimer
()
{
...
...
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