diff options
| author | 2021-01-12 10:51:42 -0500 | |
|---|---|---|
| committer | 2021-01-12 14:18:50 -0500 | |
| commit | f7e9cd57fbbdc16201dcffe2c35cd67d8b0e0443 (patch) | |
| tree | 55a5d1b61344b2cec73e86f21f829e11b6696cfb | |
| parent | 19d37240a51eafe10f7f2dc4c8f638588df52d19 (diff) | |
Release screenshot WindowContext when process ends
Bug: 176600157
Fix: 176600157
Test: manual -- reproducible by taking a screenshot several times
(5-10) in quick succession, and observing crash in logs. Crash no
longer occurs when we release the WindowContext when the screenshot
process is destroyed.
Change-Id: I33047ffb03867f65b591a1b43f6a56d49093fc0e
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java | 12 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java | 3 |
2 files changed, 13 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java index a60c24146d9f..7d5779949074 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java @@ -38,6 +38,7 @@ import android.app.ActivityOptions; import android.app.ExitTransitionCoordinator; import android.app.ExitTransitionCoordinator.ExitTransitionCallbacks; import android.app.Notification; +import android.app.WindowContext; import android.content.ComponentName; import android.content.Context; import android.content.pm.ActivityInfo; @@ -165,7 +166,7 @@ public class ScreenshotController { // From WizardManagerHelper.java private static final String SETTINGS_SECURE_USER_SETUP_COMPLETE = "user_setup_complete"; - private final Context mContext; + private final WindowContext mContext; private final ScreenshotNotificationsController mNotificationsController; private final ScreenshotSmartActions mScreenshotSmartActions; private final UiEventLogger mUiEventLogger; @@ -240,7 +241,7 @@ public class ScreenshotController { final DisplayManager dm = requireNonNull(context.getSystemService(DisplayManager.class)); final Display display = dm.getDisplay(DEFAULT_DISPLAY); final Context displayContext = context.createDisplayContext(display); - mContext = displayContext.createWindowContext(TYPE_SCREENSHOT, null); + mContext = (WindowContext) displayContext.createWindowContext(TYPE_SCREENSHOT, null); mWindowManager = mContext.getSystemService(WindowManager.class); mAccessibilityManager = AccessibilityManager.getInstance(mContext); @@ -352,6 +353,13 @@ public class ScreenshotController { } /** + * Release the constructed window context. + */ + void releaseContext() { + mContext.release(); + } + + /** * Update resources on configuration change. Reinflate for theme/color changes. */ private void reloadAssets() { diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java b/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java index c2b20d37f3f3..c33bbc51ed5b 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java @@ -123,6 +123,9 @@ public class TakeScreenshotService extends Service { @Override public void onDestroy() { super.onDestroy(); + if (mScreenshot != null) { + mScreenshot.releaseContext(); + } if (DEBUG_SERVICE) { Log.d(TAG, "onDestroy"); } |