Fix the memory leak caused by the accessibility menu in SystemUI

When you turn on the "Accessibility Menu shortcut" switch in settings,
it starts a service and creates a new A11yMenuOverlayLayout.

However, the layout is not set to null at the right time, causing the
A11yMenuOverlayLayout to be repeatedly created and leading to a memory
leak.

Change-Id: I2368a1bbbbe0159755859651ecf53831ac70db37
Signed-off-by: Jia Jia <jia.jia@zte.com.cn>
diff --git a/packages/SystemUI/accessibility/accessibilitymenu/src/com/android/systemui/accessibility/accessibilitymenu/AccessibilityMenuService.java b/packages/SystemUI/accessibility/accessibilitymenu/src/com/android/systemui/accessibility/accessibilitymenu/AccessibilityMenuService.java
index 085fc29..b05d2ae 100644
--- a/packages/SystemUI/accessibility/accessibilitymenu/src/com/android/systemui/accessibility/accessibilitymenu/AccessibilityMenuService.java
+++ b/packages/SystemUI/accessibility/accessibilitymenu/src/com/android/systemui/accessibility/accessibilitymenu/AccessibilityMenuService.java
@@ -387,6 +387,10 @@
         unregisterReceiver(mToggleMenuReceiver);
         mPrefs.unregisterOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener);
         sInitialized = false;
+        if (mA11yMenuLayout != null) {
+            mA11yMenuLayout.clearLayout();
+            mA11yMenuLayout = null;
+        }
         return super.onUnbind(intent);
     }
 
diff --git a/packages/SystemUI/accessibility/accessibilitymenu/src/com/android/systemui/accessibility/accessibilitymenu/view/A11yMenuOverlayLayout.java b/packages/SystemUI/accessibility/accessibilitymenu/src/com/android/systemui/accessibility/accessibilitymenu/view/A11yMenuOverlayLayout.java
index edd6a48..1be04f8 100644
--- a/packages/SystemUI/accessibility/accessibilitymenu/src/com/android/systemui/accessibility/accessibilitymenu/view/A11yMenuOverlayLayout.java
+++ b/packages/SystemUI/accessibility/accessibilitymenu/src/com/android/systemui/accessibility/accessibilitymenu/view/A11yMenuOverlayLayout.java
@@ -151,6 +151,14 @@
         return mLayout;
     }
 
+    public void clearLayout() {
+        if (mLayout != null) {
+            mWindowManager.removeView(mLayout);
+            mLayout.setOnTouchListener(null);
+            mLayout = null;
+        }
+    }
+
     /** Updates view layout with new layout parameters only. */
     public void updateViewLayout() {
         if (mLayout == null || mLayoutParameter == null) {