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

Commit aef74111 authored by Charles Chen's avatar Charles Chen
Browse files

Move clean up logic to SystemUiContext

Move SystemUiContext clean up logic to SystemUiContext
to make ContextImpl more clear

Test: atest SystemUiContextTest
Flag: EXEMPT minor refactor
Fixes: 409612558
Change-Id: I0d635d463588c7daa90c1b70873f063ae2333274
parent cd5ab8a2
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();
        }
    }
}