-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this avoids potential issues with GenericForegroundService which eg. may block app start.
- Loading branch information
Showing
6 changed files
with
73 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.thoughtcrime.securesms.service; | ||
|
||
import android.app.Notification; | ||
import android.app.Service; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.IBinder; | ||
|
||
import androidx.annotation.Nullable; | ||
import androidx.core.app.NotificationCompat; | ||
import androidx.core.content.ContextCompat; | ||
|
||
import org.thoughtcrime.securesms.R; | ||
import org.thoughtcrime.securesms.notifications.NotificationCenter; | ||
|
||
public final class FetchForegroundService extends Service { | ||
private static final Object SERVICE_LOCK = new Object(); | ||
private static Intent service; | ||
|
||
public static void start(Context context) { | ||
GenericForegroundService.createFgNotificationChannel(context); | ||
synchronized (SERVICE_LOCK) { | ||
if (service == null) { | ||
service = new Intent(context, FetchForegroundService.class); | ||
ContextCompat.startForegroundService(context, service); | ||
} | ||
} | ||
} | ||
|
||
public static void stop(Context context) { | ||
synchronized (SERVICE_LOCK) { | ||
if (service != null) { | ||
context.stopService(service); | ||
service = null; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
|
||
Notification notification = new NotificationCompat.Builder(this, NotificationCenter.CH_GENERIC) | ||
.setContentTitle(getString(R.string.connectivity_updating)) | ||
.setSmallIcon(R.drawable.notification_permanent) | ||
.build(); | ||
|
||
startForeground(NotificationCenter.ID_FETCH, notification); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
stopForeground(true); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public IBinder onBind(Intent intent) { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters