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

Commit b2451418 authored by Fan Zhang's avatar Fan Zhang
Browse files

Store the application context statically in FeatureFactory

It stores the application context in a static class, and will be
destoryed when application stops.

Bug: 124701288
Test: robo
Change-Id: I4678072f3f38ae682be6ba075c85e63c49f8febe
parent cd9ef2ab
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.Nullable;

import com.android.settings.R;
import com.android.settings.accounts.AccountFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProvider;
@@ -50,6 +52,7 @@ public abstract class FeatureFactory {
    private static final boolean DEBUG = false;

    protected static FeatureFactory sFactory;
    protected static Context sAppContext;

    /**
     * Returns a factory for creating feature controllers. Creates the factory if it does not
@@ -60,6 +63,9 @@ public abstract class FeatureFactory {
        if (sFactory != null) {
            return sFactory;
        }
        if (sAppContext == null) {
            sAppContext = context.getApplicationContext();
        }

        if (DEBUG) Log.d(LOG_TAG, "getFactory");
        final String clsName = context.getString(R.string.config_featureFactory);
@@ -76,6 +82,16 @@ public abstract class FeatureFactory {
        return sFactory;
    }

    /**
     * Returns an application {@link Context} used to create this {@link FeatureFactory}. If the
     * factory has not been properly created yet (aka {@link #getFactory} has not been called), this
     * will return null.
     */
    @Nullable
    public static Context getAppContext() {
        return sAppContext;
    }

    public abstract AssistGestureFeatureProvider getAssistGestureFeatureProvider();

    public abstract SuggestionFeatureProvider getSuggestionFeatureProvider(Context context);