feat(postit): keep Android SignalR chat in background without ongoing notification
Share the chat transport between UI, calls and an opt-in background service. Restore account rooms and attempt boot restart, keeping event alerts independent from connection permissions. Document Android limits and add lifecycle regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
a39c3912ea
commit
311d55dcc6
32 changed files with 2210 additions and 143 deletions
43
src/PostIt/PostIt.Android/Services/ChatBootReceiver.cs
Normal file
43
src/PostIt/PostIt.Android/Services/ChatBootReceiver.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Util;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using PostIt.Models;
|
||||
using PostIt.Services;
|
||||
|
||||
namespace PostIt.Android.Services;
|
||||
|
||||
[BroadcastReceiver(Name = "fr.pschneider.postit.ChatBootReceiver", Enabled = true, Exported = true)]
|
||||
[IntentFilter([Intent.ActionBootCompleted])]
|
||||
public sealed class ChatBootReceiver : BroadcastReceiver
|
||||
{
|
||||
public override void OnReceive(Context? context, Intent? intent)
|
||||
{
|
||||
if (context is null || intent?.Action != Intent.ActionBootCompleted || !ChatBootState.OptedIn) return;
|
||||
var epoch = AndroidBackgroundChatService.Epoch.Restore();
|
||||
if (epoch is null) return;
|
||||
var pending = GoAsync();
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
YavscApiClient? api = null;
|
||||
try
|
||||
{
|
||||
api = AndroidServiceProvider.GetOrCreate().GetRequiredService<YavscApiClient>();
|
||||
if (!ChatBootState.CanStart(api)) return;
|
||||
var identity = ChatBootState.Identity(api);
|
||||
if (identity is null || !AndroidBackgroundChatService.StartNative(context, epoch, identity)) return;
|
||||
Log.Info("PostIt.Chat", "Best-effort chat restart requested after boot.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("PostIt.Chat", "Boot restart rejected: " + ex);
|
||||
if (api is not null)
|
||||
AndroidSettings.ReportError(api.Settings,
|
||||
"Android a refuse le redemarrage de la messagerie : " + ex.Message);
|
||||
}
|
||||
finally { pending?.Finish(); }
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue