Lock state of NotificationComparator while sorting in RankingHelper
When the default dialer or default SMS package is changed, the NotificationComparator and NotificationMessagingUtil update their cached copy of this value, which is used to evaluate isImportantOngoing and isImportantMessaging (two of the criteria involved in the comparison). However, if this is changed _while a sort() is ongoing_, then the results of element comparison could potentially be inconsistent whenever notifications posted by the new or previous package are involved. In the worst case this could result in a system crash ("IllegalArgumentException: Comparison method violates its general contract!"). This CL introduces a lock object in NotificationComparator that should be acquired and held for the full duration of the sort. Default package changes that arrive within this time will be processed afterwards. Fixes: 293249306 Test: atest NotificationComparatorTest -- testChangeDialerPackageWhileSorting() crashes without the synchronized block around records.sort(comparator). Change-Id: I67251437ae827c39b135f5d45cfe682aa852d09a
Loading
Please register or sign in to comment