Search Unity

Bug PushNotificationService registry leads to automatic game pause on Android v13.

Discussion in 'Player Engagement' started by Ohilo, Jun 2, 2023.

  1. Ohilo

    Ohilo

    Joined:
    Jul 30, 2021
    Posts:
    32
    Hi,
    I recently tried to integrate UGS services into a sample project, specifically the Push Notification Service.
    After testing it on multiple devices each with a different android version(10 - Google Pixel,11 - Samsung Galaxy M30,12- OnePlus 8T,13 - Realme X7 Max and OnePlus 8T), I observed that on both devices with Android 13 version the game pauses after the PushNotificationService registry line as seen in the code below.

    Code (CSharp):
    1.     private async void Awake()
    2.     {
    3.         InitializationOptions options = ChooseEnvironment();
    4.         try
    5.         {
    6.             await InitializeServices(options);
    7.             Debug.Log(options.ToString());
    8.             string token = await PushNotificationsService.Instance.RegisterForPushNotificationsAsync();
    9.             Debug.Log($"The push notification token is {token}");
    10.  
    11.             PushNotificationsService.Instance.OnNotificationReceived += notificationData =>
    12.             {
    13.                 Debug.Log("Data retrieved!");
    14.             };
    15.         }
    16.         catch (Exception e)
    17.         {
    18.             Debug.LogError(e.ToString());
    19.         }
    20.         LoadGameScene();
    21.     }

    I analysed the logs through AndroidLogcat and noticed that on Android 13 devices an onPause event is called the first time the app is installed on the device and launched which basically freezes the game as seen in the stack trace below. But, the beahaviour is not limited to first time launch , the game freezes on every subsequent launch of the app as well, but, the onPause event is not observed in their stack traces.
    So, I am not sure what is the root cause except that is only seen on Android 13 devices.


    Sharing the StackTrace here

    2023-06-02 19:17:22.016 13470 17658 Info Unity <Awake>d__0:MoveNext()
    2023-06-02 19:17:22.016 13470 17658 Info Unity System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
    2023-06-02 19:17:22.016 13470 17658 Info Unity System.Runtime.CompilerServices.MoveNextRunner:Run()
    2023-06-02 19:17:22.016 13470 17658 Info Unity System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
    2023-06-02 19:17:22.016 13470 17658 Info Unity System.Threading.Tasks.Task:FinishContinuations()
    2023-06-02 19:17:22.016 13470 17658 Info Unity System.Threading.Tasks.Task`1:TrySetResult(TResult)
    2023-06-02 19:17:22.016 13470 17658 Info Unity System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(TResult)
    2023-06-02 19:17:22.016 13470 17658 Info Unity <InitializeServices>d__1:MoveNext()
    2023-06-02 19:17:22.016 13470 17658 Info Unity System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
    2023-06-02 19:17:22.016 13470 17658 Info Unity System.Runtime.CompilerServices.MoveNextRunner:Run()
    2023-06-02 19:17:22.016 13470 17658 Info Unity System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
    2023-06-02 19:17:22.016 13470 17658 Info Unity System.Threading.Tasks.Task:FinishContinuations()
    2023-06-02 19:17:22.016 13470 17658 Info Unity System.Threading.Tasks.Task`1:TrySetResult(TResult)
    2023-06-02 19:17:22.016 13470 17658 Info Unity System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(TResult)
    2023-06-02 19:17:22.016 13470 17658 Info Unity Unity.Services.Core.<InitializeAsync>d__15:MoveNext()
    2023-06-02 19:17:22.016 13470 17658 Info Unity System.Thr
    2023-06-02 19:17:22.053 13470 13470 Info Unity onPause
     
  2. skipculture

    skipculture

    Joined:
    Apr 9, 2023
    Posts:
    8
    I'm experiencing this issue on iOS, this is not just Android. The game pauses/freezes when Notifications are turned Off in device settings. It does not get past the
    await PushNotificationsService.Instance.RegisterForPushNotificationsAsync(). This does not happen once notifications are turned back on for the device and relevant game/app.
     
    Last edited: Jun 26, 2023
  3. skipculture

    skipculture

    Joined:
    Apr 9, 2023
    Posts:
    8
    I've confirmed there's an issue with the RegisterForPushNotificationsAsync (when no token is received or there's an exception) the TaskCompletionSource is never resolved and the await is never returned. The method makes it to waiting on NotificationRegistrationTokenReceived to resolve the Task, even though it will never receive that callback.
     
    Last edited: Jun 26, 2023
  4. skipculture

    skipculture

    Joined:
    Apr 9, 2023
    Posts:
    8