From 5ffbb10f6e5a4012fcf2dfbf4c0589f3cedba3a4 Mon Sep 17 00:00:00 2001 From: Marco Loaiza Date: Tue, 3 Jan 2023 16:16:10 +0000 Subject: [PATCH] Check for valid last reported deviceId when starting service If last reported virtual deviceId has been removed/closed since the latest activity was started, updateDeviceId would throw an exception due to the deviceId being invalid. Bug: 264250568 Test: atest DeviceAssociationTest Change-Id: I5f57c0361f76646001cc606e819969b0114946f7 --- core/java/android/app/ActivityThread.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index afd8a52d43cea..7370280add2ba 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -4558,7 +4558,11 @@ public final class ActivityThread extends ClientTransactionHandler service.attach(context, this, data.info.name, data.token, app, ActivityManager.getService()); if (!service.isUiContext()) { // WindowProviderService is a UI Context. - service.updateDeviceId(mLastReportedDeviceId); + VirtualDeviceManager vdm = context.getSystemService(VirtualDeviceManager.class); + if (mLastReportedDeviceId == VirtualDeviceManager.DEVICE_ID_DEFAULT + || vdm.isValidVirtualDeviceId(mLastReportedDeviceId)) { + service.updateDeviceId(mLastReportedDeviceId); + } } service.onCreate(); mServicesData.put(data.token, data);