Skip to content

Commit 03a4c5e

Browse files
committed
Attempted to fix crash on U+.
1 parent 780c226 commit 03a4c5e

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

TMessagesProj/src/main/java/org/telegram/messenger/ApplicationLoader.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,25 @@ public static void startPushService() {
340340
editorCA.commit();
341341
ConnectionsManager.getInstance(UserConfig.selectedAccount).setPushConnectionEnabled(true);
342342
}
343+
int pendingIntentFlags;
344+
if (Build.VERSION.SDK_INT >= 34) {
345+
pendingIntentFlags = PendingIntent.FLAG_IMMUTABLE;
346+
} else {
347+
pendingIntentFlags = PendingIntent.FLAG_MUTABLE;
348+
}
343349
if (enabled) {
344350
Log.d("TFOSS", "Trying to start push service every minute");
345351
// Telegram-FOSS: unconditionally enable push service
346352
AlarmManager am = (AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE);
347353
Intent i = new Intent(applicationContext, NotificationsService.class);
348-
pendingIntent = PendingIntent.getBroadcast(applicationContext, 0, i, PendingIntent.FLAG_MUTABLE);
354+
try {
355+
pendingIntent = PendingIntent.getBroadcast(applicationContext, 0, i, pendingIntentFlags);
349356

350357
am.cancel(pendingIntent);
351358
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 60000, pendingIntent);
359+
} catch (Throwable ignore) {
360+
Log.d("Fork Client", "Failed to set intent");
361+
}
352362
try {
353363
Log.d("TFOSS", "Starting push service...");
354364
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@@ -361,13 +371,16 @@ public static void startPushService() {
361371
}
362372
} else {
363373
applicationContext.stopService(new Intent(applicationContext, NotificationsService.class));
364-
374+
try {
365375
PendingIntent pintent = PendingIntent.getService(applicationContext, 0, new Intent(applicationContext, NotificationsService.class), PendingIntent.FLAG_MUTABLE);
366376
AlarmManager alarm = (AlarmManager)applicationContext.getSystemService(Context.ALARM_SERVICE);
367377
alarm.cancel(pintent);
368-
if (pendingIntent != null) {
369-
alarm.cancel(pendingIntent);
370-
}
378+
if (pendingIntent != null) {
379+
alarm.cancel(pendingIntent);
380+
}
381+
} catch (Throwable ignore) {
382+
Log.d("Fork Client", "Failed to set intent");
383+
}
371384
}
372385
}
373386

TMessagesProj/src/main/java/org/telegram/messenger/NotificationsService.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.os.Build;
2121
import android.os.IBinder;
2222
import androidx.core.app.NotificationCompat;
23+
import android.util.Log;
2324

2425
public class NotificationsService extends Service {
2526

@@ -28,20 +29,30 @@ public void onCreate() {
2829
super.onCreate();
2930
ApplicationLoader.postInitApplication();
3031
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
32+
int pendingIntentFlags;
33+
if (Build.VERSION.SDK_INT >= 34) {
34+
pendingIntentFlags = PendingIntent.FLAG_IMMUTABLE;
35+
} else {
36+
pendingIntentFlags = PendingIntent.FLAG_MUTABLE;
37+
}
3138
String CHANNEL_ID = "push_service_channel";
3239
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
3340
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,"Push Notifications Service",NotificationManager.IMPORTANCE_DEFAULT);
3441
notificationManager.createNotificationChannel(channel);
3542
Intent explainIntent = new Intent("android.intent.action.VIEW");
3643
explainIntent.setData(Uri.parse("https://github.com/Telegram-FOSS-Team/Telegram-FOSS/blob/master/Notifications.md"));
37-
PendingIntent explainPendingIntent = PendingIntent.getActivity(this, 0, explainIntent, PendingIntent.FLAG_MUTABLE);
44+
try {
45+
PendingIntent explainPendingIntent = PendingIntent.getActivity(this, 0, explainIntent, pendingIntentFlags);
3846
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
3947
.setContentIntent(explainPendingIntent)
4048
.setShowWhen(false)
4149
.setOngoing(true)
4250
.setSmallIcon(R.drawable.notification)
4351
.setContentText("Push service: tap to learn more").build();
4452
startForeground(9999,notification);
53+
} catch (Throwable ignore) {
54+
Log.d("Fork Client", "Failed to set intent");
55+
}
4556
}
4657
}
4758

0 commit comments

Comments
 (0)