package u8; import android.content.Context; import android.content.Intent; import android.os.SystemClock; import android.text.TextUtils; import android.util.SparseArray; import com.vivo.push.util.VivoPushException; import d9.b0; import d9.c; import d9.e0; import d9.g; import d9.u; import d9.y; import java.util.List; import org.json.JSONException; import org.json.JSONObject; import w8.b; import w8.f; import w8.m; import z8.i0; /* compiled from: PushClientManager */ public final class h { /* renamed from: s reason: collision with root package name */ public static volatile h f136197s; /* renamed from: a reason: collision with root package name */ public long f136198a = -1; /* renamed from: b reason: collision with root package name */ public long f136199b = -1; /* renamed from: c reason: collision with root package name */ public long f136200c = -1; /* renamed from: d reason: collision with root package name */ public long f136201d = -1; /* renamed from: e reason: collision with root package name */ public long f136202e = -1; /* renamed from: f reason: collision with root package name */ public long f136203f = -1; /* renamed from: g reason: collision with root package name */ public Context f136204g; /* renamed from: h reason: collision with root package name */ public boolean f136205h = true; /* renamed from: i reason: collision with root package name */ public g f136206i; /* renamed from: j reason: collision with root package name */ public String f136207j; /* renamed from: k reason: collision with root package name */ public String f136208k; /* renamed from: l reason: collision with root package name */ public SparseArray<a> f136209l = new SparseArray<>(); /* renamed from: m reason: collision with root package name */ public int f136210m = 0; /* renamed from: n reason: collision with root package name */ public Boolean f136211n; /* renamed from: o reason: collision with root package name */ public Long f136212o; /* renamed from: p reason: collision with root package name */ public boolean f136213p; /* renamed from: q reason: collision with root package name */ public b f136214q = new g(); /* renamed from: r reason: collision with root package name */ public int f136215r; /* compiled from: PushClientManager */ public static class a { /* renamed from: a reason: collision with root package name */ public a f136216a; /* renamed from: b reason: collision with root package name */ public b f136217b; /* renamed from: c reason: collision with root package name */ public a f136218c; /* renamed from: d reason: collision with root package name */ public Runnable f136219d; /* renamed from: e reason: collision with root package name */ public Object[] f136220e; public a(b bVar, a aVar) { this.f136217b = bVar; this.f136216a = aVar; } public final void a() { Runnable runnable = this.f136219d; if (runnable == null) { u.a("PushClientManager", "task is null"); } else { runnable.run(); } } public final void b(int i10, Object... objArr) { this.f136220e = objArr; a aVar = this.f136218c; if (aVar != null) { aVar.a(i10); } a aVar2 = this.f136216a; if (aVar2 != null) { aVar2.a(i10); } } public final void c(Runnable runnable) { this.f136219d = runnable; } public final void d(a aVar) { this.f136218c = aVar; } public final Object[] e() { return this.f136220e; } } public static synchronized h e() { h hVar; synchronized (h.class) { if (f136197s == null) { f136197s = new h(); } hVar = f136197s; } return hVar; } public static boolean n(long j14) { long elapsedRealtime = SystemClock.elapsedRealtime(); return j14 == -1 || elapsedRealtime <= j14 || elapsedRealtime >= j14 + 2000; } public final String A() { if (!TextUtils.isEmpty(this.f136207j)) { return this.f136207j; } g gVar = this.f136206i; String j14 = gVar != null ? gVar.j("APP_TOKEN", null) : ""; u(j14); return j14; } public final boolean B() { return this.f136205h; } public final Context C() { return this.f136204g; } public final void D() { this.f136206i.b(); } public final int E() { return this.f136215r; } public final long F() { Context context = this.f136204g; if (context == null) { return -1; } if (this.f136212o == null) { this.f136212o = Long.valueOf(e0.a(context)); } return this.f136212o.longValue(); } public final void G() { this.f136208k = null; this.f136206i.l("APP_ALIAS"); } public final boolean H() { if (this.f136211n == null) { this.f136211n = Boolean.valueOf(F() >= 1230 && e0.o(this.f136204g)); } return this.f136211n.booleanValue(); } public final synchronized String b(a aVar) { int i10; this.f136209l.put(this.f136210m, aVar); i10 = this.f136210m; this.f136210m = i10 + 1; return Integer.toString(i10); } public final a d(w8.a aVar, a aVar2) { a aVar3 = new a(aVar, aVar2); String b14 = b(aVar3); aVar.n(b14); aVar3.c(new k(this, aVar, b14)); return aVar3; } public final synchronized void f(Context context) { if (this.f136204g == null) { this.f136204g = c.c(context); this.f136213p = y.h(context, context.getPackageName()); b0.o().n(this.f136204g); m(new f()); g gVar = new g(); this.f136206i = gVar; gVar.c(this.f136204g, "com.vivo.push_preferences.appconfig_v1"); this.f136207j = A(); this.f136208k = this.f136206i.j("APP_ALIAS", null); } } public final void g(Intent intent, c9.a aVar) { p b14 = this.f136214q.b(intent); Context context = e().f136204g; if (b14 == null) { u.a("PushClientManager", "sendCommand, null command!"); if (context != null) { u.m(context, "[执行指令失败]指令空!"); return; } return; } i0 a14 = this.f136214q.a(b14); if (a14 == null) { u.a("PushClientManager", "sendCommand, null command task! pushCommand = ".concat(String.valueOf(b14))); if (context != null) { u.m(context, "[执行指令失败]指令" + b14 + "任务空!"); return; } return; } if (context != null && !(b14 instanceof m)) { u.e(context, "[接收指令]".concat(String.valueOf(b14))); } a14.c(aVar); n.b(a14); } public final void h(String str) { this.f136207j = str; this.f136206i.g("APP_TOKEN", str); } public final void i(String str, int i10) { a w14 = w(str); if (w14 != null) { w14.b(i10, new Object[0]); } else { u.n("PushClientManager", "notifyStatusChanged token is null"); } } public final void j(String str, int i10, Object... objArr) { a w14 = w(str); if (w14 != null) { w14.b(i10, objArr); } else { u.n("PushClientManager", "notifyApp token is null"); } } public final void k(List<String> list) { JSONObject jSONObject; try { if (list.size() > 0) { String j14 = this.f136206i.j("APP_TAGS", null); if (TextUtils.isEmpty(j14)) { jSONObject = new JSONObject(); } else { jSONObject = new JSONObject(j14); } for (String str : list) { jSONObject.put(str, System.currentTimeMillis()); } String jSONObject2 = jSONObject.toString(); if (TextUtils.isEmpty(jSONObject2)) { this.f136206i.l("APP_TAGS"); } else { this.f136206i.g("APP_TAGS", jSONObject2); } } } catch (JSONException e14) { e14.printStackTrace(); this.f136206i.l("APP_TAGS"); } } public final void l(a aVar) { if (this.f136204g != null) { String A = A(); this.f136207j = A; if (!TextUtils.isEmpty(A)) { if (aVar != null) { aVar.a(0); } } else if (n(this.f136198a)) { this.f136198a = SystemClock.elapsedRealtime(); String packageName = this.f136204g.getPackageName(); a aVar2 = null; if (this.f136204g != null) { w8.a aVar3 = new w8.a(true, packageName); aVar3.p(); aVar3.r(); aVar3.s(); aVar3.m(100); if (this.f136213p) { if (H()) { aVar2 = d(aVar3, aVar); } else if (aVar != null) { aVar.a(101); } } else if (aVar3.l(this.f136204g) == 2) { aVar2 = d(aVar3, aVar); } else { m(aVar3); if (aVar != null) { aVar.a(0); } } } else if (aVar != null) { aVar.a(102); } if (aVar2 != null) { aVar2.d(new j(this, aVar2)); aVar2.a(); } } else if (aVar != null) { aVar.a(1002); } } else if (aVar != null) { aVar.a(102); } } public final void m(p pVar) { Context context = e().f136204g; if (pVar == null) { u.a("PushClientManager", "sendCommand, null command!"); if (context != null) { u.m(context, "[执行指令失败]指令空!"); return; } return; } m c14 = this.f136214q.c(pVar); if (c14 == null) { u.a("PushClientManager", "sendCommand, null command task! pushCommand = ".concat(String.valueOf(pVar))); if (context != null) { u.m(context, "[执行指令失败]指令" + pVar + "任务空!"); return; } return; } u.n("PushClientManager", "client--sendCommand, command = ".concat(String.valueOf(pVar))); n.b(c14); } public final void p() throws VivoPushException { Context context = this.f136204g; if (context != null) { e0.j(context); } } public final void q(String str) { this.f136208k = str; this.f136206i.g("APP_ALIAS", str); } public final void r(List<String> list) { JSONObject jSONObject; try { if (list.size() > 0) { String j14 = this.f136206i.j("APP_TAGS", null); if (TextUtils.isEmpty(j14)) { jSONObject = new JSONObject(); } else { jSONObject = new JSONObject(j14); } for (String str : list) { jSONObject.remove(str); } String jSONObject2 = jSONObject.toString(); if (TextUtils.isEmpty(jSONObject2)) { this.f136206i.l("APP_TAGS"); } else { this.f136206i.g("APP_TAGS", jSONObject2); } } } catch (JSONException e14) { e14.printStackTrace(); this.f136206i.l("APP_TAGS"); } } public final void u(String str) { n.d(new i(this, str)); } public final void v(List<String> list) { if (list.contains(this.f136208k)) { G(); } } /* JADX WARNING: Exception block dominator not found, dom blocks: [] */ public final synchronized a w(String str) { if (str != null) { int parseInt = Integer.parseInt(str); a aVar = this.f136209l.get(parseInt); this.f136209l.delete(parseInt); return aVar; } return null; } public final boolean x() { if (this.f136204g == null) { u.n("PushClientManager", "support:context is null"); return false; } Boolean valueOf = Boolean.valueOf(H()); this.f136211n = valueOf; return valueOf.booleanValue(); } public final void y(String str) { n.a(new l(this, str)); } public final boolean z() { return this.f136213p; } }