Release leashes of insets controls if they are not needed

Previously, leashes would be only released by GC in some cases, but the
timing could be late. This CL proactively release them as long as they
are not needed. The cases were:

1. The leashes in DisplayImeController. It didn't release leashes while
   receiving a new one.

2. The leashes returned from addWindow/relayoutWindow. The leashes would
   be copied to prevent others from releasing them before writeToParcel.
   The copied leashes could be redundant after writeToParcel.

3. The leashes held by the client whose window is removed. If a window
   is removed, the server won't invoke mClient.insetsControlChanged, so
   the client would never get notified about losing control to release
   the leashes. This could happen if the window doesn't have an exiting
   animation.

Fix: 175851610
Test: Steps in the bug.
Test: Show and dismiss a dialog which doesn't have FLAG_ALT_FOCUSABLE_IM
      or any window animation. Repeat this thousands of times. And see
      if there are many insets leashes as offscreen layers in `dumpsys
      SurfaceFlinger`
Change-Id: I5eb774ac071154a8d7205dbd1ab4a5f8eca215c3
4 files changed