From a254049856f00083ea42c8007916f118d05ce1d4 Mon Sep 17 00:00:00 2001 From: Alexander Roederer Date: Thu, 17 Aug 2023 13:59:51 +0000 Subject: [PATCH] Closes file descriptor after loading ranking map Closes file descriptor after loading ranking map from SharedMemory object. Bug: 249848655 Test: atest NotificationRankingUpdateTest, manual flash+NotificationShellCmd to issue 500 notifications with reranking. Change-Id: I66779f4eae5ff93cc6a90d3fd00b829ab3670cff --- .../service/notification/NotificationRankingUpdate.java | 1 + .../service/notification/NotificationRankingUpdateTest.java | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/java/android/service/notification/NotificationRankingUpdate.java b/core/java/android/service/notification/NotificationRankingUpdate.java index 75640bd47ab9b..f3b4c6da4a01e 100644 --- a/core/java/android/service/notification/NotificationRankingUpdate.java +++ b/core/java/android/service/notification/NotificationRankingUpdate.java @@ -92,6 +92,7 @@ public class NotificationRankingUpdate implements Parcelable { mapParcel.recycle(); if (buffer != null) { mRankingMapFd.unmap(buffer); + mRankingMapFd.close(); } } } else { diff --git a/core/tests/coretests/src/android/service/notification/NotificationRankingUpdateTest.java b/core/tests/coretests/src/android/service/notification/NotificationRankingUpdateTest.java index a84ac55f0d5a2..55ded9c8813d0 100644 --- a/core/tests/coretests/src/android/service/notification/NotificationRankingUpdateTest.java +++ b/core/tests/coretests/src/android/service/notification/NotificationRankingUpdateTest.java @@ -136,7 +136,11 @@ public class NotificationRankingUpdateTest { NotificationListenerService.RankingMap retrievedRankings = retrievedRankingUpdate.getRankingMap(); assertNotNull(retrievedRankings); - assertTrue(retrievedRankingUpdate.isFdNotNullAndClosed()); + // The rankingUpdate file descriptor is only non-null in the new path. + if (SystemUiSystemPropertiesFlags.getResolver().isEnabled( + SystemUiSystemPropertiesFlags.NotificationFlags.RANKING_UPDATE_ASHMEM)) { + assertTrue(retrievedRankingUpdate.isFdNotNullAndClosed()); + } NotificationListenerService.Ranking retrievedRanking = new NotificationListenerService.Ranking(); assertTrue(retrievedRankings.getRanking(TEST_KEY, retrievedRanking));