Move shortcut creation/updates off the main thread for the common cases

These caused quite a few ANRs due to long Binder calls in ShortcutManager.getDynamicShortcuts()
This commit is contained in:
Cameron Gutman 2023-10-26 00:24:44 -05:00
parent ebfe843299
commit 0da47da8d8
2 changed files with 20 additions and 20 deletions

View File

@ -127,6 +127,7 @@ public class Game extends Activity implements SurfaceHolder.Callback,
private int suppressPipRefCount = 0; private int suppressPipRefCount = 0;
private String pcName; private String pcName;
private String appName; private String appName;
private NvApp app;
private float desiredRefreshRate; private float desiredRefreshRate;
private InputCaptureProvider inputCaptureProvider; private InputCaptureProvider inputCaptureProvider;
@ -146,8 +147,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
private int requestedNotificationOverlayVisibility = View.GONE; private int requestedNotificationOverlayVisibility = View.GONE;
private TextView performanceOverlayView; private TextView performanceOverlayView;
private ShortcutHelper shortcutHelper;
private MediaCodecDecoderRenderer decoderRenderer; private MediaCodecDecoderRenderer decoderRenderer;
private boolean reportedCrash; private boolean reportedCrash;
@ -318,10 +317,11 @@ public class Game extends Activity implements SurfaceHolder.Callback,
int httpsPort = Game.this.getIntent().getIntExtra(EXTRA_HTTPS_PORT, 0); // 0 is treated as unknown int httpsPort = Game.this.getIntent().getIntExtra(EXTRA_HTTPS_PORT, 0); // 0 is treated as unknown
int appId = Game.this.getIntent().getIntExtra(EXTRA_APP_ID, StreamConfiguration.INVALID_APP_ID); int appId = Game.this.getIntent().getIntExtra(EXTRA_APP_ID, StreamConfiguration.INVALID_APP_ID);
String uniqueId = Game.this.getIntent().getStringExtra(EXTRA_UNIQUEID); String uniqueId = Game.this.getIntent().getStringExtra(EXTRA_UNIQUEID);
String uuid = Game.this.getIntent().getStringExtra(EXTRA_PC_UUID);
boolean appSupportsHdr = Game.this.getIntent().getBooleanExtra(EXTRA_APP_HDR, false); boolean appSupportsHdr = Game.this.getIntent().getBooleanExtra(EXTRA_APP_HDR, false);
byte[] derCertData = Game.this.getIntent().getByteArrayExtra(EXTRA_SERVER_CERT); byte[] derCertData = Game.this.getIntent().getByteArrayExtra(EXTRA_SERVER_CERT);
app = new NvApp(appName != null ? appName : "app", appId, appSupportsHdr);
X509Certificate serverCert = null; X509Certificate serverCert = null;
try { try {
if (derCertData != null) { if (derCertData != null) {
@ -337,17 +337,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
return; return;
} }
// Report this shortcut being used
ComputerDetails computer = new ComputerDetails();
computer.name = pcName;
computer.uuid = uuid;
shortcutHelper = new ShortcutHelper(this);
shortcutHelper.reportComputerShortcutUsed(computer);
if (appName != null) {
// This may be null if launched from the "Resume Session" PC context menu item
shortcutHelper.reportGameLaunched(computer, new NvApp(appName, appId, appSupportsHdr));
}
// Initialize the MediaCodec helper before creating the decoder // Initialize the MediaCodec helper before creating the decoder
GlPreferences glPrefs = GlPreferences.readPreferences(this); GlPreferences glPrefs = GlPreferences.readPreferences(this);
MediaCodecHelper.initialize(this, glPrefs.glRenderer); MediaCodecHelper.initialize(this, glPrefs.glRenderer);
@ -479,7 +468,7 @@ public class Game extends Activity implements SurfaceHolder.Callback,
.setResolution(prefConfig.width, prefConfig.height) .setResolution(prefConfig.width, prefConfig.height)
.setLaunchRefreshRate(prefConfig.fps) .setLaunchRefreshRate(prefConfig.fps)
.setRefreshRate(chosenFrameRate) .setRefreshRate(chosenFrameRate)
.setApp(new NvApp(appName != null ? appName : "app", appId, appSupportsHdr)) .setApp(app)
.setBitrate(prefConfig.bitrate) .setBitrate(prefConfig.bitrate)
.setEnableSops(prefConfig.enableSops) .setEnableSops(prefConfig.enableSops)
.enableLocalAudioPlayback(prefConfig.playHostAudio) .enableLocalAudioPlayback(prefConfig.playHostAudio)
@ -2445,6 +2434,17 @@ public class Game extends Activity implements SurfaceHolder.Callback,
hideSystemUi(1000); hideSystemUi(1000);
} }
}); });
// Report this shortcut being used (off the main thread to prevent ANRs)
ComputerDetails computer = new ComputerDetails();
computer.name = pcName;
computer.uuid = Game.this.getIntent().getStringExtra(EXTRA_PC_UUID);
ShortcutHelper shortcutHelper = new ShortcutHelper(this);
shortcutHelper.reportComputerShortcutUsed(computer);
if (appName != null) {
// This may be null if launched from the "Resume Session" PC context menu item
shortcutHelper.reportGameLaunched(computer, app);
}
} }
@Override @Override

View File

@ -260,6 +260,11 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
updateComputer(details); updateComputer(details);
} }
}); });
// Add a launcher shortcut for this PC (off the main thread to prevent ANRs)
if (details.pairState == PairState.PAIRED) {
shortcutHelper.createAppViewShortcutForOnlineHost(details);
}
} }
} }
}); });
@ -720,11 +725,6 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
} }
} }
// Add a launcher shortcut for this PC
if (details.pairState == PairState.PAIRED) {
shortcutHelper.createAppViewShortcutForOnlineHost(details);
}
if (existingEntry != null) { if (existingEntry != null) {
// Replace the information in the existing entry // Replace the information in the existing entry
existingEntry.details = details; existingEntry.details = details;