package com.ubt.jimu.base.cache; import android.content.SharedPreferences; import android.text.TextUtils; import android.util.Base64; import com.ubt.jimu.JimuApplication; import com.ubtech.utils.XLog; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.StreamCorruptedException; /* loaded from: classes.dex */ public final class SharePreferenceHelper { public static final String AUTHOR_TOKEN = "author_token"; public static final String CURRENT_PACKAGE_IMAGE_PATH = "current_package_image_path"; public static final String KEY_SCAN_TIPS_READ = "scan_tips_read"; private static final String SP_FILE_NAME_EXTRA = "file_extra"; public static final String SP_FILE_NAME_SETTING = "setting"; public static final String SP_FILE_NAME_USER = "file_user"; public static final String SP_KEY_APP_CHECKED_UPDATE = "sp_key_app_checked_update"; public static final String SP_KEY_APP_NEED_UPDATE = "sp_key_app_need_upadte"; public static final String SP_KEY_APP_UPDATE_URL = "sp_key_app_update_url"; public static final String SP_KEY_APP_VERSION_NAME = "sp_key_app_version_name"; public static final String SP_KEY_AUTO_CONNECT = "auto_connect"; public static final String SP_KEY_CONNECTION_STATUS = "jimu_robot_connection_status"; public static final String SP_KEY_ELECTRICITY_PROTECT = "electricity_protect"; public static final String SP_KEY_FLIPPER_PAGE_INDEX = "sp_key_flipper_page_index"; public static final String SP_KEY_INFO_TO = "info_to"; public static final String SP_KEY_LAST_PARENT_EMAIL = "sp_key_last_parent_email"; public static final String SP_KEY_PACKAGE_ID = "sp_key_package_id"; public static final String SP_KEY_PACKAGE_NAME = "sp_key_package_name"; public static final String SP_KEY_REGISTER_ACCOUNT = "sp_key_register_account"; public static final String SP_KEY_REGISTER_BIRTHDAY = "sp_key_register_birthday"; public static final String SP_KEY_REGISTER_COUNTRY = "sp_key_register_country"; public static final String SP_KEY_ROBOT_ID = "sp_key_robot_id"; public static final String SP_KEY_ROBOT_IMAGE = "robot_image_url"; public static final String SP_KEY_ROBOT_NAME = "robot_name"; public static final String SP_KEY_SEARCH_HISTORY = "search_history"; public static final String SP_KEY_START_FINISH_HOME_GUIDE = "sp_key_finish_home_guide"; public static final String SP_KEY_START_FROM_SPLASH = "sp_key_start_from_splash"; public static final String SP_KEY_USER_ID = "key_user_id"; public static final String SP_KEY_UUID = "sp_key_uuid"; public static final String SP_KEY_WIFI_VIEW = "wifi_view"; private String setting; public SharePreferenceHelper() { this(false); } public Boolean getBoolean(String str, Boolean bool) { return Boolean.valueOf(JimuApplication.l().getSharedPreferences(this.setting, 0).getBoolean(str, bool.booleanValue())); } public float getFloat(String str, float f) { return JimuApplication.l().getSharedPreferences(this.setting, 0).getFloat(str, f); } public int getInt(String str, int i) { return JimuApplication.l().getSharedPreferences(this.setting, 0).getInt(str, i); } public Long getLong(String str, Long l) { return Long.valueOf(JimuApplication.l().getSharedPreferences(this.setting, 0).getLong(str, l.longValue())); } public String getString(String str, String str2) { return JimuApplication.l().getSharedPreferences(this.setting, 0).getString(str, str2); } public void put(String str, Object obj) { SharedPreferences.Editor edit = JimuApplication.l().getSharedPreferences(this.setting, 4).edit(); if (obj instanceof Boolean) { edit.putBoolean(str, ((Boolean) obj).booleanValue()); } else if (obj instanceof Float) { edit.putFloat(str, ((Float) obj).floatValue()); } else if (obj instanceof Integer) { edit.putInt(str, ((Integer) obj).intValue()); } else if (obj instanceof Long) { edit.putLong(str, ((Long) obj).longValue()); } else if (obj instanceof String) { edit.putString(str, (String) obj); } if (edit.commit()) { return; } XLog.b("SharePreferenceHelper", "commit SP failed!"); } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r0v13, types: [T, java.lang.Object] */ /* JADX WARN: Type inference failed for: r0v2 */ /* JADX WARN: Type inference failed for: r0v3 */ /* JADX WARN: Type inference failed for: r0v4, types: [T] */ /* JADX WARN: Type inference failed for: r0v6 */ /* JADX WARN: Type inference failed for: r0v7, types: [java.io.ObjectInputStream] */ /* JADX WARN: Type inference failed for: r5v1, types: [boolean] */ /* JADX WARN: Type inference failed for: r5v10, types: [java.io.ByteArrayInputStream] */ /* JADX WARN: Type inference failed for: r5v12, types: [java.io.ByteArrayInputStream, java.io.InputStream] */ /* JADX WARN: Type inference failed for: r5v2 */ /* JADX WARN: Type inference failed for: r5v3 */ /* JADX WARN: Type inference failed for: r5v4 */ /* JADX WARN: Type inference failed for: r5v5, types: [java.io.ByteArrayInputStream] */ /* JADX WARN: Type inference failed for: r5v8, types: [java.io.ByteArrayInputStream] */ public T readObject(String str, String str2) { ObjectInputStream objectInputStream; String string = JimuApplication.l().getSharedPreferences(str, 0).getString(str2, ""); ?? isEmpty = TextUtils.isEmpty(string); ?? r0 = (T) null; if (isEmpty != 0) { return null; } byte[] decode = Base64.decode(string.getBytes(), 0); try { } catch (IOException e) { e.printStackTrace(); return (T) r0; } try { try { isEmpty = new ByteArrayInputStream(decode); } catch (StreamCorruptedException e2) { e = e2; objectInputStream = null; isEmpty = 0; } catch (IOException e3) { e = e3; objectInputStream = null; isEmpty = 0; } catch (Throwable th) { th = th; isEmpty = 0; } try { objectInputStream = new ObjectInputStream(isEmpty); } catch (StreamCorruptedException e4) { e = e4; objectInputStream = null; } catch (IOException e5) { e = e5; objectInputStream = null; } catch (Throwable th2) { th = th2; if (isEmpty != 0) { try { isEmpty.close(); } catch (Exception e6) { e6.printStackTrace(); } } if (r0 == 0) { throw th; } try { r0.close(); throw th; } catch (IOException e7) { e7.printStackTrace(); throw th; } } try { try { r0 = (T) objectInputStream.readObject(); try { isEmpty.close(); } catch (Exception e8) { e8.printStackTrace(); } try { objectInputStream.close(); } catch (IOException e9) { e9.printStackTrace(); } return r0; } catch (StreamCorruptedException e10) { e = e10; e.printStackTrace(); if (isEmpty != 0) { try { isEmpty.close(); } catch (Exception e11) { e11.printStackTrace(); } } if (objectInputStream != null) { objectInputStream.close(); } return (T) r0; } catch (IOException e12) { e = e12; e.printStackTrace(); if (isEmpty != 0) { try { isEmpty.close(); } catch (Exception e13) { e13.printStackTrace(); } } if (objectInputStream != null) { objectInputStream.close(); } return (T) r0; } } catch (ClassNotFoundException e14) { e14.printStackTrace(); try { isEmpty.close(); } catch (Exception e15) { e15.printStackTrace(); } objectInputStream.close(); return (T) r0; } } catch (Throwable th3) { r0 = (T) decode; th = th3; } } public void saveObject(String str, String str2, Object obj) { ObjectOutputStream objectOutputStream; SharedPreferences sharedPreferences = JimuApplication.l().getSharedPreferences(str, 0); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream2 = null; try { try { try { objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); try { objectOutputStream.writeObject(obj); String encodeToString = Base64.encodeToString(byteArrayOutputStream.toByteArray(), 0); SharedPreferences.Editor edit = sharedPreferences.edit(); edit.putString(str2, encodeToString); if (!edit.commit()) { XLog.b("SharePreferenceHelper", "commit SP failed!"); } try { objectOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } byteArrayOutputStream.close(); } catch (IOException e2) { e = e2; objectOutputStream2 = objectOutputStream; e.printStackTrace(); if (objectOutputStream2 != null) { try { objectOutputStream2.close(); } catch (IOException e3) { e3.printStackTrace(); } } byteArrayOutputStream.close(); } catch (Throwable th) { th = th; if (objectOutputStream != null) { try { objectOutputStream.close(); } catch (IOException e4) { e4.printStackTrace(); } } try { byteArrayOutputStream.close(); throw th; } catch (IOException e5) { e5.printStackTrace(); throw th; } } } catch (Throwable th2) { th = th2; objectOutputStream = objectOutputStream2; } } catch (IOException e6) { e = e6; } } catch (IOException e7) { e7.printStackTrace(); } } public SharePreferenceHelper(boolean z) { this.setting = z ? SP_FILE_NAME_USER : SP_FILE_NAME_SETTING; } private SharePreferenceHelper(String str) { this.setting = str; } public void saveObject(String str, Object obj) { saveObject(this.setting, str, obj); } public T readObject(String str) { return readObject(this.setting, str); } }