Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 94d8c279 authored by xiaomei.li's avatar xiaomei.li Committed by Joey Rizzoli
Browse files

Ensure that the decor view is attached to window.

In paticular case, the preserve DecorView object may not attach to window,and
when update the decor view layout params, WMS found that it not attached to
window manager will throw IllegalArgumentException, it will lead app to crash.

Test: activity switch case, multi-window case [work fine]

Change-Id: I52c64ac76c8a84b95e5e105fa586628a8284932b
parent 07ece0ca
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ import com.android.internal.app.IVoiceInteractor;
import com.android.internal.app.ToolbarActionBar;
import com.android.internal.app.WindowDecorActionBar;
import com.android.internal.policy.PhoneWindow;
import com.android.internal.policy.DecorView;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -5133,6 +5134,7 @@ public class Activity extends ContextThemeWrapper
            ViewManager wm = getWindowManager();
            wm.addView(mDecor, getWindow().getAttributes());
            mWindowAdded = true;
            DecorView.setAddedToWindow(mDecor);
        }
        mDecor.setVisibility(View.VISIBLE);
    }
+6 −1
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ import com.android.internal.os.BinderInternal;
import com.android.internal.os.RuntimeInit;
import com.android.internal.os.SamplingProfilerIntegration;
import com.android.internal.os.SomeArgs;
import com.android.internal.policy.DecorView;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.FastPrintWriter;
import com.android.org.conscrypt.OpenSSLSocketImpl;
@@ -3523,7 +3524,10 @@ public final class ActivityThread {
                l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
                l.softInputMode |= forwardBit;
                if (r.mPreserveWindow) {
                    a.mWindowAdded = true;
                    // if the preserve decor view is not attached to window, we
                    // should make sure that it will been attached in the following
                    // workflow.
                    if(DecorView.isAddedToWindow(decor)) a.mWindowAdded = true;
                    r.mPreserveWindow = false;
                    // Normally the ViewRoot sets up callbacks with the Activity
                    // in addView->ViewRootImpl#setView. If we are instead reusing
@@ -3537,6 +3541,7 @@ public final class ActivityThread {
                if (a.mVisibleFromClient && !a.mWindowAdded) {
                    a.mWindowAdded = true;
                    wm.addView(decor, l);
                    DecorView.setAddedToWindow(a.mDecor);
                }

            // If the window has already been added, but during resume
+15 −0
Original line number Diff line number Diff line
@@ -230,6 +230,8 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
    private final Paint mVerticalResizeShadowPaint = new Paint();
    private final Paint mHorizontalResizeShadowPaint = new Paint();

    private boolean mIsAddedToWindow = false;

    DecorView(Context context, int featureId, PhoneWindow window,
            WindowManager.LayoutParams params) {
        super(context);
@@ -2395,4 +2397,17 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
            }
        }
    }

    public static void setAddedToWindow(View v) {
        if (v instanceof DecorView) {
            ((DecorView) v).mIsAddedToWindow = true;
        }
    }

    public static boolean isAddedToWindow(View v) {
        if (v instanceof DecorView) {
            return ((DecorView) v).mIsAddedToWindow;
        }
        return false;
    }
}