From d23610698308248ce58a020ee13175f4d908633b Mon Sep 17 00:00:00 2001 From: charid Date: Tue, 23 Jul 2024 17:46:11 +0530 Subject: [PATCH] Ensure TetheringService binder is alive after system_server crash servicemanager does not restart on a system_server crash, so mConnectorSupplier might temporarily return a stale version of TetheringService. Any operation on the stale binder causes a DeadObjectException. This change adds a check to ensure the binder is alive before use and falls back to polling servicemanager. Bug: 353920381 Bug: 271276384 Change-Id: I549d5a07966ebaed7e4a4ebe96e831dcac3b05bd Signed-off-by: charid --- .../TetheringLib/src/android/net/TetheringManager.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tethering/common/TetheringLib/src/android/net/TetheringManager.java b/Tethering/common/TetheringLib/src/android/net/TetheringManager.java index bc771da4ef..3292a7b133 100644 --- a/Tethering/common/TetheringLib/src/android/net/TetheringManager.java +++ b/Tethering/common/TetheringLib/src/android/net/TetheringManager.java @@ -321,7 +321,9 @@ public class TetheringManager { // up and be sent from a worker thread; later, they are always sent from the caller thread. // Considering that it's just oneway binder calls, and ordering is preserved, this seems // better than inconsistent behavior persisting after boot. - if (connector != null) { + // If system server restarted, mConnectorSupplier might temporarily return a stale (i.e. + // dead) version of TetheringService. + if (connector != null && connector.isBinderAlive()) { mConnector = ITetheringConnector.Stub.asInterface(connector); } else { startPollingForConnector(); @@ -356,9 +358,8 @@ public class TetheringManager { } catch (InterruptedException e) { // Not much to do here, the system needs to wait for the connector } - final IBinder connector = mConnectorSupplier.get(); - if (connector != null) { + if (connector != null && connector.isBinderAlive()) { onTetheringConnected(ITetheringConnector.Stub.asInterface(connector)); return; }