OSDN Git Service

Don't inflate LegacyGlobalActions until its shown
authorJason Monk <jmonk@google.com>
Thu, 23 Mar 2017 19:40:21 +0000 (15:40 -0400)
committerJason Monk <jmonk@google.com>
Thu, 23 Mar 2017 22:39:19 +0000 (18:39 -0400)
It has some buggy code that depends on it being shown directly
after being instantiated, so make sure we don't instantiate it
until we need it.

Test: See bug, its complicated
Change-Id: Ic4863f53abaeb2d2070258a7f65b214376fb2889
Fixes: 36556777

services/core/java/com/android/server/policy/GlobalActions.java

index db23a6a..342ec4b 100644 (file)
@@ -29,9 +29,10 @@ class GlobalActions implements GlobalActionsListener {
     private static final boolean DEBUG = false;
 
     private final Context mContext;
-    private final LegacyGlobalActions mLegacyGlobalActions;
     private final StatusBarManagerInternal mStatusBarInternal;
     private final Handler mHandler;
+    private final WindowManagerFuncs mWindowManagerFuncs;
+    private LegacyGlobalActions mLegacyGlobalActions;
     private boolean mKeyguardShowing;
     private boolean mDeviceProvisioned;
     private boolean mStatusBarConnected;
@@ -40,8 +41,7 @@ class GlobalActions implements GlobalActionsListener {
     public GlobalActions(Context context, WindowManagerFuncs windowManagerFuncs) {
         mContext = context;
         mHandler = new Handler();
-        mLegacyGlobalActions = new LegacyGlobalActions(context, windowManagerFuncs,
-                this::onGlobalActionsDismissed);
+        mWindowManagerFuncs = windowManagerFuncs;
         mStatusBarInternal = LocalServices.getService(StatusBarManagerInternal.class);
 
         // Some form factors do not have a status bar.
@@ -50,6 +50,12 @@ class GlobalActions implements GlobalActionsListener {
         }
     }
 
+    private void ensureLegacyCreated() {
+        if (mLegacyGlobalActions != null) return;
+        mLegacyGlobalActions = new LegacyGlobalActions(mContext, mWindowManagerFuncs,
+                this::onGlobalActionsDismissed);
+    }
+
     public void showDialog(boolean keyguardShowing, boolean deviceProvisioned) {
         if (DEBUG) Slog.d(TAG, "showDialog " + keyguardShowing + " " + deviceProvisioned);
         mKeyguardShowing = keyguardShowing;
@@ -60,6 +66,7 @@ class GlobalActions implements GlobalActionsListener {
             mHandler.postDelayed(mShowTimeout, 5000);
         } else {
             // SysUI isn't alive, show legacy menu.
+            ensureLegacyCreated();
             mLegacyGlobalActions.showDialog(mKeyguardShowing, mDeviceProvisioned);
         }
     }
@@ -83,6 +90,7 @@ class GlobalActions implements GlobalActionsListener {
         mStatusBarConnected = connected;
         if (mShowing && !mStatusBarConnected) {
             // Status bar died but we need to be showing global actions still, show the legacy.
+            ensureLegacyCreated();
             mLegacyGlobalActions.showDialog(mKeyguardShowing, mDeviceProvisioned);
         }
     }
@@ -92,6 +100,7 @@ class GlobalActions implements GlobalActionsListener {
         public void run() {
             if (DEBUG) Slog.d(TAG, "Global actions timeout");
             // We haven't heard from sysui, show the legacy dialog.
+            ensureLegacyCreated();
             mLegacyGlobalActions.showDialog(mKeyguardShowing, mDeviceProvisioned);
         }
     };