diff options
author | 2025-04-07 15:32:40 +0000 | |
---|---|---|
committer | 2025-04-10 16:12:54 -0700 | |
commit | 6219daf776c77d3053b9d1ea7b63324285c302ea (patch) | |
tree | 53908886a16902a3e908e42890e06b777ca77471 | |
parent | 8416f01401b1abbc9cc74a4a1b298eddab056da1 (diff) |
fix(magnification): catch the unregister failing exception to prevent system crash
For b/399282180, the context intent receiver unregistering is called
when the FullScreenMagnificationGestureHandler#onDestroy, which implies
the handler is not needed anymore. That is, the fail execption when
unregistering would not affect the user experience, and it should not
make the system crash too.
Therefore, we use try-catch to catch the exception to prevent system
crash. Besides, since we still need more clues to identify the root
cause for the exception, we also log the exception for future
investigations.
This fix should be low risk, since we only catch the exception to
prevent the crash, and no logic changes.
Bug: 399282180
Flag: EXEMPT bugfix
Test: manually
atest FullScreenMagnificationGestureHandlerTest
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:782870d5a691b44837bc0b5308eb7c02a22cb483)
Merged-In: I916719958ce3954076a1ad240ffaf150d619cd16
Change-Id: I916719958ce3954076a1ad240ffaf150d619cd16
-rw-r--r-- | services/accessibility/java/com/android/server/accessibility/magnification/FullScreenMagnificationGestureHandler.java | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/services/accessibility/java/com/android/server/accessibility/magnification/FullScreenMagnificationGestureHandler.java b/services/accessibility/java/com/android/server/accessibility/magnification/FullScreenMagnificationGestureHandler.java index 59b4a1613e08..919b33415646 100644 --- a/services/accessibility/java/com/android/server/accessibility/magnification/FullScreenMagnificationGestureHandler.java +++ b/services/accessibility/java/com/android/server/accessibility/magnification/FullScreenMagnificationGestureHandler.java @@ -1745,6 +1745,7 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH * BroadcastReceiver used to cancel the magnification shortcut when the screen turns off */ private static class ScreenStateReceiver extends BroadcastReceiver { + private static final String TAG = ScreenStateReceiver.class.getName(); private final Context mContext; private final FullScreenMagnificationGestureHandler mGestureHandler; @@ -1759,7 +1760,16 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH } public void unregister() { - mContext.unregisterReceiver(this); + try { + mContext.unregisterReceiver(this); + } catch (IllegalArgumentException exception) { + // b/399282180: the unregister happens when the handler is destroyed (cleanup). The + // cleanup process should not cause the system crash, also the failure of unregister + // will not affect the user experience since it's for the destroyed handler. + // Therefore, we use try-catch here, to catch the exception to prevent crash, and + // log the exception for future investigations. + Slog.e(TAG, "Failed to unregister receiver: " + exception); + } } @Override |