Magisk/app/src/main/java/a/w.java

43 lines
1.0 KiB
Java
Raw Normal View History

2018-12-27 14:07:47 +00:00
package a;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import com.topjohnwu.magisk.base.DelegateWorker;
2019-08-08 07:59:23 +00:00
import java.lang.reflect.ParameterizedType;
2019-01-28 21:12:59 +00:00
public abstract class w<T extends DelegateWorker> extends Worker {
2018-12-27 14:07:47 +00:00
/* Wrapper class to workaround Proguard -keep class * extends Worker */
private T base;
@SuppressWarnings("unchecked")
w(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
try {
base = ((Class<T>) ((ParameterizedType) getClass().getGenericSuperclass())
.getActualTypeArguments()[0]).newInstance();
2019-08-08 07:59:23 +00:00
base.attachWorker(this);
2018-12-27 21:15:59 +00:00
} catch (Exception ignored) {}
2018-12-27 14:07:47 +00:00
}
@NonNull
@Override
public Result doWork() {
if (base == null)
return Result.failure();
return base.doWork();
}
2019-01-28 21:12:59 +00:00
@Override
public void onStopped() {
if (base != null)
base.onStopped();
}
2018-12-27 14:07:47 +00:00
}