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

Commit e9c58d5b authored by Charles Chen's avatar Charles Chen Committed by Android (Google) Code Review
Browse files

Merge "Move clean up logic to SystemUiContext" into main

parents 236a3c6f aef74111
Loading
Loading
Loading
Loading
+0 −25
Original line number Diff line number Diff line
@@ -340,14 +340,6 @@ class ContextImpl extends Context {
    @ContextType
    private int mContextType;

    /**
     * {@code true} to indicate that the {@link Context} owns the {@link #getWindowContextToken()}
     * and is responsible for detaching the token when the Context is released.
     *
     * @see #finalize()
     */
    private boolean mOwnsToken = false;

    private final Object mDatabasesDirLock = new Object();
    @GuardedBy("mDatabasesDirLock")
    private File mDatabasesDir;
@@ -3423,22 +3415,6 @@ class ContextImpl extends Context {
        mContentCaptureOptions = options;
    }

    @Override
    protected void finalize() throws Throwable {
        // If mToken is a WindowTokenClient, the Context is usually associated with a
        // WindowContainer. We should detach from WindowContainer when the Context is finalized
        // if this Context is not a WindowContext. WindowContext finalization is handled in
        // WindowContext class.
        try {
            if (mToken instanceof WindowTokenClient && mOwnsToken) {
                WindowTokenClientController.getInstance()
                        .detachIfNeeded((WindowTokenClient) mToken);
            }
        } finally {
            super.finalize();
        }
    }

    @UnsupportedAppUsage
    static ContextImpl createSystemContext(ActivityThread mainThread) {
        LoadedApk packageInfo = new LoadedApk(mainThread);
@@ -3473,7 +3449,6 @@ class ContextImpl extends Context {
        // Step 3. Associate the SystemUiContext with the display specified with ID.
        WindowTokenClientController.getInstance().attachToDisplayContent(token, displayId);
        context.mContextType = CONTEXT_TYPE_SYSTEM_OR_SYSTEM_UI;
        context.mOwnsToken = true;
        return systemUiContext;
    }

+14 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Configuration;

import java.util.Objects;

/**
 * System Context to be used for UI. This Context has resources that can be themed.
 *
@@ -60,4 +62,16 @@ public class SystemUiContext extends ContextWrapper implements ConfigurationDisp
        // We should report all config changes to update fields obtained from resources.
        return true;
    }

    @Override
    protected void finalize() throws Throwable {
        // We should detach from WindowContainer when the Context is finalized since SystemUiContext
        // associates the DisplayContent with #getDisplayId().
        try {
            final WindowTokenClient token = (WindowTokenClient) getWindowContextToken();
            WindowTokenClientController.getInstance().detachIfNeeded(Objects.requireNonNull(token));
        } finally {
            super.finalize();
        }
    }
}