ScheduleService.java 源代码
package com.x8zs.model;
import android.app.IntentService;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;
import com.blankj.utilcode.util.NetworkUtils;
import com.x8zs.ad.AdManagerEx;
public class ScheduleService extends IntentService {
private static volatile boolean f21583q;
private static volatile boolean f21584r;
private static BroadcastReceiver f21585s = new a();
class a extends BroadcastReceiver {
a() {
}
@Override
public void onReceive(Context context, Intent intent) {
if (NetworkUtils.c()) {
if (!ScheduleService.f21583q) {
Log.d("ScheduleService", "network connected, start worker");
ScheduleService.d(context, false);
return;
} else {
Log.d("ScheduleService", "network connected, already working");
return;
}
}
Log.d("ScheduleService", "network disconnected");
}
}
public ScheduleService() {
super("ScheduleService");
}
private static void b(Context context) {
try {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
intentFilter.addAction("android.net.wifi.WIFI_STATE_CHANGED");
intentFilter.addAction("android.net.wifi.STATE_CHANGE");
context.registerReceiver(f21585s, intentFilter);
} catch (Throwable th) {
th.printStackTrace();
}
}
public static void c(Context context) {
d(context, false);
b(context);
}
public static void d(Context context, boolean z6) {
try {
Intent intent = new Intent(context, (Class<?>) ScheduleService.class);
intent.putExtra("force", z6);
context.startService(intent);
} catch (Throwable th) {
th.printStackTrace();
}
}
@Override
protected void onHandleIntent(Intent intent) {
boolean z6;
f21583q = true;
if (intent != null) {
z6 = intent.getBooleanExtra("force", false);
} else {
z6 = false;
}
b.b().k(z6);
AdManagerEx.getInstance().syncAdConfig(z6);
if (!f21584r) {
X8DataModel.A0(this).q1();
X8DataModel.A0(this).r1();
new c(this).e();
f21584r = true;
}
stopSelf();
f21583q = false;
}
}