package com.kwai.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.IBinder; import android.os.IInterface; import android.os.RemoteException; import com.kwai.filedownloader.e.d; import com.kwai.filedownloader.e.f; import com.kwai.filedownloader.event.DownloadServiceConnectChangedEvent; import com.kwai.filedownloader.u; import java.util.ArrayList; import java.util.HashMap; import java.util.List; public abstract class a<CALLBACK extends Binder, INTERFACE extends IInterface> implements ServiceConnection, u { private final ArrayList<Runnable> bHf = new ArrayList<>(); private final CALLBACK bJS; private volatile INTERFACE bJT; private final HashMap<String, Object> bJU = new HashMap<>(); private final List<Context> bJV = new ArrayList(); private final Class<?> bJq; protected a(Class<?> cls) { this.bJq = cls; this.bJS = abV(); } private void a(Context context, Runnable runnable) { if (!f.em(context)) { if (d.bKs) { d.e(this, "bindStartByContext %s", context.getClass().getSimpleName()); } Intent intent = new Intent(context, this.bJq); if (!this.bJV.contains(context)) { this.bJV.add(context); } context.bindService(intent, this, 1); 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"); } private void cT(boolean z) { if (d.bKs) { d.e(this, "release connect resources %s", this.bJT); } this.bJT = null; com.kwai.filedownloader.f.abE().c(new DownloadServiceConnectChangedEvent(DownloadServiceConnectChangedEvent.ConnectStatus.lost, this.bJq)); } /* access modifiers changed from: protected */ public abstract void a(INTERFACE v, CALLBACK callback); /* access modifiers changed from: protected */ public abstract CALLBACK abV(); /* access modifiers changed from: protected */ public final INTERFACE ado() { return this.bJT; } /* access modifiers changed from: protected */ public abstract INTERFACE b(IBinder iBinder); @Override // com.kwai.filedownloader.u public final void ej(Context context) { a(context, (Runnable) null); } @Override // com.kwai.filedownloader.u public final boolean isConnected() { return ado() != null; } public void onServiceConnected(ComponentName componentName, IBinder iBinder) { this.bJT = b(iBinder); if (d.bKs) { d.e(this, "onServiceConnected %s %s", componentName, this.bJT); } try { a(this.bJT, this.bJS); } catch (RemoteException e) { e.printStackTrace(); } this.bHf.clear(); for (Runnable runnable : (List) this.bHf.clone()) { runnable.run(); } com.kwai.filedownloader.f.abE().c(new DownloadServiceConnectChangedEvent(DownloadServiceConnectChangedEvent.ConnectStatus.connected, this.bJq)); } public void onServiceDisconnected(ComponentName componentName) { if (d.bKs) { d.e(this, "onServiceDisconnected %s %s", componentName, this.bJT); } cT(true); } }