From d0bd08b4b91d290bbebc760802b28a11c17fcd36 Mon Sep 17 00:00:00 2001 From: lpeter Date: Tue, 16 Jun 2020 13:57:01 +0800 Subject: [PATCH] Add try-catch for the augmented autofill UI to avoid crashing It is hard to reproduce this issue, it would better add try-catch for the augmented autofill UI as regular autofill UI did. Bug: 149744098 Test: atest CtsAutoFillServiceTestCases Change-Id: I808ac48476ef96b8944e762dd5c41413da3a2c2e --- .../autofill/augmented/FillWindow.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/core/java/android/service/autofill/augmented/FillWindow.java b/core/java/android/service/autofill/augmented/FillWindow.java index 077df6cf16ef1..8e866466e8dfd 100644 --- a/core/java/android/service/autofill/augmented/FillWindow.java +++ b/core/java/android/service/autofill/augmented/FillWindow.java @@ -208,12 +208,18 @@ public final class FillWindow implements AutoCloseable { if (sDebug) Log.d(TAG, "handleShow()"); synchronized (mLock) { if (mWm != null && mFillView != null) { - p.flags |= WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; - if (!mShowing) { - mWm.addView(mFillView, p); - mShowing = true; - } else { - mWm.updateViewLayout(mFillView, p); + try { + p.flags |= WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; + if (!mShowing) { + mWm.addView(mFillView, p); + mShowing = true; + } else { + mWm.updateViewLayout(mFillView, p); + } + } catch (WindowManager.BadTokenException e) { + if (sDebug) Log.d(TAG, "Filed with token " + p.token + " gone."); + } catch (IllegalStateException e) { + if (sDebug) Log.d(TAG, "Exception showing window."); } } } @@ -223,8 +229,12 @@ public final class FillWindow implements AutoCloseable { if (sDebug) Log.d(TAG, "handleHide()"); synchronized (mLock) { if (mWm != null && mFillView != null && mShowing) { - mWm.removeView(mFillView); - mShowing = false; + try { + mWm.removeView(mFillView); + mShowing = false; + } catch (IllegalStateException e) { + if (sDebug) Log.d(TAG, "Exception hiding window."); + } } } }