最右.apk(点击下载) / a.java


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.f;
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> avh = new ArrayList<>();
    private final CALLBACK axX;
    public volatile INTERFACE axY;
    private final HashMap<String, Object> axZ = new HashMap<>();
    private final Class<?> axt;
    private final List<Context> aya = new ArrayList();

    public a(Class<?> cls) {
        this.axt = cls;
        this.axX = rm();
    }

    public abstract INTERFACE a(IBinder iBinder);

    public abstract void a(INTERFACE v, CALLBACK callback);

    @Override // com.kwai.filedownloader.u
    public final void cw(Context context) {
        if (!f.cy(context)) {
            if (d.ayy) {
                d.e(this, "bindStartByContext %s", context.getClass().getSimpleName());
            }
            Intent intent = new Intent(context, this.axt);
            if (!this.aya.contains(context)) {
                this.aya.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");
    }

    @Override // com.kwai.filedownloader.u
    public final boolean isConnected() {
        return this.axY != null;
    }

    public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
        this.axY = a(iBinder);
        if (d.ayy) {
            d.e(this, "onServiceConnected %s %s", componentName, this.axY);
        }
        try {
            a(this.axY, this.axX);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        this.avh.clear();
        for (Runnable runnable : (List) this.avh.clone()) {
            runnable.run();
        }
        f.a.auN.c(new DownloadServiceConnectChangedEvent(DownloadServiceConnectChangedEvent.ConnectStatus.connected, this.axt));
    }

    public void onServiceDisconnected(ComponentName componentName) {
        if (d.ayy) {
            d.e(this, "onServiceDisconnected %s %s", componentName, this.axY);
        }
        if (d.ayy) {
            d.e(this, "release connect resources %s", this.axY);
        }
        this.axY = null;
        f.a.auN.c(new DownloadServiceConnectChangedEvent(DownloadServiceConnectChangedEvent.ConnectStatus.lost, this.axt));
    }

    public abstract CALLBACK rm();
}