package cn.jiguang.ai; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.database.Cursor; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.IBinder; import android.text.TextUtils; import cn.jiguang.ak.c; import cn.jiguang.o.d; import cn.jiguang.o.e; import cn.jiguang.v.f; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.json.JSONObject; public class a extends e { private Context a; private cn.jiguang.aj.a c; private String d; /* renamed from: cn.jiguang.ai.a$a reason: collision with other inner class name */ private static class C0002a extends e { private Context a; public C0002a(Context context) { this.a = context; this.b = "JWake#RequestConfigAction"; } @Override // cn.jiguang.o.e public void a() { a.d(this.a); } } /* access modifiers changed from: private */ public static class b implements ServiceConnection { private Context a; public b(Context context) { this.a = context; } public void onServiceConnected(ComponentName componentName, IBinder iBinder) { try { cn.jiguang.af.a.a("JWake", "unbind wake ServiceConnection"); this.a.getApplicationContext().unbindService(this); } catch (Throwable th) { cn.jiguang.af.a.d("JWake", "onServiceConnected throwable" + th.getMessage()); } } public void onServiceDisconnected(ComponentName componentName) { } } public a(Context context, String str) { this.a = context; this.d = str; this.b = "JWake"; } public static Object a(Context context, Object obj) { if (!(obj instanceof List)) { return obj; } return c.a(cn.jiguang.ak.b.b(context), (List) obj); } /* JADX WARNING: Removed duplicated region for block: B:45:0x0147 */ public static List<cn.jiguang.aj.b> a(Context context, List<cn.jiguang.aj.c> list) { boolean z; boolean z2; boolean z3; boolean z4; boolean z5; Throwable th; cn.jiguang.af.a.a("JWake", "[wake] wakeTargets:" + list); cn.jiguang.o.b.c(context, "JWake"); cn.jiguang.o.b.a(context); if (list == null || list.size() <= 0) { cn.jiguang.af.a.d("JWake", "there are no wakeTarget"); return null; } HashMap hashMap = new HashMap(); hashMap.put("from_package", context.getPackageName()); ArrayList arrayList = new ArrayList(); for (cn.jiguang.aj.c cVar : list) { cn.jiguang.af.a.a("JWake", "start wake target:" + cVar); if (cVar == null) { cn.jiguang.af.a.d("JWake", "wakeTarget is null, continue another wake"); } else if (cVar.c == 2) { cn.jiguang.af.a.d("JWake", "command this app is not allow to wake package:" + cVar.a + ",service:" + cVar.b); } else { cn.jiguang.aj.b bVar = new cn.jiguang.aj.b(); bVar.a = cVar.a; boolean z6 = false; if ((cVar.f & 1) == 0 || cVar.e == null || cn.jiguang.ak.a.a(context)) { z = false; } else { try { Bundle a2 = c.a(hashMap); a2.putInt("type", 8); Intent intent = cVar.e; if (intent != null) { intent.addFlags(268435456); intent.putExtras(a2); context.startActivity(intent); try { if (intent.getComponent() != null) { cn.jiguang.o.b.c(context, "cn.jpush.android.service.DActivity".equals(intent.getComponent().getClassName()) ? "JWake_dactivity" : "JWake_activity"); } cn.jiguang.af.a.a("JWake", "use ACTIVITY wake up ,start activity:" + cVar.a + "," + cVar.e); z = true; z4 = true; } catch (Throwable th2) { th = th2; z5 = true; cn.jiguang.af.a.a("JWake", "Fail to start activity caused by:" + th); z = z5; z4 = false; bVar.b.put(8, Boolean.valueOf(z4)); if (!z) { } arrayList.add(bVar); } bVar.b.put(8, Boolean.valueOf(z4)); } else { cn.jiguang.af.a.d("JWake", "Fail to start activity ,activityIntent is null !!"); z = false; z4 = false; bVar.b.put(8, Boolean.valueOf(z4)); } } catch (Throwable th3) { th = th3; z5 = false; cn.jiguang.af.a.a("JWake", "Fail to start activity caused by:" + th); z = z5; z4 = false; bVar.b.put(8, Boolean.valueOf(z4)); if (!z) { } arrayList.add(bVar); } } if (!z) { int i = !TextUtils.isEmpty(cVar.b) ? (Build.VERSION.SDK_INT < 26 || cVar.c < 26) ? 3 : 2 : 0; if (!TextUtils.isEmpty(cVar.d)) { i |= 4; } cn.jiguang.af.a.a("JWake", "use OLD wake up ,wake type is :" + i); int i2 = i & 2; if (!(i2 == 0 && (i & 1) == 0)) { ComponentName componentName = new ComponentName(cVar.a, cVar.b); Intent intent2 = new Intent(); intent2.setComponent(componentName); if (Build.VERSION.SDK_INT >= 12) { intent2.setFlags(32); } Bundle a3 = c.a(hashMap); a3.putInt("type", 2); if (a3 != null) { intent2.putExtras(a3); } if (i2 != 0) { try { z3 = context.getApplicationContext().bindService(intent2, new b(context), 1); } catch (Throwable th4) { cn.jiguang.af.a.d("JWake", "bindService throwable:" + th4.getMessage()); z3 = false; } bVar.b.put(2, Boolean.valueOf(z3)); } if ((i & 1) != 0) { try { if (context.startService(intent2) != null) { z2 = true; bVar.b.put(1, Boolean.valueOf(z2)); } } catch (Throwable th5) { cn.jiguang.af.a.d("JWake", "startService throwable:" + th5.getMessage()); } z2 = false; bVar.b.put(1, Boolean.valueOf(z2)); } } if ((i & 4) != 0) { try { if (!TextUtils.isEmpty(cVar.d)) { ContentResolver contentResolver = context.getApplicationContext().getContentResolver(); String str = cVar.d; if (!str.startsWith("content://")) { str = "content://" + str; } hashMap.put("type", "4"); String b2 = c.b(hashMap); if (!TextUtils.isEmpty(b2)) { str = str + b2; } Cursor query = contentResolver.query(Uri.parse(str), null, null, null, null); if (query != null && !query.isClosed()) { query.close(); } z6 = true; } } catch (Throwable th6) { cn.jiguang.af.a.d("JWake", "getContentResolver throwable:" + th6.getMessage()); } bVar.b.put(4, Boolean.valueOf(z6)); } cn.jiguang.af.a.a("JWake", "wakeResult:" + bVar.toString()); } arrayList.add(bVar); } } return arrayList; } public static void a(Context context) { try { d.a(new C0002a(context)); } catch (Throwable th) { cn.jiguang.af.a.d("JWake", "[requestConfig failed] " + th.getMessage()); } } private static void a(Context context, cn.jiguang.aj.a aVar) { boolean z = false; if ((cn.jiguang.o.b.b(context) || aVar.e) && aVar.b && aVar.d) { z = true; } cn.jiguang.ak.a.a(context, z); } public static void a(Context context, String str) { try { d.a(new a(context, str)); } catch (Throwable th) { cn.jiguang.af.a.d("JWake", "[doAction failed] " + str + " :" + th.getMessage()); } } private boolean a(String str) { String str2; StringBuilder sb; String str3; if (this.c.p != null && this.c.p.contains(str)) { str2 = "JWake"; sb = new StringBuilder(); sb.append(str); str3 = " is in black list"; } else if (TextUtils.isEmpty(this.c.n)) { return false; } else { if (this.c.n.equals("exclude")) { if (!this.c.o.contains(str)) { return false; } str2 = "JWake"; sb = new StringBuilder(); sb.append(str); str3 = " is in excloude list"; } else if (!this.c.n.equals("include") || this.c.o.contains(str)) { return false; } else { str2 = "JWake"; sb = new StringBuilder(); sb.append(str); str3 = " is not in include list"; } } sb.append(str3); cn.jiguang.af.a.a(str2, sb.toString()); return true; } public static Object b(Context context) { boolean z = cn.jiguang.ak.b.b(context).e || cn.jiguang.o.b.b(context); cn.jiguang.af.a.a("JWake", "isActionUserEnable :" + z); return Boolean.valueOf(z); } private boolean b() { boolean z = this.c.e || cn.jiguang.o.b.b(this.a); cn.jiguang.af.a.a("JWake", "isActionUserEnable :" + z); return z; } private void c() { long j = this.c.l; long d2 = cn.jiguang.o.b.d(this.a, "JWakeConfigHelper"); long currentTimeMillis = System.currentTimeMillis(); cn.jiguang.af.a.a("JWake", "[refeshWakeConfig] currentTimeMillis:" + currentTimeMillis + ",lastBusinessTime:" + d2 + ",wakeConfigInterval:" + j); if (currentTimeMillis - d2 >= j) { cn.jiguang.aj.a d3 = d(this.a); if (d3 != null) { this.c = d3; return; } return; } cn.jiguang.af.a.a("JWake", "need not get wake config"); } /* access modifiers changed from: private */ public static cn.jiguang.aj.a d(Context context) { try { JSONObject a2 = cn.jiguang.ak.b.a(context); if (a2 == null) { return null; } cn.jiguang.ak.b.a(context, f.c(a2.toString())); return cn.jiguang.ak.b.a(context, a2); } catch (Throwable th) { cn.jiguang.af.a.d("JWake", "[requestConfigNow] failed:" + th.getMessage()); return null; } } /* JADX WARNING: Removed duplicated region for block: B:30:0x00e5 */ /* JADX WARNING: Removed duplicated region for block: B:32:0x00fe */ /* JADX WARNING: Removed duplicated region for block: B:55:0x0158 A[ADDED_TO_REGION, Catch:{ URISyntaxException -> 0x017c }] */ private List<cn.jiguang.aj.c> d() { cn.jiguang.aj.c cVar; HashMap<String, cn.jiguang.aj.c> hashMap; URISyntaxException e; boolean z; ArrayList arrayList = new ArrayList(); HashMap<String, cn.jiguang.aj.c> a2 = c.a(this.a); HashMap hashMap2 = (HashMap) this.c.k; long d2 = cn.jiguang.o.b.d(this.a, "JWake_account"); long d3 = cn.jiguang.o.b.d(this.a, "JWake_activity"); long d4 = cn.jiguang.o.b.d(this.a, "JWake_dactivity"); long currentTimeMillis = System.currentTimeMillis(); int i = ((currentTimeMillis - d2) > this.c.q ? 1 : ((currentTimeMillis - d2) == this.c.q ? 0 : -1)); HashMap<String, cn.jiguang.aj.c> hashMap3 = a2; boolean z2 = currentTimeMillis - d3 >= this.c.s; boolean z3 = currentTimeMillis - d4 >= this.c.r || this.d.equals("start"); cn.jiguang.af.a.a("JWake", "currentTimeMillis:" + currentTimeMillis + ",lastAccountTime:" + d2 + ",lastActivityTime:" + d3 + ",lastDActivityTime:" + d4); if (hashMap2 != null) { Iterator it = hashMap2.entrySet().iterator(); while (it.hasNext() && arrayList.size() < this.c.f) { Map.Entry entry = (Map.Entry) it.next(); String str = (String) entry.getKey(); if (!a(str)) { cn.jiguang.aj.d dVar = (cn.jiguang.aj.d) entry.getValue(); Intent intent = null; if (hashMap3 != null) { hashMap = hashMap3; if (hashMap.containsKey(str)) { cVar = hashMap.get(str); if (cVar != null) { cn.jiguang.af.a.d("JWake", str + " not found targetInfo"); } else if (cVar != null) { cVar.f = dVar.a; cn.jiguang.af.a.a("JWake", "not support acc"); try { if ((cVar.f & 1) != 0) { if (TextUtils.isEmpty(dVar.f)) { if (z3) { intent = new Intent(); intent.setClassName(str, "cn.jpush.android.service.DActivity"); z = cn.jiguang.ak.a.a(this.a, str, intent, false); if (z || intent == null) { cn.jiguang.af.a.d("JWake", "do not use Activity wake , activityEnable = " + z + ", intent=" + intent); } else { cVar.e = intent; } } else { cn.jiguang.af.a.a("JWake", "not DActivity time"); } } else if (z2) { try { intent = Intent.parseUri(dVar.f, 0); } catch (URISyntaxException e2) { e = e2; cn.jiguang.af.a.f("JWake", "parse package:" + str + " activity intent error:" + e); arrayList.add(cVar); hashMap3 = hashMap; } try { z = cn.jiguang.ak.a.a(this.a, str, intent, true); if (z) { } cn.jiguang.af.a.d("JWake", "do not use Activity wake , activityEnable = " + z + ", intent=" + intent); } catch (URISyntaxException e3) { e = e3; cn.jiguang.af.a.f("JWake", "parse package:" + str + " activity intent error:" + e); arrayList.add(cVar); hashMap3 = hashMap; } } else { cn.jiguang.af.a.a("JWake", "not custom Activity time"); } z = false; if (z) { } cn.jiguang.af.a.d("JWake", "do not use Activity wake , activityEnable = " + z + ", intent=" + intent); } } catch (URISyntaxException e4) { e = e4; cn.jiguang.af.a.f("JWake", "parse package:" + str + " activity intent error:" + e); arrayList.add(cVar); hashMap3 = hashMap; } arrayList.add(cVar); } hashMap3 = hashMap; } } else { hashMap = hashMap3; } cVar = dVar.d ? c.a(this.a, str) : null; if (cVar != null) { } hashMap3 = hashMap; } } } if (arrayList.size() < this.c.f && hashMap3 != null && !hashMap3.isEmpty()) { List<String> a3 = c.a(this.c, new ArrayList(hashMap3.keySet())); Collections.shuffle(a3); LinkedHashMap linkedHashMap = new LinkedHashMap(); for (String str2 : a3) { if (hashMap3.containsKey(str2)) { linkedHashMap.put(str2, hashMap3.get(str2)); } } Iterator it2 = linkedHashMap.entrySet().iterator(); while (it2.hasNext() && arrayList.size() < this.c.f) { cn.jiguang.aj.c cVar2 = (cn.jiguang.aj.c) ((Map.Entry) it2.next()).getValue(); if (!arrayList.contains(cVar2)) { arrayList.add(cVar2); } } } return arrayList; } @Override // cn.jiguang.o.e public void a() { try { cn.jiguang.af.a.a("JWake", "wake with:" + this.d); if (!d.e(this.a)) { cn.jiguang.af.a.d("JWake", "can't wake because not registered yet"); return; } this.c = cn.jiguang.ak.b.b(this.a); c(); cn.jiguang.af.a.a("JWake", "use config:" + this.c); a(this.a, this.c); if (!b()) { cn.jiguang.af.a.a("JWake", "wake is disabled by user"); return; } if (this.c.a) { if (this.c.c) { if (this.c.i && this.d.equals("start")) { c.a(this.a, this.c, a(this.a, d())); return; } else if (!this.c.h) { cn.jiguang.af.a.a("JWake", "time disabled"); return; } else { long d2 = cn.jiguang.o.b.d(this.a, "JWake"); long j = this.c.g; long currentTimeMillis = System.currentTimeMillis(); cn.jiguang.af.a.a("JWake", "[wakeUp]currentTimeMillis:" + currentTimeMillis + ",lastBusinessTime:" + d2 + ",wakeInterval:" + j); if (currentTimeMillis - d2 >= j) { c.a(this.a, this.c, a(this.a, d())); return; } cn.jiguang.af.a.a("JWake", "need not wake up"); return; } } } cn.jiguang.af.a.a("JWake", "wake is disabled by server"); } catch (Throwable th) { cn.jiguang.af.a.d("JWake", "wake failed:" + th.getMessage()); } } }