From 1b16c57b5777833fe63ce71ec1f0195478151b76 Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Thu, 19 Dec 2019 13:03:38 -0800 Subject: [PATCH] Fix system service crash on radio session death. DO NOT MERGE This is a partial cherry-pick from ag/7063548 Bug: 140203726 Test: adb shell am start -S -W -n com.android.car.radio/.RadioActivity (multiple times) Change-Id: I6f16ff6eb82fca63c697d284fb3f45c2bb2be38c --- .../server/broadcastradio/hal2/RadioModule.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java b/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java index 85ca627e3b021..2d96d8978e579 100644 --- a/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java +++ b/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java @@ -233,18 +233,24 @@ class RadioModule { } private void fanoutAidlCallbackLocked(AidlCallbackRunnable runnable) { + List deadSessions = null; for (TunerSession tunerSession : mAidlTunerSessions) { try { runnable.run(tunerSession.mCallback); } catch (DeadObjectException ex) { - // The other side died without calling close(), so just purge it from our - // records. + // The other side died without calling close(), so just purge it from our records. Slog.e(TAG, "Removing dead TunerSession"); - mAidlTunerSessions.remove(tunerSession); + if (deadSessions == null) { + deadSessions = new ArrayList<>(); + } + deadSessions.add(tunerSession); } catch (RemoteException ex) { Slog.e(TAG, "Failed to invoke ITunerCallback: ", ex); } } + if (deadSessions != null) { + mAidlTunerSessions.removeAll(deadSessions); + } } public android.hardware.radio.ICloseHandle addAnnouncementListener(@NonNull int[] enabledTypes,