Make DynamicResource as dagger singleton (15/n)
Bug: 361850561
Test: Manual
Flag: EXEMPT Dagger Integration
Change-Id: I8a3de783de34f79c8f8f64c5c964cc1636ace1a8
diff --git a/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java b/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java
index fb486f7..1e3df1e 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.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 @@
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 fbdb5c2..fe9fd7c 100644
--- a/src/com/android/launcher3/util/DynamicResource.java
+++ b/src/com/android/launcher3/util/DynamicResource.java
@@ -22,35 +22,39 @@
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<ResourceProvider>, SafeCloseable {
+ ResourceProvider, PluginListener<ResourceProvider> {
- private static final MainThreadInitializedObject<DynamicResource> INSTANCE =
- new MainThreadInitializedObject<>(DynamicResource::new);
+ private static final DaggerSingletonObject<DynamicResource> 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