Commit d755e473 authored by Mygod's avatar Mygod

Fix #1909

parent 96fd4e75
...@@ -164,5 +164,36 @@ ...@@ -164,5 +164,36 @@
<action android:name="com.twofortyfouram.locale.intent.action.FIRE_SETTING"/> <action android:name="com.twofortyfouram.locale.intent.action.FIRE_SETTING"/>
</intent-filter> </intent-filter>
</receiver> </receiver>
<!-- https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/work/workmanager/src/main/AndroidManifest.xml -->
<provider android:name="androidx.work.impl.WorkManagerInitializer"
tools:node="remove"/>
<service android:name="androidx.work.impl.background.systemalarm.SystemAlarmService"
android:process=":bg"
android:directBootAware="true"/>
<service android:name="androidx.work.impl.background.systemjob.SystemJobService"
android:process=":bg"
android:directBootAware="true"/>
<receiver android:name="androidx.work.impl.utils.ForceStopRunnable$BroadcastReceiver"
android:process=":bg"
android:directBootAware="true"/>
<receiver android:name="androidx.work.impl.background.systemalarm.ConstraintProxy$BatteryChargingProxy"
android:process=":bg"
android:directBootAware="true"/>
<receiver android:name="androidx.work.impl.background.systemalarm.ConstraintProxy$BatteryNotLowProxy"
android:process=":bg"
android:directBootAware="true"/>
<receiver android:name="androidx.work.impl.background.systemalarm.ConstraintProxy$StorageNotLowProxy"
android:process=":bg"
android:directBootAware="true"/>
<receiver android:name="androidx.work.impl.background.systemalarm.ConstraintProxy$NetworkStateProxy"
android:process=":bg"
android:directBootAware="true"/>
<receiver android:name="androidx.work.impl.background.systemalarm.RescheduleReceiver"
android:process=":bg"
android:directBootAware="true"/>
<receiver android:name="androidx.work.impl.background.systemalarm.ConstraintProxyUpdateReceiver"
android:process=":bg"
android:directBootAware="true"/>
</application> </application>
</manifest> </manifest>
...@@ -27,18 +27,21 @@ import java.util.concurrent.TimeUnit ...@@ -27,18 +27,21 @@ import java.util.concurrent.TimeUnit
class AclSyncer : Worker() { class AclSyncer : Worker() {
companion object { companion object {
fun schedule(route: String) = WorkManager.getInstance().enqueue(OneTimeWorkRequestBuilder<AclSyncer>() private const val KEY_ROUTE = "route"
.addTag(route)
.setConstraints(Constraints.Builder() fun schedule(route: String) = WorkManager.getInstance().enqueue(OneTimeWorkRequestBuilder<AclSyncer>().run {
.setRequiredNetworkType(NetworkType.UNMETERED) setInputData(Data.Builder().putString(KEY_ROUTE, route).build())
.setRequiresCharging(true) setConstraints(Constraints.Builder()
.build()) .setRequiredNetworkType(NetworkType.UNMETERED)
.setInitialDelay(10, TimeUnit.SECONDS) .setRequiresCharging(true)
.build()) .build())
setInitialDelay(10, TimeUnit.SECONDS)
build()
})
} }
override fun doWork(): Result = try { override fun doWork(): Result = try {
val route = tags.asIterable().single()!! val route = inputData.getString(KEY_ROUTE)!!
val acl = URL("https://shadowsocks.org/acl/android/v1/$route.acl").openStream().bufferedReader() val acl = URL("https://shadowsocks.org/acl/android/v1/$route.acl").openStream().bufferedReader()
.use { it.readText() } .use { it.readText() }
Acl.getFile(route).printWriter().use { it.write(acl) } Acl.getFile(route).printWriter().use { it.write(acl) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment