package cn.jiguang.g; import android.content.Context; import android.content.SharedPreferences; import android.os.Build; import android.text.TextUtils; import cn.jiguang.android.BuildConfig; import cn.jiguang.be.d; import cn.jiguang.internal.JConstants; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class b { private static final Map<String, SharedPreferences> a = new ConcurrentHashMap(); public static <T> T a(Context context, a<T> aVar) { T t = (T) b(context, aVar); return t != null ? t : aVar.e; } private static <T> T a(SharedPreferences sharedPreferences, String str, T t) { if (sharedPreferences != null && sharedPreferences.contains(str)) { try { if (t instanceof Boolean) { return (T) Boolean.valueOf(sharedPreferences.getBoolean(str, t.booleanValue())); } if (t instanceof String) { return (T) sharedPreferences.getString(str, t); } if (t instanceof Integer) { return (T) Integer.valueOf(sharedPreferences.getInt(str, t.intValue())); } if (t instanceof Long) { return (T) Long.valueOf(sharedPreferences.getLong(str, t.longValue())); } if (t instanceof Float) { return (T) Float.valueOf(sharedPreferences.getFloat(str, t.floatValue())); } } catch (Throwable unused) { } } return null; } /* JADX DEBUG: Multi-variable search result rejected for r4v0, resolved type: cn.jiguang.g.a<T> */ /* JADX WARN: Multi-variable type inference failed */ private static <T> void a(Context context, a<T> aVar, a<T> aVar2) { Object b; if (b(context, aVar) == null && (b = b(context, aVar2)) != null) { a(context, aVar.a(b)); a(context, aVar2.a((Object) null)); } } public static void a(Context context, String str) { SharedPreferences d = d(context, str); if (d != null) { d.edit().clear().apply(); } } public static void a(Context context, a<?>... aVarArr) { SharedPreferences d; if (aVarArr != null && aVarArr.length > 0) { HashMap hashMap = new HashMap(); for (a<?> aVar : aVarArr) { SharedPreferences.Editor editor = (SharedPreferences.Editor) hashMap.get(aVar.c); if (editor == null && (d = d(context, aVar.c)) != null) { editor = d.edit(); hashMap.put(aVar.c, editor); } a(editor, aVar.d, aVar.e, aVar.g); } for (SharedPreferences.Editor editor2 : hashMap.values()) { editor2.commit(); } } } private static <T> void a(SharedPreferences.Editor editor, String str, T t, boolean z) { if (editor == null) { return; } if (t == null) { editor.remove(str); } else if (t instanceof Boolean) { editor.putBoolean(str, t.booleanValue()); } else if (t instanceof String) { if (z) { T t2 = t; if (t2.length() > 0) { t = (T) d.a(t2); } } editor.putString(str, t); } else if (t instanceof Integer) { editor.putInt(str, t.intValue()); } else if (t instanceof Long) { editor.putLong(str, t.longValue()); } else if (t instanceof Float) { editor.putFloat(str, t.floatValue()); } } /* JADX DEBUG: Multi-variable search result rejected for r4v0, resolved type: cn.jiguang.g.a<T> */ /* JADX WARN: Multi-variable type inference failed */ public static <T> T b(Context context, a<T> aVar) { Object a2 = a(d(context, aVar.c), aVar.d, aVar.e); if (a2 == null && aVar.f) { a2 = (T) a(c(context, aVar.c), aVar.d, aVar.e); } if (a2 == null) { return null; } if (aVar.g && (a2 instanceof String)) { String str = (String) a2; if (str.length() > 0) { a2 = (T) d.b(str); } } aVar.a(a2); return (T) a2; } private static void b(Context context, String str) { a D; a<String> D2; String str2; a<String> i; String str3 = (String) a(context, a.w()); if ((TextUtils.isEmpty(str3) || str3.startsWith("1.")) && BuildConfig.VERSION_NAME.startsWith("2.")) { if (str.equals(a.a)) { a(context, a.i(), a.i().h("cn.jpush.android.user.profile")); a(context, a.j(), a.j().h("cn.jpush.android.user.profile")); D = a.k(); i = a.k().h("cn.jpush.android.user.profile"); } else if (str.equals("cn.jiguang.sdk.user.set.profile")) { a(context, a.l(), a.l().h("cn.jpush.preferences.v2")); D = a.m(); i = a.m().a("cn.jpush.android.user.profile"); } else { if (str.equals("cn.jiguang.sdk.user.profile")) { a(context, a.c(), a.c().h("cn.jpush.android.user.profile").i("device_uid")); a(context, a.d(), a.d().h("cn.jpush.android.user.profile").i("device_registration_id")); D = a.e(); D2 = a.e().h("cn.jpush.android.user.profile"); str2 = "device_password"; } else if (str.equals("cn.jiguang.sdk.address")) { a(context, a.P(), a.P().h("cn.jpush.android.user.profile").i("conn")); D = a.Q(); D2 = a.Q().h("cn.jpush.android.user.profile"); str2 = "srv"; } else if (str.equals(a.b)) { a(context, a.C(), a.C().i("device_registered_appkey")); D = a.D(); D2 = a.D(); str2 = "imei"; } else { return; } i = D2.i(str2); } a(context, D, i); } } private static SharedPreferences c(Context context, String str) { Context appContext = JConstants.getAppContext(context); if (appContext == null) { return null; } if (Build.VERSION.SDK_INT >= 11) { appContext.getSharedPreferences(str, 4); } return appContext.getSharedPreferences(str, 0); } private static SharedPreferences d(Context context, String str) { Context appContext; if (TextUtils.isEmpty(str)) { return null; } SharedPreferences sharedPreferences = a.get(str); if (sharedPreferences != null || (appContext = JConstants.getAppContext(context)) == null) { return sharedPreferences; } SharedPreferences sharedPreferences2 = appContext.getSharedPreferences(str, 0); a.put(str, sharedPreferences2); b(appContext, str); return sharedPreferences2; } }