花瓣 v4.6.12版本的 MD5 值为:6a3515d4d16d98931f1b3d25a91b257e
以下内容为反编译后的 a.java 源代码,内容仅作参考
package com.liulishuo.filedownloader.services;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.os.IInterface;
import android.os.RemoteException;
import com.liulishuo.filedownloader.l0.c;
import com.liulishuo.filedownloader.z;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public abstract class a<CALLBACK extends Binder, INTERFACE extends IInterface> implements z, ServiceConnection {
private volatile INTERFACE b;
private final Class<?> c;
protected boolean f9994d = false;
private final HashMap<String, Object> f9995e = new HashMap<>();
private final List<Context> f9996f = new ArrayList();
private final ArrayList<Runnable> f9997g = new ArrayList<>();
private final CALLBACK a = b();
public a(Class<?> cls) {
this.c = cls;
}
private void h(boolean z) {
if (!z && this.b != null) {
try {
i(this.b, this.a);
} catch (RemoteException e2) {
e2.printStackTrace();
}
}
if (com.liulishuo.filedownloader.p0.e.a) {
com.liulishuo.filedownloader.p0.e.a(this, "release connect resources %s", this.b);
}
this.b = null;
com.liulishuo.filedownloader.g.f().a(new com.liulishuo.filedownloader.l0.c(z ? c.a.lost : c.a.disconnected, this.c));
}
@Override
public void A(Context context) {
y(context, null);
}
protected abstract INTERFACE a(IBinder iBinder);
protected abstract CALLBACK b();
protected CALLBACK c() {
return this.a;
}
public INTERFACE d() {
return this.b;
}
protected Object e(String str) {
return this.f9995e.remove(str);
}
protected String f(Object obj) {
if (obj == null) {
return null;
}
String obj2 = obj.toString();
this.f9995e.put(obj2, obj);
return obj2;
}
protected abstract void g(INTERFACE r1, CALLBACK callback) throws RemoteException;
protected abstract void i(INTERFACE r1, CALLBACK callback) throws RemoteException;
@Override
public boolean isConnected() {
return d() != null;
}
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
this.b = a(iBinder);
if (com.liulishuo.filedownloader.p0.e.a) {
com.liulishuo.filedownloader.p0.e.a(this, "onServiceConnected %s %s", componentName, this.b);
}
try {
g(this.b, this.a);
} catch (RemoteException e2) {
e2.printStackTrace();
}
this.f9997g.clear();
for (Runnable runnable : (List) this.f9997g.clone()) {
runnable.run();
}
com.liulishuo.filedownloader.g.f().a(new com.liulishuo.filedownloader.l0.c(c.a.connected, this.c));
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
if (com.liulishuo.filedownloader.p0.e.a) {
com.liulishuo.filedownloader.p0.e.a(this, "onServiceDisconnected %s %s", componentName, this.b);
}
h(true);
}
@Override
public boolean x() {
return this.f9994d;
}
@Override
public void y(Context context, Runnable runnable) {
if (!com.liulishuo.filedownloader.p0.h.N(context)) {
if (com.liulishuo.filedownloader.p0.e.a) {
com.liulishuo.filedownloader.p0.e.a(this, "bindStartByContext %s", context.getClass().getSimpleName());
}
Intent intent = new Intent(context, this.c);
if (runnable != null && !this.f9997g.contains(runnable)) {
this.f9997g.add(runnable);
}
if (!this.f9996f.contains(context)) {
this.f9996f.add(context);
}
boolean U = com.liulishuo.filedownloader.p0.h.U(context);
this.f9994d = U;
intent.putExtra(com.liulishuo.filedownloader.p0.b.a, U);
context.bindService(intent, this, 1);
if (this.f9994d) {
if (com.liulishuo.filedownloader.p0.e.a) {
com.liulishuo.filedownloader.p0.e.a(this, "start foreground service", new Object[0]);
}
if (Build.VERSION.SDK_INT >= 26) {
context.startForegroundService(intent);
return;
}
return;
}
context.startService(intent);
return;
}
throw new IllegalStateException("Fatal-Exception: You can't bind the FileDownloadService in :filedownloader process.\n It's the invalid operation and is likely to cause unexpected problems.\n Maybe you want to use non-separate process mode for FileDownloader, More detail about non-separate mode, please move to wiki manually: https://github.com/lingochamp/FileDownloader/wiki/filedownloader.properties");
}
@Override
public void z(Context context) {
if (this.f9996f.contains(context)) {
if (com.liulishuo.filedownloader.p0.e.a) {
com.liulishuo.filedownloader.p0.e.a(this, "unbindByContext %s", context);
}
this.f9996f.remove(context);
if (this.f9996f.isEmpty()) {
h(false);
}
Intent intent = new Intent(context, this.c);
context.unbindService(this);
context.stopService(intent);
}
}
}