feat: Add option to clear home screen in settings (#6125)

Signed-off-by: abhixv <abhi.sharma1@hotmail.com>
This commit is contained in:
Abhishek Sharma
2025-12-20 03:26:30 +05:30
committed by Pun Butrach
parent 9898749619
commit 5f3a03f4fb
1577 changed files with 112563 additions and 80248 deletions
@@ -18,30 +18,18 @@ package com.android.launcher3.util;
import static android.provider.Settings.System.ACCELEROMETER_ROTATION;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import android.content.ContentResolver;
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 android.util.Log;
import androidx.annotation.UiThread;
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 java.util.function.Function;
import javax.inject.Inject;
/**
* ContentObserver over Settings keys that also has a caching layer.
@@ -57,8 +45,7 @@ import javax.inject.Inject;
*
* Cache will also be updated if a key queried is missing (even if it has no listeners registered).
*/
@LauncherAppSingleton
public class SettingsCache extends ContentObserver {
public class SettingsCache extends ContentObserver implements SafeCloseable {
/** Hidden field Settings.Secure.NOTIFICATION_BADGING */
public static final Uri NOTIFICATION_BADGING_URI =
@@ -80,31 +67,27 @@ public class SettingsCache extends ContentObserver {
private static final String SYSTEM_URI_PREFIX = Settings.System.CONTENT_URI.toString();
private static final String GLOBAL_URI_PREFIX = Settings.Global.CONTENT_URI.toString();
private final Function<Uri, CopyOnWriteArrayList<OnChangeListener>> mListenerMapper = uri -> {
registerUriAsync(uri);
return new CopyOnWriteArrayList<>();
};
/**
* Caches the last seen value for registered keys.
*/
private final Map<Uri, Boolean> mKeyCache = new ConcurrentHashMap<>();
private final Map<Uri, CopyOnWriteArrayList<OnChangeListener>> mListenerMap =
new ConcurrentHashMap<>();
private Map<Uri, Boolean> mKeyCache = new ConcurrentHashMap<>();
private final Map<Uri, CopyOnWriteArrayList<OnChangeListener>> mListenerMap = new HashMap<>();
protected final ContentResolver mResolver;
/**
* Singleton instance
*/
public static final DaggerSingletonObject<SettingsCache> INSTANCE =
new DaggerSingletonObject<>(LauncherBaseAppComponent::getSettingsCache);
public static MainThreadInitializedObject<SettingsCache> INSTANCE =
new MainThreadInitializedObject<>(SettingsCache::new);
@Inject
SettingsCache(@ApplicationContext Context context, DaggerSingletonTracker tracker) {
super(new Handler(Looper.getMainLooper()));
private SettingsCache(Context context) {
super(new Handler());
mResolver = context.getContentResolver();
tracker.addCloseable(() ->
UI_HELPER_EXECUTOR.execute(() -> mResolver.unregisterContentObserver(this)));
}
@Override
public void close() {
mResolver.unregisterContentObserver(this);
}
@Override
@@ -112,12 +95,11 @@ public class SettingsCache extends ContentObserver {
// We use default of 1, but if we're getting an onChange call, can assume a non-default
// value will exist
boolean newVal = updateValue(uri, 1 /* Effectively Unused */);
List<OnChangeListener> listeners = mListenerMap.get(uri);
if (listeners == null) {
if (!mListenerMap.containsKey(uri)) {
return;
}
for (OnChangeListener listener : listeners) {
for (OnChangeListener listener : mListenerMap.get(uri)) {
listener.onSettingsChanged(newVal);
}
}
@@ -138,26 +120,23 @@ public class SettingsCache extends ContentObserver {
if (mKeyCache.containsKey(keySetting)) {
return mKeyCache.get(keySetting);
} else {
try {
return updateValue(keySetting, defaultValue);
} catch (SecurityException e) {
Log.d("LC_SettingsCache", "Key not readable, assume false for " + keySetting.toString());
return false;
}
return updateValue(keySetting, defaultValue);
}
}
private void registerUriAsync(Uri uri) {
UI_HELPER_EXECUTOR.execute(() -> mResolver.registerContentObserver(uri, false, this));
}
/**
* Does not de-dupe if you add same listeners for the same key multiple times.
* Unregister once complete using {@link #unregister(Uri, OnChangeListener)}
*/
@UiThread
public void register(Uri uri, OnChangeListener changeListener) {
mListenerMap.computeIfAbsent(uri, mListenerMapper).add(changeListener);
if (mListenerMap.containsKey(uri)) {
mListenerMap.get(uri).add(changeListener);
} else {
CopyOnWriteArrayList<OnChangeListener> l = new CopyOnWriteArrayList<>();
l.add(changeListener);
mListenerMap.put(uri, l);
mResolver.registerContentObserver(uri, false, this);
}
}
private boolean updateValue(Uri keyUri, int defaultValue) {