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
This commit is contained in:
@@ -20,6 +20,8 @@ import android.content.Context;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.accounts.AccountFeatureProvider;
|
import com.android.settings.accounts.AccountFeatureProvider;
|
||||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||||
@@ -50,6 +52,7 @@ public abstract class FeatureFactory {
|
|||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
protected static FeatureFactory sFactory;
|
protected static FeatureFactory sFactory;
|
||||||
|
protected static Context sAppContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a factory for creating feature controllers. Creates the factory if it does not
|
* 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) {
|
if (sFactory != null) {
|
||||||
return sFactory;
|
return sFactory;
|
||||||
}
|
}
|
||||||
|
if (sAppContext == null) {
|
||||||
|
sAppContext = context.getApplicationContext();
|
||||||
|
}
|
||||||
|
|
||||||
if (DEBUG) Log.d(LOG_TAG, "getFactory");
|
if (DEBUG) Log.d(LOG_TAG, "getFactory");
|
||||||
final String clsName = context.getString(R.string.config_featureFactory);
|
final String clsName = context.getString(R.string.config_featureFactory);
|
||||||
@@ -76,6 +82,16 @@ public abstract class FeatureFactory {
|
|||||||
return sFactory;
|
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 AssistGestureFeatureProvider getAssistGestureFeatureProvider();
|
||||||
|
|
||||||
public abstract SuggestionFeatureProvider getSuggestionFeatureProvider(Context context);
|
public abstract SuggestionFeatureProvider getSuggestionFeatureProvider(Context context);
|
||||||
|
Reference in New Issue
Block a user