Fix leakage of pointer location

When display is removing, we should explicitly remove the pointer
location view to ensure the client object would be released.

Bug: 239078899
Test: Enabled pointer location, add/remove virtual display, check if
      the surface would be released.
Change-Id: I89ef3dc8e5b4aa8c3b7d5c1393d6543a9d3d67db
This commit is contained in:
Arthur Hung
2022-08-01 08:10:44 +00:00
parent 867250736a
commit 5a47857643
2 changed files with 9 additions and 1 deletions

View File

@@ -828,6 +828,8 @@ public class PointerLocationView extends View implements InputDeviceListener,
mSystemGestureExclusionListener, mContext.getDisplayId());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
} catch (IllegalArgumentException e) {
Log.e(TAG, "Failed to unregister window manager callbacks", e);
}
}

View File

@@ -2907,7 +2907,10 @@ public class DisplayPolicy {
return;
}
mDisplayContent.unregisterPointerEventListener(mPointerLocationView);
if (!mDisplayContent.isRemoved()) {
mDisplayContent.unregisterPointerEventListener(mPointerLocationView);
}
final WindowManager wm = mContext.getSystemService(WindowManager.class);
wm.removeView(mPointerLocationView);
mPointerLocationView = null;
@@ -2932,6 +2935,9 @@ public class DisplayPolicy {
mHandler.post(mGestureNavigationSettingsObserver::unregister);
mHandler.post(mForceShowNavBarSettingsObserver::unregister);
mImmersiveModeConfirmation.release();
if (mService.mPointerLocationEnabled) {
setPointerLocationEnabled(false);
}
}
@VisibleForTesting