翰林优商.apk(点击下载) / a.java


package com.ss.android.downloadlib.a.b;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.ResolveInfo;
import android.os.IBinder;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Pair;
import com.baidu.mobads.sdk.api.IAdInterListener;
import com.mbridge.msdk.foundation.entity.CampaignEx;
import com.ss.android.downloadlib.a.b.c;
import com.ss.android.downloadlib.addownload.j;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;

/* compiled from: AidlClient */
public class a {
    private static String d = "";
    private static String e = "";
    private static String f = "";
    private static volatile a g;
    public c a;
    public final List<AbstractC0272a> b = new ArrayList();
    public final Object c = new Object();
    private boolean h = true;
    private boolean i = false;
    private volatile boolean j = false;
    private Context k;
    private final List<Pair<b, d>> l = new ArrayList();
    private final ServiceConnection m = new ServiceConnection() {
        /* class com.ss.android.downloadlib.a.b.a.AnonymousClass1 */

        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            synchronized (a.this.c) {
                a.this.a(false);
                a.this.a = c.a.a(iBinder);
                a.this.c();
                for (AbstractC0272a aVar : a.this.b) {
                    aVar.a();
                }
            }
        }

        public void onServiceDisconnected(ComponentName componentName) {
            synchronized (a.this.c) {
                a.this.a(false);
                a.this.a = null;
                for (AbstractC0272a aVar : a.this.b) {
                    aVar.b();
                }
            }
        }
    };
    private String n = "";

    /* renamed from: com.ss.android.downloadlib.a.b.a$a  reason: collision with other inner class name */
    /* compiled from: AidlClient */
    public interface AbstractC0272a {
        void a();

        void b();
    }

    private a() {
    }

    public static a a() {
        if (g == null) {
            synchronized (a.class) {
                if (g == null) {
                    g = new a();
                }
            }
        }
        return g;
    }

    public boolean a(Context context, boolean z) {
        if (TextUtils.isEmpty(d)) {
            JSONObject i2 = j.i();
            String optString = i2.optString("s");
            d = com.ss.android.socialbase.appdownloader.f.c.a(i2.optString(CampaignEx.JSON_KEY_AD_Q), optString);
            e = com.ss.android.socialbase.appdownloader.f.c.a(i2.optString("u"), optString);
            f = com.ss.android.socialbase.appdownloader.f.c.a(i2.optString(IAdInterListener.AdReqParam.WIDTH), optString);
        }
        this.i = z;
        if (context == null) {
            return true;
        }
        this.k = context.getApplicationContext();
        if (TextUtils.isEmpty(f)) {
            f = this.k.getPackageName();
        }
        if (this.a != null || d()) {
            return true;
        }
        return this.k.bindService(a(context), this.m, 33);
    }

    public void b() {
        if (this.a != null) {
            this.k.unbindService(this.m);
            this.a = null;
        }
        this.b.clear();
        this.l.clear();
    }

    public Intent a(Context context) {
        Intent intent = new Intent();
        intent.setAction(d);
        List<ResolveInfo> queryIntentServices = context.getPackageManager().queryIntentServices(intent, 0);
        if (queryIntentServices == null || queryIntentServices.size() != 1) {
            return null;
        }
        for (ResolveInfo resolveInfo : queryIntentServices) {
            String str = resolveInfo.serviceInfo.packageName;
            String str2 = resolveInfo.serviceInfo.name;
            if (e.equals(str)) {
                ComponentName componentName = new ComponentName(str, str2);
                Intent intent2 = new Intent(intent);
                intent2.setComponent(componentName);
                return intent2;
            }
        }
        return null;
    }

    public void a(b bVar, d dVar) {
        synchronized (this.c) {
            bVar.e = f;
            if (TextUtils.isEmpty(bVar.f)) {
                bVar.f = this.n;
            }
            c cVar = this.a;
            if (cVar != null) {
                try {
                    cVar.a(bVar, dVar);
                } catch (RemoteException e2) {
                    e2.printStackTrace();
                }
            } else if (d() || a(this.k, this.i)) {
                this.l.add(Pair.create(bVar, dVar));
            }
        }
    }

    public void c() {
        for (Pair<b, d> pair : this.l) {
            try {
                this.a.a((b) pair.first, (d) pair.second);
            } catch (RemoteException e2) {
                e2.printStackTrace();
            }
        }
        this.l.clear();
    }

    public boolean d() {
        return this.j;
    }

    public void a(boolean z) {
        this.j = z;
    }
}