Loading packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/row/NotificationRowContentBinderImplTest.kt +2 −1 Original line number Diff line number Diff line Loading @@ -57,6 +57,7 @@ import com.android.systemui.statusbar.notification.row.NotificationRowContentBin import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_PUBLIC_SINGLE_LINE import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationCallback import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag import com.android.systemui.statusbar.notification.row.NotificationRowContentBinderImpl.InflationTaskTracker import com.android.systemui.statusbar.notification.row.shared.HeadsUpStatusBarModel import com.android.systemui.statusbar.notification.row.shared.LockscreenOtpRedaction import com.android.systemui.statusbar.notification.row.shared.NewRemoteViews Loading Loading @@ -247,7 +248,7 @@ class NotificationRowContentBinderImplTest(flags: FlagsParameterization) : Sysui parentLayout = row.privateLayout, existingView = null, existingWrapper = null, runningInflations = HashMap(), runningInflations = InflationTaskTracker(), applyCallback = object : NotificationRowContentBinderImpl.ApplyCallback() { override fun setResultView(v: View) {} Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationRowContentBinderImpl.kt +32 −17 Original line number Diff line number Diff line Loading @@ -87,7 +87,6 @@ import com.android.systemui.statusbar.policy.InflatedSmartReplyViewHolder import com.android.systemui.statusbar.policy.SmartReplyStateInflater import com.android.systemui.util.Assert import java.util.concurrent.Executor import java.util.function.Consumer import javax.inject.Inject /** Loading Loading @@ -975,7 +974,7 @@ constructor( Trace.beginAsyncSection(APPLY_TRACE_METHOD, System.identityHashCode(row)) val privateLayout = row.privateLayout val publicLayout = row.publicLayout val runningInflations = HashMap<Int, CancellationSignal>() val runningInflations = InflationTaskTracker() var flag = FLAG_CONTENT_VIEW_CONTRACTED if (reInflateFlags and flag != 0 && result.remoteViews.contracted != null) { val isNewView = Loading Loading @@ -1244,9 +1243,7 @@ constructor( cancellationSignal.setOnCancelListener { logger.logAsyncTaskProgress(entry.logKey, "apply cancelled") Trace.endAsyncSection(APPLY_TRACE_METHOD, System.identityHashCode(row)) runningInflations.values.forEach( Consumer { obj: CancellationSignal -> obj.cancel() } ) runningInflations.cancelAll() } return cancellationSignal } Loading @@ -1268,7 +1265,7 @@ constructor( parentLayout: ViewGroup?, existingView: View?, existingWrapper: NotificationViewWrapper?, runningInflations: HashMap<Int, CancellationSignal>, runningInflations: InflationTaskTracker, applyCallback: ApplyCallback, logger: NotificationRowContentBinderLogger, ) { Loading Loading @@ -1307,7 +1304,7 @@ constructor( ) // Add a running inflation to make sure we don't trigger callbacks. // Safe to do because only happens in tests. runningInflations[inflationId] = CancellationSignal() runningInflations.registerRemoteViews(inflationId, CancellationSignal()) } return } Loading Loading @@ -1339,7 +1336,7 @@ constructor( logger, "applied invalid view", ) runningInflations.remove(inflationId) runningInflations.unregisterRemoteViews(inflationId) return } if (isNewView) { Loading @@ -1347,7 +1344,7 @@ constructor( } else { existingWrapper?.onReinflated() } runningInflations.remove(inflationId) runningInflations.unregisterRemoteViews(inflationId) finishIfDone( result, isMinimized, Loading @@ -1370,7 +1367,7 @@ constructor( existingWrapper?.onReinflated() } } catch (e: InflationException) { runningInflations.remove(inflationId) runningInflations.unregisterRemoteViews(inflationId) handleInflationError( runningInflations, e, Loading @@ -1383,7 +1380,7 @@ constructor( return } runningInflations.remove(inflationId) runningInflations.unregisterRemoteViews(inflationId) finishIfDone( result, isMinimized, Loading Loading @@ -1424,7 +1421,7 @@ constructor( ) onViewApplied(newView) } catch (anotherException: Exception) { runningInflations.remove(inflationId) runningInflations.unregisterRemoteViews(inflationId) handleInflationError( runningInflations, e, Loading Loading @@ -1455,7 +1452,7 @@ constructor( remoteViewClickHandler, ) } runningInflations[inflationId] = cancellationSignal runningInflations.registerRemoteViews(inflationId, cancellationSignal) } /** Loading Loading @@ -1530,7 +1527,7 @@ constructor( } private fun handleInflationError( runningInflations: HashMap<Int, CancellationSignal>, runningInflations: InflationTaskTracker, e: Exception, notification: ExpandableNotificationRow?, entry: NotificationEntry, Loading @@ -1540,7 +1537,7 @@ constructor( ) { Assert.isMainThread() logger.logAsyncTaskException(notification?.loggingKey, logContext, e) runningInflations.values.forEach(Consumer { obj: CancellationSignal -> obj.cancel() }) runningInflations.cancelAll() callback?.handleInflationException(entry, e) } Loading @@ -1554,14 +1551,14 @@ constructor( isMinimized: Boolean, @InflationFlag reInflateFlags: Int, remoteViewCache: NotifRemoteViewCache, runningInflations: HashMap<Int, CancellationSignal>, runningInflations: InflationTaskTracker, endListener: InflationCallback?, entry: NotificationEntry, row: ExpandableNotificationRow, logger: NotificationRowContentBinderLogger, ): Boolean { Assert.isMainThread() if (runningInflations.isNotEmpty()) { if (runningInflations.isAnyActive()) { return false } logger.logAsyncTaskProgress(row.loggingKey, "finishing") Loading Loading @@ -1777,4 +1774,22 @@ constructor( "NotificationRowContentBinderImpl.AsyncInflationTask" private const val APPLY_TRACE_METHOD = "NotificationRowContentBinderImpl#apply" } class InflationTaskTracker { private val remoteViews = HashMap<Int, CancellationSignal>() fun registerRemoteViews(inflationId: Int, signal: CancellationSignal) { remoteViews[inflationId] = signal } fun unregisterRemoteViews(inflationId: Int) { remoteViews.remove(inflationId) } fun cancelAll() { remoteViews.values.forEach(CancellationSignal::cancel) } fun isAnyActive(): Boolean = remoteViews.isNotEmpty() } } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/row/NotificationRowContentBinderImplTest.kt +2 −1 Original line number Diff line number Diff line Loading @@ -57,6 +57,7 @@ import com.android.systemui.statusbar.notification.row.NotificationRowContentBin import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_PUBLIC_SINGLE_LINE import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationCallback import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag import com.android.systemui.statusbar.notification.row.NotificationRowContentBinderImpl.InflationTaskTracker import com.android.systemui.statusbar.notification.row.shared.HeadsUpStatusBarModel import com.android.systemui.statusbar.notification.row.shared.LockscreenOtpRedaction import com.android.systemui.statusbar.notification.row.shared.NewRemoteViews Loading Loading @@ -247,7 +248,7 @@ class NotificationRowContentBinderImplTest(flags: FlagsParameterization) : Sysui parentLayout = row.privateLayout, existingView = null, existingWrapper = null, runningInflations = HashMap(), runningInflations = InflationTaskTracker(), applyCallback = object : NotificationRowContentBinderImpl.ApplyCallback() { override fun setResultView(v: View) {} Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationRowContentBinderImpl.kt +32 −17 Original line number Diff line number Diff line Loading @@ -87,7 +87,6 @@ import com.android.systemui.statusbar.policy.InflatedSmartReplyViewHolder import com.android.systemui.statusbar.policy.SmartReplyStateInflater import com.android.systemui.util.Assert import java.util.concurrent.Executor import java.util.function.Consumer import javax.inject.Inject /** Loading Loading @@ -975,7 +974,7 @@ constructor( Trace.beginAsyncSection(APPLY_TRACE_METHOD, System.identityHashCode(row)) val privateLayout = row.privateLayout val publicLayout = row.publicLayout val runningInflations = HashMap<Int, CancellationSignal>() val runningInflations = InflationTaskTracker() var flag = FLAG_CONTENT_VIEW_CONTRACTED if (reInflateFlags and flag != 0 && result.remoteViews.contracted != null) { val isNewView = Loading Loading @@ -1244,9 +1243,7 @@ constructor( cancellationSignal.setOnCancelListener { logger.logAsyncTaskProgress(entry.logKey, "apply cancelled") Trace.endAsyncSection(APPLY_TRACE_METHOD, System.identityHashCode(row)) runningInflations.values.forEach( Consumer { obj: CancellationSignal -> obj.cancel() } ) runningInflations.cancelAll() } return cancellationSignal } Loading @@ -1268,7 +1265,7 @@ constructor( parentLayout: ViewGroup?, existingView: View?, existingWrapper: NotificationViewWrapper?, runningInflations: HashMap<Int, CancellationSignal>, runningInflations: InflationTaskTracker, applyCallback: ApplyCallback, logger: NotificationRowContentBinderLogger, ) { Loading Loading @@ -1307,7 +1304,7 @@ constructor( ) // Add a running inflation to make sure we don't trigger callbacks. // Safe to do because only happens in tests. runningInflations[inflationId] = CancellationSignal() runningInflations.registerRemoteViews(inflationId, CancellationSignal()) } return } Loading Loading @@ -1339,7 +1336,7 @@ constructor( logger, "applied invalid view", ) runningInflations.remove(inflationId) runningInflations.unregisterRemoteViews(inflationId) return } if (isNewView) { Loading @@ -1347,7 +1344,7 @@ constructor( } else { existingWrapper?.onReinflated() } runningInflations.remove(inflationId) runningInflations.unregisterRemoteViews(inflationId) finishIfDone( result, isMinimized, Loading @@ -1370,7 +1367,7 @@ constructor( existingWrapper?.onReinflated() } } catch (e: InflationException) { runningInflations.remove(inflationId) runningInflations.unregisterRemoteViews(inflationId) handleInflationError( runningInflations, e, Loading @@ -1383,7 +1380,7 @@ constructor( return } runningInflations.remove(inflationId) runningInflations.unregisterRemoteViews(inflationId) finishIfDone( result, isMinimized, Loading Loading @@ -1424,7 +1421,7 @@ constructor( ) onViewApplied(newView) } catch (anotherException: Exception) { runningInflations.remove(inflationId) runningInflations.unregisterRemoteViews(inflationId) handleInflationError( runningInflations, e, Loading Loading @@ -1455,7 +1452,7 @@ constructor( remoteViewClickHandler, ) } runningInflations[inflationId] = cancellationSignal runningInflations.registerRemoteViews(inflationId, cancellationSignal) } /** Loading Loading @@ -1530,7 +1527,7 @@ constructor( } private fun handleInflationError( runningInflations: HashMap<Int, CancellationSignal>, runningInflations: InflationTaskTracker, e: Exception, notification: ExpandableNotificationRow?, entry: NotificationEntry, Loading @@ -1540,7 +1537,7 @@ constructor( ) { Assert.isMainThread() logger.logAsyncTaskException(notification?.loggingKey, logContext, e) runningInflations.values.forEach(Consumer { obj: CancellationSignal -> obj.cancel() }) runningInflations.cancelAll() callback?.handleInflationException(entry, e) } Loading @@ -1554,14 +1551,14 @@ constructor( isMinimized: Boolean, @InflationFlag reInflateFlags: Int, remoteViewCache: NotifRemoteViewCache, runningInflations: HashMap<Int, CancellationSignal>, runningInflations: InflationTaskTracker, endListener: InflationCallback?, entry: NotificationEntry, row: ExpandableNotificationRow, logger: NotificationRowContentBinderLogger, ): Boolean { Assert.isMainThread() if (runningInflations.isNotEmpty()) { if (runningInflations.isAnyActive()) { return false } logger.logAsyncTaskProgress(row.loggingKey, "finishing") Loading Loading @@ -1777,4 +1774,22 @@ constructor( "NotificationRowContentBinderImpl.AsyncInflationTask" private const val APPLY_TRACE_METHOD = "NotificationRowContentBinderImpl#apply" } class InflationTaskTracker { private val remoteViews = HashMap<Int, CancellationSignal>() fun registerRemoteViews(inflationId: Int, signal: CancellationSignal) { remoteViews[inflationId] = signal } fun unregisterRemoteViews(inflationId: Int) { remoteViews.remove(inflationId) } fun cancelAll() { remoteViews.values.forEach(CancellationSignal::cancel) } fun isAnyActive(): Boolean = remoteViews.isNotEmpty() } }