Moving DisplayController to dagger

Separating various overrides to individual modules so that they can be reused in tests

Removing ContextualEduStatsManager and directly using SysUiProxy as all the usescases
are only in quickstep/
This avoids additional Module definition and delegation

Bug: 361850561
Test: Presubmit
Flag: EXEMPT dagger
Change-Id: I096459d638553991ed01766002b874589c6b976e
This commit is contained in:
Sunny Goyal committed 2025-01-14 11:40:35 -08:00
1 parent 8fa43b3bb1
commit 55dc2d1c31
27 files changed
+271 -280

No files matched your search

@@ -53,6 +53,9 @@ import com.android.launcher3.InvariantDeviceProfile.DeviceType;
import com.android.launcher3.LauncherPrefChangeListener;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.Utilities;
import com.android.launcher3.dagger.ApplicationContext;
import com.android.launcher3.dagger.LauncherAppComponent;
import com.android.launcher3.dagger.LauncherAppSingleton;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.util.window.CachedDisplayInfo;
import com.android.launcher3.util.window.WindowManagerProxy;
@@ -67,11 +70,14 @@ import java.util.Objects;
import java.util.Set;
import java.util.StringJoiner;
import javax.inject.Inject;
/**
* Utility class to cache properties of default display to avoid a system RPC on every call.
*/
@SuppressLint("NewApi")
public class DisplayController implements ComponentCallbacks, SafeCloseable,
@LauncherAppSingleton
public class DisplayController implements ComponentCallbacks,
DesktopVisibilityListener {
private static final String TAG = "DisplayController";
@@ -82,8 +88,8 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable,
// TODO(b/254119092) remove all logs with this tag
public static final String TASKBAR_NOT_DESTROYED_TAG = "b/254119092";
public static final MainThreadInitializedObject<DisplayController> INSTANCE =
new MainThreadInitializedObject<>(DisplayController::new);
public static final DaggerSingletonObject<DisplayController> INSTANCE =
new DaggerSingletonObject<>(LauncherAppComponent::getDisplayController);
public static final int CHANGE_ACTIVE_SCREEN = 1 << 0;
public static final int CHANGE_ROTATION = 1 << 1;
@@ -101,6 +107,7 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable,
private static final String TARGET_OVERLAY_PACKAGE = "android";
private final Context mContext;
private final WindowManagerProxy mWMProxy;
// Null for SDK < S
private final Context mWindowContext;
@@ -117,13 +124,31 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable,
private Info mInfo;
private boolean mDestroyed = false;
private LauncherPrefChangeListener mTaskbarPinningPreferenceChangeListener;
@VisibleForTesting
protected DisplayController(Context context) {
@Inject
protected DisplayController(@ApplicationContext Context context,
WindowManagerProxy wmProxy,
LauncherPrefs prefs,
DaggerSingletonTracker lifecycle) {
mContext = context;
mWMProxy = wmProxy;
if (enableTaskbarPinning()) {
attachTaskbarPinningSharedPreferenceChangeListener(mContext);
LauncherPrefChangeListener prefListener = key -> {
boolean isTaskbarPinningChanged = TASKBAR_PINNING_KEY.equals(key)
&& mInfo.mIsTaskbarPinned != prefs.get(TASKBAR_PINNING);
boolean isTaskbarPinningDesktopModeChanged =
TASKBAR_PINNING_DESKTOP_MODE_KEY.equals(key)
&& mInfo.mIsTaskbarPinnedInDesktopMode != prefs.get(
TASKBAR_PINNING_IN_DESKTOP_MODE);
if (isTaskbarPinningChanged || isTaskbarPinningDesktopModeChanged) {
notifyConfigChange();
}
};
prefs.addListener(prefListener, TASKBAR_PINNING);
prefs.addListener(prefListener, TASKBAR_PINNING_IN_DESKTOP_MODE);
lifecycle.addCloseable(() -> prefs.removeListener(
prefListener, TASKBAR_PINNING, TASKBAR_PINNING_IN_DESKTOP_MODE));
}
Display display = context.getSystemService(DisplayManager.class)
@@ -134,31 +159,17 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable,
// Initialize navigation mode change listener
mReceiver.registerPkgActions(mContext, TARGET_OVERLAY_PACKAGE, ACTION_OVERLAY_CHANGED);
WindowManagerProxy wmProxy = WindowManagerProxy.INSTANCE.get(context);
mInfo = new Info(mWindowContext, wmProxy,
wmProxy.estimateInternalDisplayBounds(mWindowContext));
wmProxy.registerDesktopVisibilityListener(this);
FileLog.i(TAG, "(CTOR) perDisplayBounds: " + mInfo.mPerDisplayBounds);
}
private void attachTaskbarPinningSharedPreferenceChangeListener(Context context) {
mTaskbarPinningPreferenceChangeListener = key -> {
LauncherPrefs prefs = LauncherPrefs.get(mContext);
boolean isTaskbarPinningChanged = TASKBAR_PINNING_KEY.equals(key)
&& mInfo.mIsTaskbarPinned != prefs.get(TASKBAR_PINNING);
boolean isTaskbarPinningDesktopModeChanged =
TASKBAR_PINNING_DESKTOP_MODE_KEY.equals(key)
&& mInfo.mIsTaskbarPinnedInDesktopMode != prefs.get(
TASKBAR_PINNING_IN_DESKTOP_MODE);
if (isTaskbarPinningChanged || isTaskbarPinningDesktopModeChanged) {
notifyConfigChange();
}
};
LauncherPrefs.get(context).addListener(
mTaskbarPinningPreferenceChangeListener, TASKBAR_PINNING);
LauncherPrefs.get(context).addListener(
mTaskbarPinningPreferenceChangeListener, TASKBAR_PINNING_IN_DESKTOP_MODE);
lifecycle.addCloseable(() -> {
mDestroyed = true;
mWindowContext.unregisterComponentCallbacks(this);
mReceiver.unregisterReceiverSafely(mContext);
wmProxy.unregisterDesktopVisibilityListener(this);
});
}
/**
@@ -207,20 +218,6 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable,
return INSTANCE.get(context).getInfo().showLockedTaskbarOnHome();
}
@Override
public void close() {
mDestroyed = true;
if (enableTaskbarPinning()) {
LauncherPrefs.get(mContext).removeListener(
mTaskbarPinningPreferenceChangeListener, TASKBAR_PINNING);
LauncherPrefs.get(mContext).removeListener(
mTaskbarPinningPreferenceChangeListener, TASKBAR_PINNING_IN_DESKTOP_MODE);
}
mWindowContext.unregisterComponentCallbacks(this);
mReceiver.unregisterReceiverSafely(mContext);
WindowManagerProxy.INSTANCE.get(mContext).unregisterDesktopVisibilityListener(this);
}
@Override
public void onDesktopVisibilityChanged(boolean visible) {
notifyConfigChange();
@@ -259,7 +256,7 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable,
|| !mInfo.mScreenSizeDp.equals(
new PortraitSize(config.screenHeightDp, config.screenWidthDp))
|| mWindowContext.getDisplay().getRotation() != mInfo.rotation
|| WindowManagerProxy.INSTANCE.get(mContext).showLockedTaskbarOnHome(mWindowContext)
|| mWMProxy.showLockedTaskbarOnHome(mWindowContext)
!= mInfo.showLockedTaskbarOnHome()) {
notifyConfigChange();
}
@@ -286,17 +283,16 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable,
@AnyThread
public void notifyConfigChange() {
WindowManagerProxy wmProxy = WindowManagerProxy.INSTANCE.get(mContext);
Info oldInfo = mInfo;
Context displayInfoContext = mWindowContext;
Info newInfo = new Info(displayInfoContext, wmProxy, oldInfo.mPerDisplayBounds);
Info newInfo = new Info(displayInfoContext, mWMProxy, oldInfo.mPerDisplayBounds);
if (newInfo.densityDpi != oldInfo.densityDpi || newInfo.fontScale != oldInfo.fontScale
|| newInfo.getNavigationMode() != oldInfo.getNavigationMode()) {
// Cache may not be valid anymore, recreate without cache
newInfo = new Info(displayInfoContext, wmProxy,
wmProxy.estimateInternalDisplayBounds(displayInfoContext));
newInfo = new Info(displayInfoContext, mWMProxy,
mWMProxy.estimateInternalDisplayBounds(displayInfoContext));
}
int change = 0;