package com.firemint.realracing; import android.app.AlarmManager; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; import android.os.SystemClock; import androidx.core.app.JobIntentService; import androidx.core.app.NotificationCompat; /* loaded from: classes2.dex */ public class DelayedNotificationService extends JobIntentService { private static final String ACTION_NOTIFICATION_DISMISSED = "ACTION_NOTIFICATION_DISMISSED"; private static final int JOB_ID = 9999; private static final boolean LOG_ERROR_ENABLED = false; private static final boolean LOG_INFO_ENABLED = false; private static final String LOG_TAG = "RR3_DelayedNotifSvc"; private static final int SUMMARY_NOTIFICATION_ID = 999; private static int m_currentNotificationId = -2; private static int m_pendingIntentRequestCode; private static void LogError(String str) { } private static void LogInfo(String str) { } public boolean ShouldNotificationPlaySound(int i) { return i != 2; } public static void enqueueWork(Context context, Intent intent) { LogInfo("DelayedNotificationService - enqueueWork"); try { JobIntentService.enqueueWork(context, (Class) DelayedNotificationService.class, JOB_ID, intent); } catch (Exception e) { e.printStackTrace(); } } public void NotificationDismissed() { SerialiseNotificationsHelper.ClearAll(getApplicationContext()); } public String GetNotificationGroupKey(Context context) { return "NOTIF_GROUP_" + context.getResources().getString(R.string.cc_game_id); } @Override // androidx.core.app.JobIntentService public void onHandleWork(Intent intent) { String str; Notification notification; int i; Notification CreateBigTextNotification; LogInfo("DelayedNotificationService - onHandleWork"); if (intent == null) { return; } LogInfo("DelayedNotificationService: onHandleWork"); if (intent.getAction() != null && intent.getAction().equals(ACTION_NOTIFICATION_DISMISSED)) { NotificationDismissed(); return; } int intExtra = intent.getIntExtra("id", -2); String stringExtra = intent.getStringExtra("message"); String stringExtra2 = intent.getStringExtra("deepLinkUrl"); boolean z = stringExtra2 != null && (stringExtra2.contains("MultiplayerInvite") || stringExtra2.contains("RaceTeamsAdmin")); MainActivity mainActivity = MainActivity.instance; if (mainActivity != null && mainActivity.hasWindowFocus() && stringExtra != null && stringExtra2 != null) { MainActivity.instance.HandleDeepLink(stringExtra, stringExtra2); return; } if (intExtra == 1) { if (!IsConnectedToNetwork()) { showDelayedNotification(intent, Platform.INTERNET_CONNECTION_DELAY); return; } else if (intent.getIntExtra("reminder", 0) >= 1) { showDelayedNotification(intent, 172800); } } Context applicationContext = getApplicationContext(); NotificationManager notificationManager = (NotificationManager) getSystemService("notification"); SerialisedNotificationInfo GetSavedInfo = SerialiseNotificationsHelper.GetSavedInfo(applicationContext); int GetNotificationCount = GetSavedInfo.GetNotificationCount(); long currentTimeMillis = System.currentTimeMillis(); int i2 = m_pendingIntentRequestCode + 1; m_pendingIntentRequestCode = i2; Intent intent2 = new Intent(this, (Class) UnpackAssetsActivity.class); if (stringExtra2 != null) { intent2.putExtra("deepLinkUrl", stringExtra2); } PendingIntent activity = PendingIntent.getActivity(this, i2, intent2, 335544320); Notification.Builder autoCancel = new Notification.Builder(applicationContext).setContentTitle(GetNotificationContentTitle(applicationContext, intExtra)).setContentText(stringExtra).setSmallIcon(R.mipmap.icon_notification).setContentIntent(activity).setAutoCancel(true); if (intExtra == 2) { currentTimeMillis = 0; } Notification.Builder when = autoCancel.setWhen(currentTimeMillis); if (MainActivity.IsAtLeastAPI(21)) { when.setColor(applicationContext.getResources().getColor(R.color.NotificationColor)); } if (MainActivity.IsAtLeastAPI(20)) { when.setGroup(GetNotificationGroupKey(applicationContext)); } if (MainActivity.IsAtLeastAPI(26)) { str = new NotificationChannelHelper(applicationContext).NotificationToChannelId(intExtra); when.setChannelId(str); } else { str = null; } String str2 = str; if (ShouldNotificationPlaySound(intExtra)) { when.setSound(GetNotificationSoundUri(applicationContext)); } if (z) { when.setTicker(stringExtra); } Intent intent3 = new Intent(this, (Class) DelayedNotificationService.class); intent3.setAction(ACTION_NOTIFICATION_DISMISSED); when.setDeleteIntent(PendingIntent.getService(this, i2, intent3, 201326592)); if (MainActivity.IsAtLeastAPI(16)) { if (MainActivity.IsAtLeastAPI(24) || GetNotificationCount == 0) { CreateBigTextNotification = CreateBigTextNotification(when, stringExtra); } else { CreateBigTextNotification = CreateStackedNotification(GetSavedInfo, when, stringExtra); } notification = CreateBigTextNotification; if (MainActivity.IsAtLeastAPI(24) && GetNotificationCount >= 1) { PostSummaryNotification(notificationManager, applicationContext, activity, "", str2); } } else { notification = when.getNotification(); } if (intExtra != 2) { SerialiseNotificationsHelper.AddNotification(getApplicationContext(), stringExtra); } LogInfo("DelayedNotificationService: showing notification id: " + intExtra + " msg: " + stringExtra); try { if (ShouldGenerateUniqueNotificationId(intExtra)) { i = m_currentNotificationId + 1; m_currentNotificationId = i; } else { i = -2; } MainActivity.logi("Posting notification with id: " + i); notificationManager.notify(i, notification); } catch (Exception e) { LogInfo("DelayedNotificationService: Notification Exception: " + e.toString()); } } public String GetNotificationContentTitle(Context context, int i) { return context.getResources().getString(R.string.app_name); } public boolean ShouldGenerateUniqueNotificationId(int i) { return MainActivity.IsAtLeastAPI(24) && i != 2; } public Notification CreateStackedNotification(SerialisedNotificationInfo serialisedNotificationInfo, Notification.Builder builder, String str) { String str2; Notification.InboxStyle inboxStyle = new Notification.InboxStyle(builder); inboxStyle.addLine(str); int i = 0; for (int GetNotificationCount = serialisedNotificationInfo.GetNotificationCount() - 1; GetNotificationCount >= 0; GetNotificationCount--) { try { str2 = serialisedNotificationInfo.GetNotificationString(GetNotificationCount); } catch (Exception e) { LogError("Error getting notification string: " + e.toString()); str2 = ""; } inboxStyle.addLine(str2); i++; if (i >= 4) { break; } } return inboxStyle.build(); } public void PostSummaryNotification(NotificationManager notificationManager, Context context, PendingIntent pendingIntent, String str, String str2) { Notification.Builder groupSummary = new Notification.Builder(getApplicationContext()).setSmallIcon(R.mipmap.icon_notification).setColor(context.getResources().getColor(R.color.NotificationColor)).setStyle(new Notification.BigTextStyle().setSummaryText(str)).setContentIntent(pendingIntent).setGroup(GetNotificationGroupKey(context)).setGroupSummary(true); if (MainActivity.IsAtLeastAPI(26)) { groupSummary.setChannelId(str2); } notificationManager.notify(999, groupSummary.build()); } public Notification CreateBigTextNotification(Notification.Builder builder, String str) { return new Notification.BigTextStyle(builder).bigText(str).build(); } public static Uri GetNotificationSoundUri(Context context) { return Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.push_notification); } private boolean IsConnectedToNetwork() { NetworkInfo activeNetworkInfo; ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService("connectivity"); return connectivityManager != null && (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) != null && activeNetworkInfo.isAvailable() && activeNetworkInfo.isConnected(); } public void showDelayedNotification(Intent intent, int i) { int intExtra; long elapsedRealtime = SystemClock.elapsedRealtime() + (i * 1000); int intExtra2 = intent.getIntExtra("id", -2); LogInfo("Notifications : showDelayedNotification: " + intent.getStringExtra("message") + " " + i); if (intExtra2 == 1 && (intExtra = intent.getIntExtra("reminder", 0)) >= 1 && i == 172800) { intent.putExtra("reminder", intExtra - 1); } ((AlarmManager) getSystemService(NotificationCompat.CATEGORY_ALARM)).set(3, elapsedRealtime, PendingIntent.getService(this, 0, intent, 335544320)); } }