diff --git a/app/src/main/java/com/limelight/Game.java b/app/src/main/java/com/limelight/Game.java index b3c33d2c..17ae85c1 100644 --- a/app/src/main/java/com/limelight/Game.java +++ b/app/src/main/java/com/limelight/Game.java @@ -516,6 +516,9 @@ public class Game extends Activity implements SurfaceHolder.Callback, performanceOverlayView.setVisibility(View.GONE); notificationOverlayView.setVisibility(View.GONE); + + // Update GameManager state to indicate we're in PiP (still gaming, but interruptible) + UiHelper.notifyStreamEnteringPiP(this); } else { isHidingOverlays = false; @@ -531,6 +534,9 @@ public class Game extends Activity implements SurfaceHolder.Callback, } notificationOverlayView.setVisibility(requestedNotificationOverlayVisibility); + + // Update GameManager state to indicate we're out of PiP (gaming, non-interruptible) + UiHelper.notifyStreamExitingPiP(this); } } } @@ -1600,6 +1606,9 @@ public class Game extends Activity implements SurfaceHolder.Callback, controllerHandler.stop(); + // Update GameManager state to indicate we're no longer in game + UiHelper.notifyStreamEnded(this); + // Stop may take a few hundred ms to do some network I/O to tell // the server we're going away and clean up. Let it run in a separate // thread to keep things smooth for the UI. Inside moonlight-common, @@ -1780,6 +1789,9 @@ public class Game extends Activity implements SurfaceHolder.Callback, // Keep the display on getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + // Update GameManager state to indicate we're in game + UiHelper.notifyStreamConnected(Game.this); + hideSystemUi(1000); } }); @@ -1829,6 +1841,9 @@ public class Game extends Activity implements SurfaceHolder.Callback, if (!attemptedConnection) { attemptedConnection = true; + // Update GameManager state to indicate we're "loading" while connecting + UiHelper.notifyStreamConnecting(Game.this); + decoderRenderer.setRenderTarget(holder); conn.start(PlatformBinding.getAudioRenderer(), decoderRenderer, Game.this); } diff --git a/app/src/main/java/com/limelight/utils/UiHelper.java b/app/src/main/java/com/limelight/utils/UiHelper.java index 6394e533..7e54df94 100644 --- a/app/src/main/java/com/limelight/utils/UiHelper.java +++ b/app/src/main/java/com/limelight/utils/UiHelper.java @@ -2,6 +2,8 @@ package com.limelight.utils; import android.app.Activity; import android.app.AlertDialog; +import android.app.GameManager; +import android.app.GameState; import android.app.UiModeManager; import android.content.Context; import android.content.DialogInterface; @@ -13,6 +15,7 @@ import android.view.View; import android.view.WindowInsets; import android.view.WindowManager; +import com.limelight.Game; import com.limelight.R; import com.limelight.nvstream.http.ComputerDetails; import com.limelight.preferences.PreferenceConfiguration; @@ -24,6 +27,39 @@ public class UiHelper { private static final int TV_VERTICAL_PADDING_DP = 15; private static final int TV_HORIZONTAL_PADDING_DP = 15; + private static void setGameModeStatus(Context context, boolean streaming, boolean loading, boolean interruptible) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + GameManager gameManager = context.getSystemService(GameManager.class); + + if (streaming) { + gameManager.setGameState(new GameState(loading, interruptible ? GameState.MODE_GAMEPLAY_INTERRUPTIBLE : GameState.MODE_GAMEPLAY_UNINTERRUPTIBLE)); + } + else { + gameManager.setGameState(new GameState(loading, GameState.MODE_NONE)); + } + } + } + + public static void notifyStreamConnecting(Context context) { + setGameModeStatus(context, true, true, true); + } + + public static void notifyStreamConnected(Context context) { + setGameModeStatus(context, true, false, false); + } + + public static void notifyStreamEnteringPiP(Context context) { + setGameModeStatus(context, true, false, true); + } + + public static void notifyStreamExitingPiP(Context context) { + setGameModeStatus(context, true, false, false); + } + + public static void notifyStreamEnded(Context context) { + setGameModeStatus(context, false, false, false); + } + public static void setLocale(Activity activity) { String locale = PreferenceConfiguration.readPreferences(activity).language; @@ -68,6 +104,9 @@ public class UiHelper { View rootView = activity.findViewById(android.R.id.content); UiModeManager modeMgr = (UiModeManager) activity.getSystemService(Context.UI_MODE_SERVICE); + // Set GameState.MODE_NONE initially for all activities + setGameModeStatus(activity, false, false, false); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { // Allow this non-streaming activity to layout under notches. //