[Dagger] Make SettingsCache provided by DaggerSingletonObject
Test: presubmit Bug: 361850561 Flag: NONE - dagger Change-Id: Id709a6e1d14446b8361cf292d5f5422f2ea3524c
This commit is contained in:
@@ -25,14 +25,21 @@ import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.launcher3.dagger.ApplicationContext;
|
||||
import com.android.launcher3.dagger.LauncherAppSingleton;
|
||||
import com.android.launcher3.dagger.LauncherBaseAppComponent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* ContentObserver over Settings keys that also has a caching layer.
|
||||
* Consumers can register for callbacks via {@link #register(Uri, OnChangeListener)} and
|
||||
@@ -47,6 +54,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
*
|
||||
* Cache will also be updated if a key queried is missing (even if it has no listeners registered).
|
||||
*/
|
||||
@LauncherAppSingleton
|
||||
public class SettingsCache extends ContentObserver implements SafeCloseable {
|
||||
|
||||
/** Hidden field Settings.Secure.NOTIFICATION_BADGING */
|
||||
@@ -79,12 +87,14 @@ public class SettingsCache extends ContentObserver implements SafeCloseable {
|
||||
/**
|
||||
* Singleton instance
|
||||
*/
|
||||
public static MainThreadInitializedObject<SettingsCache> INSTANCE =
|
||||
new MainThreadInitializedObject<>(SettingsCache::new);
|
||||
public static final DaggerSingletonObject<SettingsCache> INSTANCE =
|
||||
new DaggerSingletonObject<>(LauncherBaseAppComponent::getSettingsCache);
|
||||
|
||||
private SettingsCache(Context context) {
|
||||
super(new Handler());
|
||||
@Inject
|
||||
SettingsCache(@ApplicationContext final Context context, DaggerSingletonTracker tracker) {
|
||||
super(new Handler(Looper.getMainLooper()));
|
||||
mResolver = context.getContentResolver();
|
||||
ExecutorUtil.executeSyncOnMainOrFail(() -> tracker.addCloseable(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user