Make DynamicResource as dagger singleton (15/n)

Bug: 361850561
Test: Manual
Flag: EXEMPT Dagger Integration
Change-Id: I8a3de783de34f79c8f8f64c5c964cc1636ace1a8
This commit is contained in:
Anushree Ganjam
2024-12-03 12:01:45 -08:00
parent 040aad2cb2
commit b60be0896d
2 changed files with 17 additions and 11 deletions
@@ -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();
@@ -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<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