package com.firemint.realracing; import android.annotation.TargetApi; import android.app.AlarmManager; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import androidx.core.app.NotificationCompat; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import org.json.JSONArray; import org.json.JSONObject; /* loaded from: classes2.dex */ public class LocalNotificationsCenter { public static final String EXTRA_FIRE_TIME = "firetime"; public static final String EXTRA_ID = "id"; public static final String EXTRA_LAUNCH_URL = "deepLinkUrl"; public static final String EXTRA_LAUNCH_URL_MP_INVITE = "MultiplayerInvite"; public static final String EXTRA_LAUNCH_URL_RT_ADMIN = "RaceTeamsAdmin"; public static final String EXTRA_MESSAGE = "message"; public static final String EXTRA_REMINDER = "reminder"; private static final String FILENAME = "notifications.dat"; private static final boolean LOG_ENABLED = false; private static final String LOG_TAG = "LocalNotificationsCntr"; private static HashMap mNotificationsIntent = new HashMap<>(); /* JADX INFO: Access modifiers changed from: private */ public static void LogError(String str) { } private static void LogInfo(String str) { } public static class LocalNotification { public long mDelayTime; public int mId; public String mMessage; public int mReminderRemain = -1; public String mURL; public JSONObject Serialise() { JSONObject jSONObject = new JSONObject(); try { jSONObject.put("id", this.mId); jSONObject.put("firetime", this.mDelayTime); jSONObject.put("message", this.mMessage); jSONObject.put("deepLinkUrl", this.mURL); jSONObject.put("reminder", this.mReminderRemain); } catch (Exception e) { LocalNotificationsCenter.LogError(e.getMessage()); } return jSONObject; } public void Serialise(JSONObject jSONObject) { try { this.mId = jSONObject.optInt("id"); this.mDelayTime = jSONObject.optLong("firetime"); this.mMessage = jSONObject.optString("message"); this.mURL = jSONObject.optString("deepLinkUrl"); this.mReminderRemain = jSONObject.optInt("reminder"); } catch (Exception e) { LocalNotificationsCenter.LogError(e.getMessage()); } } public LocalNotification(JSONObject jSONObject) { Serialise(jSONObject); } public LocalNotification(int i, String str, String str2) { this.mId = i; this.mMessage = str; this.mURL = str2; } } public static boolean AreNotificationsSupported() { if (MainActivity.instance != null) { return !MainActivity.getIsAndroidTv(); } return false; } @TargetApi(19) public static PendingIntent CreateNotificationIntent(LocalNotification localNotification) { Context GetContext = AppProxy.GetContext(); Intent intent = new Intent(GetContext, (Class) LocalNotificationBroadcastReceiver.class); intent.setType("type" + localNotification.mMessage + "-" + localNotification.mDelayTime); intent.putExtra("message", localNotification.mMessage); intent.putExtra("id", localNotification.mId); int i = localNotification.mReminderRemain; if (i != -1) { intent.putExtra("reminder", i); } if (localNotification.mURL.length() > 0) { intent.putExtra("deepLinkUrl", localNotification.mURL); } return PendingIntent.getBroadcast(GetContext, 0, intent, 201326592); } @TargetApi(19) public static void showNotification(int i, String str, long j, String str2) { if (str2 == null) { str2 = ""; } LocalNotification localNotification = new LocalNotification(i, str, str2); localNotification.mDelayTime = System.currentTimeMillis() + (1000 * j); LogInfo("showNotification id: " + i + " delay: " + j + " msg: " + str); StringBuilder sb = new StringBuilder(); sb.append("showNotification current time: "); sb.append(System.currentTimeMillis()); LogInfo(sb.toString()); LogInfo("showNotification fire time: " + localNotification.mDelayTime); LogInfo("showNotification url: " + str2); if (i == 1) { localNotification.mReminderRemain = 2 - ((int) Math.floor((System.currentTimeMillis() - Platform.getAppInstallTime()) / 172800000)); } showNotification(localNotification); } /* JADX WARN: Removed duplicated region for block: B:14:0x0051 */ /* JADX WARN: Removed duplicated region for block: B:17:? A[RETURN, SYNTHETIC] */ @android.annotation.TargetApi(19) /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public static void showNotification(com.firemint.realracing.LocalNotificationsCenter.LocalNotification r5) { /* boolean r0 = AreNotificationsSupported() if (r0 == 0) goto L56 if (r5 != 0) goto L9 goto L56 L9: android.app.PendingIntent r0 = CreateNotificationIntent(r5) android.content.Context r1 = com.firemint.realracing.AppProxy.GetContext() // Catch: java.lang.Exception -> L2c java.lang.String r2 = "alarm" java.lang.Object r1 = r1.getSystemService(r2) // Catch: java.lang.Exception -> L2c android.app.AlarmManager r1 = (android.app.AlarmManager) r1 // Catch: java.lang.Exception -> L2c int r2 = android.os.Build.VERSION.SDK_INT // Catch: java.lang.Exception -> L2c r3 = 33 r4 = 1 if (r2 < r3) goto L2e boolean r2 = com.firemint.realracing.LocalNotificationsCenter$$ExternalSyntheticApiModelOutline0.m(r1) // Catch: java.lang.Exception -> L2c if (r2 != 0) goto L2e long r2 = r5.mDelayTime // Catch: java.lang.Exception -> L2c r1.set(r4, r2, r0) // Catch: java.lang.Exception -> L2c goto L4c L2c: r1 = move-exception goto L34 L2e: long r2 = r5.mDelayTime // Catch: java.lang.Exception -> L2c r1.setExact(r4, r2, r0) // Catch: java.lang.Exception -> L2c goto L4c L34: java.lang.StringBuilder r2 = new java.lang.StringBuilder r2.() java.lang.String r3 = "showNotification: failed to set alarm: " r2.append(r3) java.lang.String r1 = r1.toString() r2.append(r1) java.lang.String r1 = r2.toString() LogError(r1) L4c: int r1 = r5.mId r2 = 2 if (r1 == r2) goto L56 java.util.HashMap r1 = com.firemint.realracing.LocalNotificationsCenter.mNotificationsIntent r1.put(r5, r0) L56: return */ throw new UnsupportedOperationException("Method not decompiled: com.firemint.realracing.LocalNotificationsCenter.showNotification(com.firemint.realracing.LocalNotificationsCenter$LocalNotification):void"); } public static void CancelAllNotifications() { LogInfo("CancelAllNotifications: start"); if (mNotificationsIntent.size() <= 0) { LoadNotifications(false); } Context GetContext = AppProxy.GetContext(); ((NotificationManager) GetContext.getSystemService("notification")).cancelAll(); Iterator it = mNotificationsIntent.keySet().iterator(); while (it.hasNext()) { CancelNotification((LocalNotification) it.next()); } mNotificationsIntent.clear(); SaveNotifications(); LogInfo("CancelAllNotifications: end"); SerialiseNotificationsHelper.ClearAll(GetContext); } public static void CancelNotification(LocalNotification localNotification) { Context GetContext = AppProxy.GetContext(); NotificationManager notificationManager = (NotificationManager) GetContext.getSystemService("notification"); AlarmManager alarmManager = (AlarmManager) GetContext.getSystemService(NotificationCompat.CATEGORY_ALARM); PendingIntent pendingIntent = mNotificationsIntent.get(localNotification); if (pendingIntent == null) { pendingIntent = CreateNotificationIntent(localNotification); } try { LogInfo("Cancelling notification: " + localNotification.mId); notificationManager.cancel(localNotification.mId); if (pendingIntent != null) { alarmManager.cancel(pendingIntent); pendingIntent.cancel(); } } catch (Exception e) { LogError("CancelNotification: failed to cancel alarm: " + e.toString()); } } public static void CancelNotification(int i, String str) { Context GetContext = AppProxy.GetContext(); AlarmManager alarmManager = (AlarmManager) GetContext.getSystemService(NotificationCompat.CATEGORY_ALARM); Intent intent = new Intent(GetContext, (Class) LocalNotificationBroadcastReceiver.class); intent.setType("type" + str); PendingIntent broadcast = PendingIntent.getBroadcast(GetContext, 0, intent, 335544320); try { ((NotificationManager) GetContext.getSystemService("notification")).cancel(i); alarmManager.cancel(broadcast); } catch (Exception e) { LogError("CancelNotification: failed to cancel alarm: " + e.toString()); } } public static void SaveNotifications() { SaveNotifications(mNotificationsIntent.keySet()); } public static void SaveNotifications(Iterable iterable) { LogInfo("SaveNotifications() Num:" + mNotificationsIntent.size()); try { JSONArray jSONArray = new JSONArray(); Iterator it = iterable.iterator(); while (it.hasNext()) { jSONArray.put(it.next().Serialise()); } FileOutputStream fileOutputStream = new FileOutputStream(new File(Platform.getExternalStorageDir(AppProxy.GetContext()), FILENAME)); ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); objectOutputStream.writeObject(jSONArray.toString()); objectOutputStream.close(); fileOutputStream.close(); } catch (Exception e) { LogError("SaveNotifications failed: " + e.toString()); } } public static void LoadNotifications(boolean z) { for (LocalNotification localNotification : LoadNotifications()) { if (z) { showNotification(localNotification); } else { mNotificationsIntent.put(localNotification, null); } } } public static Iterable LoadNotifications() { ArrayList arrayList = new ArrayList(); LogInfo("LoadNotifications()"); try { File file = new File(Platform.getExternalStorageDir(AppProxy.GetContext()), FILENAME); if (file.exists()) { LogInfo("Found saved file. Loading information"); FileInputStream fileInputStream = new FileInputStream(file); ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); String str = (String) objectInputStream.readObject(); objectInputStream.close(); fileInputStream.close(); JSONArray jSONArray = new JSONArray(str); for (int i = 0; i < jSONArray.length(); i++) { arrayList.add(new LocalNotification(jSONArray.getJSONObject(i))); } } else { LogError("File not found"); } } catch (Exception e) { LogError("LoadNotifications failed: " + e.toString()); } return arrayList; } }