diff --git a/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java b/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java index fb486f7c43..1e3df1e0fb 100644 --- a/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java +++ b/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java @@ -24,6 +24,7 @@ import com.android.launcher3.model.ItemInstallQueue; import com.android.launcher3.pm.InstallSessionHelper; import com.android.launcher3.util.ApiWrapper; import com.android.launcher3.util.DaggerSingletonTracker; +import com.android.launcher3.util.DynamicResource; import com.android.launcher3.util.MSDLPlayerWrapper; import com.android.launcher3.util.PackageManagerHelper; import com.android.launcher3.util.PluginManagerWrapper; @@ -48,6 +49,7 @@ public interface LauncherBaseAppComponent { ApiWrapper getApiWrapper(); ContextualEduStatsManager getContextualEduStatsManager(); CustomWidgetManager getCustomWidgetManager(); + DynamicResource getDynamicResource(); IconShape getIconShape(); InstallSessionHelper getInstallSessionHelper(); ItemInstallQueue getItemInstallQueue(); diff --git a/src/com/android/launcher3/util/DynamicResource.java b/src/com/android/launcher3/util/DynamicResource.java index fbdb5c2aa8..fe9fd7c566 100644 --- a/src/com/android/launcher3/util/DynamicResource.java +++ b/src/com/android/launcher3/util/DynamicResource.java @@ -22,35 +22,39 @@ import androidx.annotation.DimenRes; import androidx.annotation.FractionRes; import androidx.annotation.IntegerRes; +import com.android.launcher3.dagger.ApplicationContext; +import com.android.launcher3.dagger.LauncherAppSingleton; +import com.android.launcher3.dagger.LauncherBaseAppComponent; import com.android.systemui.plugins.PluginListener; import com.android.systemui.plugins.ResourceProvider; +import javax.inject.Inject; + /** * Utility class to support customizing resource values using plugins * * To load resources, call - * DynamicResource.provider(context).getInt(resId) or any other supported methods + * DynamicResource.provider(context).getInt(resId) or any other supported methods * * To allow customization for a particular resource, add them to dynamic_resources.xml */ +@LauncherAppSingleton public class DynamicResource implements - ResourceProvider, PluginListener, SafeCloseable { + ResourceProvider, PluginListener { - private static final MainThreadInitializedObject INSTANCE = - new MainThreadInitializedObject<>(DynamicResource::new); + private static final DaggerSingletonObject INSTANCE = + new DaggerSingletonObject<>(LauncherBaseAppComponent::getDynamicResource); private final Context mContext; private ResourceProvider mPlugin; - private DynamicResource(Context context) { + @Inject + public DynamicResource(@ApplicationContext Context context, + PluginManagerWrapper pluginManagerWrapper, DaggerSingletonTracker tracker) { mContext = context; - PluginManagerWrapper.INSTANCE.get(context).addPluginListener(this, + pluginManagerWrapper.addPluginListener(this, ResourceProvider.class, false /* allowedMultiple */); - } - - @Override - public void close() { - PluginManagerWrapper.INSTANCE.get(mContext).removePluginListener(this); + tracker.addCloseable(() -> pluginManagerWrapper.removePluginListener(this)); } @Override