package com.xiaomi.mipush.sdk; import android.content.Context; import android.content.SharedPreferences; import android.text.TextUtils; import com.xiaomi.push.g; import com.xiaomi.push.i; import java.util.HashMap; import java.util.Map; import org.json.JSONObject; public class b { private static volatile b a; /* renamed from: a reason: collision with other field name */ private Context f6705a; /* renamed from: a reason: collision with other field name */ private a f6706a; /* renamed from: a reason: collision with other field name */ String f6707a; /* renamed from: a reason: collision with other field name */ private Map<String, a> f6708a; public static class a { public int a = 1; /* renamed from: a reason: collision with other field name */ private Context f6709a; /* renamed from: a reason: collision with other field name */ public String f6710a; /* renamed from: a reason: collision with other field name */ public boolean f6711a = true; public String b; /* renamed from: b reason: collision with other field name */ public boolean f6712b = false; public String c; public String d; public String e; public String f; public String g; public String h; public a(Context context) { this.f6709a = context; } public static a a(Context context, String str) { try { JSONObject jSONObject = new JSONObject(str); a aVar = new a(context); aVar.f6710a = jSONObject.getString("appId"); aVar.b = jSONObject.getString("appToken"); aVar.c = jSONObject.getString("regId"); aVar.d = jSONObject.getString("regSec"); aVar.f = jSONObject.getString("devId"); aVar.e = jSONObject.getString("vName"); aVar.f6711a = jSONObject.getBoolean("valid"); aVar.f6712b = jSONObject.getBoolean("paused"); aVar.a = jSONObject.getInt("envType"); aVar.g = jSONObject.getString("regResource"); return aVar; } catch (Throwable th) { com.xiaomi.channel.commonutils.logger.b.a(th); return null; } } private String a() { Context context = this.f6709a; return g.m9381a(context, context.getPackageName()); } public static String a(a aVar) { try { JSONObject jSONObject = new JSONObject(); jSONObject.put("appId", aVar.f6710a); jSONObject.put("appToken", aVar.b); jSONObject.put("regId", aVar.c); jSONObject.put("regSec", aVar.d); jSONObject.put("devId", aVar.f); jSONObject.put("vName", aVar.e); jSONObject.put("valid", aVar.f6711a); jSONObject.put("paused", aVar.f6712b); jSONObject.put("envType", aVar.a); jSONObject.put("regResource", aVar.g); return jSONObject.toString(); } catch (Throwable th) { com.xiaomi.channel.commonutils.logger.b.a(th); return null; } } /* renamed from: a reason: collision with other method in class */ public void m9099a() { b.a(this.f6709a).edit().clear().commit(); this.f6710a = null; this.b = null; this.c = null; this.d = null; this.f = null; this.e = null; this.f6711a = false; this.f6712b = false; this.h = null; this.a = 1; } public void a(int i) { this.a = i; } public void a(String str, String str2) { this.c = str; this.d = str2; this.f = i.l(this.f6709a); this.e = a(); this.f6711a = true; } public void a(String str, String str2, String str3) { this.f6710a = str; this.b = str2; this.g = str3; SharedPreferences.Editor edit = b.a(this.f6709a).edit(); edit.putString("appId", this.f6710a); edit.putString("appToken", str2); edit.putString("regResource", str3); edit.commit(); } public void a(boolean z) { this.f6712b = z; } /* renamed from: a reason: collision with other method in class */ public boolean m9100a() { return m9101a(this.f6710a, this.b); } /* renamed from: a reason: collision with other method in class */ public boolean m9101a(String str, String str2) { boolean equals = TextUtils.equals(this.f6710a, str); boolean equals2 = TextUtils.equals(this.b, str2); boolean z = !TextUtils.isEmpty(this.c); boolean z2 = !TextUtils.isEmpty(this.d); boolean z3 = TextUtils.equals(this.f, i.l(this.f6709a)) || TextUtils.equals(this.f, i.k(this.f6709a)); boolean z4 = equals && equals2 && z && z2 && z3; if (!z4) { com.xiaomi.channel.commonutils.logger.b.e(String.format("register invalid, aid=%s;atn=%s;rid=%s;rse=%s;did=%s", Boolean.valueOf(equals), Boolean.valueOf(equals2), Boolean.valueOf(z), Boolean.valueOf(z2), Boolean.valueOf(z3))); } return z4; } public void b() { this.f6711a = false; b.a(this.f6709a).edit().putBoolean("valid", this.f6711a).commit(); } public void b(String str, String str2, String str3) { this.c = str; this.d = str2; this.f = i.l(this.f6709a); this.e = a(); this.f6711a = true; this.h = str3; SharedPreferences.Editor edit = b.a(this.f6709a).edit(); edit.putString("regId", str); edit.putString("regSec", str2); edit.putString("devId", this.f); edit.putString("vName", a()); edit.putBoolean("valid", true); edit.putString("appRegion", str3); edit.commit(); } public void c(String str, String str2, String str3) { this.f6710a = str; this.b = str2; this.g = str3; } } private b(Context context) { this.f6705a = context; c(); } public static SharedPreferences a(Context context) { return context.getSharedPreferences("mipush", 0); } /* renamed from: a reason: collision with other method in class */ public static b m9086a(Context context) { if (a == null) { synchronized (b.class) { if (a == null) { a = new b(context); } } } return a; } private void c() { this.f6706a = new a(this.f6705a); this.f6708a = new HashMap(); SharedPreferences a2 = a(this.f6705a); this.f6706a.f6710a = a2.getString("appId", null); this.f6706a.b = a2.getString("appToken", null); this.f6706a.c = a2.getString("regId", null); this.f6706a.d = a2.getString("regSec", null); this.f6706a.f = a2.getString("devId", null); if (!TextUtils.isEmpty(this.f6706a.f) && i.m9476a(this.f6706a.f)) { this.f6706a.f = i.l(this.f6705a); a2.edit().putString("devId", this.f6706a.f).commit(); } this.f6706a.e = a2.getString("vName", null); this.f6706a.f6711a = a2.getBoolean("valid", true); this.f6706a.f6712b = a2.getBoolean("paused", false); this.f6706a.a = a2.getInt("envType", 1); this.f6706a.g = a2.getString("regResource", null); this.f6706a.h = a2.getString("appRegion", null); } public int a() { return this.f6706a.a; } public a a(String str) { if (this.f6708a.containsKey(str)) { return this.f6708a.get(str); } String str2 = "hybrid_app_info_" + str; SharedPreferences a2 = a(this.f6705a); if (!a2.contains(str2)) { return null; } a a3 = a.a(this.f6705a, a2.getString(str2, "")); this.f6708a.put(str2, a3); return a3; } /* renamed from: a reason: collision with other method in class */ public String m9087a() { return this.f6706a.f6710a; } /* renamed from: a reason: collision with other method in class */ public void m9088a() { this.f6706a.m9099a(); } public void a(int i) { this.f6706a.a(i); a(this.f6705a).edit().putInt("envType", i).commit(); } /* renamed from: a reason: collision with other method in class */ public void m9089a(String str) { SharedPreferences.Editor edit = a(this.f6705a).edit(); edit.putString("vName", str); edit.commit(); this.f6706a.e = str; } public void a(String str, a aVar) { this.f6708a.put(str, aVar); String a2 = a.a(aVar); a(this.f6705a).edit().putString("hybrid_app_info_" + str, a2).commit(); } public void a(String str, String str2, String str3) { this.f6706a.a(str, str2, str3); } public void a(boolean z) { this.f6706a.a(z); a(this.f6705a).edit().putBoolean("paused", z).commit(); } /* renamed from: a reason: collision with other method in class */ public boolean m9090a() { Context context = this.f6705a; return !TextUtils.equals(g.m9381a(context, context.getPackageName()), this.f6706a.e); } public boolean a(String str, String str2) { return this.f6706a.m9101a(str, str2); } /* renamed from: a reason: collision with other method in class */ public boolean m9091a(String str, String str2, String str3) { a a2 = a(str3); return a2 != null && TextUtils.equals(str, a2.f6710a) && TextUtils.equals(str2, a2.b); } public String b() { return this.f6706a.b; } /* renamed from: b reason: collision with other method in class */ public void m9092b() { this.f6706a.b(); } public void b(String str) { this.f6708a.remove(str); a(this.f6705a).edit().remove("hybrid_app_info_" + str).commit(); } public void b(String str, String str2, String str3) { this.f6706a.b(str, str2, str3); } /* renamed from: b reason: collision with other method in class */ public boolean m9093b() { if (this.f6706a.m9100a()) { return true; } com.xiaomi.channel.commonutils.logger.b.m9051a("Don't send message before initialization succeeded!"); return false; } /* renamed from: c reason: collision with other method in class */ public String m9094c() { return this.f6706a.c; } /* renamed from: c reason: collision with other method in class */ public boolean m9095c() { return this.f6706a.m9100a(); } public String d() { return this.f6706a.d; } /* renamed from: d reason: collision with other method in class */ public boolean m9096d() { return !TextUtils.isEmpty(this.f6706a.f6710a) && !TextUtils.isEmpty(this.f6706a.b) && !TextUtils.isEmpty(this.f6706a.c) && !TextUtils.isEmpty(this.f6706a.d); } public String e() { return this.f6706a.g; } /* renamed from: e reason: collision with other method in class */ public boolean m9097e() { return this.f6706a.f6712b; } public String f() { return this.f6706a.h; } /* renamed from: f reason: collision with other method in class */ public boolean m9098f() { return !this.f6706a.f6711a; } }