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
5df42638
Commit
5df42638
authored
Jan 28, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More complete DelegateWorker
parent
976c2996
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
1 deletion
+87
-1
w.java
app/src/full/java/a/w.java
+8
-1
DelegateWorker.java
...ll/java/com/topjohnwu/magisk/services/DelegateWorker.java
+79
-0
No files found.
app/src/full/java/a/w.java
View file @
5df42638
...
...
@@ -10,7 +10,7 @@ import androidx.annotation.NonNull;
import
androidx.work.Worker
;
import
androidx.work.WorkerParameters
;
public
class
w
<
T
extends
DelegateWorker
>
extends
Worker
{
public
abstract
class
w
<
T
extends
DelegateWorker
>
extends
Worker
{
/* Wrapper class to workaround Proguard -keep class * extends Worker */
...
...
@@ -22,6 +22,7 @@ public class w<T extends DelegateWorker> extends Worker {
try
{
base
=
((
Class
<
T
>)
((
ParameterizedType
)
getClass
().
getGenericSuperclass
())
.
getActualTypeArguments
()[
0
]).
newInstance
();
base
.
setActualWorker
(
this
);
}
catch
(
Exception
ignored
)
{}
}
...
...
@@ -32,4 +33,10 @@ public class w<T extends DelegateWorker> extends Worker {
return
Result
.
failure
();
return
base
.
doWork
();
}
@Override
public
void
onStopped
()
{
if
(
base
!=
null
)
base
.
onStopped
();
}
}
app/src/full/java/com/topjohnwu/magisk/services/DelegateWorker.java
View file @
5df42638
package
com
.
topjohnwu
.
magisk
.
services
;
import
android.content.Context
;
import
android.net.Network
;
import
android.net.Uri
;
import
com.google.common.util.concurrent.ListenableFuture
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.UUID
;
import
java.util.concurrent.Executor
;
import
androidx.annotation.MainThread
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.RequiresApi
;
import
androidx.annotation.RestrictTo
;
import
androidx.work.Data
;
import
androidx.work.ListenableWorker
;
import
androidx.work.WorkerFactory
;
import
androidx.work.impl.utils.taskexecutor.TaskExecutor
;
public
abstract
class
DelegateWorker
{
private
ListenableWorker
worker
;
@NonNull
public
abstract
ListenableWorker
.
Result
doWork
();
public
void
onStopped
()
{}
public
void
setActualWorker
(
ListenableWorker
w
)
{
worker
=
w
;
}
@NonNull
public
Context
getApplicationContext
()
{
return
worker
.
getApplicationContext
();
}
@NonNull
public
UUID
getId
()
{
return
worker
.
getId
();
}
@NonNull
public
Data
getInputData
()
{
return
worker
.
getInputData
();
}
@NonNull
public
Set
<
String
>
getTags
()
{
return
worker
.
getTags
();
}
@NonNull
@RequiresApi
(
24
)
public
List
<
Uri
>
getTriggeredContentUris
()
{
return
worker
.
getTriggeredContentUris
();
}
@NonNull
@RequiresApi
(
24
)
public
List
<
String
>
getTriggeredContentAuthorities
()
{
return
worker
.
getTriggeredContentAuthorities
();
}
@Nullable
@RequiresApi
(
28
)
public
Network
getNetwork
()
{
return
worker
.
getNetwork
();
}
public
int
getRunAttemptCount
()
{
return
worker
.
getRunAttemptCount
();
}
@NonNull
@MainThread
public
ListenableFuture
<
ListenableWorker
.
Result
>
startWork
()
{
return
worker
.
startWork
();
}
public
boolean
isStopped
()
{
return
worker
.
isStopped
();
}
}
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