diff options
| author | 2023-03-02 23:42:36 +0000 | |
|---|---|---|
| committer | 2023-03-07 23:03:24 +0000 | |
| commit | 0c52d29a32e00bffa54eb5904960a1b5432eba61 (patch) | |
| tree | f59a4122646752c08cb7b26d67091a1422111f1e | |
| parent | a43f32d50c45ce9324818a54560d1419ef904bb9 (diff) | |
Fix RegionSampler crashes
RegionSampler was crashing due to (1) the LS Smartspace not checking for
the View's existence in the RegionSampler map and (2) adding regions
that were out of bounds. These crashes prevented RegionSampler from
working properly (i.e. being able to edit thresholds from ag/21145349).
This change also addresses some faulty logic in ClockEventController that was causing only the large clock view to be sampled. Now, both the small clock and large clock are being sampled when there's a layout change detected.
Bug: 202758428
Flag: region_sampling
Test: manual (verified no more error logs related to RegionSampler in Logcat)
Change-Id: I7895f1c2aa8fb19feac325df71d8b7f04c39717b
3 files changed, 29 insertions, 31 deletions
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSampler.kt b/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSampler.kt index 9a581aaa9b2c..482158e80d0f 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSampler.kt +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSampler.kt @@ -91,6 +91,22 @@ constructor( val sampledRegion = calculateSampledRegion(sampledView) val regions = ArrayList<RectF>() val sampledRegionWithOffset = convertBounds(sampledRegion) + + if ( + sampledRegionWithOffset.left < 0.0 || + sampledRegionWithOffset.right > 1.0 || + sampledRegionWithOffset.top < 0.0 || + sampledRegionWithOffset.bottom > 1.0 + ) { + android.util.Log.e( + "RegionSampler", + "view out of bounds: $sampledRegion | " + + "screen width: ${displaySize.x}, screen height: ${displaySize.y}", + Exception() + ) + return + } + regions.add(sampledRegionWithOffset) wallpaperManager?.removeOnColorsChangedListener(this) diff --git a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt index 92ee37310130..4aaa566eb852 100644 --- a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt +++ b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt @@ -21,6 +21,7 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.content.res.Resources +import android.graphics.Rect import android.text.format.DateFormat import android.util.TypedValue import android.view.View @@ -119,10 +120,6 @@ constructor( private val mLayoutChangedListener = object : View.OnLayoutChangeListener { - private var currentSmallClockView: View? = null - private var currentLargeClockView: View? = null - private var currentSmallClockLocation = IntArray(2) - private var currentLargeClockLocation = IntArray(2) override fun onLayoutChange( view: View?, @@ -135,6 +132,8 @@ constructor( oldRight: Int, oldBottom: Int ) { + view?.removeOnLayoutChangeListener(this) + val parent = (view?.parent) as FrameLayout // don't pass in negative bounds when clocks are in transition state @@ -142,31 +141,12 @@ constructor( return } - // SMALL CLOCK - if (parent.id == R.id.lockscreen_clock_view) { - // view bounds have changed due to clock size changing (i.e. different character - // widths) - // AND/OR the view has been translated when transitioning between small and - // large clock - if ( - view != currentSmallClockView || - !view.locationOnScreen.contentEquals(currentSmallClockLocation) - ) { - currentSmallClockView = view - currentSmallClockLocation = view.locationOnScreen - updateRegionSampler(view) - } - } - // LARGE CLOCK - else if (parent.id == R.id.lockscreen_clock_view_large) { - if ( - view != currentLargeClockView || - !view.locationOnScreen.contentEquals(currentLargeClockLocation) - ) { - currentLargeClockView = view - currentLargeClockLocation = view.locationOnScreen - updateRegionSampler(view) - } + val currentViewRect = Rect(left, top, right, bottom) + val oldViewRect = Rect(oldLeft, oldTop, oldRight, oldBottom) + + if (currentViewRect.width() != oldViewRect.width() || + currentViewRect.height() != oldViewRect.height()) { + updateRegionSampler(view) } } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt index b0ad6a1ffbd8..37538a3ca93b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt @@ -500,8 +500,10 @@ constructor( private fun updateTextColorFromRegionSampler() { smartspaceViews.forEach { - val textColor = regionSamplers.getValue(it).currentForegroundColor() - it.setPrimaryTextColor(textColor) + val textColor = regionSamplers.get(it)?.currentForegroundColor() + if (textColor != null) { + it.setPrimaryTextColor(textColor) + } } } |