package com.seewo.ota.v;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import com.seewo.libmyousdk.model.RomUpdateInfo;
import com.seewo.ota.OTAApplication;
import com.seewo.ota.R;
import com.seewo.ota.activity.DirectOTADialog;
import com.seewo.ota.v.u.r;
import com.seewo.ota.v.u.s;
import d.e.h.a.b;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/* JADX INFO: compiled from: UpdateFactory.java */
/* JADX INFO: loaded from: classes.dex */
public class p implements com.seewo.ota.p.b {
    private static volatile p o;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private Context f2369b;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private k f2370f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private k f2371g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private k f2372h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private n f2373i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private o f2374j;
    private DirectOTADialog m;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private final Map<String, com.seewo.ota.p.b> f2375k = new HashMap();
    private final List<k> l = new ArrayList();
    protected final s n = new a();

    /* JADX INFO: compiled from: UpdateFactory.java */
    class a implements s {
        a() {
        }

        @Override // com.seewo.ota.v.u.s
        public void a(int i2) {
            p.this.a(i2);
        }

        @Override // com.seewo.ota.v.u.s
        public void b() {
            p.this.b();
        }

        @Override // com.seewo.ota.v.u.s
        public void c(int i2, Object obj) {
            p.this.c(i2, obj);
        }

        @Override // com.seewo.ota.v.u.s, android.os.RecoverySystem.ProgressListener
        public void onProgress(int i2) {
            p.this.d(i2);
        }
    }

    private p() {
    }

    public static p r() {
        if (o == null) {
            synchronized (p.class) {
                if (o == null) {
                    o = new p();
                }
            }
        }
        return o;
    }

    private k t(int i2) {
        if (i2 == 0) {
            return this.f2370f;
        }
        Iterator<k> it = this.l.iterator();
        if (it.hasNext()) {
            return it.next();
        }
        return null;
    }

    public void A(int i2) {
        k kVarT = t(i2);
        if (kVarT != null) {
            kVarT.N();
        }
    }

    public void B(int i2) {
        k kVarT = t(i2);
        if (kVarT != null) {
            kVarT.O();
        }
    }

    public void C(int i2) {
        k kVarT = t(i2);
        if (kVarT != null) {
            kVarT.P();
        }
    }

    public void D() {
        k kVar = this.f2370f;
        if (kVar != null) {
            kVar.R();
        }
        for (k kVar2 : this.l) {
            if (kVar2 != null) {
                kVar2.R();
            }
        }
        this.l.clear();
        this.f2375k.clear();
    }

    public void E(String str) {
        this.f2375k.remove(str);
    }

    public void F(int i2) {
        k kVarT = t(i2);
        if (kVarT != null) {
            kVarT.S(false);
        }
    }

    public void G(File file) {
        H(file, this.f2369b.getResources().getBoolean(R.bool.is_auto_upgrade_by_file), true);
    }

    public void H(File file, boolean z, boolean z2) {
        com.seewo.ota.m.s.f2178f.B(this.f2369b, new RomUpdateInfo(file.getName(), "-1", true, file.getName(), file.getPath(), file.getPath(), (int) file.length(), file.getName(), false, false), 1, file.getPath(), z, z2);
    }

    @Override // com.seewo.ota.p.b
    public void a(int i2) {
        Iterator<com.seewo.ota.p.b> it = this.f2375k.values().iterator();
        while (it.hasNext()) {
            it.next().a(i2);
        }
    }

    @Override // com.seewo.ota.p.b
    public void b() {
        Iterator<com.seewo.ota.p.b> it = this.f2375k.values().iterator();
        while (it.hasNext()) {
            it.next().b();
        }
    }

    @Override // com.seewo.ota.p.b
    public void c(int i2, Object obj) {
        Iterator<com.seewo.ota.p.b> it = this.f2375k.values().iterator();
        while (it.hasNext()) {
            it.next().c(i2, obj);
        }
    }

    @Override // com.seewo.ota.p.b
    public void d(int i2) {
        Iterator<com.seewo.ota.p.b> it = this.f2375k.values().iterator();
        while (it.hasNext()) {
            it.next().d(i2);
        }
    }

    @Override // com.seewo.ota.p.b
    public void e(int i2, int i3) {
        Iterator<com.seewo.ota.p.b> it = this.f2375k.values().iterator();
        while (it.hasNext()) {
            it.next().e(i2, i3);
        }
    }

    public void f(int i2) {
        k kVarT = t(i2);
        if (kVarT != null) {
            kVarT.h();
        }
    }

    @Override // com.seewo.ota.p.b
    public void g(int i2, int i3, RomUpdateInfo romUpdateInfo, boolean z) {
        Iterator<com.seewo.ota.p.b> it = this.f2375k.values().iterator();
        while (it.hasNext()) {
            it.next().g(i2, i3, romUpdateInfo, z);
        }
    }

    @Override // com.seewo.ota.p.b
    public void h(int i2, int i3) {
        Iterator<com.seewo.ota.p.b> it = this.f2375k.values().iterator();
        while (it.hasNext()) {
            it.next().h(i2, i3);
        }
    }

    @Override // com.seewo.ota.p.b
    public void i(int i2) {
        Iterator<com.seewo.ota.p.b> it = this.f2375k.values().iterator();
        while (it.hasNext()) {
            it.next().i(i2);
        }
    }

    @Override // com.seewo.ota.p.b
    public void j(RomUpdateInfo romUpdateInfo, int i2, boolean z, boolean z2) {
        Iterator<com.seewo.ota.p.b> it = this.f2375k.values().iterator();
        while (it.hasNext()) {
            it.next().j(romUpdateInfo, i2, z, z2);
        }
    }

    public void k(int i2) {
        k kVarT = t(i2);
        if (kVarT != null) {
            kVarT.i();
        }
    }

    public void l(int i2, boolean z) {
        if (com.seewo.vcommons.data.c.a(OTAApplication.b(), "KEY_DISABLE_SYSTEM_UPDATE", false)) {
            Log.d("UpdateFactory", "checkUpdate is Disable:" + i2);
            return;
        }
        if (this.f2369b.getResources().getBoolean(R.bool.support_auto_usb_update) && !com.seewo.ota.util.n.b().d() && !z) {
            this.f2372h.j(false);
            return;
        }
        k kVarT = t(i2);
        if (kVarT != null) {
            kVarT.j(z);
        }
    }

    public void m(com.seewo.ota.p.b bVar) {
        if (!com.seewo.ota.data.b.i().u()) {
            Log.i("UpdateFactory", "checkUpdateThird: not support third update");
            return;
        }
        if (this.f2374j == null) {
            this.f2374j = new o(this.f2369b, bVar);
        }
        this.f2374j.j(true);
    }

    public void n() {
        if (this.m == null) {
            this.m = new DirectOTADialog(this.f2369b);
        }
        if (this.m.isShowing()) {
            return;
        }
        this.m.show();
    }

    public int o() {
        return com.seewo.ota.data.b.i().q() ? 1 : 0;
    }

    public int p(int i2) {
        k kVarT = t(i2);
        if (kVarT != null) {
            return kVarT.u();
        }
        return 5;
    }

    public int q(int i2) {
        k kVarT = t(i2);
        if (kVarT != null) {
            return kVarT.v();
        }
        return 0;
    }

    public RomUpdateInfo s(int i2) {
        k kVarT = t(i2);
        if (kVarT != null) {
            return kVarT.z();
        }
        return null;
    }

    public Bundle u(int i2) {
        k kVarT = t(i2);
        RomUpdateInfo romUpdateInfoZ = kVarT != null ? kVarT.z() : null;
        Bundle bundle = new Bundle();
        if (romUpdateInfoZ != null) {
            bundle.putString("UPDATE_URL", romUpdateInfoZ.getDownloadUrl());
            bundle.putString("UPDATE_VERSION", romUpdateInfoZ.getVersionCode());
            bundle.putLong("UPDATE_SIZE", romUpdateInfoZ.getFileSize());
            bundle.putString("UPDATE_DESC", romUpdateInfoZ.getUpdateDesc());
            bundle.putBoolean("UPDATE_IS_FORCE_UPDATE", romUpdateInfoZ.isForceUpdate());
            bundle.putBoolean("UPDATE_IS_SILENT_DOWNLOAD", romUpdateInfoZ.isSilentDownload());
        }
        return bundle;
    }

    public int v(int i2) {
        k kVarT = t(i2);
        return kVarT != null ? kVarT.C() : b.a.NONE.ordinal();
    }

    public void w(Context context) {
        this.f2369b = context.getApplicationContext();
        if (com.seewo.ota.data.b.i().s()) {
            m mVar = new m(this.f2369b, this);
            this.f2370f = mVar;
            mVar.Q();
        }
        if (com.seewo.ota.data.b.i().q()) {
            l lVar = new l(this.f2369b, this);
            this.f2371g = lVar;
            lVar.Q();
            this.l.add(this.f2371g);
        }
        if (com.seewo.ota.data.b.i().t()) {
            n nVar = new n(this.f2369b, this);
            this.f2373i = nVar;
            nVar.Q();
            this.l.add(this.f2373i);
        }
        this.f2372h = new q(this.f2369b, this);
        r.d().l("UpdateFactory", this.n);
    }

    public boolean x() {
        return !this.l.isEmpty();
    }

    public void y(String str, com.seewo.ota.p.b bVar) {
        if (bVar != null) {
            this.f2375k.put(str, bVar);
        }
    }

    public void z(int i2, String str) {
        k kVarT = t(i2);
        if (kVarT != null) {
            kVarT.M(str);
        }
    }
}
