Skip to content

Commit 98e9748

Browse files
committed
Fixed notification to skip foreground service when UnifiedPush active.
1 parent dc065b9 commit 98e9748

1 file changed

Lines changed: 29 additions & 20 deletions

File tree

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

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -368,27 +368,36 @@ public static void startPushService() {
368368
pendingIntentFlags = PendingIntent.FLAG_MUTABLE;
369369
}
370370
if (enabled) {
371-
Log.d("TFOSS", "Trying to start push service every minute");
372-
// Telegram-FOSS: unconditionally enable push service
373-
AlarmManager am = (AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE);
374-
Intent i = new Intent(applicationContext, NotificationsService.class);
375-
try {
376-
pendingIntent = PendingIntent.getBroadcast(applicationContext, 0, i, pendingIntentFlags);
377-
378-
am.cancel(pendingIntent);
379-
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 60000, pendingIntent);
380-
} catch (Throwable ignore) {
381-
Log.d("Fork Client", "Failed to set intent");
382-
}
383-
try {
384-
Log.d("TFOSS", "Starting push service...");
385-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
386-
applicationContext.startForegroundService(new Intent(applicationContext, NotificationsService.class));
387-
} else {
388-
applicationContext.startService(new Intent(applicationContext, NotificationsService.class));
371+
// Check if UnifiedPush is active and working
372+
boolean unifiedPushActive = getPushProvider() instanceof PushListenerController.UnifiedPushListenerServiceProvider &&
373+
getPushProvider().hasServices() &&
374+
!TextUtils.isEmpty(SharedConfig.pushString) &&
375+
SharedConfig.pushType == PushListenerController.PUSH_TYPE_SIMPLE;
376+
377+
if (!unifiedPushActive) {
378+
Log.d("TFOSS", "Trying to start push service every minute");
379+
AlarmManager am = (AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE);
380+
Intent i = new Intent(applicationContext, NotificationsService.class);
381+
try {
382+
pendingIntent = PendingIntent.getBroadcast(applicationContext, 0, i, pendingIntentFlags);
383+
384+
am.cancel(pendingIntent);
385+
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 60000, pendingIntent);
386+
} catch (Throwable ignore) {
387+
Log.d("Fork Client", "Failed to set intent");
389388
}
390-
} catch (Throwable ignore) {
391-
Log.d("TFOSS", "Failed to start push service");
389+
try {
390+
Log.d("TFOSS", "Starting push service...");
391+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
392+
applicationContext.startForegroundService(new Intent(applicationContext, NotificationsService.class));
393+
} else {
394+
applicationContext.startService(new Intent(applicationContext, NotificationsService.class));
395+
}
396+
} catch (Throwable ignore) {
397+
Log.d("TFOSS", "Failed to start push service");
398+
}
399+
} else {
400+
Log.d("Fork Client", "UnifiedPush is active, skipping foreground service");
392401
}
393402
} else {
394403
applicationContext.stopService(new Intent(applicationContext, NotificationsService.class));

0 commit comments

Comments
 (0)