Merge "Revert "Migrating RecentsAnimationDeviceState and dependent obje..."" into main

This commit is contained in:
Liana Kazanova (xWF)
2025-01-22 14:05:04 -08:00
committed by Android (Google) Code Review
18 changed files with 171 additions and 271 deletions
@@ -21,9 +21,7 @@ import dagger.Module;
@Module(includes = {
WindowManagerProxyModule.class,
ApiWrapperModule.class,
PluginManagerWrapperModule.class,
StaticObjectModule.class,
AppModule.class
PluginManagerWrapperModule.class
})
public class LauncherAppModule {
}
@@ -27,7 +27,6 @@ import com.android.launcher3.util.ApiWrapper;
import com.android.launcher3.util.DaggerSingletonTracker;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DynamicResource;
import com.android.launcher3.util.LockedUserState;
import com.android.launcher3.util.MSDLPlayerWrapper;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PluginManagerWrapper;
@@ -69,7 +68,6 @@ public interface LauncherBaseAppComponent {
ThemeManager getThemeManager();
DisplayController getDisplayController();
WallpaperColorHints getWallpaperColorHints();
LockedUserState getLockedUserState();
/** Builder for LauncherBaseAppComponent. */
interface Builder {
@@ -20,17 +20,10 @@ import android.content.Intent
import android.os.Process
import android.os.UserManager
import androidx.annotation.VisibleForTesting
import com.android.launcher3.dagger.ApplicationContext
import com.android.launcher3.dagger.LauncherAppComponent
import com.android.launcher3.dagger.LauncherAppSingleton
import com.android.launcher3.util.Executors.MAIN_EXECUTOR
import com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR
import javax.inject.Inject
@LauncherAppSingleton
class LockedUserState
@Inject
constructor(@ApplicationContext private val context: Context, lifeCycle: DaggerSingletonTracker) {
class LockedUserState(private val mContext: Context) : SafeCloseable {
val isUserUnlockedAtLauncherStartup: Boolean
var isUserUnlocked = false
private set(value) {
@@ -43,7 +36,7 @@ constructor(@ApplicationContext private val context: Context, lifeCycle: DaggerS
private val mUserUnlockedActions: RunnableList = RunnableList()
@VisibleForTesting
val userUnlockedReceiver =
val mUserUnlockedReceiver =
SimpleBroadcastReceiver(UI_HELPER_EXECUTOR) {
if (Intent.ACTION_USER_UNLOCKED == it.action) {
isUserUnlocked = true
@@ -60,8 +53,8 @@ constructor(@ApplicationContext private val context: Context, lifeCycle: DaggerS
isUserUnlocked = checkIsUserUnlocked()
isUserUnlockedAtLauncherStartup = isUserUnlocked
if (!isUserUnlocked) {
userUnlockedReceiver.register(
context,
mUserUnlockedReceiver.register(
mContext,
{
// If user is unlocked while registering broadcast receiver, we should update
// [isUserUnlocked], which will call [notifyUserUnlocked] in setter
@@ -69,18 +62,22 @@ constructor(@ApplicationContext private val context: Context, lifeCycle: DaggerS
MAIN_EXECUTOR.execute { isUserUnlocked = true }
}
},
Intent.ACTION_USER_UNLOCKED,
Intent.ACTION_USER_UNLOCKED
)
}
lifeCycle.addCloseable { userUnlockedReceiver.unregisterReceiverSafely(context) }
}
private fun checkIsUserUnlocked() =
context.getSystemService(UserManager::class.java)!!.isUserUnlocked(Process.myUserHandle())
mContext.getSystemService(UserManager::class.java)!!.isUserUnlocked(Process.myUserHandle())
private fun notifyUserUnlocked() {
mUserUnlockedActions.executeAllAndDestroy()
userUnlockedReceiver.unregisterReceiverSafely(context)
mUserUnlockedReceiver.unregisterReceiverSafely(mContext)
}
/** Stops the receiver from listening for ACTION_USER_UNLOCK broadcasts. */
override fun close() {
mUserUnlockedReceiver.unregisterReceiverSafely(mContext)
}
/**
@@ -91,7 +88,9 @@ constructor(@ApplicationContext private val context: Context, lifeCycle: DaggerS
mUserUnlockedActions.add(action)
}
/** Removes a previously queued `Runnable` to be run when the user is unlocked. */
/**
* Removes a previously queued `Runnable` to be run when the user is unlocked.
*/
fun removeOnUserUnlockedRunnable(action: Runnable) {
mUserUnlockedActions.remove(action)
}
@@ -99,7 +98,7 @@ constructor(@ApplicationContext private val context: Context, lifeCycle: DaggerS
companion object {
@VisibleForTesting
@JvmField
val INSTANCE = DaggerSingletonObject(LauncherAppComponent::getLockedUserState)
val INSTANCE = MainThreadInitializedObject { LockedUserState(it) }
@JvmStatic fun get(context: Context): LockedUserState = INSTANCE.get(context)
}
@@ -34,11 +34,11 @@ 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;
@@ -57,7 +57,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 =
@@ -79,17 +79,11 @@ 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;
/**
@@ -102,8 +96,12 @@ public class SettingsCache extends ContentObserver {
SettingsCache(@ApplicationContext Context context, DaggerSingletonTracker tracker) {
super(new Handler(Looper.getMainLooper()));
mResolver = context.getContentResolver();
tracker.addCloseable(() ->
UI_HELPER_EXECUTOR.execute(() -> mResolver.unregisterContentObserver(this)));
tracker.addCloseable(this);
}
@Override
public void close() {
UI_HELPER_EXECUTOR.execute(() -> mResolver.unregisterContentObserver(this));
}
@Override
@@ -111,12 +109,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);
}
}
@@ -141,17 +138,22 @@ public class SettingsCache extends ContentObserver {
}
}
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);
Preconditions.assertUIThread();
if (mListenerMap.containsKey(uri)) {
mListenerMap.get(uri).add(changeListener);
} else {
CopyOnWriteArrayList<OnChangeListener> l = new CopyOnWriteArrayList<>();
l.add(changeListener);
mListenerMap.put(uri, l);
UI_HELPER_EXECUTOR.execute(
() -> mResolver.registerContentObserver(uri, false, this));
}
}
private boolean updateValue(Uri keyUri, int defaultValue) {