Merge changes from topic "implementWorkSchedulerViewAndUpdateColorsOfFab" into main
* changes:
Make sure work button is collapsed when keyboard is up upon going to app drawer
Implement the work scheduler view and update colors of FAB
diff --git a/aconfig/launcher.aconfig b/aconfig/launcher.aconfig
index 5373147..5101851 100644
--- a/aconfig/launcher.aconfig
+++ b/aconfig/launcher.aconfig
@@ -501,8 +501,15 @@
}
flag {
- name: "enable_launcher_pill"
+ name: "enable_contrast_tiles"
namespace: "launcher"
- description: "Enable Workspace Launcher Pill in Simple Mode View."
+ description: "Enable launcher app contrast tiles."
bug: "341217082"
+}
+
+flag {
+ name: "msdl_feedback"
+ namespace: "launcher"
+ description: "Enable MSDL feedback for Launcher interactions"
+ bug: "377496684"
}
\ No newline at end of file
diff --git a/quickstep/res/layout/task_desktop.xml b/quickstep/res/layout/task_desktop.xml
index 1564653..0472007 100644
--- a/quickstep/res/layout/task_desktop.xml
+++ b/quickstep/res/layout/task_desktop.xml
@@ -19,16 +19,11 @@
android:id="@+id/task_view_desktop"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:clipChildren="true"
- android:clipToPadding="true"
android:contentDescription="@string/recent_task_desktop"
android:defaultFocusHighlightEnabled="false"
android:focusable="true"
- android:padding="0.1dp"
launcher:focusBorderColor="?attr/materialColorOutline"
launcher:hoverBorderColor="?attr/materialColorPrimary">
- <!-- Setting a padding of 0.1 dp since android:clipToPadding needs a non-zero value for
- padding to work-->
<View
android:id="@+id/background"
android:layout_width="match_parent"
@@ -40,4 +35,9 @@
android:layout_height="wrap_content"
android:inflatedId="@id/icon" />
+ <com.android.quickstep.views.DesktopTaskContentView
+ android:id="@+id/desktop_content"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+
</com.android.quickstep.views.DesktopTaskView>
diff --git a/quickstep/res/values/config.xml b/quickstep/res/values/config.xml
index 3ae2b89..5c80575 100644
--- a/quickstep/res/values/config.xml
+++ b/quickstep/res/values/config.xml
@@ -34,7 +34,6 @@
<string name="taskbar_view_callbacks_factory_class" translatable="false">com.android.launcher3.taskbar.TaskbarViewCallbacksFactory</string>
<string name="launcher_restore_event_logger_class" translatable="false">com.android.quickstep.LauncherRestoreEventLoggerImpl</string>
<string name="taskbar_edu_tooltip_controller_class" translatable="false">com.android.launcher3.taskbar.TaskbarEduTooltipController</string>
- <string name="contextual_edu_manager_class" translatable="false">com.android.quickstep.contextualeducation.SystemContextualEduStatsManager</string>
<string name="nav_handle_long_press_handler_class" translatable="false"></string>
<string name="contextual_search_invoker_class" translatable="false"></string>
<string name="contextual_search_state_manager_class" translatable="false"></string>
diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml
index 451ba55..782a705 100644
--- a/quickstep/res/values/dimens.xml
+++ b/quickstep/res/values/dimens.xml
@@ -111,6 +111,7 @@
<dimen name="motion_pause_detector_speed_very_slow">0.0285dp</dimen>
<dimen name="motion_pause_detector_speed_slow">0.15dp</dimen>
<dimen name="motion_pause_detector_speed_somewhat_fast">0.285dp</dimen>
+ <dimen name="motion_pause_detector_speed_trackpad_somewhat_fast">0.7dp</dimen>
<dimen name="motion_pause_detector_speed_fast">1.4dp</dimen>
<dimen name="motion_pause_detector_min_displacement_from_app">36dp</dimen>
<dimen name="quickstep_fling_threshold_speed">0.5dp</dimen>
diff --git a/quickstep/src/com/android/launcher3/WidgetPickerActivity.java b/quickstep/src/com/android/launcher3/WidgetPickerActivity.java
index 955388d..bd2c7cc 100644
--- a/quickstep/src/com/android/launcher3/WidgetPickerActivity.java
+++ b/quickstep/src/com/android/launcher3/WidgetPickerActivity.java
@@ -23,6 +23,8 @@
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
+import static java.util.Collections.emptyList;
+
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ClipData;
@@ -44,6 +46,7 @@
import com.android.launcher3.model.StringCache;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.model.WidgetPredictionsRequester;
+import com.android.launcher3.model.WidgetsFilterDataProvider;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.PackageItemInfo;
@@ -112,6 +115,7 @@
private WidgetPredictionsRequester mWidgetPredictionsRequester;
private final WidgetPickerDataProvider mWidgetPickerDataProvider =
new WidgetPickerDataProvider();
+ private WidgetsFilterDataProvider mWidgetsFilterDataProvider;
private int mDesiredWidgetWidth;
private int mDesiredWidgetHeight;
@@ -133,13 +137,13 @@
@Nullable
private WidgetsFullSheet mWidgetSheet;
- private final Predicate<WidgetItem> mWidgetsFilter = widget -> {
+ private final Predicate<WidgetItem> mNoShortcutsFilter = widget -> {
final WidgetAcceptabilityVerdict verdict =
isWidgetAcceptable(widget, /* applySizeFilter=*/ false);
verdict.maybeLogVerdict();
return verdict.isAcceptable;
};
- private final Predicate<WidgetItem> mDefaultWidgetsFilter = widget -> {
+ private final Predicate<WidgetItem> mHostSizeAndNoShortcutsFilter = widget -> {
final WidgetAcceptabilityVerdict verdict =
isWidgetAcceptable(widget, /* applySizeFilter=*/ true);
verdict.maybeLogVerdict();
@@ -157,6 +161,7 @@
InvariantDeviceProfile idp = mApp.getInvariantDeviceProfile();
mDeviceProfile = idp.getDeviceProfile(this);
mModel = new WidgetsModel();
+ mWidgetsFilterDataProvider = WidgetsFilterDataProvider.Companion.newInstance(this);
setContentView(R.layout.widget_picker_activity);
mDragLayer = findViewById(R.id.drag_layer);
@@ -288,13 +293,16 @@
private void refreshAndBindWidgets() {
MODEL_EXECUTOR.execute(() -> {
LauncherAppState app = LauncherAppState.getInstance(this);
+ // Don't have to setup filters - its setup when launcher loads
+ // Just refresh filters with available cached info.
+ mModel.updateWidgetFilters(mWidgetsFilterDataProvider);
mModel.update(app, null);
StringCache stringCache = new StringCache();
stringCache.loadStrings(this);
bindStringCache(stringCache);
- bindWidgets(mModel.getWidgetsByPackageItem());
+ bindWidgets(mModel.getWidgetsByPackageItem(), mModel.getDefaultWidgetsFilter());
// Open sheet once widgets are available, so that it doesn't interrupt the open
// animation.
openWidgetsSheet();
@@ -310,14 +318,23 @@
MAIN_EXECUTOR.execute(() -> mStringCache = stringCache);
}
- private void bindWidgets(Map<PackageItemInfo, List<WidgetItem>> widgets) {
+ private void bindWidgets(Map<PackageItemInfo, List<WidgetItem>> widgets,
+ @Nullable Predicate<WidgetItem> defaultWidgetsFilter) {
WidgetsListBaseEntriesBuilder builder = new WidgetsListBaseEntriesBuilder(
mApp.getContext());
- final List<WidgetsListBaseEntry> allWidgets = builder.build(widgets, mWidgetsFilter);
- final List<WidgetsListBaseEntry> defaultWidgets =
- shouldShowDefaultWidgets() ? builder.build(widgets,
- mDefaultWidgetsFilter) : List.of();
+ final List<WidgetsListBaseEntry> allWidgets = builder.build(widgets, mNoShortcutsFilter);
+
+ // Default list is shown if either defaultWidgetsFilter exists or host has additionally
+ // enforced size filtering.
+ @Nullable Predicate<WidgetItem> defaultListFilter =
+ hasHostSizeFilters() ? mHostSizeAndNoShortcutsFilter : null;
+ if (defaultWidgetsFilter != null) {
+ defaultListFilter = defaultListFilter != null ? defaultListFilter.and(
+ defaultWidgetsFilter) : defaultWidgetsFilter;
+ }
+ final List<WidgetsListBaseEntry> defaultWidgets = defaultListFilter != null ? builder.build(
+ widgets, defaultListFilter) : emptyList();
MAIN_EXECUTOR.execute(
() -> mWidgetPickerDataProvider.setWidgets(allWidgets, defaultWidgets));
@@ -342,6 +359,7 @@
@Override
protected void onDestroy() {
super.onDestroy();
+ MODEL_EXECUTOR.execute(() -> mWidgetsFilterDataProvider.destroy());
if (mWidgetPredictionsRequester != null) {
mWidgetPredictionsRequester.clear();
}
@@ -398,7 +416,7 @@
}
}
- private boolean shouldShowDefaultWidgets() {
+ private boolean hasHostSizeFilters() {
// If optional filters such as size filter are present, we display them as default widgets.
return mDesiredWidgetWidth != 0 || mDesiredWidgetHeight != 0;
}
diff --git a/quickstep/src/com/android/launcher3/desktop/DesktopAppLaunchTransition.kt b/quickstep/src/com/android/launcher3/desktop/DesktopAppLaunchTransition.kt
index dd2ff2d..6916a1d 100644
--- a/quickstep/src/com/android/launcher3/desktop/DesktopAppLaunchTransition.kt
+++ b/quickstep/src/com/android/launcher3/desktop/DesktopAppLaunchTransition.kt
@@ -32,6 +32,8 @@
import androidx.core.animation.addListener
import com.android.app.animation.Interpolators
import com.android.quickstep.RemoteRunnable
+import com.android.wm.shell.shared.animation.MinimizeAnimator
+import com.android.wm.shell.shared.animation.WindowAnimator
import java.util.concurrent.Executor
/**
@@ -77,7 +79,13 @@
val launchAnimator =
createLaunchAnimator(getLaunchChange(info), transaction, finishCallback)
val minimizeChange = getMinimizeChange(info) ?: return listOf(launchAnimator)
- val minimizeAnimator = createMinimizeAnimator(minimizeChange, transaction, finishCallback)
+ val minimizeAnimator =
+ MinimizeAnimator.create(
+ context.resources.displayMetrics,
+ minimizeChange,
+ transaction,
+ finishCallback,
+ )
return listOf(launchAnimator, minimizeAnimator)
}
@@ -96,7 +104,7 @@
): Animator {
val boundsAnimator =
WindowAnimator.createBoundsAnimator(
- context,
+ context.resources.displayMetrics,
launchBoundsAnimationDef,
change,
transaction,
@@ -115,32 +123,6 @@
}
}
- private fun createMinimizeAnimator(
- change: Change,
- transaction: Transaction,
- onAnimFinish: (Animator) -> Unit,
- ): Animator {
- val boundsAnimator =
- WindowAnimator.createBoundsAnimator(
- context,
- minimizeBoundsAnimationDef,
- change,
- transaction,
- )
- val alphaAnimator =
- ValueAnimator.ofFloat(1f, 0f).apply {
- duration = MINIMIZE_ANIM_ALPHA_DURATION_MS
- interpolator = Interpolators.LINEAR
- addUpdateListener { animation ->
- transaction.setAlpha(change.leash, animation.animatedValue as Float).apply()
- }
- }
- return AnimatorSet().apply {
- playTogether(boundsAnimator, alphaAnimator)
- addListener(onEnd = { animation -> onAnimFinish(animation) })
- }
- }
-
companion object {
private val LAUNCH_CHANGE_MODES = intArrayOf(TRANSIT_OPEN, TRANSIT_TO_FRONT)
@@ -154,13 +136,5 @@
startScale = 0.97f,
interpolator = Interpolators.STANDARD_DECELERATE,
)
-
- private val minimizeBoundsAnimationDef =
- WindowAnimator.BoundsAnimationParams(
- durationMs = 200,
- endOffsetYDp = 12f,
- endScale = 0.97f,
- interpolator = Interpolators.STANDARD_ACCELERATE,
- )
}
}
diff --git a/quickstep/src/com/android/launcher3/desktop/WindowAnimator.kt b/quickstep/src/com/android/launcher3/desktop/WindowAnimator.kt
deleted file mode 100644
index 1a99a36..0000000
--- a/quickstep/src/com/android/launcher3/desktop/WindowAnimator.kt
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2024 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.desktop
-
-import android.animation.RectEvaluator
-import android.animation.ValueAnimator
-import android.content.Context
-import android.graphics.Rect
-import android.util.TypedValue
-import android.view.SurfaceControl
-import android.view.animation.Interpolator
-import android.window.TransitionInfo
-
-/** Creates animations that can be applied to windows/surfaces. */
-object WindowAnimator {
-
- /** Parameters defining a window bounds animation. */
- data class BoundsAnimationParams(
- val durationMs: Long,
- val startOffsetYDp: Float = 0f,
- val endOffsetYDp: Float = 0f,
- val startScale: Float = 1f,
- val endScale: Float = 1f,
- val interpolator: Interpolator,
- )
-
- /**
- * Creates an animator to reposition and scale the bounds of the leash of the given change.
- *
- * @param boundsAnimDef the parameters for the animation itself (duration, scale, position)
- * @param change the change to which the animation should be applied
- * @param transaction the transaction to apply the animation to
- */
- fun createBoundsAnimator(
- context: Context,
- boundsAnimDef: BoundsAnimationParams,
- change: TransitionInfo.Change,
- transaction: SurfaceControl.Transaction,
- ): ValueAnimator {
- val startBounds =
- createBounds(
- context,
- change.startAbsBounds,
- boundsAnimDef.startScale,
- boundsAnimDef.startOffsetYDp,
- )
- val leash = change.leash
- val endBounds =
- createBounds(
- context,
- change.startAbsBounds,
- boundsAnimDef.endScale,
- boundsAnimDef.endOffsetYDp,
- )
- return ValueAnimator.ofObject(RectEvaluator(), startBounds, endBounds).apply {
- duration = boundsAnimDef.durationMs
- interpolator = boundsAnimDef.interpolator
- addUpdateListener { animation ->
- val animBounds = animation.animatedValue as Rect
- val animScale = 1 - (1 - boundsAnimDef.endScale) * animation.animatedFraction
- transaction
- .setPosition(leash, animBounds.left.toFloat(), animBounds.top.toFloat())
- .setScale(leash, animScale, animScale)
- .apply()
- }
- }
- }
-
- private fun createBounds(context: Context, origBounds: Rect, scale: Float, offsetYDp: Float) =
- Rect(origBounds).apply {
- check(scale in 0.0..1.0)
- // Scale the bounds down with an anchor in the center
- inset(
- (origBounds.width().toFloat() * (1 - scale) / 2).toInt(),
- (origBounds.height().toFloat() * (1 - scale) / 2).toInt(),
- )
- val offsetYPx =
- TypedValue.applyDimension(
- TypedValue.COMPLEX_UNIT_DIP,
- offsetYDp,
- context.resources.displayMetrics,
- )
- .toInt()
- offset(/* dx= */ 0, offsetYPx)
- }
-}
diff --git a/quickstep/src/com/android/launcher3/taskbar/FallbackTaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/FallbackTaskbarUIController.java
index 929e793..6a908ca 100644
--- a/quickstep/src/com/android/launcher3/taskbar/FallbackTaskbarUIController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/FallbackTaskbarUIController.java
@@ -25,20 +25,24 @@
import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.statemanager.StateManager;
-import com.android.quickstep.RecentsActivity;
+import com.android.launcher3.statemanager.StatefulContainer;
import com.android.quickstep.TopTaskTracker;
import com.android.quickstep.fallback.RecentsState;
import com.android.quickstep.util.TISBindHelper;
import com.android.quickstep.views.RecentsView;
+import com.android.quickstep.views.RecentsViewContainer;
import java.util.stream.Stream;
/**
* A data source which integrates with the fallback RecentsActivity instance (for 3P launchers).
+ * @param <T> The type of the RecentsViewContainer that will handle Recents state changes.
*/
-public class FallbackTaskbarUIController extends TaskbarUIController {
+public class FallbackTaskbarUIController
+ <T extends RecentsViewContainer & StatefulContainer<RecentsState>>
+ extends TaskbarUIController {
- private final RecentsActivity mRecentsActivity;
+ private final T mRecentsContainer;
private final StateManager.StateListener<RecentsState> mStateListener =
new StateManager.StateListener<RecentsState>() {
@@ -46,8 +50,12 @@
public void onStateTransitionStart(RecentsState toState) {
animateToRecentsState(toState);
+ RecentsView recentsView = getRecentsView();
+ if (recentsView == null) {
+ return;
+ }
// Handle tapping on live tile.
- getRecentsView().setTaskLaunchListener(toState == RecentsState.DEFAULT
+ recentsView.setTaskLaunchListener(toState == RecentsState.DEFAULT
? (() -> animateToRecentsState(RecentsState.BACKGROUND_APP)) : null);
}
@@ -63,23 +71,26 @@
}
};
- public FallbackTaskbarUIController(RecentsActivity recentsActivity) {
- mRecentsActivity = recentsActivity;
+ public FallbackTaskbarUIController(T recentsContainer) {
+ mRecentsContainer = recentsContainer;
}
@Override
protected void init(TaskbarControllers taskbarControllers) {
super.init(taskbarControllers);
- mRecentsActivity.setTaskbarUIController(this);
- mRecentsActivity.getStateManager().addStateListener(mStateListener);
+ mRecentsContainer.setTaskbarUIController(this);
+ mRecentsContainer.getStateManager().addStateListener(mStateListener);
}
@Override
protected void onDestroy() {
super.onDestroy();
- getRecentsView().setTaskLaunchListener(null);
- mRecentsActivity.setTaskbarUIController(null);
- mRecentsActivity.getStateManager().removeStateListener(mStateListener);
+ RecentsView recentsView = getRecentsView();
+ if (recentsView != null) {
+ recentsView.setTaskLaunchListener(null);
+ }
+ mRecentsContainer.setTaskbarUIController(null);
+ mRecentsContainer.getStateManager().removeStateListener(mStateListener);
}
/**
@@ -108,8 +119,8 @@
}
@Override
- public RecentsView getRecentsView() {
- return mRecentsActivity.getOverviewPanel();
+ public @Nullable RecentsView getRecentsView() {
+ return mRecentsContainer.getOverviewPanel();
}
@Override
@@ -131,11 +142,11 @@
@Nullable
@Override
protected TISBindHelper getTISBindHelper() {
- return mRecentsActivity.getTISBindHelper();
+ return mRecentsContainer.getTISBindHelper();
}
@Override
protected String getTaskbarUIControllerName() {
- return "FallbackTaskbarUIController";
+ return "FallbackTaskbarUIController<" + mRecentsContainer.getClass().getSimpleName() + ">";
}
}
diff --git a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java
index 3f71870..7a63f74 100644
--- a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java
@@ -31,12 +31,14 @@
import androidx.annotation.Nullable;
import com.android.internal.jank.Cuj;
+import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatorListeners;
import com.android.launcher3.desktop.DesktopAppLaunchTransition;
import com.android.launcher3.taskbar.overlay.TaskbarOverlayContext;
import com.android.launcher3.taskbar.overlay.TaskbarOverlayDragLayer;
+import com.android.launcher3.util.DisplayController;
import com.android.launcher3.views.BaseDragLayer;
import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.util.GroupTask;
@@ -101,7 +103,16 @@
boolean hasDesktopTask,
boolean wasDesktopTaskFilteredOut,
boolean wasOpenedFromTaskbar) {
- positionView(wasOpenedFromTaskbar);
+ final boolean isTransientTaskBar = DisplayController.isTransientTaskbar(
+ mControllers.taskbarActivityContext);
+ positionView(wasOpenedFromTaskbar, isTransientTaskBar);
+
+ // Keep the taskbar unstashed if the KQS is opened.
+ if (wasOpenedFromTaskbar && isTransientTaskBar) {
+ mControllers.taskbarStashController.updateTaskbarTimeout(/* isAutohideSuspended= */
+ true);
+ }
+
mOverlayContext.getDragLayer().addView(mKeyboardQuickSwitchView);
mOnDesktop = onDesktop;
mWasDesktopTaskFilteredOut = wasDesktopTaskFilteredOut;
@@ -117,7 +128,7 @@
/* useDesktopTaskView= */ !onDesktop && hasDesktopTask);
}
- protected void positionView(boolean wasOpenedFromTaskbar) {
+ protected void positionView(boolean wasOpenedFromTaskbar, boolean isTransientTaskbar) {
if (!wasOpenedFromTaskbar) {
// Keep the default positioning.
return;
@@ -128,8 +139,16 @@
final Resources resources = mKeyboardQuickSwitchView.getResources();
final int marginHorizontal = resources.getDimensionPixelSize(
R.dimen.keyboard_quick_switch_margin_ends);
- final int marginBottom = resources.getDimensionPixelSize(
+
+ final DeviceProfile dp = mControllers.taskbarActivityContext.getDeviceProfile();
+ // Calculate the additional margin space that the KQS should move up for the transient
+ // taskbar. The value of spaceForTaskbar is the distance between the bottom of the KQS
+ // view with 0 bottom margin to the top of the transient taskbar view.
+ final int spaceForTaskbar = isTransientTaskbar ? dp.taskbarHeight + dp.taskbarBottomMargin
+ - dp.stashedTaskbarHeight : 0;
+ final int marginBottom = spaceForTaskbar + resources.getDimensionPixelSize(
R.dimen.keyboard_quick_switch_margin_bottom);
+
lp.setMargins(marginHorizontal, 0, marginHorizontal, marginBottom);
lp.width = BaseDragLayer.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java
index 4a85acc..5a63ca6 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java
@@ -169,7 +169,7 @@
taskbarOverlayController.init(this);
taskbarAllAppsController.init(this, sharedState.allAppsVisible);
navButtonController.init(this);
- bubbleControllers.ifPresent(controllers -> controllers.init(this));
+ bubbleControllers.ifPresent(controllers -> controllers.init(sharedState, this));
taskbarInsetsController.init(this);
voiceInteractionWindowController.init(this);
taskbarRecentAppsController.init(this);
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt
index 325a0d3..a8ce10f 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt
@@ -21,7 +21,6 @@
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.Region
-import android.inputmethodservice.InputMethodService.ENABLE_HIDE_IME_CAPTION_BAR
import android.os.Binder
import android.os.IBinder
import android.view.DisplayInfo
@@ -259,7 +258,7 @@
// When in gesture nav, report the stashed height to the IME, to allow hiding the
// IME navigation bar.
val imeInsetsSize =
- if (ENABLE_HIDE_IME_CAPTION_BAR && context.isGestureNav) {
+ if (context.isGestureNav) {
getInsetsForGravity(controllers.taskbarStashController.stashedHeight, gravity)
} else {
getInsetsForGravity(taskbarHeightForIme, gravity)
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
index c18cf28..fa54f7c 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
@@ -71,7 +71,9 @@
import com.android.quickstep.AllAppsActionManager;
import com.android.quickstep.RecentsActivity;
import com.android.quickstep.SystemUiProxy;
+import com.android.quickstep.fallback.window.RecentsWindowManager;
import com.android.quickstep.util.ContextualSearchInvoker;
+import com.android.quickstep.views.RecentsViewContainer;
import com.android.systemui.shared.statusbar.phone.BarTransitions;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.shared.system.QuickStepContract.SystemUiStateFlags;
@@ -115,7 +117,6 @@
private WindowManager mWindowManager;
private FrameLayout mTaskbarRootLayout;
private boolean mAddedWindow;
- private boolean mIsSuspended;
private final TaskbarNavButtonController mNavButtonController;
private final ComponentCallbacks mComponentCallbacks;
@@ -131,6 +132,8 @@
private TaskbarActivityContext mTaskbarActivityContext;
private StatefulActivity mActivity;
+ private RecentsViewContainer mRecentsViewContainer;
+
/**
* Cache a copy here so we can initialize state whenever taskbar is recreated, since
* this class does not get re-initialized w/ new taskbars.
@@ -404,9 +407,28 @@
}
mUnfoldProgressProvider.setSourceProvider(unfoldTransitionProgressProvider);
+ if (activity instanceof RecentsViewContainer recentsViewContainer) {
+ setRecentsViewContainer(recentsViewContainer);
+ }
+ }
+
+ /**
+ * Sets the current RecentsViewContainer, from which we create a TaskbarUIController.
+ */
+ public void setRecentsViewContainer(@NonNull RecentsViewContainer recentsViewContainer) {
+ if (mRecentsViewContainer == recentsViewContainer) {
+ return;
+ }
+ if (mRecentsViewContainer == mActivity) {
+ // When switching to RecentsWindowManager (not an Activity), the old mActivity is not
+ // destroyed, nor is there a new Activity to replace it. Thus if we don't clear it here,
+ // it will not get re-set properly if we return to the Activity (e.g. NexusLauncher).
+ mActivityOnDestroyCallback.run();
+ }
+ mRecentsViewContainer = recentsViewContainer;
if (mTaskbarActivityContext != null) {
mTaskbarActivityContext.setUIController(
- createTaskbarUIControllerForActivity(mActivity));
+ createTaskbarUIControllerForRecentsViewContainer(mRecentsViewContainer));
}
}
@@ -429,12 +451,18 @@
/**
* Creates a {@link TaskbarUIController} to use while the given StatefulActivity is active.
*/
- private TaskbarUIController createTaskbarUIControllerForActivity(StatefulActivity activity) {
- if (activity instanceof QuickstepLauncher) {
- return new LauncherTaskbarUIController((QuickstepLauncher) activity);
+ private TaskbarUIController createTaskbarUIControllerForRecentsViewContainer(
+ RecentsViewContainer container) {
+ if (container instanceof QuickstepLauncher quickstepLauncher) {
+ return new LauncherTaskbarUIController(quickstepLauncher);
}
- if (activity instanceof RecentsActivity) {
- return new FallbackTaskbarUIController((RecentsActivity) activity);
+ // If a 3P Launcher is default, always use FallbackTaskbarUIController regardless of
+ // whether the recents container is RecentsActivity or RecentsWindowManager.
+ if (container instanceof RecentsActivity recentsActivity) {
+ return new FallbackTaskbarUIController<>(recentsActivity);
+ }
+ if (container instanceof RecentsWindowManager recentsWindowManager) {
+ return new FallbackTaskbarUIController<>(recentsWindowManager);
}
return TaskbarUIController.DEFAULT;
}
@@ -446,8 +474,6 @@
*/
@VisibleForTesting
public synchronized void recreateTaskbar() {
- if (mIsSuspended) return;
-
Trace.beginSection("recreateTaskbar");
try {
DeviceProfile dp = mUserUnlocked ?
@@ -484,9 +510,9 @@
mSharedState.allAppsVisible = mSharedState.allAppsVisible && isLargeScreenTaskbar;
mTaskbarActivityContext.init(mSharedState);
- if (mActivity != null) {
+ if (mRecentsViewContainer != null) {
mTaskbarActivityContext.setUIController(
- createTaskbarUIControllerForActivity(mActivity));
+ createTaskbarUIControllerForRecentsViewContainer(mRecentsViewContainer));
}
if (enableTaskbarNoRecreate()) {
@@ -534,25 +560,25 @@
}
}
- public void checkNavBarModes() {
+ public void checkNavBarModes(int displayId) {
if (mTaskbarActivityContext != null) {
mTaskbarActivityContext.checkNavBarModes();
}
}
- public void finishBarAnimations() {
+ public void finishBarAnimations(int displayId) {
if (mTaskbarActivityContext != null) {
mTaskbarActivityContext.finishBarAnimations();
}
}
- public void touchAutoDim(boolean reset) {
+ public void touchAutoDim(int displayId, boolean reset) {
if (mTaskbarActivityContext != null) {
mTaskbarActivityContext.touchAutoDim(reset);
}
}
- public void transitionTo(@BarTransitions.TransitionMode int barMode,
+ public void transitionTo(int displayId, @BarTransitions.TransitionMode int barMode,
boolean animate) {
if (mTaskbarActivityContext != null) {
mTaskbarActivityContext.transitionTo(barMode, animate);
@@ -663,16 +689,6 @@
}
}
- /**
- * Removes Taskbar from the window manager and prevents recreation if {@code true}.
- * <p>
- * Suspending is for testing purposes only; avoid calling this method in production.
- */
- @VisibleForTesting
- public void setSuspended(boolean isSuspended) {
- mIsSuspended = isSuspended;
- }
-
private void addTaskbarRootViewToWindow() {
if (enableTaskbarNoRecreate() && !mAddedWindow && mTaskbarActivityContext != null) {
mWindowManager.addView(mTaskbarRootLayout,
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarSharedState.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarSharedState.java
index 729cbe9..a64dab1 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarSharedState.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarSharedState.java
@@ -30,6 +30,10 @@
import android.view.InsetsFrameProvider;
import com.android.systemui.shared.system.QuickStepContract.SystemUiStateFlags;
+import com.android.wm.shell.shared.bubbles.BubbleBarLocation;
+import com.android.wm.shell.shared.bubbles.BubbleInfo;
+
+import java.util.List;
/**
* State shared across different taskbar instance
@@ -69,6 +73,15 @@
public boolean allAppsVisible = false;
+ public BubbleBarLocation bubbleBarLocation;
+
+ public List<BubbleInfo> bubbleInfoItems;
+
+ /** Returns whether there are a saved bubbles. */
+ public boolean hasSavedBubbles() {
+ return bubbleInfoItems != null && !bubbleInfoItems.isEmpty();
+ }
+
// LauncherTaskbarUIController#mTaskbarInAppDisplayProgressMultiProp
public float[] inAppDisplayProgressMultiPropValues = new float[DISPLAY_PROGRESS_COUNT];
diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java
index b22fd6f..30e4e47 100644
--- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java
@@ -35,6 +35,7 @@
import android.util.ArrayMap;
import android.util.Log;
+import com.android.launcher3.taskbar.TaskbarSharedState;
import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController;
import com.android.launcher3.util.Executors.SimpleThreadFactory;
import com.android.quickstep.SystemUiProxy;
@@ -47,6 +48,7 @@
import com.android.wm.shell.shared.bubbles.RemovedBubble;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -112,6 +114,7 @@
private BubbleBarItem mSelectedBubble;
+ private TaskbarSharedState mSharedState;
private ImeVisibilityChecker mImeVisibilityChecker;
private BubbleBarViewController mBubbleBarViewController;
private BubbleStashController mBubbleStashController;
@@ -173,12 +176,25 @@
public void onDestroy() {
mSystemUiProxy.setBubblesListener(null);
+ // Saves bubble bar state
+ BubbleInfo[] bubbleInfoItems = new BubbleInfo[mBubbles.size()];
+ mBubbles.values().forEach(bubbleBarBubble -> {
+ int index = mBubbleBarViewController.bubbleViewIndex(bubbleBarBubble.getView());
+ if (index < 0 || index >= bubbleInfoItems.length) {
+ Log.e(TAG, "Found improper index: " + index + " for " + bubbleBarBubble);
+ } else {
+ bubbleInfoItems[index] = bubbleBarBubble.getInfo();
+ }
+ });
+ mSharedState.bubbleInfoItems = Arrays.asList(bubbleInfoItems);
}
/** Initializes controllers. */
public void init(BubbleControllers bubbleControllers,
BubbleBarLocationListener bubbleBarLocationListener,
- ImeVisibilityChecker imeVisibilityChecker) {
+ ImeVisibilityChecker imeVisibilityChecker,
+ TaskbarSharedState sharedState) {
+ mSharedState = sharedState;
mImeVisibilityChecker = imeVisibilityChecker;
mBubbleBarViewController = bubbleControllers.bubbleBarViewController;
mBubbleStashController = bubbleControllers.bubbleStashController;
@@ -188,6 +204,7 @@
mBubbleBarLocationListener = bubbleBarLocationListener;
bubbleControllers.runAfterInit(() -> {
+ restoreSavedState(sharedState);
mBubbleBarViewController.setHiddenForBubbles(
!sBubbleBarEnabled || mBubbles.isEmpty());
mBubbleStashedHandleViewController.ifPresent(
@@ -266,6 +283,26 @@
}
}
+ private void restoreSavedState(TaskbarSharedState sharedState) {
+ if (sharedState.bubbleBarLocation != null) {
+ updateBubbleBarLocationInternal(sharedState.bubbleBarLocation);
+ }
+ List<BubbleInfo> bubbleInfos = sharedState.bubbleInfoItems;
+ if (bubbleInfos == null || bubbleInfos.isEmpty()) return;
+ // Iterate in reverse because new bubbles are added in front and the list is in order.
+ for (int i = bubbleInfos.size() - 1; i >= 0; i--) {
+ BubbleBarBubble bubble = mBubbleCreator.populateBubble(mContext,
+ bubbleInfos.get(i), mBarView, /* existingBubble = */ null);
+ if (bubble == null) {
+ Log.e(TAG, "Could not instantiate BubbleBarBubble for " + bubbleInfos.get(i));
+ continue;
+ }
+ addBubbleInternally(bubble, /* showAppBadge = */
+ mBubbleBarViewController.isExpanded() || i == 0,
+ /* isExpanding = */ false, /* suppressAnimation = */ true);
+ }
+ }
+
private void applyViewChanges(BubbleBarViewUpdate update) {
final boolean isCollapsed = (update.expandedChanged && !update.expanded)
|| (!update.expandedChanged && !mBubbleBarViewController.isExpanded());
@@ -277,6 +314,12 @@
update.initialState || mBubbleBarViewController.isHiddenForSysui()
|| mImeVisibilityChecker.isImeVisible();
+ if (update.initialState && mSharedState.hasSavedBubbles()) {
+ // clear restored state
+ mBubbleBarViewController.removeAllBubbles();
+ mBubbles.clear();
+ }
+
BubbleBarBubble bubbleToSelect = null;
if (Flags.enableOptionalBubbleOverflow()
@@ -347,8 +390,8 @@
for (int i = update.currentBubbles.size() - 1; i >= 0; i--) {
BubbleBarBubble bubble = update.currentBubbles.get(i);
if (bubble != null) {
- mBubbles.put(bubble.getKey(), bubble);
- mBubbleBarViewController.addBubble(bubble, isExpanding, suppressAnimation);
+ addBubbleInternally(bubble, /* showAppBadge = */ !isCollapsed || i == 0,
+ isExpanding, suppressAnimation);
if (isCollapsed) {
// If we're collapsed, the most recently added bubble will be selected.
bubbleToSelect = bubble;
@@ -420,6 +463,7 @@
}
}
if (update.bubbleBarLocation != null) {
+ mSharedState.bubbleBarLocation = update.bubbleBarLocation;
if (update.bubbleBarLocation != mBubbleBarViewController.getBubbleBarLocation()) {
updateBubbleBarLocationInternal(update.bubbleBarLocation);
}
@@ -519,6 +563,14 @@
}
}
+ private void addBubbleInternally(BubbleBarBubble bubble, boolean showAppBadge,
+ boolean isExpanding, boolean suppressAnimation) {
+ //TODO(b/360652359): remove setting scale to the app badge once issue is fixed
+ bubble.getView().setBadgeScale(showAppBadge ? 1 : 0);
+ mBubbles.put(bubble.getKey(), bubble);
+ mBubbleBarViewController.addBubble(bubble, isExpanding, suppressAnimation);
+ }
+
/** Interface for checking whether the IME is visible. */
public interface ImeVisibilityChecker {
/** Whether the IME is visible. */
diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java
index 31b1ea0..96fadf7 100644
--- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java
@@ -57,6 +57,7 @@
import com.android.launcher3.util.MultiPropertyFactory;
import com.android.launcher3.util.MultiValueAlpha;
import com.android.quickstep.SystemUiProxy;
+import com.android.wm.shell.Flags;
import com.android.wm.shell.shared.bubbles.BubbleBarLocation;
import java.io.PrintWriter;
@@ -177,6 +178,9 @@
mBubbleBarClickListener = v -> expandBubbleBar();
mBubbleDragController.setupBubbleBarView(mBarView);
mOverflowBubble = bubbleControllers.bubbleCreator.createOverflow(mBarView);
+ if (!Flags.enableOptionalBubbleOverflow()) {
+ showOverflow(true);
+ }
mBarView.setOnClickListener(mBubbleBarClickListener);
mBarView.addOnLayoutChangeListener(
(v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
@@ -324,6 +328,7 @@
}
private void onBubbleClicked(BubbleView bubbleView) {
+ if (mBubbleBarPinning.isAnimating()) return;
bubbleView.markSeen();
BubbleBarItem bubble = bubbleView.getBubble();
if (bubble == null) {
@@ -872,9 +877,14 @@
/** Animates the bubble bar to notify the user about a bubble change. */
public void animateBubbleNotification(BubbleBarBubble bubble, boolean isExpanding,
boolean isUpdate) {
- // if we're expanded, don't animate the bubble bar. just show the notification dot.
+ // if we're not already animating another bubble, update the dot visibility. otherwise the
+ // the dot will be handled as part of the animation.
+ if (!mBubbleBarViewAnimator.isAnimating()) {
+ bubble.getView().updateDotVisibility(
+ /* animate= */ !mBubbleStashController.isStashed());
+ }
+ // if we're expanded, don't animate the bubble bar.
if (isExpanded()) {
- bubble.getView().updateDotVisibility(/* animate= */ true);
return;
}
boolean isInApp = mTaskbarStashController.isInApp();
@@ -918,7 +928,7 @@
* from Launcher.
*/
public void setExpanded(boolean isExpanded) {
- if (isExpanded != mBarView.isExpanded()) {
+ if (!mBubbleBarPinning.isAnimating() && isExpanded != mBarView.isExpanded()) {
mBarView.setExpanded(isExpanded);
adjustTaskbarAndHotseatToBubbleBarState(isExpanded);
if (!isExpanded) {
@@ -1060,6 +1070,16 @@
mSystemUiProxy.removeAllBubbles();
}
+ /** Removes all existing bubble views */
+ public void removeAllBubbles() {
+ mBarView.removeAllViews();
+ }
+
+ /** Returns the view index of the existing bubble */
+ public int bubbleViewIndex(View bubbleView) {
+ return mBarView.indexOfChild(bubbleView);
+ }
+
/**
* Set listener to be notified when bubble bar bounds have changed
*/
diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java
index b5d94bd..d993685 100644
--- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java
+++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java
@@ -21,6 +21,7 @@
import android.view.View;
import com.android.launcher3.taskbar.TaskbarControllers;
+import com.android.launcher3.taskbar.TaskbarSharedState;
import com.android.launcher3.taskbar.bubbles.BubbleBarViewController.TaskbarViewPropertiesProvider;
import com.android.launcher3.taskbar.bubbles.stashing.BubbleBarLocationOnDemandListener;
import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController;
@@ -79,7 +80,7 @@
* BubbleControllers instance, but should be careful to only access things that were created
* in constructors for now, as some controllers may still be waiting for init().
*/
- public void init(TaskbarControllers taskbarControllers) {
+ public void init(TaskbarSharedState taskbarSharedState, TaskbarControllers taskbarControllers) {
BubbleBarLocationCompositeListener bubbleBarLocationListeners =
new BubbleBarLocationCompositeListener(
taskbarControllers.navbarButtonsViewController,
@@ -88,7 +89,8 @@
);
bubbleBarController.init(this,
bubbleBarLocationListeners,
- taskbarControllers.navbarButtonsViewController::isImeVisible);
+ taskbarControllers.navbarButtonsViewController::isImeVisible,
+ taskbarSharedState);
bubbleStashedHandleViewController.ifPresent(
controller -> controller.init(/* bubbleControllers = */ this));
bubbleStashController.init(
diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java
index 4f3e1ae..114edf4 100644
--- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java
+++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java
@@ -299,7 +299,8 @@
return mBubble;
}
- void updateDotVisibility(boolean animate) {
+ /** Updates the dot visibility if it's not suppressed based on whether it has unseen content. */
+ public void updateDotVisibility(boolean animate) {
if (mDotSuppressedForBubbleUpdate) {
// if the dot is suppressed for an update, there's nothing to do
return;
@@ -321,16 +322,12 @@
}
}
- /**
- * Suppresses or un-suppresses drawing the dot due to an update for this bubble.
- *
- * <p>If the dot is being suppressed and is already visible, it remains visible because it is
- * used as a starting point for the animation. If the dot is being unsuppressed, it is
- * redrawn if needed.
- */
+ /** Suppresses or un-suppresses drawing the dot due to an update for this bubble. */
public void suppressDotForBubbleUpdate(boolean suppress) {
mDotSuppressedForBubbleUpdate = suppress;
- if (!suppress) {
+ if (suppress) {
+ setDotScale(0);
+ } else {
showDotIfNeeded(/* animate= */ false);
}
}
diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimator.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimator.kt
index 78e5dbd..6c354f3 100644
--- a/quickstep/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimator.kt
+++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimator.kt
@@ -55,6 +55,8 @@
return animatingBubble.state != AnimatingBubble.State.CREATED
}
+ private var interceptedHandleAnimator = false
+
private companion object {
/** The time to show the flyout. */
const val FLYOUT_DELAY_MS: Long = 3000
@@ -133,10 +135,21 @@
dampingRatio = SpringForce.DAMPING_RATIO_MEDIUM_BOUNCY,
)
+ private fun cancelAnimationIfPending() {
+ val animatingBubble = animatingBubble ?: return
+ if (animatingBubble.state != AnimatingBubble.State.CREATED) return
+ scheduler.cancel(animatingBubble.showAnimation)
+ scheduler.cancel(animatingBubble.hideAnimation)
+ }
+
/** Animates a bubble for the state where the bubble bar is stashed. */
fun animateBubbleInForStashed(b: BubbleBarBubble, isExpanding: Boolean) {
- // TODO b/346400677: handle animations for the same bubble interrupting each other
- if (animatingBubble?.bubbleView?.bubble?.key == b.key) return
+ if (isAnimating) {
+ interruptAndUpdateAnimatingBubble(b.view, isExpanding)
+ return
+ }
+ cancelAnimationIfPending()
+
val bubbleView = b.view
val animator = PhysicsAnimator.getInstance(bubbleView)
if (animator.isRunning()) animator.cancel()
@@ -165,17 +178,19 @@
* 3. The third part is the overshoot of the spring animation, where we make the bubble fully
* visible which helps avoiding further updates when we re-enter the second part.
*/
- private fun buildHandleToBubbleBarAnimation() = Runnable {
+ private fun buildHandleToBubbleBarAnimation(initialVelocity: Float? = null) = Runnable {
moveToState(AnimatingBubble.State.ANIMATING_IN)
- // prepare the bubble bar for the animation
- bubbleBarView.visibility = VISIBLE
- bubbleBarView.alpha = 0f
- bubbleBarView.translationY = 0f
- bubbleBarView.scaleX = 1f
- bubbleBarView.scaleY = BUBBLE_ANIMATION_INITIAL_SCALE_Y
- bubbleBarView.setBackgroundScaleX(1f)
- bubbleBarView.setBackgroundScaleY(1f)
- bubbleBarView.relativePivotY = 0.5f
+ // prepare the bubble bar for the animation if we're starting fresh
+ if (initialVelocity == null) {
+ bubbleBarView.visibility = VISIBLE
+ bubbleBarView.alpha = 0f
+ bubbleBarView.translationY = 0f
+ bubbleBarView.scaleX = 1f
+ bubbleBarView.scaleY = BUBBLE_ANIMATION_INITIAL_SCALE_Y
+ bubbleBarView.setBackgroundScaleX(1f)
+ bubbleBarView.setBackgroundScaleY(1f)
+ bubbleBarView.relativePivotY = 0.5f
+ }
// this is the offset between the center of the bubble bar and the center of the stash
// handle. when the handle becomes invisible and we start animating in the bubble bar,
@@ -194,7 +209,7 @@
val totalTranslationY = bubbleStashController.bubbleBarTranslationYForTaskbar + offset
val animator = bubbleStashController.getStashedHandlePhysicsAnimator() ?: return@Runnable
animator.setDefaultSpringConfig(springConfig)
- animator.spring(DynamicAnimation.TRANSLATION_Y, totalTranslationY)
+ animator.spring(DynamicAnimation.TRANSLATION_Y, totalTranslationY, initialVelocity ?: 0f)
animator.addUpdateListener { handle, values ->
val ty = values[DynamicAnimation.TRANSLATION_Y]?.value ?: return@addUpdateListener
when {
@@ -314,7 +329,19 @@
}
}
}
- animator.addEndListener { _, _, _, canceled, _, _, _ ->
+ animator.addEndListener { _, _, _, canceled, _, finalVelocity, _ ->
+ // PhysicsAnimator calls the end listeners when the animation is replaced with a new one
+ // if we're not in ANIMATING_OUT state, then this animation never started and we should
+ // return
+ if (animatingBubble?.state != AnimatingBubble.State.ANIMATING_OUT) return@addEndListener
+ if (interceptedHandleAnimator) {
+ interceptedHandleAnimator = false
+ // post this to give a PhysicsAnimator a chance to clean up its internal listeners.
+ // otherwise this end listener will be called as soon as we create a new spring
+ // animation
+ scheduler.post(buildHandleToBubbleBarAnimation(initialVelocity = finalVelocity))
+ return@addEndListener
+ }
animatingBubble = null
if (!canceled) bubbleStashController.stashBubbleBarImmediate()
bubbleBarView.relativePivotY = 1f
@@ -326,7 +353,7 @@
val flyout = bubble?.flyoutMessage
if (flyout != null) {
bubbleBarFlyoutController.collapseFlyout {
- onFlyoutRemoved(bubble.view)
+ onFlyoutRemoved()
animator.start()
}
} else {
@@ -336,8 +363,6 @@
/** Animates to the initial state of the bubble bar, when there are no previous bubbles. */
fun animateToInitialState(b: BubbleBarBubble, isInApp: Boolean, isExpanding: Boolean) {
- // TODO b/346400677: handle animations for the same bubble interrupting each other
- if (animatingBubble?.bubbleView?.bubble?.key == b.key) return
val bubbleView = b.view
val animator = PhysicsAnimator.getInstance(bubbleView)
if (animator.isRunning()) animator.cancel()
@@ -350,8 +375,11 @@
buildBubbleBarToHandleAnimation()
} else {
Runnable {
- bubbleBarFlyoutController.collapseFlyout { onFlyoutRemoved(bubbleView) }
- animatingBubble = null
+ moveToState(AnimatingBubble.State.ANIMATING_OUT)
+ bubbleBarFlyoutController.collapseFlyout {
+ onFlyoutRemoved()
+ animatingBubble = null
+ }
bubbleStashController.showBubbleBarImmediate()
bubbleStashController.updateTaskbarTouchRegion()
}
@@ -394,16 +422,23 @@
}
fun animateBubbleBarForCollapsed(b: BubbleBarBubble, isExpanding: Boolean) {
- // TODO b/346400677: handle animations for the same bubble interrupting each other
- if (animatingBubble?.bubbleView?.bubble?.key == b.key) return
+ if (isAnimating) {
+ interruptAndUpdateAnimatingBubble(b.view, isExpanding)
+ return
+ }
+ cancelAnimationIfPending()
+
val bubbleView = b.view
val animator = PhysicsAnimator.getInstance(bubbleView)
if (animator.isRunning()) animator.cancel()
// first bounce the bubble bar and show the flyout. Then hide the flyout.
val showAnimation = buildBubbleBarBounceAnimation()
val hideAnimation = Runnable {
- bubbleBarFlyoutController.collapseFlyout { onFlyoutRemoved(bubbleView) }
- animatingBubble = null
+ moveToState(AnimatingBubble.State.ANIMATING_OUT)
+ bubbleBarFlyoutController.collapseFlyout {
+ onFlyoutRemoved()
+ animatingBubble = null
+ }
bubbleStashController.showBubbleBarImmediate()
bubbleStashController.updateTaskbarTouchRegion()
}
@@ -449,25 +484,25 @@
val bubble = bubbleView?.bubble as? BubbleBarBubble
val flyout = bubble?.flyoutMessage
if (flyout != null) {
- bubbleView.suppressDotForBubbleUpdate(true)
bubbleBarFlyoutController.setUpAndShowFlyout(
- BubbleBarFlyoutMessage(flyout.icon, flyout.title, flyout.message)
- ) {
- moveToState(AnimatingBubble.State.IN)
- bubbleStashController.updateTaskbarTouchRegion()
- }
+ BubbleBarFlyoutMessage(flyout.icon, flyout.title, flyout.message),
+ onInit = { bubbleView.suppressDotForBubbleUpdate(true) },
+ onEnd = {
+ moveToState(AnimatingBubble.State.IN)
+ bubbleStashController.updateTaskbarTouchRegion()
+ },
+ )
} else {
moveToState(AnimatingBubble.State.IN)
}
}
private fun cancelFlyout() {
- val bubbleView = animatingBubble?.bubbleView
- bubbleBarFlyoutController.cancelFlyout { onFlyoutRemoved(bubbleView) }
+ bubbleBarFlyoutController.cancelFlyout { onFlyoutRemoved() }
}
- private fun onFlyoutRemoved(bubbleView: BubbleView?) {
- bubbleView?.suppressDotForBubbleUpdate(false)
+ private fun onFlyoutRemoved() {
+ animatingBubble?.bubbleView?.suppressDotForBubbleUpdate(false)
bubbleStashController.updateTaskbarTouchRegion()
}
@@ -507,6 +542,117 @@
}
}
+ private fun interruptAndUpdateAnimatingBubble(bubbleView: BubbleView, isExpanding: Boolean) {
+ val animatingBubble = animatingBubble ?: return
+ when (animatingBubble.state) {
+ AnimatingBubble.State.CREATED -> {} // nothing to do since the animation hasn't started
+ AnimatingBubble.State.ANIMATING_IN ->
+ updateAnimationWhileAnimatingIn(animatingBubble, bubbleView, isExpanding)
+ AnimatingBubble.State.IN ->
+ updateAnimationWhileIn(animatingBubble, bubbleView, isExpanding)
+ AnimatingBubble.State.ANIMATING_OUT ->
+ updateAnimationWhileAnimatingOut(animatingBubble, bubbleView, isExpanding)
+ }
+ }
+
+ private fun updateAnimationWhileAnimatingIn(
+ animatingBubble: AnimatingBubble,
+ bubbleView: BubbleView,
+ isExpanding: Boolean,
+ ) {
+ this.animatingBubble = animatingBubble.copy(bubbleView = bubbleView, expand = isExpanding)
+ if (!bubbleBarFlyoutController.hasFlyout()) {
+ // if the flyout does not yet exist, then we're only animating the bubble bar.
+ // the animating bubble has been updated, so the when the flyout expands it will
+ // show the right message. we only need to update the dot visibility.
+ bubbleView.updateDotVisibility(/* animate= */ !bubbleStashController.isStashed)
+ return
+ }
+
+ val bubble = bubbleView.bubble as? BubbleBarBubble
+ val flyout = bubble?.flyoutMessage
+ if (flyout != null) {
+ // the flyout is currently expanding and we need to update it with new data
+ bubbleView.suppressDotForBubbleUpdate(true)
+ bubbleBarFlyoutController.updateFlyoutWhileExpanding(flyout)
+ } else {
+ // the flyout is expanding but we don't have new flyout data to update it with,
+ // so cancel the expanding flyout.
+ cancelFlyout()
+ }
+ }
+
+ private fun updateAnimationWhileIn(
+ animatingBubble: AnimatingBubble,
+ bubbleView: BubbleView,
+ isExpanding: Boolean,
+ ) {
+ // unsuppress the current bubble because we are about to hide its flyout
+ animatingBubble.bubbleView.suppressDotForBubbleUpdate(false)
+ this.animatingBubble = animatingBubble.copy(bubbleView = bubbleView, expand = isExpanding)
+
+ // we're currently idle, waiting for the hide animation to start. update the flyout
+ // data and reschedule the hide animation to run later to give the user a chance to
+ // see the new flyout.
+ val hideAnimation = animatingBubble.hideAnimation
+ scheduler.cancel(hideAnimation)
+ scheduler.postDelayed(FLYOUT_DELAY_MS, hideAnimation)
+
+ val bubble = bubbleView.bubble as? BubbleBarBubble
+ val flyout = bubble?.flyoutMessage
+ if (flyout != null) {
+ bubbleView.suppressDotForBubbleUpdate(true)
+ bubbleBarFlyoutController.updateFlyoutFullyExpanded(flyout) {
+ bubbleStashController.updateTaskbarTouchRegion()
+ }
+ } else {
+ cancelFlyout()
+ }
+ }
+
+ private fun updateAnimationWhileAnimatingOut(
+ animatingBubble: AnimatingBubble,
+ bubbleView: BubbleView,
+ isExpanding: Boolean,
+ ) {
+ // unsuppress the current bubble because we are about to hide its flyout
+ animatingBubble.bubbleView.suppressDotForBubbleUpdate(false)
+ this.animatingBubble = animatingBubble.copy(bubbleView = bubbleView, expand = isExpanding)
+
+ // the hide animation already started so it can't be canceled, just post it again
+ val hideAnimation = animatingBubble.hideAnimation
+ scheduler.postDelayed(FLYOUT_DELAY_MS, hideAnimation)
+
+ val bubble = bubbleView.bubble as? BubbleBarBubble
+ val flyout = bubble?.flyoutMessage
+ if (bubbleBarFlyoutController.hasFlyout()) {
+ // the flyout is collapsing. update it with the new flyout
+ if (flyout != null) {
+ moveToState(AnimatingBubble.State.ANIMATING_IN)
+ bubbleView.suppressDotForBubbleUpdate(true)
+ bubbleBarFlyoutController.updateFlyoutWhileCollapsing(flyout) {
+ moveToState(AnimatingBubble.State.IN)
+ bubbleStashController.updateTaskbarTouchRegion()
+ }
+ } else {
+ cancelFlyout()
+ moveToState(AnimatingBubble.State.IN)
+ }
+ } else {
+ // the flyout is already gone. if we're animating the handle cancel it. the
+ // animation itself can handle morphing back into the bubble bar and restarting
+ // and show the flyout.
+ val handleAnimator = bubbleStashController.getStashedHandlePhysicsAnimator()
+ if (handleAnimator != null && handleAnimator.isRunning()) {
+ interceptedHandleAnimator = true
+ handleAnimator.cancel()
+ }
+
+ // if we're not animating the handle, then the hide animation simply hides the
+ // flyout, but if the flyout is gone then the animation has ended.
+ }
+ }
+
private fun cancelHideAnimation() {
val hideAnimation = animatingBubble?.hideAnimation ?: return
scheduler.cancel(hideAnimation)
diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/flyout/BubbleBarFlyoutController.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/flyout/BubbleBarFlyoutController.kt
index f389d7e..7b20eea 100644
--- a/quickstep/src/com/android/launcher3/taskbar/bubbles/flyout/BubbleBarFlyoutController.kt
+++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/flyout/BubbleBarFlyoutController.kt
@@ -39,11 +39,14 @@
}
private var flyout: BubbleBarFlyoutView? = null
+ private var animator: ValueAnimator? = null
private val horizontalMargin =
container.context.resources.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin)
private enum class AnimationType {
- COLLAPSE,
+ /** Morphs the flyout between a dot and a rounded rectangle. */
+ MORPH,
+ /** Fades the flyout in or out. */
FADE,
}
@@ -56,7 +59,7 @@
return rect
}
- fun setUpAndShowFlyout(message: BubbleBarFlyoutMessage, onEnd: () -> Unit) {
+ fun setUpAndShowFlyout(message: BubbleBarFlyoutMessage, onInit: () -> Unit, onEnd: () -> Unit) {
flyout?.let(container::removeView)
val flyout = BubbleBarFlyoutView(container.context, positioner, flyoutScheduler)
@@ -73,16 +76,24 @@
container.addView(flyout, lp)
this.flyout = flyout
- flyout.showFromCollapsed(message) { showFlyout(AnimationType.COLLAPSE, onEnd) }
+ flyout.showFromCollapsed(message) {
+ flyout.updateExpansionProgress(0f)
+ onInit()
+ showFlyout(AnimationType.MORPH, onEnd)
+ }
}
private fun showFlyout(animationType: AnimationType, endAction: () -> Unit) {
val flyout = this.flyout ?: return
- val animator = ValueAnimator.ofFloat(0f, 1f).setDuration(ANIMATION_DURATION_MS)
+ val startValue = getCurrentAnimatedValueIfRunning() ?: 0f
+ val duration = (ANIMATION_DURATION_MS * (1f - startValue)).toLong()
+ animator?.cancel()
+ val animator = ValueAnimator.ofFloat(startValue, 1f).setDuration(duration)
+ this.animator = animator
when (animationType) {
AnimationType.FADE ->
animator.addUpdateListener { _ -> flyout.alpha = animator.animatedValue as Float }
- AnimationType.COLLAPSE ->
+ AnimationType.MORPH ->
animator.addUpdateListener { _ ->
flyout.updateExpansionProgress(animator.animatedValue as Float)
}
@@ -109,6 +120,13 @@
flyout.updateData(message) { extendTopBoundary() }
}
+ fun updateFlyoutWhileCollapsing(message: BubbleBarFlyoutMessage, onEnd: () -> Unit) {
+ val flyout = flyout ?: return
+ animator?.pause()
+ animator?.removeAllListeners()
+ flyout.updateData(message) { showFlyout(AnimationType.MORPH, onEnd) }
+ }
+
private fun extendTopBoundary() {
val flyout = flyout ?: return
val flyoutTop = flyout.top + flyout.translationY
@@ -125,25 +143,36 @@
}
fun collapseFlyout(endAction: () -> Unit) {
- hideFlyout(AnimationType.COLLAPSE) {
+ hideFlyout(AnimationType.MORPH) {
cleanupFlyoutView()
endAction()
}
}
private fun hideFlyout(animationType: AnimationType, endAction: () -> Unit) {
- // TODO: b/277815200 - stop the current animation if it's running
val flyout = this.flyout ?: return
- val animator = ValueAnimator.ofFloat(1f, 0f).setDuration(ANIMATION_DURATION_MS)
+ val startValue = getCurrentAnimatedValueIfRunning() ?: 1f
+ val duration = (ANIMATION_DURATION_MS * startValue).toLong()
+ animator?.cancel()
+ val animator = ValueAnimator.ofFloat(startValue, 0f).setDuration(duration)
+ this.animator = animator
when (animationType) {
AnimationType.FADE ->
animator.addUpdateListener { _ -> flyout.alpha = animator.animatedValue as Float }
- AnimationType.COLLAPSE ->
+ AnimationType.MORPH ->
animator.addUpdateListener { _ ->
flyout.updateExpansionProgress(animator.animatedValue as Float)
}
}
- animator.addListener(onStart = { flyout.setOnClickListener(null) }, onEnd = { endAction() })
+ animator.addListener(
+ onStart = {
+ flyout.setOnClickListener(null)
+ if (animationType == AnimationType.MORPH) {
+ flyout.updateTranslationToCollapsedPosition()
+ }
+ },
+ onEnd = { endAction() },
+ )
animator.start()
}
@@ -154,4 +183,9 @@
}
fun hasFlyout() = flyout != null
+
+ private fun getCurrentAnimatedValueIfRunning(): Float? {
+ val animator = animator ?: return null
+ return if (animator.isRunning) animator.animatedValue as Float else null
+ }
}
diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/flyout/BubbleBarFlyoutView.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/flyout/BubbleBarFlyoutView.kt
index af8aaf8..418675c 100644
--- a/quickstep/src/com/android/launcher3/taskbar/bubbles/flyout/BubbleBarFlyoutView.kt
+++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/flyout/BubbleBarFlyoutView.kt
@@ -192,18 +192,8 @@
title.alpha = 0f
message.alpha = 0f
setData(flyoutMessage)
- val txToCollapsedPosition =
- if (positioner.isOnLeft) {
- positioner.distanceToCollapsedPosition.x
- } else {
- -positioner.distanceToCollapsedPosition.x
- }
- // TODO: b/277815200 - before collapsing, recalculate translationToCollapsedPosition because
- // the collapsed position may have changed
- val tyToCollapsedPosition =
- positioner.distanceToCollapsedPosition.y + triangleHeight - triangleOverlap
- translationToCollapsedPosition = PointF(txToCollapsedPosition, tyToCollapsedPosition)
+ updateTranslationToCollapsedPosition()
collapsedSize = positioner.collapsedSize
collapsedCornerRadius = collapsedSize / 2
collapsedColor = positioner.collapsedColor
@@ -212,7 +202,7 @@
// calculate the expansion progress required before we start showing the triangle as part of
// the expansion animation
minExpansionProgressForTriangle =
- positioner.distanceToRevealTriangle / tyToCollapsedPosition
+ positioner.distanceToRevealTriangle / translationToCollapsedPosition.y
// post the request to start the expand animation to the looper so the view can measure
// itself
@@ -259,6 +249,22 @@
message.text = flyoutMessage.message
}
+ /**
+ * This should be called to update [translationToCollapsedPosition] before we start expanding or
+ * collapsing to make sure that we're animating the flyout to and from the correct position.
+ */
+ fun updateTranslationToCollapsedPosition() {
+ val txToCollapsedPosition =
+ if (positioner.isOnLeft) {
+ positioner.distanceToCollapsedPosition.x
+ } else {
+ -positioner.distanceToCollapsedPosition.x
+ }
+ val tyToCollapsedPosition =
+ positioner.distanceToCollapsedPosition.y + triangleHeight - triangleOverlap
+ translationToCollapsedPosition = PointF(txToCollapsedPosition, tyToCollapsedPosition)
+ }
+
/** Updates the flyout view with the progress of the animation. */
fun updateExpansionProgress(fraction: Float) {
expansionProgress = fraction
diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java
index 228dc91..fe68ebc 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java
@@ -139,6 +139,7 @@
import com.android.launcher3.statemanager.StateManager.StateHandler;
import com.android.launcher3.taskbar.LauncherTaskbarUIController;
import com.android.launcher3.taskbar.TaskbarManager;
+import com.android.launcher3.taskbar.TaskbarUIController;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.uioverrides.QuickstepWidgetHolder.QuickstepHolderFactory;
@@ -1089,10 +1090,12 @@
);
}
- public void setTaskbarUIController(LauncherTaskbarUIController taskbarUIController) {
- mTaskbarUIController = taskbarUIController;
+ @Override
+ public void setTaskbarUIController(@Nullable TaskbarUIController taskbarUIController) {
+ mTaskbarUIController = (LauncherTaskbarUIController) taskbarUIController;
}
+ @Override
public @Nullable LauncherTaskbarUIController getTaskbarUIController() {
return mTaskbarUIController;
}
@@ -1399,6 +1402,7 @@
}
@NonNull
+ @Override
public TISBindHelper getTISBindHelper() {
return mTISBindHelper;
}
diff --git a/quickstep/src/com/android/quickstep/RecentTasksList.java b/quickstep/src/com/android/quickstep/RecentTasksList.java
index 05bef35..714838a 100644
--- a/quickstep/src/com/android/quickstep/RecentTasksList.java
+++ b/quickstep/src/com/android/quickstep/RecentTasksList.java
@@ -20,9 +20,9 @@
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.quickstep.util.SplitScreenUtils.convertShellSplitBoundsToLauncher;
-import static com.android.wm.shell.shared.GroupedRecentTaskInfo.TYPE_FREEFORM;
+import static com.android.wm.shell.shared.GroupedTaskInfo.TYPE_FREEFORM;
-import android.app.ActivityManager;
+import android.app.ActivityManager.RunningTaskInfo;
import android.app.KeyguardManager;
import android.app.TaskInfo;
import android.content.ComponentName;
@@ -40,7 +40,7 @@
import com.android.quickstep.util.GroupTask;
import com.android.systemui.shared.recents.model.Task;
import com.android.wm.shell.recents.IRecentTasksListener;
-import com.android.wm.shell.shared.GroupedRecentTaskInfo;
+import com.android.wm.shell.shared.GroupedTaskInfo;
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus;
import java.io.PrintWriter;
@@ -76,7 +76,7 @@
private @Nullable RecentsModel.RunningTasksListener mRunningTasksListener;
private @Nullable RecentsModel.RecentTasksChangedListener mRecentTasksChangedListener;
// Tasks are stored in order of least recently launched to most recently launched.
- private ArrayList<ActivityManager.RunningTaskInfo> mRunningTasks;
+ private ArrayList<RunningTaskInfo> mRunningTasks;
public RecentTasksList(Context context, LooperExecutor mainThreadExecutor,
KeyguardManager keyguardManager, SystemUiProxy sysUiProxy,
@@ -93,32 +93,40 @@
}
@Override
- public void onRunningTaskAppeared(ActivityManager.RunningTaskInfo taskInfo) {
+ public void onRunningTaskAppeared(RunningTaskInfo taskInfo) {
mMainThreadExecutor.execute(() -> {
RecentTasksList.this.onRunningTaskAppeared(taskInfo);
});
}
@Override
- public void onRunningTaskVanished(ActivityManager.RunningTaskInfo taskInfo) {
+ public void onRunningTaskVanished(RunningTaskInfo taskInfo) {
mMainThreadExecutor.execute(() -> {
RecentTasksList.this.onRunningTaskVanished(taskInfo);
});
}
@Override
- public void onRunningTaskChanged(ActivityManager.RunningTaskInfo taskInfo) {
+ public void onRunningTaskChanged(RunningTaskInfo taskInfo) {
mMainThreadExecutor.execute(() -> {
RecentTasksList.this.onRunningTaskChanged(taskInfo);
});
}
@Override
- public void onTaskMovedToFront(ActivityManager.RunningTaskInfo taskInfo) {
+ public void onTaskMovedToFront(GroupedTaskInfo[] visibleTasks) {
mMainThreadExecutor.execute(() -> {
- topTaskTracker.onTaskMovedToFront(taskInfo);
+ // TODO(b/346588978): We currently are only sending a single task, but this will
+ // be updated once we send the full set of visible tasks
+ final TaskInfo info = visibleTasks[0].getTaskInfo1();
+ topTaskTracker.handleTaskMovedToFront(info);
});
}
+
+ @Override
+ public void onTaskInfoChanged(RunningTaskInfo taskInfo) {
+ mMainThreadExecutor.execute(() -> topTaskTracker.onTaskChanged(taskInfo));
+ }
});
// We may receive onRunningTaskAppeared events later for tasks which have already been
// included in the list returned by mSysUiProxy.getRunningTasks(), or may receive
@@ -245,7 +253,7 @@
mRecentTasksChangedListener = null;
}
- private void initRunningTasks(ArrayList<ActivityManager.RunningTaskInfo> runningTasks) {
+ private void initRunningTasks(ArrayList<RunningTaskInfo> runningTasks) {
// Tasks are retrieved in order of most recently launched/used to least recently launched.
mRunningTasks = new ArrayList<>(runningTasks);
Collections.reverse(mRunningTasks);
@@ -254,13 +262,13 @@
/**
* Gets the set of running tasks.
*/
- public ArrayList<ActivityManager.RunningTaskInfo> getRunningTasks() {
+ public ArrayList<RunningTaskInfo> getRunningTasks() {
return mRunningTasks;
}
- private void onRunningTaskAppeared(ActivityManager.RunningTaskInfo taskInfo) {
+ private void onRunningTaskAppeared(RunningTaskInfo taskInfo) {
// Make sure this task is not already in the list
- for (ActivityManager.RunningTaskInfo existingTask : mRunningTasks) {
+ for (RunningTaskInfo existingTask : mRunningTasks) {
if (taskInfo.taskId == existingTask.taskId) {
return;
}
@@ -271,9 +279,9 @@
}
}
- private void onRunningTaskVanished(ActivityManager.RunningTaskInfo taskInfo) {
+ private void onRunningTaskVanished(RunningTaskInfo taskInfo) {
// Find the task from the list of running tasks, if it exists
- for (ActivityManager.RunningTaskInfo existingTask : mRunningTasks) {
+ for (RunningTaskInfo existingTask : mRunningTasks) {
if (existingTask.taskId != taskInfo.taskId) continue;
mRunningTasks.remove(existingTask);
@@ -284,9 +292,9 @@
}
}
- private void onRunningTaskChanged(ActivityManager.RunningTaskInfo taskInfo) {
+ private void onRunningTaskChanged(RunningTaskInfo taskInfo) {
// Find the task from the list of running tasks, if it exists
- for (ActivityManager.RunningTaskInfo existingTask : mRunningTasks) {
+ for (RunningTaskInfo existingTask : mRunningTasks) {
if (existingTask.taskId != taskInfo.taskId) continue;
mRunningTasks.remove(existingTask);
@@ -304,7 +312,7 @@
@VisibleForTesting
TaskLoadResult loadTasksInBackground(int numTasks, int requestId, boolean loadKeysOnly) {
int currentUserId = Process.myUserHandle().getIdentifier();
- ArrayList<GroupedRecentTaskInfo> rawTasks;
+ ArrayList<GroupedTaskInfo> rawTasks;
try {
rawTasks = mSysUiProxy.getRecentTasks(numTasks, currentUserId);
} catch (SystemUiProxy.GetRecentTasksException e) {
@@ -327,7 +335,7 @@
TaskLoadResult allTasks = new TaskLoadResult(requestId, loadKeysOnly, rawTasks.size());
int numVisibleTasks = 0;
- for (GroupedRecentTaskInfo rawTask : rawTasks) {
+ for (GroupedTaskInfo rawTask : rawTasks) {
if (rawTask.getType() == TYPE_FREEFORM) {
// TYPE_FREEFORM tasks is only created when desktop mode can be entered,
// leftover TYPE_FREEFORM tasks created when flag was on should be ignored.
@@ -339,14 +347,13 @@
}
continue;
}
- ActivityManager.RecentTaskInfo taskInfo1 = rawTask.getTaskInfo1();
- ActivityManager.RecentTaskInfo taskInfo2 = rawTask.getTaskInfo2();
+ TaskInfo taskInfo1 = rawTask.getTaskInfo1();
+ TaskInfo taskInfo2 = rawTask.getTaskInfo2();
Task.TaskKey task1Key = new Task.TaskKey(taskInfo1);
Task task1 = loadKeysOnly
? new Task(task1Key)
: Task.from(task1Key, taskInfo1,
tmpLockedUsers.get(task1Key.userId) /* isLocked */);
- task1.setLastSnapshotData(taskInfo1);
Task task2 = null;
if (taskInfo2 != null) {
// Is split task
@@ -355,7 +362,6 @@
? new Task(task2Key)
: Task.from(task2Key, taskInfo2,
tmpLockedUsers.get(task2Key.userId) /* isLocked */);
- task2.setLastSnapshotData(taskInfo2);
} else {
// Is fullscreen task
if (numVisibleTasks > 0) {
@@ -379,17 +385,16 @@
return allTasks;
}
- private @Nullable DesktopTask createDesktopTask(GroupedRecentTaskInfo recentTaskInfo) {
+ private @Nullable DesktopTask createDesktopTask(GroupedTaskInfo recentTaskInfo) {
ArrayList<Task> tasks = new ArrayList<>(recentTaskInfo.getTaskInfoList().size());
int[] minimizedTaskIds = recentTaskInfo.getMinimizedTaskIds();
if (minimizedTaskIds.length == recentTaskInfo.getTaskInfoList().size()) {
// All Tasks are minimized -> don't create a DesktopTask
return null;
}
- for (ActivityManager.RecentTaskInfo taskInfo : recentTaskInfo.getTaskInfoList()) {
+ for (TaskInfo taskInfo : recentTaskInfo.getTaskInfoList()) {
Task.TaskKey key = new Task.TaskKey(taskInfo);
Task task = Task.from(key, taskInfo, false);
- task.setLastSnapshotData(taskInfo);
task.positionInParent = taskInfo.positionInParent;
task.appBounds = taskInfo.configuration.windowConfiguration.getAppBounds();
task.isVisible = taskInfo.isVisible;
@@ -424,14 +429,14 @@
}
writer.println(prefix + " ]");
int currentUserId = Process.myUserHandle().getIdentifier();
- ArrayList<GroupedRecentTaskInfo> rawTasks;
+ ArrayList<GroupedTaskInfo> rawTasks;
try {
rawTasks = mSysUiProxy.getRecentTasks(Integer.MAX_VALUE, currentUserId);
} catch (SystemUiProxy.GetRecentTasksException e) {
rawTasks = new ArrayList<>();
}
writer.println(prefix + " rawTasks=[");
- for (GroupedRecentTaskInfo task : rawTasks) {
+ for (GroupedTaskInfo task : rawTasks) {
TaskInfo taskInfo1 = task.getTaskInfo1();
TaskInfo taskInfo2 = task.getTaskInfo2();
ComponentName cn1 = taskInfo1.topActivity;
diff --git a/quickstep/src/com/android/quickstep/RecentsActivity.java b/quickstep/src/com/android/quickstep/RecentsActivity.java
index b19f651..6075294 100644
--- a/quickstep/src/com/android/quickstep/RecentsActivity.java
+++ b/quickstep/src/com/android/quickstep/RecentsActivity.java
@@ -70,6 +70,7 @@
import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.taskbar.FallbackTaskbarUIController;
import com.android.launcher3.taskbar.TaskbarManager;
+import com.android.launcher3.taskbar.TaskbarUIController;
import com.android.launcher3.util.ActivityOptionsWrapper;
import com.android.launcher3.util.ContextTracker;
import com.android.launcher3.util.RunnableList;
@@ -115,7 +116,7 @@
private FallbackRecentsView mFallbackRecentsView;
private OverviewActionsView<?> mActionsView;
private TISBindHelper mTISBindHelper;
- private @Nullable FallbackTaskbarUIController mTaskbarUIController;
+ private @Nullable FallbackTaskbarUIController<RecentsActivity> mTaskbarUIController;
private StateManager<RecentsState, RecentsActivity> mStateManager;
@@ -174,11 +175,14 @@
mTISBindHelper.runOnBindToTouchInteractionService(r);
}
- public void setTaskbarUIController(FallbackTaskbarUIController taskbarUIController) {
- mTaskbarUIController = taskbarUIController;
+ @Override
+ public void setTaskbarUIController(@Nullable TaskbarUIController taskbarUIController) {
+ mTaskbarUIController = (FallbackTaskbarUIController<RecentsActivity>) taskbarUIController;
}
- public FallbackTaskbarUIController getTaskbarUIController() {
+ @Nullable
+ @Override
+ public FallbackTaskbarUIController<RecentsActivity> getTaskbarUIController() {
return mTaskbarUIController;
}
@@ -515,6 +519,7 @@
}
@NonNull
+ @Override
public TISBindHelper getTISBindHelper() {
return mTISBindHelper;
}
diff --git a/quickstep/src/com/android/quickstep/RotationTouchHelper.java b/quickstep/src/com/android/quickstep/RotationTouchHelper.java
index 80c07196..79abc0f 100644
--- a/quickstep/src/com/android/quickstep/RotationTouchHelper.java
+++ b/quickstep/src/com/android/quickstep/RotationTouchHelper.java
@@ -180,6 +180,7 @@
}
}
};
+ runOnDestroy(() -> mOrientationListener.disable());
mNeedsInit = false;
}
@@ -212,6 +213,7 @@
r.run();
}
mNeedsInit = true;
+ mOnDestroyActions.clear();
}
public boolean isTaskListFrozen() {
diff --git a/quickstep/src/com/android/quickstep/SystemUiProxy.java b/quickstep/src/com/android/quickstep/SystemUiProxy.java
index c1d7ffa..73e22bb 100644
--- a/quickstep/src/com/android/quickstep/SystemUiProxy.java
+++ b/quickstep/src/com/android/quickstep/SystemUiProxy.java
@@ -54,15 +54,16 @@
import androidx.annotation.MainThread;
import androidx.annotation.Nullable;
-import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;
import com.android.internal.logging.InstanceId;
import com.android.internal.util.ScreenshotRequest;
import com.android.internal.view.AppearanceRegion;
-import com.android.launcher3.util.MainThreadInitializedObject;
+import com.android.launcher3.dagger.ApplicationContext;
+import com.android.launcher3.dagger.LauncherAppSingleton;
+import com.android.launcher3.util.DaggerSingletonObject;
import com.android.launcher3.util.Preconditions;
-import com.android.launcher3.util.SafeCloseable;
+import com.android.quickstep.dagger.QuickstepBaseAppComponent;
import com.android.quickstep.util.ActiveGestureProtoLogProxy;
import com.android.quickstep.util.ContextualSearchInvoker;
import com.android.quickstep.util.unfold.ProxyUnfoldTransitionProvider;
@@ -90,7 +91,7 @@
import com.android.wm.shell.recents.IRecentTasksListener;
import com.android.wm.shell.recents.IRecentsAnimationController;
import com.android.wm.shell.recents.IRecentsAnimationRunner;
-import com.android.wm.shell.shared.GroupedRecentTaskInfo;
+import com.android.wm.shell.shared.GroupedTaskInfo;
import com.android.wm.shell.shared.IShellTransitions;
import com.android.wm.shell.shared.bubbles.BubbleBarLocation;
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus;
@@ -109,14 +110,17 @@
import java.util.LinkedHashMap;
import java.util.List;
+import javax.inject.Inject;
+
/**
* Holds the reference to SystemUI.
*/
-public class SystemUiProxy implements ISystemUiProxy, NavHandle, SafeCloseable {
+@LauncherAppSingleton
+public class SystemUiProxy implements ISystemUiProxy, NavHandle {
private static final String TAG = "SystemUiProxy";
- public static final MainThreadInitializedObject<SystemUiProxy> INSTANCE =
- new MainThreadInitializedObject<>(SystemUiProxy::new);
+ public static final DaggerSingletonObject<SystemUiProxy> INSTANCE =
+ new DaggerSingletonObject<>(QuickstepBaseAppComponent::getSystemUiProxy);
private static final int MSG_SET_SHELF_HEIGHT = 1;
private static final int MSG_SET_LAUNCHER_KEEP_CLEAR_AREA_HEIGHT = 2;
@@ -188,8 +192,8 @@
@Nullable
private final ProxyUnfoldTransitionProvider mUnfoldTransitionProvider;
- @VisibleForTesting
- protected SystemUiProxy(Context context) {
+ @Inject
+ public SystemUiProxy(@ApplicationContext Context context) {
mContext = context;
mAsyncHandler = new Handler(UI_HELPER_EXECUTOR.getLooper(), this::handleMessageAsync);
final Intent baseIntent = new Intent().setPackage(mContext.getPackageName());
@@ -206,9 +210,6 @@
}
@Override
- public void close() { }
-
- @Override
public void onBackPressed() {
if (mSystemUiProxy != null) {
try {
@@ -1357,15 +1358,15 @@
* @throws GetRecentTasksException if IRecentTasks is not initialized, or when we get
* RemoteException from server side
*/
- public ArrayList<GroupedRecentTaskInfo> getRecentTasks(int numTasks, int userId)
- throws GetRecentTasksException {
+ public ArrayList<GroupedTaskInfo> getRecentTasks(int numTasks,
+ int userId) throws GetRecentTasksException {
if (mRecentTasks == null) {
Log.e(TAG, "getRecentTasks() failed due to null mRecentTasks");
throw new GetRecentTasksException("null mRecentTasks");
}
try {
- final GroupedRecentTaskInfo[] rawTasks = mRecentTasks.getRecentTasks(numTasks,
- RECENT_IGNORE_UNAVAILABLE, userId);
+ final GroupedTaskInfo[] rawTasks =
+ mRecentTasks.getRecentTasks(numTasks, RECENT_IGNORE_UNAVAILABLE, userId);
if (rawTasks == null) {
return new ArrayList<>();
}
diff --git a/quickstep/src/com/android/quickstep/TaskAnimationManager.java b/quickstep/src/com/android/quickstep/TaskAnimationManager.java
index 0b6794c..0ea128a 100644
--- a/quickstep/src/com/android/quickstep/TaskAnimationManager.java
+++ b/quickstep/src/com/android/quickstep/TaskAnimationManager.java
@@ -201,8 +201,7 @@
// Only finish if the end target is RECENTS. Otherwise, if the target is
// NEW_TASK, startActivityFromRecents will be skipped.
if (mLastGestureState.getEndTarget() == RECENTS) {
- finishRunningRecentsAnimation(false /* toHome */,
- true /* forceFinish */, null /* forceFinishCb */);
+ finishRunningRecentsAnimation(false /* toHome */);
}
});
}
diff --git a/quickstep/src/com/android/quickstep/TopTaskTracker.java b/quickstep/src/com/android/quickstep/TopTaskTracker.java
index 23a1ec7..c9dfe6d 100644
--- a/quickstep/src/com/android/quickstep/TopTaskTracker.java
+++ b/quickstep/src/com/android/quickstep/TopTaskTracker.java
@@ -27,6 +27,7 @@
import android.annotation.UserIdInt;
import android.app.ActivityManager.RunningTaskInfo;
+import android.app.TaskInfo;
import android.content.Context;
import androidx.annotation.NonNull;
@@ -67,7 +68,7 @@
private static final int HISTORY_SIZE = 5;
// Ordered list with first item being the most recent task.
- private final LinkedList<RunningTaskInfo> mOrderedTaskList = new LinkedList<>();
+ private final LinkedList<TaskInfo> mOrderedTaskList = new LinkedList<>();
private final Context mContext;
private final SplitStageInfo mMainStagePosition = new SplitStageInfo();
@@ -96,6 +97,10 @@
@Override
public void onTaskMovedToFront(RunningTaskInfo taskInfo) {
+ handleTaskMovedToFront(taskInfo);
+ }
+
+ public void handleTaskMovedToFront(TaskInfo taskInfo) {
mOrderedTaskList.removeIf(rto -> rto.taskId == taskInfo.taskId);
mOrderedTaskList.addFirst(taskInfo);
@@ -103,7 +108,7 @@
// display's task to the list, to avoid showing non-home display's task upon going to
// Recents animation.
if (taskInfo.displayId != DEFAULT_DISPLAY) {
- final RunningTaskInfo topTaskOnHomeDisplay = mOrderedTaskList.stream()
+ final TaskInfo topTaskOnHomeDisplay = mOrderedTaskList.stream()
.filter(rto -> rto.displayId == DEFAULT_DISPLAY).findFirst().orElse(null);
if (topTaskOnHomeDisplay != null) {
mOrderedTaskList.removeIf(rto -> rto.taskId == topTaskOnHomeDisplay.taskId);
@@ -113,9 +118,9 @@
if (mOrderedTaskList.size() >= HISTORY_SIZE) {
// If we grow in size, remove the last taskInfo which is not part of the split task.
- Iterator<RunningTaskInfo> itr = mOrderedTaskList.descendingIterator();
+ Iterator<TaskInfo> itr = mOrderedTaskList.descendingIterator();
while (itr.hasNext()) {
- RunningTaskInfo info = itr.next();
+ TaskInfo info = itr.next();
if (info.taskId != taskInfo.taskId
&& info.taskId != mMainStagePosition.taskId
&& info.taskId != mSideStagePosition.taskId) {
@@ -135,6 +140,15 @@
}
}
+ public void onTaskChanged(RunningTaskInfo taskInfo) {
+ for (int i = 0; i < mOrderedTaskList.size(); i++) {
+ if (mOrderedTaskList.get(i).taskId == taskInfo.taskId) {
+ mOrderedTaskList.set(i, taskInfo);
+ break;
+ }
+ }
+ }
+
@Override
public void onTaskStageChanged(int taskId, @StageType int stage, boolean visible) {
// If a task is not visible anymore or has been moved to undefined, stop tracking it.
@@ -206,13 +220,13 @@
Collections.addAll(mOrderedTaskList, tasks);
}
- ArrayList<RunningTaskInfo> tasks = new ArrayList<>(mOrderedTaskList);
+ ArrayList<TaskInfo> tasks = new ArrayList<>(mOrderedTaskList);
// Strip the pinned task and recents task
tasks.removeIf(t -> t.taskId == mPinnedTaskId || isRecentsTask(t));
return new CachedTaskInfo(tasks);
}
- private static boolean isRecentsTask(RunningTaskInfo task) {
+ private static boolean isRecentsTask(TaskInfo task) {
return task != null && task.configuration.windowConfiguration
.getActivityType() == ACTIVITY_TYPE_RECENTS;
}
@@ -224,10 +238,10 @@
public static class CachedTaskInfo {
@Nullable
- private final RunningTaskInfo mTopTask;
- public final List<RunningTaskInfo> mAllCachedTasks;
+ private final TaskInfo mTopTask;
+ public final List<TaskInfo> mAllCachedTasks;
- CachedTaskInfo(List<RunningTaskInfo> allCachedTasks) {
+ CachedTaskInfo(List<TaskInfo> allCachedTasks) {
mAllCachedTasks = allCachedTasks;
mTopTask = allCachedTasks.isEmpty() ? null : allCachedTasks.get(0);
}
@@ -253,7 +267,7 @@
// Not an excluded task.
return null;
}
- List<RunningTaskInfo> visibleNonExcludedTasks = mAllCachedTasks.stream()
+ List<TaskInfo> visibleNonExcludedTasks = mAllCachedTasks.stream()
.filter(t -> t.isVisible
&& (t.baseIntent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0
&& t.getActivityType() != ACTIVITY_TYPE_HOME
diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java
index 032e755..5b085d2 100644
--- a/quickstep/src/com/android/quickstep/TouchInteractionService.java
+++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java
@@ -342,36 +342,36 @@
@BinderThread
@Override
- public void checkNavBarModes() {
- MAIN_EXECUTOR.execute(() -> executeForTouchInteractionService(tis ->
- executeForTaskbarManager(TaskbarManager::checkNavBarModes)
- ));
- }
-
- @BinderThread
- @Override
- public void finishBarAnimations() {
- MAIN_EXECUTOR.execute(() -> executeForTouchInteractionService(tis ->
- executeForTaskbarManager(TaskbarManager::finishBarAnimations)
- ));
- }
-
- @BinderThread
- @Override
- public void touchAutoDim(boolean reset) {
- MAIN_EXECUTOR.execute(() -> executeForTouchInteractionService(tis ->
- executeForTaskbarManager(taskbarManager -> taskbarManager.touchAutoDim(reset))
- ));
- }
-
- @BinderThread
- @Override
- public void transitionTo(@BarTransitions.TransitionMode int barMode,
- boolean animate) {
+ public void checkNavBarModes(int displayId) {
MAIN_EXECUTOR.execute(() -> executeForTouchInteractionService(tis ->
executeForTaskbarManager(
- taskbarManager -> taskbarManager.transitionTo(barMode, animate))
- ));
+ taskbarManager -> taskbarManager.checkNavBarModes(displayId))));
+ }
+
+ @BinderThread
+ @Override
+ public void finishBarAnimations(int displayId) {
+ MAIN_EXECUTOR.execute(() -> executeForTouchInteractionService(
+ tis -> executeForTaskbarManager(
+ taskbarManager -> taskbarManager.finishBarAnimations(displayId))));
+ }
+
+ @BinderThread
+ @Override
+ public void touchAutoDim(int displayId, boolean reset) {
+ MAIN_EXECUTOR.execute(() -> executeForTouchInteractionService(
+ tis -> executeForTaskbarManager(
+ taskbarManager -> taskbarManager.touchAutoDim(displayId, reset))));
+ }
+
+ @BinderThread
+ @Override
+ public void transitionTo(int displayId, @BarTransitions.TransitionMode int barMode,
+ boolean animate) {
+ MAIN_EXECUTOR.execute(() -> executeForTouchInteractionService(
+ tis -> executeForTaskbarManager(
+ taskbarManager -> taskbarManager.transitionTo(displayId, barMode,
+ animate))));
}
@BinderThread
@@ -776,10 +776,13 @@
mAllAppsActionManager.setHomeAndOverviewSame(isHomeAndOverviewSame);
RecentsViewContainer newOverviewContainer =
mOverviewComponentObserver.getContainerInterface().getCreatedContainer();
- if (newOverviewContainer != null
- && newOverviewContainer instanceof StatefulActivity activity) {
- //TODO(b/368030750) refactor taskbarManager to accept RecentsViewContainer
- mTaskbarManager.setActivity(activity);
+ if (newOverviewContainer != null) {
+ if (newOverviewContainer instanceof StatefulActivity activity) {
+ // This will also call setRecentsViewContainer() internally.
+ mTaskbarManager.setActivity(activity);
+ } else {
+ mTaskbarManager.setRecentsViewContainer(newOverviewContainer);
+ }
}
mTISBinder.onOverviewTargetChange();
}
diff --git a/quickstep/src/com/android/quickstep/contextualeducation/SystemContextualEduStatsManager.java b/quickstep/src/com/android/quickstep/contextualeducation/SystemContextualEduStatsManager.java
index d470b88..6a72537 100644
--- a/quickstep/src/com/android/quickstep/contextualeducation/SystemContextualEduStatsManager.java
+++ b/quickstep/src/com/android/quickstep/contextualeducation/SystemContextualEduStatsManager.java
@@ -16,29 +16,28 @@
package com.android.quickstep.contextualeducation;
-import android.content.Context;
-
import com.android.launcher3.contextualeducation.ContextualEduStatsManager;
+import com.android.launcher3.dagger.LauncherAppSingleton;
import com.android.quickstep.SystemUiProxy;
import com.android.systemui.contextualeducation.GestureType;
+import javax.inject.Inject;
+
/**
* A class to update contextual education data via {@link SystemUiProxy}
*/
+@LauncherAppSingleton
public class SystemContextualEduStatsManager extends ContextualEduStatsManager {
- private Context mContext;
+ private final SystemUiProxy mSystemUiProxy;
- public SystemContextualEduStatsManager(Context context) {
- mContext = context;
+ @Inject
+ public SystemContextualEduStatsManager(SystemUiProxy systemUiProxy) {
+ mSystemUiProxy = systemUiProxy;
}
@Override
public void updateEduStats(boolean isTrackpadGesture, GestureType gestureType) {
- SystemUiProxy.INSTANCE.get(mContext).updateContextualEduStats(isTrackpadGesture,
+ mSystemUiProxy.updateContextualEduStats(isTrackpadGesture,
gestureType.name());
}
-
- @Override
- public void close() {
- }
}
diff --git a/quickstep/src/com/android/quickstep/dagger/QuickStepModule.java b/quickstep/src/com/android/quickstep/dagger/QuickStepModule.java
index 3870b9b..9f6360b 100644
--- a/quickstep/src/com/android/quickstep/dagger/QuickStepModule.java
+++ b/quickstep/src/com/android/quickstep/dagger/QuickStepModule.java
@@ -15,10 +15,12 @@
*/
package com.android.quickstep.dagger;
+import com.android.launcher3.contextualeducation.ContextualEduStatsManager;
import com.android.launcher3.uioverrides.SystemApiWrapper;
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapperImpl;
import com.android.launcher3.util.ApiWrapper;
import com.android.launcher3.util.PluginManagerWrapper;
+import com.android.quickstep.contextualeducation.SystemContextualEduStatsManager;
import dagger.Binds;
import dagger.Module;
@@ -28,4 +30,6 @@
@Binds abstract PluginManagerWrapper bindPluginManagerWrapper(PluginManagerWrapperImpl impl);
@Binds abstract ApiWrapper bindApiWrapper(SystemApiWrapper systemApiWrapper);
+ @Binds abstract ContextualEduStatsManager bindContextualEduStatsManager(
+ SystemContextualEduStatsManager manager);
}
diff --git a/quickstep/src/com/android/quickstep/dagger/QuickstepBaseAppComponent.java b/quickstep/src/com/android/quickstep/dagger/QuickstepBaseAppComponent.java
index 977c036..b2670e8 100644
--- a/quickstep/src/com/android/quickstep/dagger/QuickstepBaseAppComponent.java
+++ b/quickstep/src/com/android/quickstep/dagger/QuickstepBaseAppComponent.java
@@ -19,6 +19,7 @@
import com.android.launcher3.dagger.LauncherAppComponent;
import com.android.launcher3.dagger.LauncherBaseAppComponent;
import com.android.launcher3.model.WellbeingModel;
+import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.util.AsyncClockEventDelegate;
/**
@@ -34,4 +35,6 @@
WellbeingModel getWellbeingModel();
AsyncClockEventDelegate getAsyncClockEventDelegate();
+
+ SystemUiProxy getSystemUiProxy();
}
diff --git a/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowManager.kt b/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowManager.kt
index 3017df2..843ef6c 100644
--- a/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowManager.kt
+++ b/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowManager.kt
@@ -18,6 +18,7 @@
import android.animation.AnimatorSet
import android.app.ActivityOptions
+import android.content.ComponentName
import android.content.Context
import android.content.LocusId
import android.os.Bundle
@@ -39,6 +40,7 @@
import com.android.launcher3.statemanager.StateManager
import com.android.launcher3.statemanager.StateManager.AtomicAnimationFactory
import com.android.launcher3.statemanager.StatefulContainer
+import com.android.launcher3.taskbar.TaskbarUIController
import com.android.launcher3.util.ContextTracker
import com.android.launcher3.util.DisplayController
import com.android.launcher3.util.RunnableList
@@ -116,6 +118,7 @@
private var callbacks: RecentsAnimationCallbacks? = null
+ private var taskbarUIController: TaskbarUIController? = null
private var tisBindHelper: TISBindHelper = TISBindHelper(this) {}
// Callback array that corresponds to events defined in @ActivityEvent
@@ -215,6 +218,11 @@
)
}
+ private val onBackInvokedCallback: () -> Unit = {
+ // If we are in live tile mode, launch the live task, otherwise return home
+ recentsView?.runningTaskView?.launchWithAnimation() ?: startHome()
+ }
+
private fun cleanupRecentsWindow() {
RecentsWindowProtoLogProxy.logCleanup(isShowing())
if (isShowing()) {
@@ -238,6 +246,10 @@
}
windowManager.addView(windowView, windowLayoutParams)
+ windowView
+ ?.findOnBackInvokedDispatcher()
+ ?.registerSystemOnBackInvokedCallback(onBackInvokedCallback)
+
windowView?.systemUiVisibility =
(View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
@@ -276,6 +288,10 @@
}
}
+ override fun getComponentName(): ComponentName {
+ return ComponentName(this, RecentsWindowManager::class.java)
+ }
+
override fun canStartHomeSafely(): Boolean {
val overviewCommandHelper = tisBindHelper.overviewCommandHelper
return overviewCommandHelper == null || overviewCommandHelper.canStartHomeSafely()
@@ -285,6 +301,18 @@
return tisBindHelper.desktopVisibilityController
}
+ override fun setTaskbarUIController(taskbarUIController: TaskbarUIController?) {
+ this.taskbarUIController = taskbarUIController
+ }
+
+ override fun getTaskbarUIController(): TaskbarUIController? {
+ return taskbarUIController
+ }
+
+ override fun getTISBindHelper(): TISBindHelper {
+ return tisBindHelper
+ }
+
fun registerInitListener(onInitListener: Predicate<Boolean>) {
this.onInitListener = onInitListener
}
diff --git a/quickstep/src/com/android/quickstep/recents/data/TasksRepository.kt b/quickstep/src/com/android/quickstep/recents/data/TasksRepository.kt
index 4f38ec7..275af00 100644
--- a/quickstep/src/com/android/quickstep/recents/data/TasksRepository.kt
+++ b/quickstep/src/com/android/quickstep/recents/data/TasksRepository.kt
@@ -73,13 +73,17 @@
getTaskDataById(taskId).map { it?.thumbnail }.distinctUntilChangedBy { it?.snapshotId }
override fun setVisibleTasks(visibleTaskIdList: Set<Int>) {
- Log.d(TAG, "setVisibleTasks: $visibleTaskIdList")
-
// Remove tasks are no longer visible
val tasksNoLongerVisible = taskRequests.keys.subtract(visibleTaskIdList)
removeTasks(tasksNoLongerVisible)
// Add new tasks to be requested
- visibleTaskIdList.subtract(taskRequests.keys).forEach { taskId -> requestTaskData(taskId) }
+ val newlyVisibleTasks = visibleTaskIdList.subtract(taskRequests.keys)
+ newlyVisibleTasks.forEach { taskId -> requestTaskData(taskId) }
+
+ if (tasksNoLongerVisible.isNotEmpty() || newlyVisibleTasks.isNotEmpty()) {
+ Log.d(TAG, "setVisibleTasks to: $visibleTaskIdList, " +
+ "removed: $tasksNoLongerVisible, added: $newlyVisibleTasks")
+ }
}
private fun requestTaskData(taskId: Int) {
diff --git a/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java b/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java
index 8762e86..623bc53 100644
--- a/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java
+++ b/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java
@@ -39,6 +39,7 @@
// The percentage of the previous speed that determines whether this is a rapid deceleration.
// The bigger this number, the easier it is to trigger the first pause.
private static final float RAPID_DECELERATION_FACTOR = 0.6f;
+ private static final float RAPID_DECELERATION_FACTOR_TRACKPAD = 0.85f;
/** If no motion is added for this amount of time, assume the motion has paused. */
private static final long FORCE_PAUSE_TIMEOUT = 300;
@@ -57,6 +58,7 @@
private final float mSpeedVerySlow;
private final float mSpeedSlow;
private final float mSpeedSomewhatFast;
+ private final float mSpeedTrackpadSomewhatFast;
private final float mSpeedFast;
private final Alarm mForcePauseTimeout;
private final boolean mMakePauseHarderToTrigger;
@@ -95,6 +97,8 @@
mSpeedVerySlow = res.getDimension(R.dimen.motion_pause_detector_speed_very_slow);
mSpeedSlow = res.getDimension(R.dimen.motion_pause_detector_speed_slow);
mSpeedSomewhatFast = res.getDimension(R.dimen.motion_pause_detector_speed_somewhat_fast);
+ mSpeedTrackpadSomewhatFast = res.getDimension(
+ R.dimen.motion_pause_detector_speed_trackpad_somewhat_fast);
mSpeedFast = res.getDimension(R.dimen.motion_pause_detector_speed_fast);
mForcePauseTimeout = new Alarm();
mForcePauseTimeout.setOnAlarmListener(alarm -> {
@@ -183,7 +187,9 @@
// takes too long, so also check for a rapid deceleration.
boolean isRapidDeceleration =
speed < previousSpeed * getRapidDecelerationFactor();
- isPaused = isRapidDeceleration && speed < mSpeedSomewhatFast;
+ boolean notSuperFast = speed < mSpeedSomewhatFast
+ || (mIsTrackpadGesture && speed < mSpeedTrackpadSomewhatFast);
+ isPaused = isRapidDeceleration && notSuperFast;
isPausedReason = new ActiveGestureLog.CompoundString(
"Didn't have back to back slow speeds, checking for rapid "
+ " deceleration on first pause only");
@@ -265,7 +271,8 @@
private float getRapidDecelerationFactor() {
return mIsTrackpadGesture ? Float.parseFloat(
Utilities.getSystemProperty("trackpad_in_app_swipe_up_deceleration_factor",
- String.valueOf(RAPID_DECELERATION_FACTOR))) : RAPID_DECELERATION_FACTOR;
+ String.valueOf(RAPID_DECELERATION_FACTOR_TRACKPAD)))
+ : RAPID_DECELERATION_FACTOR;
}
public interface OnMotionPauseListener {
diff --git a/quickstep/src/com/android/quickstep/util/SplitToWorkspaceController.java b/quickstep/src/com/android/quickstep/util/SplitToWorkspaceController.java
index 4962367..bdfaa48 100644
--- a/quickstep/src/com/android/quickstep/util/SplitToWorkspaceController.java
+++ b/quickstep/src/com/android/quickstep/util/SplitToWorkspaceController.java
@@ -48,8 +48,11 @@
import com.android.launcher3.uioverrides.QuickstepLauncher;
import com.android.quickstep.views.FloatingTaskView;
import com.android.quickstep.views.RecentsView;
+import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.system.InteractionJankMonitorWrapper;
+import java.util.Collections;
+
/** Handles when the stage split lands on the home screen. */
public class SplitToWorkspaceController {
@@ -133,10 +136,20 @@
// Use Launcher's default click handler
return false;
}
-
- mController.setSecondTask(intent, user, (ItemInfo) tag);
-
- startWorkspaceAnimation(view, null /*bitmap*/, bitmapInfo.newIcon(mLauncher));
+ // Check for background task matching this tag; if we find one, set second task
+ // via task instead of intent so the bounds and windowing mode will be corrected.
+ mController.findLastActiveTasksAndRunCallback(
+ Collections.singletonList(((ItemInfo) tag).getComponentKey()),
+ false /* findExactPairMatch */,
+ foundTasks -> {
+ Task foundTask = foundTasks[0];
+ if (foundTask != null) {
+ mController.setSecondTask(foundTask, (ItemInfo) tag);
+ } else {
+ mController.setSecondTask(intent, user, (ItemInfo) tag);
+ }
+ startWorkspaceAnimation(view, null /*bitmap*/, bitmapInfo.newIcon(mLauncher));
+ });
return true;
}
diff --git a/quickstep/src/com/android/quickstep/views/DesktopTaskContentView.kt b/quickstep/src/com/android/quickstep/views/DesktopTaskContentView.kt
new file mode 100644
index 0000000..481acac
--- /dev/null
+++ b/quickstep/src/com/android/quickstep/views/DesktopTaskContentView.kt
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.quickstep.views
+
+import android.content.Context
+import android.graphics.Outline
+import android.graphics.Rect
+import android.util.AttributeSet
+import android.view.View
+import android.view.ViewOutlineProvider
+import android.widget.FrameLayout
+import com.android.quickstep.views.TaskView.FullscreenDrawParams
+
+class DesktopTaskContentView
+@JvmOverloads
+constructor(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) {
+ private val currentFullscreenParams = FullscreenDrawParams(context)
+ private val taskCornerRadius: Float
+ get() = currentFullscreenParams.cornerRadius
+
+ private val bounds = Rect()
+
+ init {
+ clipToOutline = true
+ outlineProvider =
+ object : ViewOutlineProvider() {
+ override fun getOutline(view: View, outline: Outline) {
+ outline.setRoundRect(bounds, taskCornerRadius)
+ }
+ }
+ }
+
+ override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
+ super.onSizeChanged(w, h, oldw, oldh)
+ bounds.set(0, 0, w, h)
+ invalidateOutline()
+ }
+}
diff --git a/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt b/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt
index 15b0a6b..5e842aa 100644
--- a/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt
+++ b/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt
@@ -26,6 +26,7 @@
import android.util.Log
import android.view.Gravity
import android.view.View
+import android.widget.FrameLayout
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.updateLayoutParams
import com.android.launcher3.Flags.enableRefactorTaskThumbnail
@@ -81,12 +82,12 @@
private val tempRect = Rect()
private lateinit var backgroundView: View
private lateinit var iconView: TaskViewIcon
- private var childCountAtInflation = 0
+ private lateinit var contentView: FrameLayout
override fun onFinishInflate() {
super.onFinishInflate()
backgroundView =
- findViewById<View>(R.id.background)!!.apply {
+ findViewById<View>(R.id.background).apply {
updateLayoutParams<LayoutParams> {
topMargin = container.deviceProfile.overviewTaskThumbnailTopMarginPx
}
@@ -113,7 +114,12 @@
)
setText(resources.getText(R.string.recent_task_desktop))
}
- childCountAtInflation = childCount
+ contentView =
+ findViewById<FrameLayout>(R.id.desktop_content).apply {
+ updateLayoutParams<LayoutParams> {
+ topMargin = container.deviceProfile.overviewTaskThumbnailTopMarginPx
+ }
+ }
}
/** Updates this desktop task to the gives task list defined in `tasks` */
@@ -137,13 +143,8 @@
} else {
taskThumbnailViewDeprecatedPool!!.view
}
+ contentView.addView(snapshotView, 0)
- addView(
- snapshotView,
- // Add snapshotView to the front after initial views e.g. icon and
- // background.
- childCountAtInflation,
- )
TaskContainer(
this,
task,
@@ -164,7 +165,7 @@
super.onRecycle()
visibility = VISIBLE
taskContainers.forEach {
- removeView(it.snapshotView)
+ contentView.removeView(it.snapshotView)
if (enableRefactorTaskThumbnail()) {
taskThumbnailViewPool!!.recycle(it.thumbnailView)
} else {
@@ -227,9 +228,7 @@
width = (taskSize.width() * scaleWidth).toInt()
height = (taskSize.height() * scaleHeight).toInt()
leftMargin = (positionInParent.x * scaleWidth).toInt()
- topMargin =
- (positionInParent.y * scaleHeight).toInt() +
- container.deviceProfile.overviewTaskThumbnailTopMarginPx
+ topMargin = (positionInParent.y * scaleHeight).toInt()
}
if (DEBUG) {
with(it.snapshotView.layoutParams as LayoutParams) {
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index 2d0f15e..9a8041b 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -1245,21 +1245,24 @@
// - It's the focused task to be moved to the front, we immediately re-add the task
if (child instanceof TaskView && child != mSplitHiddenTaskView
&& child != mMovingTaskView) {
- TaskView taskView = (TaskView) child;
- for (int i : taskView.getTaskIds()) {
- mHasVisibleTaskData.delete(i);
- }
- if (child instanceof GroupedTaskView) {
- mGroupedTaskViewPool.recycle((GroupedTaskView) taskView);
- } else if (child instanceof DesktopTaskView) {
- mDesktopTaskViewPool.recycle((DesktopTaskView) taskView);
- } else {
- mTaskViewPool.recycle(taskView);
- }
- mActionsView.updateHiddenFlags(HIDDEN_NO_TASKS, getTaskViewCount() == 0);
+ clearAndRecycleTaskView((TaskView) child);
}
}
+ private void clearAndRecycleTaskView(TaskView taskView) {
+ for (int taskId : taskView.getTaskIds()) {
+ mHasVisibleTaskData.delete(taskId);
+ }
+ if (taskView instanceof GroupedTaskView) {
+ mGroupedTaskViewPool.recycle((GroupedTaskView) taskView);
+ } else if (taskView instanceof DesktopTaskView) {
+ mDesktopTaskViewPool.recycle((DesktopTaskView) taskView);
+ } else {
+ mTaskViewPool.recycle(taskView);
+ }
+ mActionsView.updateHiddenFlags(HIDDEN_NO_TASKS, getTaskViewCount() == 0);
+ }
+
@Override
public void onViewAdded(View child) {
super.onViewAdded(child);
@@ -5303,6 +5306,13 @@
mSplitHiddenTaskViewIndex = -1;
if (mSplitHiddenTaskView != null) {
mSplitHiddenTaskView.setThumbnailVisibility(VISIBLE, INVALID_TASK_ID);
+ // mSplitHiddenTaskView is set when split select animation starts. The TaskView is only
+ // removed when when the animation finishes. So in the case of overview being dismissed
+ // during the animation, we should not call clearAndRecycleTaskView() because it has
+ // not been removed yet.
+ if (mSplitHiddenTaskView.getParent() == null) {
+ clearAndRecycleTaskView(mSplitHiddenTaskView);
+ }
mSplitHiddenTaskView = null;
}
}
diff --git a/quickstep/src/com/android/quickstep/views/RecentsViewContainer.java b/quickstep/src/com/android/quickstep/views/RecentsViewContainer.java
index d8036aa..b04753b 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsViewContainer.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsViewContainer.java
@@ -16,8 +16,6 @@
package com.android.quickstep.views;
-import android.app.Activity;
-import android.content.ComponentName;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.LocusId;
@@ -27,13 +25,16 @@
import android.view.View;
import android.view.Window;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.launcher3.BaseActivity;
import com.android.launcher3.logger.LauncherAtom;
import com.android.launcher3.statehandlers.DesktopVisibilityController;
+import com.android.launcher3.taskbar.TaskbarUIController;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.ScrimView;
+import com.android.quickstep.util.TISBindHelper;
/**
* Interface to be implemented by the parent view of RecentsView
@@ -212,4 +213,10 @@
@Nullable
DesktopVisibilityController getDesktopVisibilityController();
+
+ void setTaskbarUIController(@Nullable TaskbarUIController taskbarUIController);
+
+ @Nullable TaskbarUIController getTaskbarUIController();
+
+ @NonNull TISBindHelper getTISBindHelper();
}
diff --git a/quickstep/src/com/android/quickstep/views/TaskContainer.kt b/quickstep/src/com/android/quickstep/views/TaskContainer.kt
index 959516f..25aba39 100644
--- a/quickstep/src/com/android/quickstep/views/TaskContainer.kt
+++ b/quickstep/src/com/android/quickstep/views/TaskContainer.kt
@@ -151,7 +151,7 @@
if (enableRefactorTaskThumbnail()) {
bindThumbnailView()
} else {
- thumbnailViewDeprecated.bind(task, overlay)
+ thumbnailViewDeprecated.bind(task, overlay, taskView)
}
overlay.init()
}
diff --git a/quickstep/src/com/android/quickstep/views/TaskThumbnailViewDeprecated.java b/quickstep/src/com/android/quickstep/views/TaskThumbnailViewDeprecated.java
index 56ca043..5dbc2ef 100644
--- a/quickstep/src/com/android/quickstep/views/TaskThumbnailViewDeprecated.java
+++ b/quickstep/src/com/android/quickstep/views/TaskThumbnailViewDeprecated.java
@@ -110,6 +110,7 @@
private TaskView.FullscreenDrawParams mFullscreenParams;
private ImageView mSplashView;
private Drawable mSplashViewDrawable;
+ private TaskView mTaskView;
@Nullable
private Task mTask;
@@ -153,10 +154,11 @@
/**
* Updates the thumbnail to draw the provided task
*/
- public void bind(Task task, TaskOverlay<?> overlay) {
+ public void bind(Task task, TaskOverlay<?> overlay, TaskView taskView) {
mOverlay = overlay;
mOverlay.reset();
mTask = task;
+ mTaskView = taskView;
int color = task == null ? Color.BLACK : task.colorBackground | 0xFF000000;
mPaint.setColor(color);
mBackgroundPaint.setColor(color);
@@ -292,8 +294,8 @@
public void drawOnCanvas(Canvas canvas, float x, float y, float width, float height,
float cornerRadius) {
- if (mTask != null && getTaskView().isRunningTask()
- && !getTaskView().getShouldShowScreenshot()) {
+ if (mTask != null && mTaskView.isRunningTask()
+ && !mTaskView.getShouldShowScreenshot()) {
canvas.drawRoundRect(x, y, width, height, cornerRadius, cornerRadius, mClearPaint);
canvas.drawRoundRect(x, y, width, height, cornerRadius, cornerRadius,
mDimmingPaintAfterClearing);
@@ -334,10 +336,6 @@
}
}
- public TaskView getTaskView() {
- return (TaskView) getParent();
- }
-
public void setOverlayEnabled(boolean overlayEnabled) {
if (mOverlayEnabled != overlayEnabled) {
mOverlayEnabled = overlayEnabled;
@@ -390,9 +388,9 @@
float viewCenterY = viewHeight / 2f;
float centeredDrawableLeft = (viewWidth - drawableWidth) / 2f;
float centeredDrawableTop = (viewHeight - drawableHeight) / 2f;
- float nonGridScale = getTaskView() == null ? 1 : 1 / getTaskView().getNonGridScale();
- float recentsMaxScale = getTaskView() == null || getTaskView().getRecentsView() == null
- ? 1 : 1 / getTaskView().getRecentsView().getMaxScaleForFullScreen();
+ float nonGridScale = mTaskView == null ? 1 : 1 / mTaskView.getNonGridScale();
+ float recentsMaxScale = mTaskView == null || mTaskView.getRecentsView() == null
+ ? 1 : 1 / mTaskView.getRecentsView().getMaxScaleForFullScreen();
float scaleX = nonGridScale * recentsMaxScale * (1 / getScaleX());
float scaleY = nonGridScale * recentsMaxScale * (1 / getScaleY());
@@ -419,7 +417,7 @@
}
private boolean isThumbnailRotationDifferentFromTask() {
- RecentsView recents = getTaskView().getRecentsView();
+ RecentsView recents = mTaskView.getRecentsView();
if (recents == null || mThumbnailData == null) {
return false;
}
@@ -467,7 +465,7 @@
if (mBitmapShader != null && mThumbnailData != null) {
mPreviewRect.set(0, 0, mThumbnailData.getThumbnail().getWidth(),
mThumbnailData.getThumbnail().getHeight());
- int currentRotation = getTaskView().getOrientedState().getRecentsActivityRotation();
+ int currentRotation = mTaskView.getOrientedState().getRecentsActivityRotation();
boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
mPreviewPositionHelper.updateThumbnailMatrix(mPreviewRect, mThumbnailData,
getMeasuredWidth(), getMeasuredHeight(), dp.isTablet, currentRotation, isRtl);
@@ -475,7 +473,7 @@
mBitmapShader.setLocalMatrix(mPreviewPositionHelper.getMatrix());
mPaint.setShader(mBitmapShader);
}
- getTaskView().updateCurrentFullscreenParams();
+ mTaskView.updateCurrentFullscreenParams();
invalidate();
}
diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarAutohideSuspendControllerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarAutohideSuspendControllerTest.kt
index 59900b1..cfa12e2 100644
--- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarAutohideSuspendControllerTest.kt
+++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarAutohideSuspendControllerTest.kt
@@ -33,36 +33,27 @@
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
-import org.junit.rules.TestRule
import org.junit.runner.RunWith
-import org.junit.runners.model.Statement
@RunWith(LauncherMultivalentJUnit::class)
@EmulatedDevices(["pixelTablet2023"])
class TaskbarAutohideSuspendControllerTest {
- @get:Rule(order = 0) val context = TaskbarWindowSandboxContext.create()
- @get:Rule(order = 1) val animatorTestRule = AnimatorTestRule(this)
- @get:Rule(order = 2)
- val systemUiProxyRule = TestRule { base, _ ->
- object : Statement() {
- override fun evaluate() {
- getInstrumentation().runOnMainSync {
- context.putObject(
- SystemUiProxy.INSTANCE,
- object : SystemUiProxy(context) {
- override fun notifyTaskbarAutohideSuspend(suspend: Boolean) {
- latestSuspendNotification = suspend
- }
- },
- )
+ @get:Rule(order = 0)
+ val context =
+ TaskbarWindowSandboxContext.create { builder ->
+ builder.bindSystemUiProxy(
+ object : SystemUiProxy(this) {
+ override fun notifyTaskbarAutohideSuspend(suspend: Boolean) {
+ super.notifyTaskbarAutohideSuspend(suspend)
+ latestSuspendNotification = suspend
+ }
}
- base.evaluate()
- }
+ )
}
- }
- @get:Rule(order = 3) val taskbarModeRule = TaskbarModeRule(context)
- @get:Rule(order = 4) val taskbarUnitTestRule = TaskbarUnitTestRule(this, context)
+ @get:Rule(order = 1) val animatorTestRule = AnimatorTestRule(this)
+ @get:Rule(order = 2) val taskbarModeRule = TaskbarModeRule(context)
+ @get:Rule(order = 3) val taskbarUnitTestRule = TaskbarUnitTestRule(this, context)
@InjectController lateinit var autohideSuspendController: TaskbarAutohideSuspendController
@InjectController lateinit var stashController: TaskbarStashController
diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarScrimViewControllerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarScrimViewControllerTest.kt
index 12e84b8..3912051 100644
--- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarScrimViewControllerTest.kt
+++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarScrimViewControllerTest.kt
@@ -42,7 +42,18 @@
@RunWith(LauncherMultivalentJUnit::class)
@EmulatedDevices(["pixelTablet2023"])
class TaskbarScrimViewControllerTest {
- @get:Rule(order = 0) val context = TaskbarWindowSandboxContext.create()
+ @get:Rule(order = 0)
+ val context =
+ TaskbarWindowSandboxContext.create { builder ->
+ builder.bindSystemUiProxy(
+ object : SystemUiProxy(this) {
+ override fun onBackPressed() {
+ super.onBackPressed()
+ backPressed = true
+ }
+ }
+ )
+ }
@get:Rule(order = 1) val taskbarModeRule = TaskbarModeRule(context)
@get:Rule(order = 2) val animatorTestRule = AnimatorTestRule(this)
@get:Rule(order = 3) val taskbarUnitTestRule = TaskbarUnitTestRule(this, context)
@@ -53,6 +64,8 @@
private val animationDuration =
context.resources.getInteger(android.R.integer.config_mediumAnimTime).toLong()
+ private var backPressed = false
+
@Test
@TaskbarMode(PINNED)
fun testOnTaskbarVisibleChanged_onlyTaskbarVisible_noScrim() {
@@ -130,16 +143,6 @@
@Test
@TaskbarMode(PINNED)
fun testOnClick_scrimShown_performsSystemBack() {
- var backPressed = false
- context.putObject(
- SystemUiProxy.INSTANCE,
- object : SystemUiProxy(context) {
- override fun onBackPressed() {
- backPressed = true
- }
- },
- )
-
getInstrumentation().runOnMainSync {
scrimViewController.updateStateForSysuiFlags(SYSUI_STATE_BUBBLES_EXPANDED, true)
scrimViewController.onTaskbarVisibilityChanged(VISIBLE)
diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimatorTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimatorTest.kt
index b0d01d3..48f3fc2 100644
--- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimatorTest.kt
+++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimatorTest.kt
@@ -25,6 +25,7 @@
import android.view.View
import android.view.View.VISIBLE
import android.widget.FrameLayout
+import android.widget.TextView
import androidx.core.animation.AnimatorTestRule
import androidx.core.graphics.drawable.toBitmap
import androidx.dynamicanimation.animation.DynamicAnimation
@@ -834,23 +835,27 @@
// advance the animation handler by the duration of the initial lift
InstrumentationRegistry.getInstrumentation().runOnMainSync {
- animatorTestRule.advanceTimeBy(250)
+ animatorTestRule.advanceTimeBy(100)
}
- // the lift animation is complete; the spring back animation should start now
- InstrumentationRegistry.getInstrumentation().runOnMainSync {}
- barAnimator.assertIsRunning()
- PhysicsAnimatorTestUtils.blockUntilFirstAnimationFrameWhereTrue(barAnimator) { true }
+ // send the expand signal in the middle of the lift animation
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ animator.expandedWhileAnimating()
+ }
+
+ // let the lift animation complete
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ animatorTestRule.advanceTimeBy(150)
+ }
// verify there is a pending hide animation
assertThat(animatorScheduler.delayedBlock).isNotNull()
assertThat(animator.isAnimating).isTrue()
- InstrumentationRegistry.getInstrumentation().runOnMainSync {
- animator.expandedWhileAnimating()
- }
-
- // let the animation finish
+ // the lift animation is complete; the spring back animation should start now. wait for it
+ // to complete
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {}
+ barAnimator.assertIsRunning()
PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
// verify that the hide animation was canceled
@@ -923,6 +928,344 @@
assertThat(notifiedExpanded).isTrue()
}
+ @Test
+ fun interruptAnimation_whileAnimatingIn() {
+ setUpBubbleBar()
+ setUpBubbleStashController()
+
+ val handle = View(context)
+ val handleAnimator = PhysicsAnimator.getInstance(handle)
+ whenever(bubbleStashController.getStashedHandlePhysicsAnimator()).thenReturn(handleAnimator)
+
+ val animator =
+ BubbleBarViewAnimator(
+ bubbleBarView,
+ bubbleStashController,
+ flyoutController,
+ onExpandedNoOp,
+ animatorScheduler,
+ )
+
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ animator.animateBubbleInForStashed(bubble, isExpanding = false)
+ }
+
+ // let the animation start and wait until the first frame
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {}
+ PhysicsAnimatorTestUtils.blockUntilFirstAnimationFrameWhereTrue(handleAnimator) { true }
+
+ handleAnimator.assertIsRunning()
+ assertThat(animator.isAnimating).isTrue()
+
+ val updatedBubble =
+ bubble.copy(flyoutMessage = bubble.flyoutMessage!!.copy(message = "updated message"))
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ bubbleView.setBubble(updatedBubble)
+ animator.animateBubbleInForStashed(updatedBubble, isExpanding = false)
+ }
+
+ PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
+
+ assertThat(handle.alpha).isEqualTo(0)
+ assertThat(handle.translationY)
+ .isEqualTo(DIFF_BETWEEN_HANDLE_AND_BAR_CENTERS + BAR_TRANSLATION_Y_FOR_TASKBAR)
+ assertThat(bubbleBarView.visibility).isEqualTo(VISIBLE)
+ assertThat(bubbleBarView.scaleX).isEqualTo(1)
+ assertThat(bubbleBarView.scaleY).isEqualTo(1)
+ assertThat(bubbleBarView.translationY).isEqualTo(BAR_TRANSLATION_Y_FOR_TASKBAR)
+ assertThat(animator.isAnimating).isTrue()
+
+ waitForFlyoutToShow()
+ assertThat(flyoutView!!.findViewById<TextView>(R.id.bubble_flyout_text).text)
+ .isEqualTo("updated message")
+
+ // run the hide animation
+ assertThat(animatorScheduler.delayedBlock).isNotNull()
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(animatorScheduler.delayedBlock!!)
+
+ waitForFlyoutToHide()
+
+ // let the animation start and wait for it to complete
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {}
+ PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
+
+ assertThat(handle.alpha).isEqualTo(1)
+ assertThat(handle.translationY).isEqualTo(0)
+ assertThat(bubbleBarView.alpha).isEqualTo(0)
+ assertThat(animator.isAnimating).isFalse()
+ verify(bubbleStashController).stashBubbleBarImmediate()
+ }
+
+ @Test
+ fun interruptAnimation_whileIn() {
+ setUpBubbleBar()
+ setUpBubbleStashController()
+
+ val handle = View(context)
+ val handleAnimator = PhysicsAnimator.getInstance(handle)
+ whenever(bubbleStashController.getStashedHandlePhysicsAnimator()).thenReturn(handleAnimator)
+
+ val animator =
+ BubbleBarViewAnimator(
+ bubbleBarView,
+ bubbleStashController,
+ flyoutController,
+ onExpandedNoOp,
+ animatorScheduler,
+ )
+
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ animator.animateBubbleInForStashed(bubble, isExpanding = false)
+ }
+
+ // let the animation start and wait for it to complete
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {}
+ PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
+
+ assertThat(handle.alpha).isEqualTo(0)
+ assertThat(handle.translationY)
+ .isEqualTo(DIFF_BETWEEN_HANDLE_AND_BAR_CENTERS + BAR_TRANSLATION_Y_FOR_TASKBAR)
+ assertThat(bubbleBarView.visibility).isEqualTo(VISIBLE)
+ assertThat(bubbleBarView.scaleX).isEqualTo(1)
+ assertThat(bubbleBarView.scaleY).isEqualTo(1)
+ assertThat(bubbleBarView.translationY).isEqualTo(BAR_TRANSLATION_Y_FOR_TASKBAR)
+ assertThat(animator.isAnimating).isTrue()
+
+ waitForFlyoutToShow()
+
+ assertThat(flyoutView!!.findViewById<TextView>(R.id.bubble_flyout_text).text)
+ .isEqualTo("message")
+
+ // verify the hide animation is pending
+ assertThat(animatorScheduler.delayedBlock).isNotNull()
+
+ val updatedBubble =
+ bubble.copy(flyoutMessage = bubble.flyoutMessage!!.copy(message = "updated message"))
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ bubbleView.setBubble(updatedBubble)
+ animator.animateBubbleInForStashed(updatedBubble, isExpanding = false)
+ }
+
+ // verify the hide animation was rescheduled
+ assertThat(animatorScheduler.canceledBlock).isNotNull()
+ assertThat(animatorScheduler.delayedBlock).isNotNull()
+
+ waitForFlyoutToFadeOutAndBackIn()
+
+ assertThat(flyoutView!!.findViewById<TextView>(R.id.bubble_flyout_text).text)
+ .isEqualTo("updated message")
+
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(animatorScheduler.delayedBlock!!)
+
+ waitForFlyoutToHide()
+
+ // let the animation start and wait for it to complete
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {}
+ PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
+
+ assertThat(handle.alpha).isEqualTo(1)
+ assertThat(handle.translationY).isEqualTo(0)
+ assertThat(bubbleBarView.alpha).isEqualTo(0)
+ assertThat(animator.isAnimating).isFalse()
+ verify(bubbleStashController).stashBubbleBarImmediate()
+ }
+
+ @Test
+ fun interruptAnimation_whileAnimatingOut_whileCollapsingFlyout() {
+ setUpBubbleBar()
+ setUpBubbleStashController()
+
+ val handle = View(context)
+ val handleAnimator = PhysicsAnimator.getInstance(handle)
+ whenever(bubbleStashController.getStashedHandlePhysicsAnimator()).thenReturn(handleAnimator)
+
+ val animator =
+ BubbleBarViewAnimator(
+ bubbleBarView,
+ bubbleStashController,
+ flyoutController,
+ onExpandedNoOp,
+ animatorScheduler,
+ )
+
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ animator.animateBubbleInForStashed(bubble, isExpanding = false)
+ }
+
+ // let the animation start and wait for it to complete
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {}
+ PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
+
+ assertThat(handle.alpha).isEqualTo(0)
+ assertThat(handle.translationY)
+ .isEqualTo(DIFF_BETWEEN_HANDLE_AND_BAR_CENTERS + BAR_TRANSLATION_Y_FOR_TASKBAR)
+ assertThat(bubbleBarView.visibility).isEqualTo(VISIBLE)
+ assertThat(bubbleBarView.scaleX).isEqualTo(1)
+ assertThat(bubbleBarView.scaleY).isEqualTo(1)
+ assertThat(bubbleBarView.translationY).isEqualTo(BAR_TRANSLATION_Y_FOR_TASKBAR)
+ assertThat(animator.isAnimating).isTrue()
+
+ waitForFlyoutToShow()
+
+ assertThat(flyoutView!!.findViewById<TextView>(R.id.bubble_flyout_text).text)
+ .isEqualTo("message")
+
+ // run the hide animation
+ assertThat(animatorScheduler.delayedBlock).isNotNull()
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(animatorScheduler.delayedBlock!!)
+
+ // interrupt the animation while the flyout is collapsing
+ val updatedBubble =
+ bubble.copy(flyoutMessage = bubble.flyoutMessage!!.copy(message = "updated message"))
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ animatorTestRule.advanceTimeBy(100)
+ bubbleView.setBubble(updatedBubble)
+ animator.animateBubbleInForStashed(updatedBubble, isExpanding = false)
+
+ // the flyout should now reverse and expand
+ animatorTestRule.advanceTimeBy(100)
+ }
+
+ assertThat(flyoutView!!.findViewById<TextView>(R.id.bubble_flyout_text).text)
+ .isEqualTo("updated message")
+
+ assertThat(handle.alpha).isEqualTo(0)
+ assertThat(handle.translationY)
+ .isEqualTo(DIFF_BETWEEN_HANDLE_AND_BAR_CENTERS + BAR_TRANSLATION_Y_FOR_TASKBAR)
+ assertThat(bubbleBarView.visibility).isEqualTo(VISIBLE)
+ assertThat(bubbleBarView.scaleX).isEqualTo(1)
+ assertThat(bubbleBarView.scaleY).isEqualTo(1)
+ assertThat(bubbleBarView.translationY).isEqualTo(BAR_TRANSLATION_Y_FOR_TASKBAR)
+
+ // verify the hide animation was rescheduled and run it
+ assertThat(animatorScheduler.delayedBlock).isNotNull()
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(animatorScheduler.delayedBlock!!)
+
+ waitForFlyoutToHide()
+
+ // let the animation start and wait for it to complete
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {}
+ PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
+
+ assertThat(handle.alpha).isEqualTo(1)
+ assertThat(handle.translationY).isEqualTo(0)
+ assertThat(bubbleBarView.alpha).isEqualTo(0)
+ assertThat(animator.isAnimating).isFalse()
+ verify(bubbleStashController).stashBubbleBarImmediate()
+ }
+
+ @Test
+ fun interruptAnimation_whileAnimatingOut_barToHandle() {
+ setUpBubbleBar()
+ setUpBubbleStashController()
+
+ val handle = View(context)
+ val handleAnimator = PhysicsAnimator.getInstance(handle)
+ whenever(bubbleStashController.getStashedHandlePhysicsAnimator()).thenReturn(handleAnimator)
+
+ val animator =
+ BubbleBarViewAnimator(
+ bubbleBarView,
+ bubbleStashController,
+ flyoutController,
+ onExpandedNoOp,
+ animatorScheduler,
+ )
+
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ animator.animateBubbleInForStashed(bubble, isExpanding = false)
+ }
+
+ // let the animation start and wait for it to complete
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {}
+ PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
+
+ assertThat(handle.alpha).isEqualTo(0)
+ assertThat(handle.translationY)
+ .isEqualTo(DIFF_BETWEEN_HANDLE_AND_BAR_CENTERS + BAR_TRANSLATION_Y_FOR_TASKBAR)
+ assertThat(bubbleBarView.visibility).isEqualTo(VISIBLE)
+ assertThat(bubbleBarView.scaleX).isEqualTo(1)
+ assertThat(bubbleBarView.scaleY).isEqualTo(1)
+ assertThat(bubbleBarView.translationY).isEqualTo(BAR_TRANSLATION_Y_FOR_TASKBAR)
+ assertThat(animator.isAnimating).isTrue()
+
+ waitForFlyoutToShow()
+
+ assertThat(flyoutView!!.findViewById<TextView>(R.id.bubble_flyout_text).text)
+ .isEqualTo("message")
+
+ // run the hide animation
+ assertThat(animatorScheduler.delayedBlock).isNotNull()
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(animatorScheduler.delayedBlock!!)
+
+ waitForFlyoutToHide()
+
+ // interrupt the animation while the bar is animating to the handle
+ PhysicsAnimatorTestUtils.blockUntilFirstAnimationFrameWhereTrue(handleAnimator) {
+ bubbleBarView.alpha < 0.5
+ }
+
+ // we're about to interrupt the animation which will cancel the current animation and start
+ // a new one. pause the scheduler to delay starting the new animation. this allows us to run
+ // the test deterministically
+ animatorScheduler.pauseScheduler = true
+
+ val updatedBubble =
+ bubble.copy(flyoutMessage = bubble.flyoutMessage!!.copy(message = "updated message"))
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ bubbleView.setBubble(updatedBubble)
+ animator.animateBubbleInForStashed(updatedBubble, isExpanding = false)
+ }
+
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {}
+ PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
+
+ // verify there's a new job scheduled and start it. this is starting the animation from the
+ // handle back to the bar
+ assertThat(animatorScheduler.pausedBlock).isNotNull()
+ animatorScheduler.pauseScheduler = false
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(animatorScheduler.pausedBlock!!)
+
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {}
+ PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
+
+ waitForFlyoutToShow()
+
+ assertThat(flyoutView!!.findViewById<TextView>(R.id.bubble_flyout_text).text)
+ .isEqualTo("updated message")
+ assertThat(handle.alpha).isEqualTo(0)
+ assertThat(handle.translationY)
+ .isEqualTo(DIFF_BETWEEN_HANDLE_AND_BAR_CENTERS + BAR_TRANSLATION_Y_FOR_TASKBAR)
+ assertThat(bubbleBarView.visibility).isEqualTo(VISIBLE)
+ assertThat(bubbleBarView.scaleX).isEqualTo(1)
+ assertThat(bubbleBarView.scaleY).isEqualTo(1)
+ assertThat(bubbleBarView.translationY).isEqualTo(BAR_TRANSLATION_Y_FOR_TASKBAR)
+
+ // run the hide animation
+ assertThat(animatorScheduler.delayedBlock).isNotNull()
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(animatorScheduler.delayedBlock!!)
+
+ waitForFlyoutToHide()
+
+ PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
+
+ // verify the hide animation was rescheduled and run it
+ assertThat(animatorScheduler.delayedBlock).isNotNull()
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(animatorScheduler.delayedBlock!!)
+
+ waitForFlyoutToHide()
+
+ // let the animation start and wait for it to complete
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {}
+ PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
+
+ assertThat(handle.alpha).isEqualTo(1)
+ assertThat(handle.translationY).isEqualTo(0)
+ assertThat(bubbleBarView.alpha).isEqualTo(0)
+ assertThat(animator.isAnimating).isFalse()
+ verify(bubbleStashController).stashBubbleBarImmediate()
+ }
+
private fun setUpBubbleBar() {
bubbleBarView = BubbleBarView(context)
InstrumentationRegistry.getInstrumentation().runOnMainSync {
@@ -1019,18 +1362,25 @@
private fun waitForFlyoutToShow() {
InstrumentationRegistry.getInstrumentation().runOnMainSync {
- animatorTestRule.advanceTimeBy(300)
+ animatorTestRule.advanceTimeBy(250)
}
assertThat(flyoutView).isNotNull()
}
private fun waitForFlyoutToHide() {
InstrumentationRegistry.getInstrumentation().runOnMainSync {
- animatorTestRule.advanceTimeBy(300)
+ animatorTestRule.advanceTimeBy(250)
}
assertThat(flyoutView).isNull()
}
+ private fun waitForFlyoutToFadeOutAndBackIn() {
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ animatorTestRule.advanceTimeBy(500)
+ }
+ assertThat(flyoutView).isNotNull()
+ }
+
private fun <T> PhysicsAnimator<T>.assertIsRunning() {
InstrumentationRegistry.getInstrumentation().runOnMainSync {
assertThat(isRunning()).isTrue()
@@ -1045,20 +1395,30 @@
private class TestBubbleBarViewAnimatorScheduler : BubbleBarViewAnimator.Scheduler {
+ var pauseScheduler = false
+ var pausedBlock: Runnable? = null
+ private set
+
var delayedBlock: Runnable? = null
private set
+ var canceledBlock: Runnable? = null
+ private set
+
override fun post(block: Runnable) {
+ if (pauseScheduler) {
+ pausedBlock = block
+ return
+ }
block.run()
}
override fun postDelayed(delayMillis: Long, block: Runnable) {
- check(delayedBlock == null) { "there is already a pending block waiting to run" }
delayedBlock = block
}
override fun cancel(block: Runnable) {
- check(delayedBlock == block) { "the pending block does not match the canceled block" }
+ canceledBlock = delayedBlock
delayedBlock = null
}
}
diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/flyout/BubbleBarFlyoutControllerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/flyout/BubbleBarFlyoutControllerTest.kt
index 50bb9bc..2997ac9 100644
--- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/flyout/BubbleBarFlyoutControllerTest.kt
+++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/flyout/BubbleBarFlyoutControllerTest.kt
@@ -76,7 +76,7 @@
@Test
fun flyoutPosition_left() {
InstrumentationRegistry.getInstrumentation().runOnMainSync {
- flyoutController.setUpAndShowFlyout(flyoutMessage) {}
+ setupAndShowFlyout()
assertThat(flyoutContainer.childCount).isEqualTo(1)
val flyout = flyoutContainer.getChildAt(0)
val lp = flyout.layoutParams as FrameLayout.LayoutParams
@@ -89,7 +89,7 @@
fun flyoutPosition_right() {
onLeft = false
InstrumentationRegistry.getInstrumentation().runOnMainSync {
- flyoutController.setUpAndShowFlyout(flyoutMessage) {}
+ setupAndShowFlyout()
assertThat(flyoutContainer.childCount).isEqualTo(1)
val flyout = flyoutContainer.getChildAt(0)
val lp = flyout.layoutParams as FrameLayout.LayoutParams
@@ -101,7 +101,7 @@
@Test
fun flyoutMessage() {
InstrumentationRegistry.getInstrumentation().runOnMainSync {
- flyoutController.setUpAndShowFlyout(flyoutMessage) {}
+ setupAndShowFlyout()
assertThat(flyoutContainer.childCount).isEqualTo(1)
val flyout = flyoutContainer.getChildAt(0)
val sender = flyout.findViewById<TextView>(R.id.bubble_flyout_title)
@@ -114,7 +114,7 @@
@Test
fun hideFlyout_removedFromContainer() {
InstrumentationRegistry.getInstrumentation().runOnMainSync {
- flyoutController.setUpAndShowFlyout(flyoutMessage) {}
+ setupAndShowFlyout()
assertThat(flyoutController.hasFlyout()).isTrue()
assertThat(flyoutContainer.childCount).isEqualTo(1)
flyoutController.collapseFlyout {}
@@ -130,7 +130,7 @@
// boundary
flyoutTy = -50f
InstrumentationRegistry.getInstrumentation().runOnMainSync {
- flyoutController.setUpAndShowFlyout(flyoutMessage) {}
+ setupAndShowFlyout()
assertThat(flyoutContainer.childCount).isEqualTo(1)
}
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
@@ -143,7 +143,7 @@
@Test
fun showFlyout_withinBoundary() {
InstrumentationRegistry.getInstrumentation().runOnMainSync {
- flyoutController.setUpAndShowFlyout(flyoutMessage) {}
+ setupAndShowFlyout()
assertThat(flyoutContainer.childCount).isEqualTo(1)
}
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
@@ -156,7 +156,7 @@
@Test
fun collapseFlyout_resetsTopBoundary() {
InstrumentationRegistry.getInstrumentation().runOnMainSync {
- flyoutController.setUpAndShowFlyout(flyoutMessage) {}
+ setupAndShowFlyout()
assertThat(flyoutContainer.childCount).isEqualTo(1)
flyoutController.collapseFlyout {}
animatorTestRule.advanceTimeBy(300)
@@ -167,7 +167,7 @@
@Test
fun cancelFlyout_fadesOutFlyout() {
InstrumentationRegistry.getInstrumentation().runOnMainSync {
- flyoutController.setUpAndShowFlyout(flyoutMessage) {}
+ setupAndShowFlyout()
assertThat(flyoutContainer.childCount).isEqualTo(1)
val flyoutView = flyoutContainer.findViewById<View>(R.id.bubble_bar_flyout_view)
assertThat(flyoutView.alpha).isEqualTo(1f)
@@ -181,7 +181,7 @@
@Test
fun clickFlyout_notifiesCallback() {
InstrumentationRegistry.getInstrumentation().runOnMainSync {
- flyoutController.setUpAndShowFlyout(flyoutMessage) {}
+ setupAndShowFlyout()
assertThat(flyoutContainer.childCount).isEqualTo(1)
val flyoutView = flyoutContainer.findViewById<View>(R.id.bubble_bar_flyout_view)
assertThat(flyoutView.alpha).isEqualTo(1f)
@@ -194,7 +194,7 @@
@Test
fun updateFlyoutWhileExpanding() {
InstrumentationRegistry.getInstrumentation().runOnMainSync {
- flyoutController.setUpAndShowFlyout(flyoutMessage) {}
+ setupAndShowFlyout()
assertThat(flyoutController.hasFlyout()).isTrue()
val flyout = flyoutContainer.findViewById<View>(R.id.bubble_bar_flyout_view)
assertThat(flyout.findViewById<TextView>(R.id.bubble_flyout_text).text)
@@ -220,7 +220,7 @@
@Test
fun updateFlyoutFullyExpanded() {
InstrumentationRegistry.getInstrumentation().runOnMainSync {
- flyoutController.setUpAndShowFlyout(flyoutMessage) {}
+ setupAndShowFlyout()
animatorTestRule.advanceTimeBy(300)
}
assertThat(flyoutController.hasFlyout()).isTrue()
@@ -246,6 +246,44 @@
assertThat(flyoutCallbacks.topBoundaryExtendedSpace).isEqualTo(50)
}
+ @Test
+ fun updateFlyoutWhileCollapsing() {
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ setupAndShowFlyout()
+ animatorTestRule.advanceTimeBy(300)
+ }
+ assertThat(flyoutController.hasFlyout()).isTrue()
+
+ val newFlyoutMessage = flyoutMessage.copy(message = "new message")
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ var flyoutCollapsed = false
+ flyoutController.collapseFlyout { flyoutCollapsed = true }
+ // advance the fake timer so that the collapse animation runs for 125ms
+ animatorTestRule.advanceTimeBy(125)
+
+ // update the flyout in the middle of collapsing, which should start expanding it.
+ var flyoutReversed = false
+ flyoutController.updateFlyoutWhileCollapsing(newFlyoutMessage) { flyoutReversed = true }
+
+ // the collapse animation ran for 125ms when it was updated, so reversing it should only
+ // run for the same amount of time
+ animatorTestRule.advanceTimeBy(125)
+ val flyout = flyoutContainer.findViewById<View>(R.id.bubble_bar_flyout_view)
+ assertThat(flyout.alpha).isEqualTo(1)
+ assertThat(flyout.findViewById<TextView>(R.id.bubble_flyout_text).text)
+ .isEqualTo("new message")
+ // verify that we never called the end action on the collapse animation
+ assertThat(flyoutCollapsed).isFalse()
+ // verify that we called the end action on the reverse animation
+ assertThat(flyoutReversed).isTrue()
+ }
+ assertThat(flyoutController.hasFlyout()).isTrue()
+ }
+
+ private fun setupAndShowFlyout() {
+ flyoutController.setUpAndShowFlyout(flyoutMessage, {}, {})
+ }
+
class FakeFlyoutCallbacks : FlyoutCallbacks {
var topBoundaryExtendedSpace = 0
diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarUnitTestRule.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarUnitTestRule.kt
index b0d706f..096f879 100644
--- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarUnitTestRule.kt
+++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarUnitTestRule.kt
@@ -19,12 +19,10 @@
import android.app.Instrumentation
import android.app.PendingIntent
import android.content.IIntentSender
-import android.content.Intent
-import android.provider.Settings
import android.provider.Settings.Secure.NAV_BAR_KIDS_MODE
import android.provider.Settings.Secure.USER_SETUP_COMPLETE
+import android.provider.Settings.Secure.getUriFor
import androidx.test.platform.app.InstrumentationRegistry
-import androidx.test.rule.ServiceTestRule
import com.android.launcher3.LauncherAppState
import com.android.launcher3.statehandlers.DesktopVisibilityController
import com.android.launcher3.taskbar.TaskbarActivityContext
@@ -35,16 +33,12 @@
import com.android.launcher3.taskbar.bubbles.BubbleControllers
import com.android.launcher3.taskbar.rules.TaskbarUnitTestRule.InjectController
import com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR
-import com.android.launcher3.util.LauncherMultivalentJUnit.Companion.isRunningInRobolectric
import com.android.launcher3.util.TestUtil
import com.android.quickstep.AllAppsActionManager
-import com.android.quickstep.TouchInteractionService
-import com.android.quickstep.TouchInteractionService.TISBinder
import java.lang.reflect.Field
import java.lang.reflect.ParameterizedType
import java.util.Optional
import org.junit.Assume.assumeTrue
-import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
@@ -81,11 +75,6 @@
) : TestRule {
private val instrumentation = InstrumentationRegistry.getInstrumentation()
- private val serviceTestRule = ServiceTestRule()
-
- private val userSetupCompleteRule = TaskbarSecureSettingRule(USER_SETUP_COMPLETE)
- private val kidsModeRule = TaskbarSecureSettingRule(NAV_BAR_KIDS_MODE)
- private val settingRules = RuleChain.outerRule(userSetupCompleteRule).around(kidsModeRule)
private lateinit var taskbarManager: TaskbarManager
@@ -96,10 +85,6 @@
}
override fun apply(base: Statement, description: Description): Statement {
- return settingRules.apply(createStatement(base, description), description)
- }
-
- private fun createStatement(base: Statement, description: Description): Statement {
return object : Statement() {
override fun evaluate() {
@@ -111,34 +96,10 @@
}
// Process secure setting annotations.
- instrumentation.runOnMainSync {
- userSetupCompleteRule.putInt(
- if (description.getAnnotation(UserSetupMode::class.java) != null) {
- 0
- } else {
- 1
- }
- )
- kidsModeRule.putInt(
- if (description.getAnnotation(NavBarKidsMode::class.java) != null) 1 else 0
- )
- }
-
- // Check for existing Taskbar instance from Launcher process.
- val launcherTaskbarManager: TaskbarManager? =
- if (!isRunningInRobolectric) {
- try {
- val tisBinder =
- serviceTestRule.bindService(
- Intent(context, TouchInteractionService::class.java)
- ) as? TISBinder
- tisBinder?.taskbarManager
- } catch (_: Exception) {
- null
- }
- } else {
- null
- }
+ context.settingsCacheSandbox[getUriFor(USER_SETUP_COMPLETE)] =
+ if (description.getAnnotation(UserSetupMode::class.java) != null) 0 else 1
+ context.settingsCacheSandbox[getUriFor(NAV_BAR_KIDS_MODE)] =
+ if (description.getAnnotation(NavBarKidsMode::class.java) != null) 1 else 0
taskbarManager =
TestUtil.getOnUiThread {
@@ -161,20 +122,12 @@
try {
TaskbarViewController.enableModelLoadingForTests(false)
- // Replace Launcher Taskbar window with test instance.
- instrumentation.runOnMainSync {
- launcherTaskbarManager?.setSuspended(true)
- taskbarManager.onUserUnlocked() // Required to complete initialization.
- }
+ // Required to complete initialization.
+ instrumentation.runOnMainSync { taskbarManager.onUserUnlocked() }
base.evaluate()
} finally {
- // Revert Taskbar window.
- instrumentation.runOnMainSync {
- taskbarManager.destroy()
- launcherTaskbarManager?.setSuspended(false)
- }
-
+ instrumentation.runOnMainSync { taskbarManager.destroy() }
TaskbarViewController.enableModelLoadingForTests(true)
}
}
@@ -238,25 +191,4 @@
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
annotation class NavBarKidsMode
-
- /** Rule for Taskbar integer-based secure settings. */
- private inner class TaskbarSecureSettingRule(private val settingName: String) : TestRule {
-
- override fun apply(base: Statement, description: Description): Statement {
- return object : Statement() {
- override fun evaluate() {
- val originalValue =
- Settings.Secure.getInt(context.contentResolver, settingName, /* def= */ 0)
- try {
- base.evaluate()
- } finally {
- instrumentation.runOnMainSync { putInt(originalValue) }
- }
- }
- }
- }
-
- /** Puts [value] into secure settings under [settingName]. */
- fun putInt(value: Int) = Settings.Secure.putInt(context.contentResolver, settingName, value)
- }
}
diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarWindowSandboxContext.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarWindowSandboxContext.kt
index 2d3bfd6..8c51216 100644
--- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarWindowSandboxContext.kt
+++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarWindowSandboxContext.kt
@@ -24,11 +24,24 @@
import androidx.test.core.app.ApplicationProvider
import com.android.launcher3.FakeLauncherPrefs
import com.android.launcher3.LauncherPrefs
+import com.android.launcher3.dagger.LauncherAppComponent
+import com.android.launcher3.dagger.LauncherAppSingleton
import com.android.launcher3.util.MainThreadInitializedObject.ObjectSandbox
import com.android.launcher3.util.SandboxApplication
+import com.android.launcher3.util.SettingsCache
+import com.android.launcher3.util.SettingsCacheSandbox
+import com.android.quickstep.SystemUiProxy
+import dagger.BindsInstance
+import dagger.Component
import org.junit.rules.ExternalResource
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
+import org.junit.runner.Description
+import org.junit.runners.model.Statement
+
+/** Include additional bindings when building a [TaskbarSandboxComponent]. */
+typealias TaskbarComponentBinder =
+ TaskbarWindowSandboxContext.(TaskbarSandboxComponent.Builder) -> Unit
/**
* [SandboxApplication] for running Taskbar tests.
@@ -37,20 +50,46 @@
* [DEFAULT_DISPLAY] (i.e. test is executing on a device).
*/
class TaskbarWindowSandboxContext
-private constructor(base: SandboxApplication, val virtualDisplay: VirtualDisplay) :
- ContextWrapper(base),
- ObjectSandbox by base,
- TestRule by RuleChain.outerRule(virtualDisplayRule(virtualDisplay)).around(base) {
+private constructor(
+ private val base: SandboxApplication,
+ val virtualDisplay: VirtualDisplay,
+ private val componentBinder: TaskbarComponentBinder?,
+) : ContextWrapper(base), ObjectSandbox by base, TestRule {
- init {
- putObject(LauncherPrefs.INSTANCE, FakeLauncherPrefs(this))
+ val settingsCacheSandbox = SettingsCacheSandbox()
+
+ private val virtualDisplayRule =
+ object : ExternalResource() {
+ override fun after() = virtualDisplay.release()
+ }
+
+ private val singletonSetupRule =
+ object : ExternalResource() {
+ override fun before() {
+ val context = this@TaskbarWindowSandboxContext
+ val builder =
+ DaggerTaskbarSandboxComponent.builder()
+ .bindSystemUiProxy(SystemUiProxy(context))
+ .bindSettingsCache(settingsCacheSandbox.cache)
+ componentBinder?.invoke(context, builder)
+ base.initDaggerComponent(builder)
+
+ putObject(LauncherPrefs.INSTANCE, FakeLauncherPrefs(context))
+ }
+ }
+
+ override fun apply(statement: Statement, description: Description): Statement {
+ return RuleChain.outerRule(virtualDisplayRule)
+ .around(base)
+ .around(singletonSetupRule)
+ .apply(statement, description)
}
companion object {
private const val VIRTUAL_DISPLAY_NAME = "TaskbarSandboxDisplay"
/** Creates a [SandboxApplication] for Taskbar tests. */
- fun create(): TaskbarWindowSandboxContext {
+ fun create(componentBinder: TaskbarComponentBinder? = null): TaskbarWindowSandboxContext {
val base = ApplicationProvider.getApplicationContext<Context>()
val displayManager = checkNotNull(base.getSystemService(DisplayManager::class.java))
@@ -70,13 +109,21 @@
return TaskbarWindowSandboxContext(
SandboxApplication(base.createDisplayContext(virtualDisplay.display)),
virtualDisplay,
+ componentBinder,
)
}
}
}
-private fun virtualDisplayRule(virtualDisplay: VirtualDisplay): TestRule {
- return object : ExternalResource() {
- override fun after() = virtualDisplay.release()
+@LauncherAppSingleton
+@Component
+interface TaskbarSandboxComponent : LauncherAppComponent {
+ @Component.Builder
+ interface Builder : LauncherAppComponent.Builder {
+ @BindsInstance fun bindSystemUiProxy(proxy: SystemUiProxy): Builder
+
+ @BindsInstance fun bindSettingsCache(settingsCache: SettingsCache): Builder
+
+ override fun build(): TaskbarSandboxComponent
}
}
diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/util/SettingsCacheSandbox.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/util/SettingsCacheSandbox.kt
new file mode 100644
index 0000000..dcd5352
--- /dev/null
+++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/util/SettingsCacheSandbox.kt
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.util
+
+import android.net.Uri
+import org.mockito.kotlin.any
+import org.mockito.kotlin.doAnswer
+import org.mockito.kotlin.mock
+
+/**
+ * Provides a sandboxed [SettingsCache] for testing.
+ *
+ * Note that listeners registered to [cache] will never be invoked.
+ */
+class SettingsCacheSandbox {
+ private val values = mutableMapOf<Uri, Int>()
+
+ /** Fake cache that delegates [SettingsCache.getValue] to [values]. */
+ val cache =
+ mock<SettingsCache> {
+ on { getValue(any<Uri>()) } doAnswer { mock.getValue(it.getArgument(0), 1) }
+ on { getValue(any<Uri>(), any<Int>()) } doAnswer
+ {
+ values.getOrDefault(it.getArgument(0), it.getArgument(1)) == 1
+ }
+ }
+
+ operator fun get(key: Uri): Int? = values[key]
+
+ operator fun set(key: Uri, value: Int) {
+ values[key] = value
+ }
+}
diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt
index 1f88743..32b5b85 100644
--- a/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt
+++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt
@@ -20,9 +20,14 @@
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.launcher3.R
+import com.android.launcher3.dagger.LauncherAppComponent
+import com.android.launcher3.dagger.LauncherAppSingleton
import com.android.launcher3.util.LauncherModelHelper
+import com.android.quickstep.dagger.QuickStepModule
import com.android.systemui.contextualeducation.GestureType
import com.android.systemui.shared.system.InputConsumerController
+import dagger.BindsInstance
+import dagger.Component
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -58,7 +63,9 @@
@Before
fun setup() {
- sandboxContext.putObject(SystemUiProxy.INSTANCE, systemUiProxy)
+ sandboxContext.initDaggerComponent(
+ DaggerTestComponent.builder().bindSystemUiProxy(systemUiProxy)
+ )
val deviceState = mock(RecentsAnimationDeviceState::class.java)
whenever(deviceState.rotationTouchHelper).thenReturn(mock(RotationTouchHelper::class.java))
gestureState = spy(GestureState(OverviewComponentObserver(sandboxContext, deviceState), 0))
@@ -71,7 +78,7 @@
gestureState,
0,
false,
- inputConsumerController
+ inputConsumerController,
)
underTest.onGestureStarted(/* isLikelyToStartNewTask= */ false)
}
@@ -83,7 +90,7 @@
verify(systemUiProxy)
.updateContextualEduStats(
/* isTrackpadGesture= */ eq(true),
- eq(GestureType.HOME.toString())
+ eq(GestureType.HOME.toString()),
)
}
@@ -93,7 +100,18 @@
verify(systemUiProxy)
.updateContextualEduStats(
/* isTrackpadGesture= */ eq(false),
- eq(GestureType.HOME.toString())
+ eq(GestureType.HOME.toString()),
)
}
}
+
+@LauncherAppSingleton
+@Component(modules = [QuickStepModule::class])
+interface TestComponent : LauncherAppComponent {
+ @Component.Builder
+ interface Builder : LauncherAppComponent.Builder {
+ @BindsInstance fun bindSystemUiProxy(proxy: SystemUiProxy): Builder
+
+ override fun build(): TestComponent
+ }
+}
diff --git a/quickstep/tests/src/com/android/launcher3/taskbar/FallbackTaskbarUIControllerTest.kt b/quickstep/tests/src/com/android/launcher3/taskbar/FallbackTaskbarUIControllerTest.kt
index 04012c0..df98606 100644
--- a/quickstep/tests/src/com/android/launcher3/taskbar/FallbackTaskbarUIControllerTest.kt
+++ b/quickstep/tests/src/com/android/launcher3/taskbar/FallbackTaskbarUIControllerTest.kt
@@ -33,7 +33,7 @@
@RunWith(AndroidJUnit4::class)
class FallbackTaskbarUIControllerTest : TaskbarBaseTestCase() {
- lateinit var fallbackTaskbarUIController: FallbackTaskbarUIController
+ lateinit var fallbackTaskbarUIController: FallbackTaskbarUIController<RecentsActivity>
lateinit var stateListener: StateManager.StateListener<RecentsState>
private val recentsActivity: RecentsActivity = mock()
diff --git a/quickstep/tests/src/com/android/quickstep/RecentTasksListTest.java b/quickstep/tests/src/com/android/quickstep/RecentTasksListTest.java
index 244b897..b3c486c 100644
--- a/quickstep/tests/src/com/android/quickstep/RecentTasksListTest.java
+++ b/quickstep/tests/src/com/android/quickstep/RecentTasksListTest.java
@@ -28,7 +28,9 @@
import static org.mockito.Mockito.when;
import android.app.ActivityManager;
+import android.app.ActivityManager.RecentTaskInfo;
import android.app.KeyguardManager;
+import android.app.TaskInfo;
import android.content.Context;
import android.content.res.Resources;
@@ -39,7 +41,7 @@
import com.android.quickstep.util.GroupTask;
import com.android.quickstep.views.TaskViewType;
import com.android.systemui.shared.recents.model.Task;
-import com.android.wm.shell.shared.GroupedRecentTaskInfo;
+import com.android.wm.shell.shared.GroupedTaskInfo;
import org.junit.Before;
import org.junit.Test;
@@ -91,8 +93,8 @@
@Test
public void loadTasksInBackground_onlyKeys_noValidTaskDescription() throws Exception {
- GroupedRecentTaskInfo recentTaskInfos = GroupedRecentTaskInfo.forSplitTasks(
- new ActivityManager.RecentTaskInfo(), new ActivityManager.RecentTaskInfo(), null);
+ GroupedTaskInfo recentTaskInfos = GroupedTaskInfo.forSplitTasks(
+ new RecentTaskInfo(), new RecentTaskInfo(), null);
when(mSystemUiProxy.getRecentTasks(anyInt(), anyInt()))
.thenReturn(new ArrayList<>(Collections.singletonList(recentTaskInfos)));
@@ -119,12 +121,11 @@
@Test
public void loadTasksInBackground_moreThanKeys_hasValidTaskDescription() throws Exception {
String taskDescription = "Wheeee!";
- ActivityManager.RecentTaskInfo task1 = new ActivityManager.RecentTaskInfo();
+ RecentTaskInfo task1 = new RecentTaskInfo();
task1.taskDescription = new ActivityManager.TaskDescription(taskDescription);
- ActivityManager.RecentTaskInfo task2 = new ActivityManager.RecentTaskInfo();
+ RecentTaskInfo task2 = new RecentTaskInfo();
task2.taskDescription = new ActivityManager.TaskDescription();
- GroupedRecentTaskInfo recentTaskInfos = GroupedRecentTaskInfo.forSplitTasks(task1, task2,
- null);
+ GroupedTaskInfo recentTaskInfos = GroupedTaskInfo.forSplitTasks(task1, task2, null);
when(mSystemUiProxy.getRecentTasks(anyInt(), anyInt()))
.thenReturn(new ArrayList<>(Collections.singletonList(recentTaskInfos)));
@@ -138,11 +139,11 @@
@Test
public void loadTasksInBackground_freeformTask_createsDesktopTask() throws Exception {
- ActivityManager.RecentTaskInfo[] tasks = {
+ List<TaskInfo> tasks = Arrays.asList(
createRecentTaskInfo(1 /* taskId */),
createRecentTaskInfo(4 /* taskId */),
- createRecentTaskInfo(5 /* taskId */)};
- GroupedRecentTaskInfo recentTaskInfos = GroupedRecentTaskInfo.forFreeformTasks(
+ createRecentTaskInfo(5 /* taskId */));
+ GroupedTaskInfo recentTaskInfos = GroupedTaskInfo.forFreeformTasks(
tasks, Collections.emptySet() /* minimizedTaskIds */);
when(mSystemUiProxy.getRecentTasks(anyInt(), anyInt()))
.thenReturn(new ArrayList<>(Collections.singletonList(recentTaskInfos)));
@@ -162,14 +163,13 @@
@Test
public void loadTasksInBackground_freeformTask_onlyMinimizedTasks_doesNotCreateDesktopTask()
throws Exception {
- ActivityManager.RecentTaskInfo[] tasks = {
+ List<TaskInfo> tasks = Arrays.asList(
createRecentTaskInfo(1 /* taskId */),
createRecentTaskInfo(4 /* taskId */),
- createRecentTaskInfo(5 /* taskId */)};
+ createRecentTaskInfo(5 /* taskId */));
Set<Integer> minimizedTaskIds =
Arrays.stream(new Integer[]{1, 4, 5}).collect(Collectors.toSet());
- GroupedRecentTaskInfo recentTaskInfos =
- GroupedRecentTaskInfo.forFreeformTasks(tasks, minimizedTaskIds);
+ GroupedTaskInfo recentTaskInfos = GroupedTaskInfo.forFreeformTasks(tasks, minimizedTaskIds);
when(mSystemUiProxy.getRecentTasks(anyInt(), anyInt()))
.thenReturn(new ArrayList<>(Collections.singletonList(recentTaskInfos)));
@@ -179,8 +179,8 @@
assertEquals(0, taskList.size());
}
- private ActivityManager.RecentTaskInfo createRecentTaskInfo(int taskId) {
- ActivityManager.RecentTaskInfo recentTaskInfo = new ActivityManager.RecentTaskInfo();
+ private TaskInfo createRecentTaskInfo(int taskId) {
+ RecentTaskInfo recentTaskInfo = new RecentTaskInfo();
recentTaskInfo.taskId = taskId;
return recentTaskInfo;
}
diff --git a/quickstep/tests/src/com/android/quickstep/TaplTestsOverviewDesktop.kt b/quickstep/tests/src/com/android/quickstep/TaplTestsOverviewDesktop.kt
index 2a8afbf..120a89b 100644
--- a/quickstep/tests/src/com/android/quickstep/TaplTestsOverviewDesktop.kt
+++ b/quickstep/tests/src/com/android/quickstep/TaplTestsOverviewDesktop.kt
@@ -104,28 +104,36 @@
@Test
@PortraitLandscape
- fun dismissFocusedTask_thenDesktopTask_thenFocusedTaskIsCentered() {
+ fun dismissTasks_whenDesktopTask_IsInTheCenter() {
// Create extra activity to be DesktopTaskView
startTestActivity(TEST_ACTIVITY_EXTRA)
mLauncher.goHome().switchToOverview()
+
val desktop = moveTaskToDesktop(TEST_ACTIVITY_EXTRA)
+ var overview = desktop.switchToOverview()
- val overview = desktop.switchToOverview()
+ // Open focused task and go back to Overview to validate whether it has adjacent tasks in
+ // its both sides (grid task on left and desktop tasks at its right side)
+ val focusedTaskOpened = overview.getTestActivityTask(TEST_ACTIVITY_2).open()
- // Dismiss focused task
- val focusedTask1 = overview.getTestActivityTask(TEST_ACTIVITY_2)
- assertTaskContentDescription(focusedTask1, TEST_ACTIVITY_2)
- focusedTask1.dismiss()
-
- // Dismiss DesktopTaskView
+ // Fling to desktop task and dismiss the focused task to check repositioning of
+ // grid tasks.
+ overview = focusedTaskOpened.switchToOverview().apply { flingBackward() }
val desktopTask = overview.currentTask
assertWithMessage("The current task is not a Desktop.").that(desktopTask.isDesktop).isTrue()
+
+ // Get focused task (previously opened task) then dismiss this task
+ val focusedTaskInOverview = overview.getTestActivityTask(TEST_ACTIVITY_2)
+ assertTaskContentDescription(focusedTaskInOverview, TEST_ACTIVITY_2)
+ focusedTaskInOverview.dismiss()
+
+ // Dismiss DesktopTask to validate whether the new focused task will take its position
desktopTask.dismiss()
- // Dismiss focused task
- val focusedTask2 = overview.currentTask
- assertTaskContentDescription(focusedTask2, TEST_ACTIVITY_1)
- focusedTask2.dismiss()
+ // Dismiss last focused task
+ val lastFocusedTask = overview.currentTask
+ assertTaskContentDescription(lastFocusedTask, TEST_ACTIVITY_1)
+ lastFocusedTask.dismiss()
assertWithMessage("Still have tasks after dismissing all the tasks")
.that(mLauncher.workspace.switchToOverview().hasTasks())
diff --git a/quickstep/tests/src/com/android/quickstep/desktop/WindowAnimatorTest.kt b/quickstep/tests/src/com/android/quickstep/desktop/WindowAnimatorTest.kt
deleted file mode 100644
index e5e6df3..0000000
--- a/quickstep/tests/src/com/android/quickstep/desktop/WindowAnimatorTest.kt
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (C) 2024 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.quickstep.desktop
-
-import android.animation.ValueAnimator
-import android.content.Context
-import android.content.res.Resources
-import android.graphics.Rect
-import android.util.DisplayMetrics
-import android.view.SurfaceControl
-import android.window.TransitionInfo
-import androidx.test.ext.junit.runners.AndroidJUnit4
-import androidx.test.filters.SmallTest
-import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread
-import com.android.app.animation.Interpolators
-import com.android.launcher3.desktop.WindowAnimator
-import com.google.common.truth.Truth.assertThat
-import org.junit.Before
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.mockito.ArgumentMatchers.any
-import org.mockito.ArgumentMatchers.anyFloat
-import org.mockito.kotlin.mock
-import org.mockito.kotlin.whenever
-
-@SmallTest
-@RunWith(AndroidJUnit4::class)
-class WindowAnimatorTest {
-
- private val context = mock<Context>()
- private val resources = mock<Resources>()
- private val transaction = mock<SurfaceControl.Transaction>()
- private val change = mock<TransitionInfo.Change>()
- private val leash = mock<SurfaceControl>()
-
- private val displayMetrics = DisplayMetrics().apply { density = 1f }
-
- @Before
- fun setup() {
- whenever(context.resources).thenReturn(resources)
- whenever(resources.displayMetrics).thenReturn(displayMetrics)
- whenever(change.leash).thenReturn(leash)
- whenever(change.startAbsBounds).thenReturn(START_BOUNDS)
- whenever(transaction.setPosition(any(), anyFloat(), anyFloat())).thenReturn(transaction)
- whenever(transaction.setScale(any(), anyFloat(), anyFloat())).thenReturn(transaction)
- }
-
- @Test
- fun createBoundsAnimator_returnsCorrectDefaultAnimatorParams() = runOnUiThread {
- val boundsAnimParams =
- WindowAnimator.BoundsAnimationParams(
- durationMs = 100L,
- interpolator = Interpolators.STANDARD_ACCELERATE,
- )
-
- val valueAnimator =
- WindowAnimator.createBoundsAnimator(context, boundsAnimParams, change, transaction)
-
- assertThat(valueAnimator.duration).isEqualTo(100L)
- assertThat(valueAnimator.interpolator).isEqualTo(Interpolators.STANDARD_ACCELERATE)
- assertStartAndEndBounds(valueAnimator, startBounds = START_BOUNDS, endBounds = START_BOUNDS)
- }
-
- @Test
- fun createBoundsAnimator_startScaleAndOffset_returnsCorrectBounds() = runOnUiThread {
- val bounds = Rect(/* left= */ 100, /* top= */ 200, /* right= */ 300, /* bottom= */ 400)
- whenever(change.startAbsBounds).thenReturn(bounds)
- val boundsAnimParams =
- WindowAnimator.BoundsAnimationParams(
- durationMs = 100L,
- startOffsetYDp = 10f,
- startScale = 0.5f,
- interpolator = Interpolators.STANDARD_ACCELERATE,
- )
-
- val valueAnimator =
- WindowAnimator.createBoundsAnimator(context, boundsAnimParams, change, transaction)
-
- assertStartAndEndBounds(
- valueAnimator,
- startBounds =
- Rect(/* left= */ 150, /* top= */ 260, /* right= */ 250, /* bottom= */ 360),
- endBounds = bounds,
- )
- }
-
- @Test
- fun createBoundsAnimator_endScaleAndOffset_returnsCorrectBounds() = runOnUiThread {
- val bounds = Rect(/* left= */ 100, /* top= */ 200, /* right= */ 300, /* bottom= */ 400)
- whenever(change.startAbsBounds).thenReturn(bounds)
- val boundsAnimParams =
- WindowAnimator.BoundsAnimationParams(
- durationMs = 100L,
- endOffsetYDp = 10f,
- endScale = 0.5f,
- interpolator = Interpolators.STANDARD_ACCELERATE,
- )
-
- val valueAnimator =
- WindowAnimator.createBoundsAnimator(context, boundsAnimParams, change, transaction)
-
- assertStartAndEndBounds(
- valueAnimator,
- startBounds = bounds,
- endBounds = Rect(/* left= */ 150, /* top= */ 260, /* right= */ 250, /* bottom= */ 360),
- )
- }
-
- private fun assertStartAndEndBounds(
- valueAnimator: ValueAnimator,
- startBounds: Rect,
- endBounds: Rect,
- ) {
- valueAnimator.start()
- valueAnimator.animatedValue
- assertThat(valueAnimator.animatedValue).isEqualTo(startBounds)
- valueAnimator.end()
- assertThat(valueAnimator.animatedValue).isEqualTo(endBounds)
- }
-
- companion object {
- private val START_BOUNDS =
- Rect(/* left= */ 10, /* top= */ 20, /* right= */ 30, /* bottom= */ 40)
- }
-}
diff --git a/res/values-fr-rCA/strings.xml b/res/values-fr-rCA/strings.xml
index cae77dc..a941d88 100644
--- a/res/values-fr-rCA/strings.xml
+++ b/res/values-fr-rCA/strings.xml
@@ -192,7 +192,7 @@
<string name="private_space_label" msgid="2359721649407947001">"Espace privé"</string>
<string name="private_space_secondary_label" msgid="9203933341714508907">"Touchez pour configurer ou ouvrir"</string>
<string name="ps_container_title" msgid="4391796149519594205">"Privé"</string>
- <string name="ps_container_settings" msgid="6059734123353320479">"Paramètres de l\'Espace privé"</string>
+ <string name="ps_container_settings" msgid="6059734123353320479">"Paramètres de l\'espace privé"</string>
<string name="ps_container_unlock_button_content_description" msgid="9181551784092204234">"Privé, déverrouillé."</string>
<string name="ps_container_lock_button_content_description" msgid="5961993384382649530">"Privé, verrouillé."</string>
<string name="ps_container_lock_title" msgid="2640257399982364682">"Verrouiller"</string>
diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml
index 731f839..9cdb5aa 100644
--- a/res/values-it/strings.xml
+++ b/res/values-it/strings.xml
@@ -192,7 +192,7 @@
<string name="private_space_label" msgid="2359721649407947001">"Spazio privato"</string>
<string name="private_space_secondary_label" msgid="9203933341714508907">"Tocca per configurare o aprire"</string>
<string name="ps_container_title" msgid="4391796149519594205">"Privato"</string>
- <string name="ps_container_settings" msgid="6059734123353320479">"Impostazioni dello Spazio privato"</string>
+ <string name="ps_container_settings" msgid="6059734123353320479">"Impostazioni dello spazio privato"</string>
<string name="ps_container_unlock_button_content_description" msgid="9181551784092204234">"Privato, sbloccato."</string>
<string name="ps_container_lock_button_content_description" msgid="5961993384382649530">"Privato, bloccato."</string>
<string name="ps_container_lock_title" msgid="2640257399982364682">"Blocca"</string>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 57c9bc7..4dddb9a 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -208,8 +208,16 @@
<attr name="layout_sticky" format="boolean" />
</declare-styleable>
+ <declare-styleable name="NumRows">
+ <attr name="minDeviceWidthPx" format="float"/>
+ <attr name="minDeviceHeightPx" format="float"/>
+ <attr name="numRowsNew" format="integer"/>
+ <attr name="dbFile" />
+ </declare-styleable>
+
<declare-styleable name="GridDisplayOption">
<attr name="name" format="string" />
+ <attr name="title" />
<attr name="numRows" format="integer" />
<attr name="numColumns" format="integer" />
@@ -260,6 +268,9 @@
defaults to @dimen/taskbar_button_margin_default -->
<attr name="inlineNavButtonsEndSpacing" format="reference" />
+ <!-- Grid flips row and column count when rotating the device -->
+ <attr name="isDualGrid" format="boolean" />
+
<attr name="dbFile" format="string" />
<attr name="defaultLayoutId" format="reference" />
<attr name="demoModeLayoutId" format="reference" />
@@ -294,6 +305,7 @@
<!-- File that contains the specs for all apps icon and text size.
Needs FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE enabled -->
<attr name="allAppsCellSpecsId" format="reference" />
+ <attr name="rowCountSpecsId" format="reference" />
<!-- defaults to allAppsCellSpecsId, if not specified -->
<attr name="allAppsCellSpecsTwoPanelId" format="reference" />
diff --git a/res/values/config.xml b/res/values/config.xml
index b0b7aa2..f6f3c95 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -76,7 +76,6 @@
<string name="taskbar_view_callbacks_factory_class" translatable="false"></string>
<string name="launcher_restore_event_logger_class" translatable="false"></string>
<string name="taskbar_edu_tooltip_controller_class" translatable="false"></string>
- <string name="contextual_edu_manager_class" translatable="false"></string>
<!-- Used for determining category of a widget presented in widget recommendations. -->
<string name="widget_recommendation_category_provider_class" translatable="false"></string>
@@ -85,6 +84,9 @@
<string name="local_colors_extraction_class" translatable="false"></string>
<string name="search_session_manager_class" translatable="false"></string>
+ <!-- Filters for widgets displayed in the widget picker -->
+ <string name="widgets_filter_data_provider_class" translatable="false"></string>
+
<!-- Scalable Grid configuration -->
<!-- This is a float because it is converted to dp later in DeviceProfile -->
<dimen name="hotseat_bar_bottom_space_default">48</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index af57c86..746bd7e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -355,8 +355,9 @@
<!-- Title for an app whose download has been started. -->
<string name="app_waiting_download_title"><xliff:g id="name" example="Messenger">%1$s</xliff:g> waiting to install</string>
<!-- Title for an app which is archived. -->
- <string name="app_archived_title"><xliff:g id="name" example="Messenger">%1$s</xliff:g> is archived. Tap to download and restore.</string>
-
+ <string name="app_archived_title"><xliff:g id="name" example="Messenger">%1$s</xliff:g> is archived.</string>
+ <!-- Accessibility Action for an app which is archived. -->
+ <string name="app_unarchiving_action">download and restore</string>
<!-- Title shown on the alert dialog prompting the user to update the application in market
in order to re-enable the disabled shortcuts -->
diff --git a/res/xml/backupscheme.xml b/res/xml/backupscheme.xml
index 0f0dde2..58916a8 100644
--- a/res/xml/backupscheme.xml
+++ b/res/xml/backupscheme.xml
@@ -2,7 +2,10 @@
<full-backup-content xmlns:android="http://schemas.android.com/apk/res/android">
<include domain="database" path="launcher.db" />
+ <include domain="database" path="launcher_5_by_8.db" />
<include domain="database" path="launcher_6_by_5.db" />
+ <include domain="database" path="launcher_5_by_6.db" />
+ <include domain="database" path="launcher_4_by_6.db" />
<include domain="database" path="launcher_4_by_5.db" />
<include domain="database" path="launcher_4_by_4.db" />
<include domain="database" path="launcher_3_by_3.db" />
diff --git a/res/xml/default_workspace_5x8.xml b/res/xml/default_workspace_5x8.xml
new file mode 100644
index 0000000..b078cfd
--- /dev/null
+++ b/res/xml/default_workspace_5x8.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<favorites xmlns:launcher="http://schemas.android.com/apk/res-auto/com.android.launcher3">
+
+ <!-- Hotseat (We use the screen as the position of the item in the hotseat) -->
+ <!-- Mail Calendar Gallery Store Internet Camera -->
+ <resolve
+ launcher:container="-101"
+ launcher:screen="0"
+ launcher:x="0"
+ launcher:y="0" >
+ <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_EMAIL;end" />
+ <favorite launcher:uri="mailto:" />
+ </resolve>
+
+ <resolve
+ launcher:container="-101"
+ launcher:screen="1"
+ launcher:x="1"
+ launcher:y="0" >
+ <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_CALENDAR;end" />
+ </resolve>
+
+ <resolve
+ launcher:container="-101"
+ launcher:screen="2"
+ launcher:x="2"
+ launcher:y="0" >
+ <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_GALLERY;end" />
+ <favorite launcher:uri="#Intent;type=images/*;end" />
+ </resolve>
+
+ <resolve
+ launcher:container="-101"
+ launcher:screen="3"
+ launcher:x="3"
+ launcher:y="0" >
+ <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_MARKET;end" />
+ <favorite launcher:uri="market://details?id=com.android.launcher" />
+ </resolve>
+
+ <resolve
+ launcher:container="-101"
+ launcher:screen="4"
+ launcher:x="4"
+ launcher:y="0" >
+ <favorite
+ launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_BROWSER;end" />
+ <favorite launcher:uri="http://www.example.com/" />
+ </resolve>
+
+ <!-- Resolve camera intent if GoogleCamera is not available e.g. on emulator -->
+ <resolve
+ launcher:container="-101"
+ launcher:screen="5"
+ launcher:x="5"
+ launcher:y="0" >
+ <favorite launcher:uri="#Intent;action=android.media.action.STILL_IMAGE_CAMERA;end" />
+ <favorite launcher:uri="#Intent;action=android.intent.action.CAMERA_BUTTON;end" />
+ </resolve>
+
+</favorites>
diff --git a/res/xml/paddings_5x8.xml b/res/xml/paddings_5x8.xml
new file mode 100644
index 0000000..afa70c5
--- /dev/null
+++ b/res/xml/paddings_5x8.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2024 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<device-paddings xmlns:launcher="http://schemas.android.com/apk/res-auto" >
+
+ <device-padding
+ launcher:maxEmptySpace="100dp">
+ <workspaceTopPadding
+ launcher:a="0.31"
+ launcher:b="0"/>
+ <workspaceBottomPadding
+ launcher:a="0.69"
+ launcher:b="0"/>
+ <hotseatBottomPadding
+ launcher:a="0"
+ launcher:b="0"/>
+ </device-padding>
+
+ <device-padding
+ launcher:maxEmptySpace="9999dp">
+ <workspaceTopPadding
+ launcher:a="0.48"
+ launcher:b="0"/>
+ <workspaceBottomPadding
+ launcher:a="0.52"
+ launcher:b="0"/>
+ <hotseatBottomPadding
+ launcher:a="0"
+ launcher:b="0"/>
+ </device-padding>
+</device-paddings>
\ No newline at end of file
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index 909272e..34cf56b 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -57,12 +57,14 @@
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewDebug;
+import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.TextView;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.annotation.VisibleForTesting;
+import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import com.android.launcher3.accessibility.BaseAccessibilityDelegate;
import com.android.launcher3.dot.DotInfo;
@@ -519,6 +521,16 @@
}
}
+ @Override
+ public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfo(info);
+ if (getTag() instanceof ItemInfoWithIcon infoWithIcon && infoWithIcon.isInactiveArchive()) {
+ info.addAction(new AccessibilityNodeInfo.AccessibilityAction(
+ AccessibilityNodeInfoCompat.ACTION_CLICK,
+ getContext().getString(R.string.app_unarchiving_action)));
+ }
+ }
+
/** This is used for testing to forcefully set the display. */
@VisibleForTesting
public void setDisplay(int display) {
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index ece6540..7112a1b 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -52,15 +52,14 @@
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.icons.DotRenderer;
-import com.android.launcher3.logging.FileLog;
import com.android.launcher3.model.DeviceGridState;
import com.android.launcher3.provider.RestoreDbTask;
import com.android.launcher3.testing.shared.ResourceUtils;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController.Info;
-import com.android.launcher3.util.LockedUserState;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.Partner;
+import com.android.launcher3.util.ResourceHelper;
import com.android.launcher3.util.SafeCloseable;
import com.android.launcher3.util.WindowBounds;
import com.android.launcher3.util.window.WindowManagerProxy;
@@ -186,6 +185,8 @@
@XmlRes
public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
@XmlRes
+ public int rowCountSpecsId = INVALID_RESOURCE_HANDLE;;
+ @XmlRes
public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
@XmlRes
public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
@@ -232,8 +233,6 @@
if (!newGridName.equals(gridName)) {
LauncherPrefs.get(context).put(GRID_NAME, newGridName);
}
- LockedUserState.get(context).runOnUserUnlocked(() ->
- new DeviceGridState(this).writeToPrefs(context));
DisplayController.INSTANCE.get(context).setPriorityListener(
(displayContext, info, flags) -> {
@@ -303,35 +302,6 @@
DisplayController.INSTANCE.executeIfCreated(dc -> dc.setPriorityListener(null));
}
- /**
- * Reinitialize the current grid after a restore, where some grids might now be disabled.
- */
- public void reinitializeAfterRestore(Context context) {
- String currentGridName = getCurrentGridName(context);
- String currentDbFile = dbFile;
- String newGridName = initGrid(context, currentGridName);
- String newDbFile = dbFile;
- FileLog.d(TAG, "Reinitializing grid after restore."
- + " currentGridName=" + currentGridName
- + ", currentDbFile=" + currentDbFile
- + ", newGridName=" + newGridName
- + ", newDbFile=" + newDbFile);
- if (!newDbFile.equals(currentDbFile)) {
- FileLog.d(TAG, "Restored grid is disabled : " + currentGridName
- + ", migrating to: " + newGridName
- + ", removing all other grid db files");
- for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
- if (gridDbFile.equals(currentDbFile)) {
- continue;
- }
- if (context.getDatabasePath(gridDbFile).delete()) {
- FileLog.d(TAG, "Removed old grid db file: " + gridDbFile);
- }
- }
- setCurrentGrid(context, newGridName);
- }
- }
-
public static String getCurrentGridName(Context context) {
return LauncherPrefs.get(context).get(GRID_NAME);
}
@@ -340,15 +310,29 @@
Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
@DeviceType int deviceType = displayInfo.getDeviceType();
- ArrayList<DisplayOption> allOptions =
+ List<DisplayOption> allOptions =
getPredefinedDeviceProfiles(context, gridName, deviceType,
RestoreDbTask.isPending(context));
+
+ // Filter out options that don't have the same number of columns as the grid
+ DeviceGridState deviceGridState = new DeviceGridState(context);
+ List<DisplayOption> allOptionsFilteredByColCount =
+ filterByColumnCount(allOptions, deviceGridState.getColumns());
+
DisplayOption displayOption =
- invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
+ invDistWeightedInterpolate(displayInfo, allOptionsFilteredByColCount.isEmpty()
+ ? new ArrayList<>(allOptions)
+ : new ArrayList<>(allOptionsFilteredByColCount), deviceType);
initGrid(context, displayInfo, displayOption, deviceType);
return displayOption.grid.name;
}
+ private List<DisplayOption> filterByColumnCount(
+ List<DisplayOption> allOptions, int numColumns) {
+ return allOptions.stream().filter(
+ option -> option.grid.numColumns == numColumns).toList();
+ }
+
/**
* @deprecated This is a temporary solution because on the backup and restore case we modify the
* IDP, this resets it. b/332974074
@@ -383,6 +367,7 @@
isScalable = closestProfile.isScalable;
devicePaddingId = closestProfile.devicePaddingId;
workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
+ rowCountSpecsId = closestProfile.mRowCountSpecsId;
workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
allAppsSpecsId = closestProfile.mAllAppsSpecsId;
allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
@@ -495,7 +480,6 @@
mChangeListeners.remove(listener);
}
-
public void setCurrentGrid(Context context, String gridName) {
LauncherPrefs.get(context).put(GRID_NAME, gridName);
MAIN_EXECUTOR.execute(() -> {
@@ -526,7 +510,7 @@
}
}
- private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
+ private static List<DisplayOption> getPredefinedDeviceProfiles(Context context,
String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
ArrayList<DisplayOption> profiles = new ArrayList<>();
@@ -539,7 +523,8 @@
&& GridOption.TAG_NAME.equals(parser.getName())) {
GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
- if (gridOption.isEnabled(deviceType) || allowDisabledGrid) {
+ if ((gridOption.isEnabled(deviceType) || allowDisabledGrid)
+ && gridOption.filterByFlag(deviceType)) {
final int displayDepth = parser.getDepth();
while (((type = parser.next()) != XmlPullParser.END_TAG
|| parser.getDepth() > displayDepth)
@@ -566,13 +551,16 @@
}
}
}
- if (filteredProfiles.isEmpty()) {
- // No grid found, use the default options
+ if (filteredProfiles.isEmpty() && TextUtils.isEmpty(gridName)) {
+ // Use the default options since gridName is empty and there's no valid grids.
for (DisplayOption option : profiles) {
if (option.canBeDefault) {
filteredProfiles.add(option);
}
}
+ } else if (filteredProfiles.isEmpty()) {
+ // In this case we had a grid selected but we couldn't find it.
+ filteredProfiles.addAll(profiles);
}
if (filteredProfiles.isEmpty()) {
throw new RuntimeException("No display option with canBeDefault=true");
@@ -581,6 +569,72 @@
}
/**
+ * Parses through the xml to find NumRows specs. Then calls findBestRowCount to get the correct
+ * row count for this GridOption.
+ *
+ * @return the result of {@link #findBestRowCount(List, Context, int)}.
+ */
+ public static NumRows getRowCount(ResourceHelper resourceHelper, Context context,
+ int deviceType) {
+ ArrayList<NumRows> rowCounts = new ArrayList<>();
+
+ try (XmlResourceParser parser = resourceHelper.getXml()) {
+ final int depth = parser.getDepth();
+ int type;
+ while (((type = parser.next()) != XmlPullParser.END_TAG
+ || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
+ if ((type == XmlPullParser.START_TAG)
+ && "NumRows".equals(parser.getName())) {
+ rowCounts.add(new NumRows(context, Xml.asAttributeSet(parser)));
+ }
+ }
+ } catch (IOException | XmlPullParserException e) {
+ throw new RuntimeException(e);
+ }
+
+ return findBestRowCount(rowCounts, context, deviceType);
+ }
+
+ /**
+ * @return the biggest row count that fits the display dimensions spec using NumRows to
+ * determine that. If no best row count is found, return -1.
+ */
+ public static NumRows findBestRowCount(List<NumRows> list, Context context,
+ @DeviceType int deviceType) {
+ Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
+ int minWidthPx = Integer.MAX_VALUE;
+ int minHeightPx = Integer.MAX_VALUE;
+ for (WindowBounds bounds : displayInfo.supportedBounds) {
+ boolean isTablet = displayInfo.isTablet(bounds);
+ if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
+ // For split displays, take half width per page
+ minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
+ minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
+ } else if (!isTablet && bounds.isLandscape()) {
+ // We will use transposed layout in this case
+ minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
+ minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
+ } else {
+ minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
+ minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
+ }
+ }
+
+ NumRows selectedRow = null;
+ for (NumRows item: list) {
+ if (minWidthPx >= item.mMinDeviceWidthPx && minHeightPx >= item.mMinDeviceHeightPx) {
+ if (selectedRow == null || selectedRow.mNumRowsNew < item.mNumRowsNew) {
+ selectedRow = item;
+ }
+ }
+ }
+ if (selectedRow != null) {
+ return selectedRow;
+ }
+ return null;
+ }
+
+ /**
* Returns the GridOption associated to the given file name or null if the fileName is not
* supported.
* Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
@@ -626,6 +680,7 @@
return parseAllDefinedGridOptions(context)
.stream()
.filter(go -> go.isEnabled(deviceType))
+ .filter(go -> go.filterByFlag(deviceType))
.collect(Collectors.toList());
}
@@ -709,7 +764,7 @@
}
private static DisplayOption invDistWeightedInterpolate(
- Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
+ Info displayInfo, List<DisplayOption> points, @DeviceType int deviceType) {
int minWidthPx = Integer.MAX_VALUE;
int minHeightPx = Integer.MAX_VALUE;
for (WindowBounds bounds : displayInfo.supportedBounds) {
@@ -733,7 +788,7 @@
float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
// Sort the profiles based on the closeness to the device size
- Collections.sort(points, (a, b) ->
+ points.sort((a, b) ->
Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
dist(width, height, b.minWidthDps, b.minHeightDps)));
@@ -855,6 +910,7 @@
private static final int DONT_INLINE_QSB = 0;
public final String name;
+ public final String title;
public final int numRows;
public final int numColumns;
public final int numSearchContainerColumns;
@@ -881,6 +937,7 @@
private final int demoModeLayoutId;
private final boolean isScalable;
+ private final boolean mIsDualGrid;
private final int devicePaddingId;
private final int mWorkspaceSpecsId;
private final int mWorkspaceSpecsTwoPanelId;
@@ -894,17 +951,31 @@
private final int mWorkspaceCellSpecsTwoPanelId;
private final int mAllAppsCellSpecsId;
private final int mAllAppsCellSpecsTwoPanelId;
+ private final int mRowCountSpecsId;
public GridOption(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.GridDisplayOption);
name = a.getString(R.styleable.GridDisplayOption_name);
- numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
+ title = a.getString(R.styleable.GridDisplayOption_title);
+ deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
+ DEVICE_CATEGORY_ALL);
+ mRowCountSpecsId = a.getResourceId(
+ R.styleable.GridDisplayOption_rowCountSpecsId, INVALID_RESOURCE_HANDLE);
+ mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
+ if (mRowCountSpecsId != INVALID_RESOURCE_HANDLE) {
+ ResourceHelper resourceHelper = new ResourceHelper(context, mRowCountSpecsId);
+ NumRows numR = getRowCount(resourceHelper, context, deviceCategory);
+ numRows = numR.mNumRowsNew;
+ dbFile = numR.mDbFile;
+ } else {
+ numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
+ dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
+ }
+
numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
numSearchContainerColumns = a.getInt(
R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
-
- dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
defaultLayoutId = a.getResourceId(
R.styleable.GridDisplayOption_defaultLayoutId, 0);
demoModeLayoutId = a.getResourceId(
@@ -969,8 +1040,6 @@
R.styleable.GridDisplayOption_isScalable, false);
devicePaddingId = a.getResourceId(
R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
- deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
- DEVICE_CATEGORY_ALL);
if (FeatureFlags.enableResponsiveWorkspace()) {
mWorkspaceSpecsId = a.getResourceId(
@@ -1053,6 +1122,35 @@
return false;
}
}
+
+ public boolean isNewGridOption() {
+ return mRowCountSpecsId != INVALID_RESOURCE_HANDLE;
+ }
+
+ public boolean filterByFlag(int deviceType) {
+ if (deviceType == TYPE_TABLET) {
+ return Flags.oneGridRotationHandling() == mIsDualGrid;
+ }
+ return Flags.oneGridSpecs() == isNewGridOption();
+ }
+ }
+
+ public static final class NumRows {
+ final int mNumRowsNew;
+ final float mMinDeviceWidthPx;
+ final float mMinDeviceHeightPx;
+ final String mDbFile;
+
+ NumRows(Context context, AttributeSet attrs) {
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumRows);
+
+ mNumRowsNew = (int) a.getFloat(R.styleable.NumRows_numRowsNew, 0);
+ mMinDeviceWidthPx = a.getFloat(R.styleable.NumRows_minDeviceWidthPx, 0);
+ mMinDeviceHeightPx = a.getFloat(R.styleable.NumRows_minDeviceHeightPx, 0);
+ mDbFile = a.getString(R.styleable.NumRows_dbFile);
+
+ a.recycle();
+ }
}
@VisibleForTesting
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 983cf8d..6446f7b 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2629,8 +2629,9 @@
* See {@code LauncherBindingDelegate}
*/
@Override
- public void bindAllWidgets(final List<WidgetsListBaseEntry> allWidgets) {
- mModelCallbacks.bindAllWidgets(allWidgets);
+ public void bindAllWidgets(@NonNull final List<WidgetsListBaseEntry> allWidgets,
+ @NonNull final List<WidgetsListBaseEntry> defaultWidgets) {
+ mModelCallbacks.bindAllWidgets(allWidgets, defaultWidgets);
}
@Override
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index b6da164..01d0a74 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -48,6 +48,7 @@
import com.android.launcher3.icons.LauncherIconProvider;
import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.model.ModelLauncherCallbacks;
+import com.android.launcher3.model.WidgetsFilterDataProvider;
import com.android.launcher3.notification.NotificationListener;
import com.android.launcher3.pm.InstallSessionHelper;
import com.android.launcher3.pm.InstallSessionTracker;
@@ -197,7 +198,8 @@
mIconProvider = new LauncherIconProvider(context);
mIconCache = new IconCache(mContext, mInvariantDeviceProfile,
iconCacheFileName, mIconProvider);
- mModel = new LauncherModel(context, this, mIconCache, new AppFilter(mContext),
+ mModel = new LauncherModel(context, this, mIconCache,
+ WidgetsFilterDataProvider.Companion.newInstance(context), new AppFilter(mContext),
PackageManagerHelper.INSTANCE.get(context), iconCacheFileName != null);
mOnTerminateCallback.add(mIconCache::close);
mOnTerminateCallback.add(mModel::destroy);
diff --git a/src/com/android/launcher3/LauncherFiles.java b/src/com/android/launcher3/LauncherFiles.java
index d730cea..95c0ee8 100644
--- a/src/com/android/launcher3/LauncherFiles.java
+++ b/src/com/android/launcher3/LauncherFiles.java
@@ -16,8 +16,11 @@
private static final String XML = ".xml";
public static final String LAUNCHER_DB = "launcher.db";
+ public static final String LAUNCHER_5_BY_8_DB = "launcher_5_by_8.db";
public static final String LAUNCHER_6_BY_5_DB = "launcher_6_by_5.db";
public static final String LAUNCHER_4_BY_5_DB = "launcher_4_by_5.db";
+ public static final String LAUNCHER_4_BY_6_DB = "launcher_4_by_6.db";
+ public static final String LAUNCHER_5_BY_6_DB = "launcher_5_by_6.db";
public static final String LAUNCHER_4_BY_4_DB = "launcher_4_by_4.db";
public static final String LAUNCHER_3_BY_3_DB = "launcher_3_by_3.db";
public static final String LAUNCHER_2_BY_2_DB = "launcher_2_by_2.db";
@@ -33,8 +36,11 @@
public static final List<String> GRID_DB_FILES = Collections.unmodifiableList(Arrays.asList(
LAUNCHER_DB,
+ LAUNCHER_5_BY_8_DB,
LAUNCHER_6_BY_5_DB,
LAUNCHER_4_BY_5_DB,
+ LAUNCHER_4_BY_6_DB,
+ LAUNCHER_5_BY_6_DB,
LAUNCHER_4_BY_4_DB,
LAUNCHER_3_BY_3_DB,
LAUNCHER_2_BY_2_DB));
diff --git a/src/com/android/launcher3/LauncherModel.kt b/src/com/android/launcher3/LauncherModel.kt
index 85ecd58..b56df46 100644
--- a/src/com/android/launcher3/LauncherModel.kt
+++ b/src/com/android/launcher3/LauncherModel.kt
@@ -42,6 +42,7 @@
import com.android.launcher3.model.ReloadStringCacheTask
import com.android.launcher3.model.ShortcutsChangedTask
import com.android.launcher3.model.UserLockStateChangedTask
+import com.android.launcher3.model.WidgetsFilterDataProvider
import com.android.launcher3.model.data.ItemInfo
import com.android.launcher3.model.data.WorkspaceItemInfo
import com.android.launcher3.pm.UserCache
@@ -66,6 +67,7 @@
private val context: Context,
private val mApp: LauncherAppState,
private val iconCache: IconCache,
+ private val widgetsFilterDataProvider: WidgetsFilterDataProvider,
appFilter: AppFilter,
mPmHelper: PackageManagerHelper,
isPrimaryInstance: Boolean,
@@ -140,6 +142,11 @@
owner: BgDataModel.Callbacks?,
) = ModelWriter(mApp.context, this, mBgDataModel, verifyChanges, cellPosMapper, owner)
+ /** Returns the [WidgetsFilterDataProvider] that manages widget filters. */
+ fun getWidgetsFilterDataProvider(): WidgetsFilterDataProvider {
+ return widgetsFilterDataProvider
+ }
+
/** Called when the icon for an app changes, outside of package event */
@WorkerThread
fun onAppIconChanged(packageName: String, user: UserHandle) {
@@ -160,7 +167,10 @@
/** Called when the model is destroyed */
fun destroy() {
mModelDestroyed = true
- MODEL_EXECUTOR.execute(modelDelegate::destroy)
+ MODEL_EXECUTOR.execute {
+ modelDelegate.destroy()
+ widgetsFilterDataProvider.destroy()
+ }
}
fun onBroadcastIntent(intent: Intent) {
@@ -312,6 +322,7 @@
mBgDataModel,
this.modelDelegate,
launcherBinder,
+ widgetsFilterDataProvider,
)
// Always post the loader task, instead of running directly
@@ -417,6 +428,14 @@
}
}
+ /** Called when the widget filters are refreshed and available to bind to the model. */
+ fun onWidgetFiltersLoaded() {
+ enqueueModelUpdateTask { taskController, dataModel, _ ->
+ dataModel.widgetsModel.updateWidgetFilters(widgetsFilterDataProvider)
+ taskController.bindUpdatedWidgets(dataModel)
+ }
+ }
+
fun enqueueModelUpdateTask(task: ModelUpdateTask) {
if (mModelDestroyed) {
return
diff --git a/src/com/android/launcher3/ModelCallbacks.kt b/src/com/android/launcher3/ModelCallbacks.kt
index 496d517..5d32525 100644
--- a/src/com/android/launcher3/ModelCallbacks.kt
+++ b/src/com/android/launcher3/ModelCallbacks.kt
@@ -252,8 +252,11 @@
PopupContainerWithArrow.dismissInvalidPopup(launcher)
}
- override fun bindAllWidgets(allWidgets: List<WidgetsListBaseEntry>) {
- launcher.widgetPickerDataProvider.setWidgets(allWidgets, /* defaultWidgets= */ listOf())
+ override fun bindAllWidgets(
+ allWidgets: List<WidgetsListBaseEntry>,
+ defaultWidgets: List<WidgetsListBaseEntry>,
+ ) {
+ launcher.widgetPickerDataProvider.setWidgets(allWidgets, defaultWidgets)
}
/** Returns the ids of the workspaces to bind. */
diff --git a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
index e705d94..51d1c9f 100644
--- a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
@@ -331,6 +331,9 @@
public void setLettersToScrollLayout(
List<AlphabeticalAppsList.FastScrollSectionInfo> fastScrollSections) {
+ if (fastScrollSections.isEmpty()) {
+ return;
+ }
if (mLetterList != null) {
mLetterList.removeAllViews();
}
@@ -364,6 +367,8 @@
mLetterList.addView(lastLetterListTextView);
constraintTextViewsVertically(mLetterList, textViews);
mLetterList.setVisibility(VISIBLE);
+ // Set the alpha to 0 to avoid the letter list being shown when it shouldn't be.
+ mLetterList.setAlpha(0);
}
private void constraintTextViewsVertically(ConstraintLayout constraintLayout,
diff --git a/src/com/android/launcher3/contextualeducation/ContextualEduStatsManager.java b/src/com/android/launcher3/contextualeducation/ContextualEduStatsManager.java
index da13546..5664174 100644
--- a/src/com/android/launcher3/contextualeducation/ContextualEduStatsManager.java
+++ b/src/com/android/launcher3/contextualeducation/ContextualEduStatsManager.java
@@ -16,22 +16,25 @@
package com.android.launcher3.contextualeducation;
-import static com.android.launcher3.util.MainThreadInitializedObject.forOverride;
-
-import com.android.launcher3.R;
-import com.android.launcher3.util.MainThreadInitializedObject;
-import com.android.launcher3.util.ResourceBasedOverride;
-import com.android.launcher3.util.SafeCloseable;
+import com.android.launcher3.dagger.LauncherAppSingleton;
+import com.android.launcher3.dagger.LauncherBaseAppComponent;
+import com.android.launcher3.util.DaggerSingletonObject;
import com.android.systemui.contextualeducation.GestureType;
+import javax.inject.Inject;
+
/**
* A class to update contextual education data. It is a no-op implementation and could be
- * overridden by changing the resource value [R.string.contextual_edu_manager_class] to provide
- * a real implementation.
+ * overridden through dagger modules to provide a real implementation.
*/
-public class ContextualEduStatsManager implements ResourceBasedOverride, SafeCloseable {
- public static final MainThreadInitializedObject<ContextualEduStatsManager> INSTANCE =
- forOverride(ContextualEduStatsManager.class, R.string.contextual_edu_manager_class);
+@LauncherAppSingleton
+public class ContextualEduStatsManager {
+ public static final DaggerSingletonObject<ContextualEduStatsManager> INSTANCE =
+ new DaggerSingletonObject<>(LauncherBaseAppComponent::getContextualEduStatsManager);
+
+ @Inject
+ public ContextualEduStatsManager() { }
+
/**
* Updates contextual education stats when a gesture is triggered
@@ -40,8 +43,4 @@
*/
public void updateEduStats(boolean isTrackpadGesture, GestureType gestureType) {
}
-
- @Override
- public void close() {
- }
}
diff --git a/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java b/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java
index ecc5bb2..0e20f75 100644
--- a/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java
+++ b/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java
@@ -18,12 +18,17 @@
import android.content.Context;
+import com.android.launcher3.contextualeducation.ContextualEduStatsManager;
+import com.android.launcher3.graphics.IconShape;
+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.PackageManagerHelper;
import com.android.launcher3.util.PluginManagerWrapper;
import com.android.launcher3.util.ScreenOnTracker;
import com.android.launcher3.util.SettingsCache;
+import com.android.launcher3.util.VibratorWrapper;
import com.android.launcher3.util.window.RefreshRateTracker;
import com.android.launcher3.widget.custom.CustomWidgetManager;
@@ -39,13 +44,18 @@
*/
public interface LauncherBaseAppComponent {
DaggerSingletonTracker getDaggerSingletonTracker();
- RefreshRateTracker getRefreshRateTracker();
- InstallSessionHelper getInstallSessionHelper();
ApiWrapper getApiWrapper();
+ ContextualEduStatsManager getContextualEduStatsManager();
+ CustomWidgetManager getCustomWidgetManager();
+ IconShape getIconShape();
+ InstallSessionHelper getInstallSessionHelper();
+ ItemInstallQueue getItemInstallQueue();
+ RefreshRateTracker getRefreshRateTracker();
ScreenOnTracker getScreenOnTracker();
SettingsCache getSettingsCache();
- CustomWidgetManager getCustomWidgetManager();
+ PackageManagerHelper getPackageManagerHelper();
PluginManagerWrapper getPluginManagerWrapper();
+ VibratorWrapper getVibratorWrapper();
/** Builder for LauncherBaseAppComponent. */
interface Builder {
diff --git a/src/com/android/launcher3/graphics/GridCustomizationsProvider.java b/src/com/android/launcher3/graphics/GridCustomizationsProvider.java
index bc51a66..7367f2e 100644
--- a/src/com/android/launcher3/graphics/GridCustomizationsProvider.java
+++ b/src/com/android/launcher3/graphics/GridCustomizationsProvider.java
@@ -67,7 +67,7 @@
* path: path of the shape, assuming drawn on 100x100 view port
* is_default: true if this shape option is currently set to the system
*
- * /grid_options: List the various available grid options, where each has following fields
+ * /list_options: List the various available grid options, where each has following fields
* name: key of the grid option
* rows: number of rows in the grid
* cols: number of columns in the grid
@@ -85,20 +85,22 @@
private static final String TAG = "GridCustomizationsProvider";
- private static final String KEY_SHAPE_KEY = "shape_key";
- private static final String KEY_TITLE = "title";
- private static final String KEY_PATH = "path";
- // is_default means if a certain option is currently set to the system
- private static final String KEY_IS_DEFAULT = "is_default";
- // Key of grid option. We do not change the name to grid_key for backward compatibility
- private static final String KEY_GRID_KEY = "name";
+ private static final String KEY_NAME = "name";
+ private static final String KEY_GRID_TITLE = "grid_title";
private static final String KEY_ROWS = "rows";
private static final String KEY_COLS = "cols";
private static final String KEY_PREVIEW_COUNT = "preview_count";
+ // is_default means if a certain option is currently set to the system
+ private static final String KEY_IS_DEFAULT = "is_default";
+ private static final String KEY_SHAPE_KEY = "shape_key";
+ private static final String KEY_SHAPE_TITLE = "shape_title";
+ private static final String KEY_PATH = "path";
+ // list_options is the key for grid option list
+ private static final String KEY_LIST_OPTIONS = "/list_options";
private static final String KEY_SHAPE_OPTIONS = "/shape_options";
- private static final String KEY_GRID_OPTIONS = "/grid_options";
- private static final String KEY_SHAPE_GRID = "/default_grid";
+ // default_grid is for setting grid and shape to system settings
+ private static final String KEY_DEFAULT_GRID = "/default_grid";
private static final String METHOD_GET_PREVIEW = "get_preview";
@@ -110,6 +112,7 @@
private static final String KEY_SURFACE_PACKAGE = "surface_package";
private static final String KEY_CALLBACK = "callback";
public static final String KEY_HIDE_BOTTOM_ROW = "hide_bottom_row";
+ public static final String KEY_GRID_NAME = "grid_name";
private static final int MESSAGE_ID_UPDATE_PREVIEW = 1337;
private static final int MESSAGE_ID_UPDATE_SHAPE = 2586;
@@ -133,17 +136,18 @@
if (context == null || path == null) {
return null;
}
+
switch (path) {
case KEY_SHAPE_OPTIONS: {
if (Flags.newCustomizationPickerUi()) {
MatrixCursor cursor = new MatrixCursor(new String[]{
- KEY_SHAPE_KEY, KEY_TITLE, KEY_PATH, KEY_IS_DEFAULT});
+ KEY_SHAPE_KEY, KEY_SHAPE_TITLE, KEY_PATH, KEY_IS_DEFAULT});
List<AppShape> shapes = AppShapesProvider.INSTANCE.getShapes();
for (int i = 0; i < shapes.size(); i++) {
AppShape shape = shapes.get(i);
cursor.newRow()
.add(KEY_SHAPE_KEY, shape.getKey())
- .add(KEY_TITLE, shape.getTitle())
+ .add(KEY_SHAPE_TITLE, shape.getTitle())
.add(KEY_PATH, shape.getPath())
// TODO (b/348664593): We should fetch the currently-set shape
// option from the preferences.
@@ -154,13 +158,15 @@
return null;
}
}
- case KEY_GRID_OPTIONS: {
+ case KEY_LIST_OPTIONS: {
MatrixCursor cursor = new MatrixCursor(new String[]{
- KEY_GRID_KEY, KEY_ROWS, KEY_COLS, KEY_PREVIEW_COUNT, KEY_IS_DEFAULT});
- InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(context);
- for (GridOption gridOption : idp.parseAllGridOptions(context)) {
+ KEY_NAME, KEY_GRID_TITLE, KEY_ROWS, KEY_COLS, KEY_PREVIEW_COUNT,
+ KEY_IS_DEFAULT});
+ InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(getContext());
+ for (GridOption gridOption : idp.parseAllGridOptions(getContext())) {
cursor.newRow()
- .add(KEY_GRID_KEY, gridOption.name)
+ .add(KEY_NAME, gridOption.name)
+ .add(KEY_GRID_TITLE, gridOption.title)
.add(KEY_ROWS, gridOption.numRows)
.add(KEY_COLS, gridOption.numColumns)
.add(KEY_PREVIEW_COUNT, 1)
@@ -203,7 +209,7 @@
return 0;
}
switch (path) {
- case KEY_SHAPE_GRID: {
+ case KEY_DEFAULT_GRID: {
if (Flags.newCustomizationPickerUi()) {
String shapeKey = values.getAsString(KEY_SHAPE_KEY);
Optional<AppShape> optionalShape = AppShapesProvider.INSTANCE.getShapes()
@@ -212,13 +218,13 @@
// TODO (b/348664593): Apply shapeName to the system. This needs to be a
// synchronous call.
}
- String gridKey = values.getAsString(KEY_GRID_KEY);
+ String gridName = values.getAsString(KEY_NAME);
InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(context);
// Verify that this is a valid grid option
GridOption match = null;
for (GridOption option : idp.parseAllGridOptions(context)) {
String name = option.name;
- if (name != null && name.equals(gridKey)) {
+ if (name != null && name.equals(gridName)) {
match = option;
break;
}
@@ -227,7 +233,7 @@
return 0;
}
- idp.setCurrentGrid(context, gridKey);
+ idp.setCurrentGrid(context, gridName);
if (Flags.newCustomizationPickerUi()) {
try {
// Wait for device profile to be fully reloaded and applied to the launcher
@@ -360,9 +366,9 @@
}
break;
case MESSAGE_ID_UPDATE_GRID:
- String gridKey = message.getData().getString(KEY_GRID_KEY);
- if (!TextUtils.isEmpty(gridKey)) {
- renderer.updateGrid(gridKey);
+ String gridName = message.getData().getString(KEY_GRID_NAME);
+ if (!TextUtils.isEmpty(gridName)) {
+ renderer.updateGrid(gridName);
}
break;
case MESSAGE_ID_UPDATE_COLOR:
diff --git a/src/com/android/launcher3/graphics/IconShape.java b/src/com/android/launcher3/graphics/IconShape.java
index 5f8f2dc..cb14587 100644
--- a/src/com/android/launcher3/graphics/IconShape.java
+++ b/src/com/android/launcher3/graphics/IconShape.java
@@ -41,10 +41,12 @@
import com.android.launcher3.R;
import com.android.launcher3.anim.RoundedRectRevealOutlineProvider;
+import com.android.launcher3.dagger.ApplicationContext;
+import com.android.launcher3.dagger.LauncherAppSingleton;
+import com.android.launcher3.dagger.LauncherBaseAppComponent;
import com.android.launcher3.icons.GraphicsUtils;
import com.android.launcher3.icons.IconNormalizer;
-import com.android.launcher3.util.MainThreadInitializedObject;
-import com.android.launcher3.util.SafeCloseable;
+import com.android.launcher3.util.DaggerSingletonObject;
import com.android.launcher3.views.ClipPathView;
import org.xmlpull.v1.XmlPullParser;
@@ -54,19 +56,22 @@
import java.util.ArrayList;
import java.util.List;
+import javax.inject.Inject;
+
/**
* Abstract representation of the shape of an icon shape
*/
-public final class IconShape implements SafeCloseable {
+@LauncherAppSingleton
+public final class IconShape {
- public static final MainThreadInitializedObject<IconShape> INSTANCE =
- new MainThreadInitializedObject<>(IconShape::new);
-
+ public static DaggerSingletonObject<IconShape> INSTANCE =
+ new DaggerSingletonObject<>(LauncherBaseAppComponent::getIconShape);
private ShapeDelegate mDelegate = new Circle();
private float mNormalizationScale = ICON_VISIBLE_AREA_FACTOR;
- private IconShape(Context context) {
+ @Inject
+ public IconShape(@ApplicationContext Context context) {
pickBestShape(context);
}
@@ -78,9 +83,6 @@
return mNormalizationScale;
}
- @Override
- public void close() { }
-
/**
* Initializes the shape which is closest to the {@link AdaptiveIconDrawable}
*/
diff --git a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
index 1dd7d45..94c36c0 100644
--- a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
+++ b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
@@ -305,7 +305,9 @@
bgModel,
LauncherAppState.getInstance(previewContext).getModel().getModelDelegate(),
new BaseLauncherBinder(LauncherAppState.getInstance(previewContext), bgModel,
- /* bgAllAppsList= */ null, new Callbacks[0])) {
+ /* bgAllAppsList= */ null, new Callbacks[0]),
+ LauncherAppState.getInstance(
+ previewContext).getModel().getWidgetsFilterDataProvider()) {
@Override
public void run() {
diff --git a/src/com/android/launcher3/icons/MonochromeIconFactory.java b/src/com/android/launcher3/icons/MonochromeIconFactory.java
deleted file mode 100644
index 2854d51..0000000
--- a/src/com/android/launcher3/icons/MonochromeIconFactory.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.launcher3.icons;
-
-import static android.graphics.Paint.FILTER_BITMAP_FLAG;
-
-import android.annotation.TargetApi;
-import android.graphics.Bitmap;
-import android.graphics.Bitmap.Config;
-import android.graphics.BlendMode;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.ColorFilter;
-import android.graphics.ColorMatrix;
-import android.graphics.ColorMatrixColorFilter;
-import android.graphics.Paint;
-import android.graphics.PixelFormat;
-import android.graphics.Rect;
-import android.graphics.drawable.AdaptiveIconDrawable;
-import android.graphics.drawable.Drawable;
-import android.os.Build;
-
-import androidx.annotation.WorkerThread;
-
-import com.android.launcher3.icons.BaseIconFactory.ClippedMonoDrawable;
-
-import java.nio.ByteBuffer;
-
-/**
- * Utility class to generate monochrome icons version for a given drawable.
- */
-@TargetApi(Build.VERSION_CODES.TIRAMISU)
-public class MonochromeIconFactory extends Drawable {
-
- private final Bitmap mFlatBitmap;
- private final Canvas mFlatCanvas;
- private final Paint mCopyPaint;
-
- private final Bitmap mAlphaBitmap;
- private final Canvas mAlphaCanvas;
- private final byte[] mPixels;
-
- private final int mBitmapSize;
- private final int mEdgePixelLength;
-
- private final Paint mDrawPaint;
- private final Rect mSrcRect;
-
- MonochromeIconFactory(int iconBitmapSize) {
- float extraFactor = AdaptiveIconDrawable.getExtraInsetFraction();
- float viewPortScale = 1 / (1 + 2 * extraFactor);
- mBitmapSize = Math.round(iconBitmapSize * 2 * viewPortScale);
- mPixels = new byte[mBitmapSize * mBitmapSize];
- mEdgePixelLength = mBitmapSize * (mBitmapSize - iconBitmapSize) / 2;
-
- mFlatBitmap = Bitmap.createBitmap(mBitmapSize, mBitmapSize, Config.ARGB_8888);
- mFlatCanvas = new Canvas(mFlatBitmap);
-
- mAlphaBitmap = Bitmap.createBitmap(mBitmapSize, mBitmapSize, Config.ALPHA_8);
- mAlphaCanvas = new Canvas(mAlphaBitmap);
-
- mDrawPaint = new Paint(FILTER_BITMAP_FLAG);
- mDrawPaint.setColor(Color.WHITE);
- mSrcRect = new Rect(0, 0, mBitmapSize, mBitmapSize);
-
- mCopyPaint = new Paint(FILTER_BITMAP_FLAG);
- mCopyPaint.setBlendMode(BlendMode.SRC);
-
- // Crate a color matrix which converts the icon to grayscale and then uses the average
- // of RGB components as the alpha component.
- ColorMatrix satMatrix = new ColorMatrix();
- satMatrix.setSaturation(0);
- float[] vals = satMatrix.getArray();
- vals[15] = vals[16] = vals[17] = .3333f;
- vals[18] = vals[19] = 0;
- mCopyPaint.setColorFilter(new ColorMatrixColorFilter(vals));
- }
-
- private void drawDrawable(Drawable drawable) {
- if (drawable != null) {
- drawable.setBounds(0, 0, mBitmapSize, mBitmapSize);
- drawable.draw(mFlatCanvas);
- }
- }
-
- /**
- * Creates a monochrome version of the provided drawable
- */
- @WorkerThread
- public Drawable wrap(AdaptiveIconDrawable icon) {
- mFlatCanvas.drawColor(Color.BLACK);
- drawDrawable(icon.getBackground());
- drawDrawable(icon.getForeground());
- generateMono();
- return new ClippedMonoDrawable(this);
- }
-
- @WorkerThread
- private void generateMono() {
- mAlphaCanvas.drawBitmap(mFlatBitmap, 0, 0, mCopyPaint);
-
- // Scale the end points:
- ByteBuffer buffer = ByteBuffer.wrap(mPixels);
- buffer.rewind();
- mAlphaBitmap.copyPixelsToBuffer(buffer);
-
- int min = 0xFF;
- int max = 0;
- for (byte b : mPixels) {
- min = Math.min(min, b & 0xFF);
- max = Math.max(max, b & 0xFF);
- }
-
- if (min < max) {
- // rescale pixels to increase contrast
- float range = max - min;
-
- // In order to check if the colors should be flipped, we just take the average color
- // of top and bottom edge which should correspond to be background color. If the edge
- // colors have more opacity, we flip the colors;
- int sum = 0;
- for (int i = 0; i < mEdgePixelLength; i++) {
- sum += (mPixels[i] & 0xFF);
- sum += (mPixels[mPixels.length - 1 - i] & 0xFF);
- }
- float edgeAverage = sum / (mEdgePixelLength * 2f);
- float edgeMapped = (edgeAverage - min) / range;
- boolean flipColor = edgeMapped > .5f;
-
- for (int i = 0; i < mPixels.length; i++) {
- int p = mPixels[i] & 0xFF;
- int p2 = Math.round((p - min) * 0xFF / range);
- mPixels[i] = flipColor ? (byte) (255 - p2) : (byte) (p2);
- }
- buffer.rewind();
- mAlphaBitmap.copyPixelsFromBuffer(buffer);
- }
- }
-
- @Override
- public void draw(Canvas canvas) {
- canvas.drawBitmap(mAlphaBitmap, mSrcRect, getBounds(), mDrawPaint);
- }
-
- @Override
- public int getOpacity() {
- return PixelFormat.TRANSLUCENT;
- }
-
- @Override
- public void setAlpha(int i) {
- mDrawPaint.setAlpha(i);
- }
-
- @Override
- public void setColorFilter(ColorFilter colorFilter) {
- mDrawPaint.setColorFilter(colorFilter);
- }
-}
diff --git a/src/com/android/launcher3/model/BaseLauncherBinder.java b/src/com/android/launcher3/model/BaseLauncherBinder.java
index b51f855..c251114 100644
--- a/src/com/android/launcher3/model/BaseLauncherBinder.java
+++ b/src/com/android/launcher3/model/BaseLauncherBinder.java
@@ -24,6 +24,8 @@
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
+import static java.util.Collections.emptyList;
+
import android.os.Process;
import android.os.Trace;
import android.util.Log;
@@ -43,6 +45,7 @@
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
+import com.android.launcher3.model.data.PackageItemInfo;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.IntSet;
@@ -62,6 +65,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Executor;
+import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
@@ -162,9 +166,17 @@
if (!WIDGETS_ENABLED) {
return;
}
+ Map<PackageItemInfo, List<WidgetItem>>
+ widgetsByPackageItem = mBgDataModel.widgetsModel.getWidgetsByPackageItem();
List<WidgetsListBaseEntry> widgets = new WidgetsListBaseEntriesBuilder(mApp.getContext())
- .build(mBgDataModel.widgetsModel.getWidgetsByPackageItem());
- executeCallbacksTask(c -> c.bindAllWidgets(widgets), mUiExecutor);
+ .build(widgetsByPackageItem);
+ Predicate<WidgetItem> filter = mBgDataModel.widgetsModel.getDefaultWidgetsFilter();
+ List<WidgetsListBaseEntry> defaultWidgets =
+ filter != null ? new WidgetsListBaseEntriesBuilder(
+ mApp.getContext()).build(widgetsByPackageItem,
+ mBgDataModel.widgetsModel.getDefaultWidgetsFilter()) : emptyList();
+
+ executeCallbacksTask(c -> c.bindAllWidgets(widgets, defaultWidgets), mUiExecutor);
}
/**
diff --git a/src/com/android/launcher3/model/BgDataModel.java b/src/com/android/launcher3/model/BgDataModel.java
index 9a9fa5b..b9b1e98 100644
--- a/src/com/android/launcher3/model/BgDataModel.java
+++ b/src/com/android/launcher3/model/BgDataModel.java
@@ -537,7 +537,13 @@
default void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets) { }
default void bindRestoreItemsChange(HashSet<ItemInfo> updates) { }
default void bindWorkspaceComponentsRemoved(Predicate<ItemInfo> matcher) { }
- default void bindAllWidgets(List<WidgetsListBaseEntry> widgets) { }
+
+ /**
+ * Binds the app widgets to the providers that share widgets with the UI.
+ */
+ default void bindAllWidgets(@NonNull List<WidgetsListBaseEntry> widgets,
+ @NonNull List<WidgetsListBaseEntry> defaultWidgets) {
+ }
default void bindSmartspaceWidget() { }
/** Called when workspace has been bound. */
diff --git a/src/com/android/launcher3/model/DbEntry.java b/src/com/android/launcher3/model/DbEntry.java
deleted file mode 100644
index c0c51da..0000000
--- a/src/com/android/launcher3/model/DbEntry.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (C) 2024 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.model;
-
-import android.content.ContentValues;
-import android.content.Intent;
-import android.util.Log;
-
-import androidx.annotation.NonNull;
-
-import com.android.launcher3.LauncherSettings;
-import com.android.launcher3.model.data.ItemInfo;
-import com.android.launcher3.util.ContentWriter;
-
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-public class DbEntry extends ItemInfo implements Comparable<DbEntry> {
-
- private static final String TAG = "DbEntry";
-
- String mIntent;
- String mProvider;
- Map<String, Set<Integer>> mFolderItems = new HashMap<>();
-
- /**
- * Id of the specific widget.
- */
- public int appWidgetId = NO_ID;
-
- /** Comparator according to the reading order */
- @Override
- public int compareTo(DbEntry another) {
- if (screenId != another.screenId) {
- return Integer.compare(screenId, another.screenId);
- }
- if (cellY != another.cellY) {
- return Integer.compare(cellY, another.cellY);
- }
- return Integer.compare(cellX, another.cellX);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof DbEntry)) return false;
- DbEntry entry = (DbEntry) o;
- return Objects.equals(getEntryMigrationId(), entry.getEntryMigrationId());
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(getEntryMigrationId());
- }
-
- /**
- * Puts the updated DbEntry values into ContentValues which we then use to insert the
- * entry to the DB.
- */
- public void updateContentValues(ContentValues values) {
- values.put(LauncherSettings.Favorites.SCREEN, screenId);
- values.put(LauncherSettings.Favorites.CELLX, cellX);
- values.put(LauncherSettings.Favorites.CELLY, cellY);
- values.put(LauncherSettings.Favorites.SPANX, spanX);
- values.put(LauncherSettings.Favorites.SPANY, spanY);
- }
-
- @Override
- public void writeToValues(@NonNull ContentWriter writer) {
- super.writeToValues(writer);
- writer.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
- }
-
- @Override
- public void readFromValues(@NonNull ContentValues values) {
- super.readFromValues(values);
- appWidgetId = values.getAsInteger(LauncherSettings.Favorites.APPWIDGET_ID);
- }
-
- /**
- * This id is not used in the DB is only used while doing the migration and it identifies
- * an entry on each workspace. For example two calculator icons would have the same
- * migration id even thought they have different database ids.
- */
- public String getEntryMigrationId() {
- switch (itemType) {
- case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
- case LauncherSettings.Favorites.ITEM_TYPE_APP_PAIR:
- return getFolderMigrationId();
- case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
- // mProvider is the app the widget belongs to and appWidgetId it's the unique
- // is of the widget, we need both because if you remove a widget and then add it
- // again, then it can change and the WidgetProvider would not know the widget.
- return mProvider + appWidgetId;
- case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
- final String intentStr = cleanIntentString(mIntent);
- try {
- Intent i = Intent.parseUri(intentStr, 0);
- return Objects.requireNonNull(i.getComponent()).toString();
- } catch (Exception e) {
- return intentStr;
- }
- default:
- return cleanIntentString(mIntent);
- }
- }
-
- /**
- * This method should return an id that should be the same for two folders containing the
- * same elements.
- */
- @NonNull
- private String getFolderMigrationId() {
- return mFolderItems.keySet().stream()
- .map(intentString -> mFolderItems.get(intentString).size()
- + cleanIntentString(intentString))
- .sorted()
- .collect(Collectors.joining(","));
- }
-
- /**
- * This is needed because sourceBounds can change and make the id of two equal items
- * different.
- */
- @NonNull
- private String cleanIntentString(@NonNull String intentStr) {
- try {
- Intent i = Intent.parseUri(intentStr, 0);
- i.setSourceBounds(null);
- return i.toURI();
- } catch (URISyntaxException e) {
- Log.e(TAG, "Unable to parse Intent string", e);
- return intentStr;
- }
-
- }
-}
diff --git a/src/com/android/launcher3/model/DbEntry.kt b/src/com/android/launcher3/model/DbEntry.kt
new file mode 100644
index 0000000..b79d312
--- /dev/null
+++ b/src/com/android/launcher3/model/DbEntry.kt
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.model
+
+import android.content.ContentValues
+import android.content.Intent
+import android.util.Log
+import com.android.launcher3.LauncherSettings
+import com.android.launcher3.LauncherSettings.Favorites.CELLX
+import com.android.launcher3.LauncherSettings.Favorites.CELLY
+import com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION
+import com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET
+import com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APP_PAIR
+import com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_FOLDER
+import com.android.launcher3.LauncherSettings.Favorites.SCREEN
+import com.android.launcher3.LauncherSettings.Favorites.SPANX
+import com.android.launcher3.LauncherSettings.Favorites.SPANY
+import com.android.launcher3.model.data.ItemInfo
+import com.android.launcher3.util.ContentWriter
+import java.net.URISyntaxException
+import java.util.Objects
+
+class DbEntry : ItemInfo(), Comparable<DbEntry> {
+ @JvmField var mIntent: String? = null
+ @JvmField var mProvider: String? = null
+ @JvmField var mFolderItems: MutableMap<String, Set<Int>> = HashMap()
+
+ /** Id of the specific widget. */
+ @JvmField var appWidgetId: Int = NO_ID
+
+ /** Comparator according to the reading order */
+ override fun compareTo(other: DbEntry): Int {
+ if (screenId != other.screenId) {
+ return screenId.compareTo(other.screenId)
+ }
+ if (cellY != other.cellY) {
+ return cellY.compareTo(other.cellY)
+ }
+ return cellX.compareTo(other.cellX)
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) return true
+ if (other !is DbEntry) return false
+ return getEntryMigrationId() == other.getEntryMigrationId()
+ }
+
+ override fun hashCode(): Int = Objects.hash(getEntryMigrationId())
+
+ /**
+ * Puts the updated DbEntry values into ContentValues which we then use to insert the entry to
+ * the DB.
+ */
+ fun updateContentValues(values: ContentValues) =
+ values.apply {
+ put(SCREEN, screenId)
+ put(CELLX, cellX)
+ put(CELLY, cellY)
+ put(SPANX, spanX)
+ put(SPANY, spanY)
+ }
+
+ override fun writeToValues(writer: ContentWriter) {
+ super.writeToValues(writer)
+ writer.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId)
+ }
+
+ override fun readFromValues(values: ContentValues) {
+ super.readFromValues(values)
+ appWidgetId = values.getAsInteger(LauncherSettings.Favorites.APPWIDGET_ID)
+ }
+
+ /**
+ * This id is not used in the DB is only used while doing the migration and it identifies an
+ * entry on each workspace. For example two calculator icons would have the same migration id
+ * even thought they have different database ids.
+ */
+ private fun getEntryMigrationId(): String? {
+ when (itemType) {
+ ITEM_TYPE_FOLDER,
+ ITEM_TYPE_APP_PAIR -> return getFolderMigrationId()
+ ITEM_TYPE_APPWIDGET ->
+ // mProvider is the app the widget belongs to and appWidgetId it's the unique
+ // is of the widget, we need both because if you remove a widget and then add it
+ // again, then it can change and the WidgetProvider would not know the widget.
+ return mProvider + appWidgetId
+ ITEM_TYPE_APPLICATION -> {
+ val intentStr = mIntent?.let { cleanIntentString(it) }
+ try {
+ val i = Intent.parseUri(intentStr, 0)
+ return Objects.requireNonNull(i.component).toString()
+ } catch (e: Exception) {
+ return intentStr
+ }
+ }
+
+ else -> return mIntent?.let { cleanIntentString(it) }
+ }
+ }
+
+ /**
+ * This method should return an id that should be the same for two folders containing the same
+ * elements.
+ */
+ private fun getFolderMigrationId(): String =
+ mFolderItems.keys
+ .map { intentString: String ->
+ mFolderItems[intentString]?.size.toString() + cleanIntentString(intentString)
+ }
+ .sorted()
+ .joinToString(",")
+
+ /**
+ * This is needed because sourceBounds can change and make the id of two equal items different.
+ */
+ private fun cleanIntentString(intentStr: String): String {
+ try {
+ return Intent.parseUri(intentStr, 0).apply { sourceBounds = null }.toURI()
+ } catch (e: URISyntaxException) {
+ Log.e(TAG, "Unable to parse Intent string", e)
+ return intentStr
+ }
+ }
+
+ companion object {
+ private const val TAG = "DbEntry"
+ }
+}
diff --git a/src/com/android/launcher3/model/DeviceGridState.java b/src/com/android/launcher3/model/DeviceGridState.java
index 729b381..90af215 100644
--- a/src/com/android/launcher3/model/DeviceGridState.java
+++ b/src/com/android/launcher3/model/DeviceGridState.java
@@ -156,10 +156,16 @@
}
public Integer getColumns() {
+ if (TextUtils.isEmpty(mGridSizeString)) {
+ return -1;
+ }
return Integer.parseInt(String.valueOf(mGridSizeString.split(",")[0]));
}
public Integer getRows() {
+ if (TextUtils.isEmpty(mGridSizeString)) {
+ return -1;
+ }
return Integer.parseInt(String.valueOf(mGridSizeString.split(",")[1]));
}
diff --git a/src/com/android/launcher3/model/GridSizeMigrationDBController.java b/src/com/android/launcher3/model/GridSizeMigrationDBController.java
index d8ca095..2d6be7e 100644
--- a/src/com/android/launcher3/model/GridSizeMigrationDBController.java
+++ b/src/com/android/launcher3/model/GridSizeMigrationDBController.java
@@ -38,7 +38,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
-import com.android.launcher3.Flags;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.LauncherSettings;
@@ -86,6 +85,9 @@
if (needsToMigrate) {
Log.i(TAG, "Migration is needed. destDeviceState: " + destDeviceState
+ ", srcDeviceState: " + srcDeviceState);
+ } else {
+ Log.i(TAG, "Migration is not needed. destDeviceState: " + destDeviceState
+ + ", srcDeviceState: " + srcDeviceState);
}
return needsToMigrate;
}
@@ -118,21 +120,13 @@
@NonNull DatabaseHelper target,
@NonNull SQLiteDatabase source) {
- Log.i("b/360462379", "Going from " + srcDeviceState.getColumns() + "x"
- + srcDeviceState.getRows());
- Log.i("b/360462379", "Going to " + destDeviceState.getColumns() + "x"
- + destDeviceState.getRows());
-
if (!needsToMigrate(srcDeviceState, destDeviceState)) {
- Log.i("b/360462379", "Does not need to migrate.");
return true;
}
if (LauncherPrefs.get(context).get(IS_FIRST_LOAD_AFTER_RESTORE)
- && Flags.enableGridMigrationFix()
&& srcDeviceState.getColumns().equals(destDeviceState.getColumns())
&& srcDeviceState.getRows() < destDeviceState.getRows()) {
- Log.i("b/360462379", "Grid migration fix entry point.");
// Only use this strategy when comparing the previous grid to the new grid and the
// columns are the same and the destination has more rows
copyTable(source, TABLE_NAME, target.getWritableDatabase(), TABLE_NAME, context);
@@ -452,7 +446,7 @@
final Context mContext;
int mLastScreenId = -1;
- final Map<Integer, ArrayList<DbEntry>> mWorkspaceEntriesByScreenId =
+ final Map<Integer, List<DbEntry>> mWorkspaceEntriesByScreenId =
new ArrayMap<>();
public DbReader(SQLiteDatabase db, String tableName, Context context) {
diff --git a/src/com/android/launcher3/model/GridSizeMigrationLogic.java b/src/com/android/launcher3/model/GridSizeMigrationLogic.java
deleted file mode 100644
index f8c8f77..0000000
--- a/src/com/android/launcher3/model/GridSizeMigrationLogic.java
+++ /dev/null
@@ -1,481 +0,0 @@
-/*
- * Copyright (C) 2024 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.model;
-
-import static com.android.launcher3.Flags.enableSmartspaceRemovalToggle;
-import static com.android.launcher3.LauncherPrefs.IS_FIRST_LOAD_AFTER_RESTORE;
-import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME;
-import static com.android.launcher3.LauncherSettings.Favorites.TMP_TABLE;
-import static com.android.launcher3.Utilities.SHOULD_SHOW_FIRST_PAGE_WIDGET;
-import static com.android.launcher3.model.GridSizeMigrationDBController.copyCurrentGridToNewGrid;
-import static com.android.launcher3.model.GridSizeMigrationDBController.insertEntryInDb;
-import static com.android.launcher3.model.GridSizeMigrationDBController.needsToMigrate;
-import static com.android.launcher3.model.GridSizeMigrationDBController.removeEntryFromDb;
-import static com.android.launcher3.model.LoaderTask.SMARTSPACE_ON_HOME_SCREEN;
-import static com.android.launcher3.provider.LauncherDbUtils.copyTable;
-import static com.android.launcher3.provider.LauncherDbUtils.dropTable;
-
-import android.content.Context;
-import android.database.sqlite.SQLiteDatabase;
-import android.graphics.Point;
-import android.util.Log;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.VisibleForTesting;
-
-import com.android.launcher3.Flags;
-import com.android.launcher3.LauncherPrefs;
-import com.android.launcher3.LauncherSettings;
-import com.android.launcher3.config.FeatureFlags;
-import com.android.launcher3.provider.LauncherDbUtils;
-import com.android.launcher3.util.CellAndSpan;
-import com.android.launcher3.util.GridOccupancy;
-import com.android.launcher3.util.IntArray;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-public class GridSizeMigrationLogic {
-
- private static final String TAG = "GridSizeMigrationLogic";
- private static final boolean DEBUG = true;
-
- /**
- * Migrates the grid size from srcDeviceState to destDeviceState and make those changes
- * in the target DB, using the source DB to determine what to add/remove/move/resize
- * in the destination DB.
- */
- public void migrateGrid(
- @NonNull Context context,
- @NonNull DeviceGridState srcDeviceState,
- @NonNull DeviceGridState destDeviceState,
- @NonNull DatabaseHelper target,
- @NonNull SQLiteDatabase source) {
- if (!needsToMigrate(srcDeviceState, destDeviceState)) {
- return;
- }
-
- boolean isFirstLoad = LauncherPrefs.get(context).get(IS_FIRST_LOAD_AFTER_RESTORE);
- Log.d(TAG, "Begin grid migration. First load: " + isFirstLoad);
-
- // This is a special case where if the grid is the same amount of columns but a larger
- // amount of rows we simply copy over the source grid to the destination grid, rather
- // than undergoing the general grid migration.
- if (shouldMigrateToStrictlyTallerGrid(isFirstLoad, srcDeviceState, destDeviceState)) {
- copyCurrentGridToNewGrid(context, destDeviceState, target, source);
- return;
- }
- copyTable(source, TABLE_NAME, target.getWritableDatabase(), TMP_TABLE, context);
-
- long migrationStartTime = System.currentTimeMillis();
- try (LauncherDbUtils.SQLiteTransaction t =
- new LauncherDbUtils.SQLiteTransaction(target.getWritableDatabase())) {
- GridSizeMigrationDBController.DbReader srcReader = new GridSizeMigrationDBController
- .DbReader(t.getDb(), TMP_TABLE, context);
- GridSizeMigrationDBController.DbReader destReader =
- new GridSizeMigrationDBController.DbReader(
- t.getDb(), TABLE_NAME, context);
-
- Point targetSize = new Point(destDeviceState.getColumns(), destDeviceState.getRows());
-
- // Here we keep all the DB ids we have in the destination DB such that we don't assign
- // an item that we want to add to the destination DB the same id as an already existing
- // item.
- List<Integer> idsInUse = new ArrayList<>();
-
- // Migrate hotseat.
- migrateHotseat(destDeviceState.getNumHotseat(), srcReader, destReader, target,
- idsInUse);
- // Migrate workspace.
- migrateWorkspace(srcReader, destReader, target, targetSize, idsInUse);
-
- dropTable(t.getDb(), TMP_TABLE);
- t.commit();
- } catch (Exception e) {
- Log.e(TAG, "Error during grid migration", e);
- } finally {
- Log.v(TAG, "Workspace migration completed in "
- + (System.currentTimeMillis() - migrationStartTime));
-
- // Save current configuration, so that the migration does not run again.
- destDeviceState.writeToPrefs(context);
- }
- }
-
- /**
- * Handles hotseat migration.
- */
- @VisibleForTesting
- public void migrateHotseat(int destHotseatSize,
- GridSizeMigrationDBController.DbReader srcReader,
- GridSizeMigrationDBController.DbReader destReader,
- DatabaseHelper helper, List<Integer> idsInUse) {
- final List<DbEntry> srcHotseatItems =
- srcReader.loadHotseatEntries();
- final List<DbEntry> dstHotseatItems =
- destReader.loadHotseatEntries();
-
- final List<DbEntry> hotseatToBeAdded =
- getItemsToBeAdded(srcHotseatItems, dstHotseatItems);
-
- final IntArray toBeRemoved = new IntArray();
- toBeRemoved.addAll(getItemsToBeRemoved(srcHotseatItems, dstHotseatItems));
-
- if (DEBUG) {
- Log.d(TAG, "Start hotseat migration:"
- + "\n Removing Hotseat Items:"
- + dstHotseatItems.stream().filter(entry -> toBeRemoved
- .contains(entry.id)).map(DbEntry::toString)
- .collect(Collectors.joining(",\n", "[", "]"))
- + "\n Adding Hotseat Items:"
- + hotseatToBeAdded.stream().map(DbEntry::toString)
- .collect(Collectors.joining(",\n", "[", "]"))
- );
- }
-
- // Removes the items that we need to remove from the destination DB.
- if (!toBeRemoved.isEmpty()) {
- removeEntryFromDb(destReader.mDb, destReader.mTableName, toBeRemoved);
- }
-
- placeHotseatItems(hotseatToBeAdded, dstHotseatItems, destHotseatSize, helper, srcReader,
- destReader, idsInUse);
- }
-
- private void placeHotseatItems(List<DbEntry> hotseatToBeAdded,
- List<DbEntry> dstHotseatItems, int destHotseatSize,
- DatabaseHelper helper, GridSizeMigrationDBController.DbReader srcReader,
- GridSizeMigrationDBController.DbReader destReader, List<Integer> idsInUse) {
- if (hotseatToBeAdded.isEmpty()) {
- return;
- }
-
- idsInUse.addAll(dstHotseatItems.stream().map(entry -> entry.id).toList());
-
- Collections.sort(hotseatToBeAdded);
-
- List<DbEntry> placementSolutionHotseat =
- solveHotseatPlacement(destHotseatSize, dstHotseatItems, hotseatToBeAdded);
- for (DbEntry entryToPlace: placementSolutionHotseat) {
- insertEntryInDb(helper, entryToPlace, srcReader.mTableName, destReader.mTableName,
- idsInUse);
- }
- }
-
-
- /**
- * Handles workspace migration.
- */
- @VisibleForTesting
- public void migrateWorkspace(GridSizeMigrationDBController.DbReader srcReader,
- GridSizeMigrationDBController.DbReader destReader, DatabaseHelper helper,
- Point targetSize, List<Integer> idsInUse) {
- final List<DbEntry> srcWorkspaceItems =
- srcReader.loadAllWorkspaceEntries();
-
- final List<DbEntry> dstWorkspaceItems =
- destReader.loadAllWorkspaceEntries();
-
- final IntArray toBeRemoved = new IntArray();
-
- List<DbEntry> workspaceToBeAdded =
- getItemsToBeAdded(srcWorkspaceItems, dstWorkspaceItems);
- toBeRemoved.addAll(getItemsToBeRemoved(srcWorkspaceItems, dstWorkspaceItems));
-
- if (DEBUG) {
- Log.d(TAG, "Start workspace migration:"
- + "\n Source Device:"
- + srcWorkspaceItems.stream().map(
- DbEntry::toString)
- .collect(Collectors.joining(",\n", "[", "]"))
- + "\n Target Device:"
- + dstWorkspaceItems.stream().map(
- DbEntry::toString)
- .collect(Collectors.joining(",\n", "[", "]"))
- + "\n Removing Workspace Items:"
- + dstWorkspaceItems.stream().filter(entry -> toBeRemoved
- .contains(entry.id)).map(
- DbEntry::toString)
- .collect(Collectors.joining(",\n", "[", "]"))
- + "\n Adding Workspace Items:"
- + workspaceToBeAdded.stream().map(
- DbEntry::toString)
- .collect(Collectors.joining(",\n", "[", "]"))
- );
- }
-
- // Removes the items that we need to remove from the destination DB.
- if (!toBeRemoved.isEmpty()) {
- removeEntryFromDb(destReader.mDb, destReader.mTableName, toBeRemoved);
- }
-
- placeWorkspaceItems(workspaceToBeAdded, dstWorkspaceItems, targetSize.x, targetSize.y,
- helper, srcReader, destReader, idsInUse);
- }
-
- private void placeWorkspaceItems(
- List<DbEntry> workspaceToBeAdded,
- List<DbEntry> dstWorkspaceItems,
- int trgX, int trgY, DatabaseHelper helper,
- GridSizeMigrationDBController.DbReader srcReader,
- GridSizeMigrationDBController.DbReader destReader, List<Integer> idsInUse) {
- if (workspaceToBeAdded.isEmpty()) {
- return;
- }
-
- idsInUse.addAll(dstWorkspaceItems.stream().map(entry -> entry.id).toList());
-
- Collections.sort(workspaceToBeAdded);
-
-
- // First we create a collection of the screens
- List<Integer> screens = new ArrayList<>();
- for (int screenId = 0; screenId <= destReader.mLastScreenId; screenId++) {
- screens.add(screenId);
- }
-
- // Then we place the items on the screens
- WorkspaceItemsToPlace itemsToPlace =
- new WorkspaceItemsToPlace(workspaceToBeAdded);
- for (int screenId : screens) {
- if (DEBUG) {
- Log.d(TAG, "Migrating " + screenId);
- }
- itemsToPlace = solveGridPlacement(
- destReader.mContext, screenId, trgX, trgY, itemsToPlace.mRemainingItemsToPlace,
- destReader.mWorkspaceEntriesByScreenId.get(screenId));
- placeItems(itemsToPlace, helper, srcReader, destReader, idsInUse);
- while (!itemsToPlace.mPlacementSolution.isEmpty()) {
- insertEntryInDb(helper, itemsToPlace.mPlacementSolution.remove(0),
- srcReader.mTableName, destReader.mTableName, idsInUse);
- }
- if (itemsToPlace.mRemainingItemsToPlace.isEmpty()) {
- break;
- }
- }
-
- // In case the new grid is smaller, there might be some leftover items that don't fit on
- // any of the screens, in this case we add them to new screens until all of them are placed.
- int screenId = destReader.mLastScreenId + 1;
- while (!itemsToPlace.mRemainingItemsToPlace.isEmpty()) {
- itemsToPlace = solveGridPlacement(destReader.mContext, screenId,
- trgX, trgY, itemsToPlace.mRemainingItemsToPlace,
- destReader.mWorkspaceEntriesByScreenId.get(screenId));
- placeItems(itemsToPlace, helper, srcReader, destReader, idsInUse);
- screenId++;
- }
- }
-
- private void placeItems(WorkspaceItemsToPlace itemsToPlace, DatabaseHelper helper,
- GridSizeMigrationDBController.DbReader srcReader,
- GridSizeMigrationDBController.DbReader destReader, List<Integer> idsInUse) {
- while (!itemsToPlace.mPlacementSolution.isEmpty()) {
- insertEntryInDb(helper, itemsToPlace.mPlacementSolution.remove(0),
- srcReader.mTableName, destReader.mTableName, idsInUse);
- }
- }
-
-
- /**
- * Only migrate the grid in this manner if the target grid is taller and not wider.
- */
- private boolean shouldMigrateToStrictlyTallerGrid(boolean isFirstLoad,
- @NonNull DeviceGridState srcDeviceState,
- @NonNull DeviceGridState destDeviceState) {
- if (isFirstLoad
- && Flags.enableGridMigrationFix()
- && srcDeviceState.getColumns().equals(destDeviceState.getColumns())
- && srcDeviceState.getRows() < destDeviceState.getRows()) {
- return true;
- }
- return false;
- }
-
- /**
- * Finds all the items that are in the old grid which aren't in the new grid, meaning they
- * need to be added to the new grid.
- *
- * @return a list of DbEntry's which we need to add.
- */
- private List<DbEntry> getItemsToBeAdded(
- @NonNull final List<DbEntry> src,
- @NonNull final List<DbEntry> dest) {
- Map<DbEntry, Integer> entryCountDiff =
- calcDiff(src, dest);
- List<DbEntry> toBeAdded = new ArrayList<>();
- src.forEach(entry -> {
- if (entryCountDiff.get(entry) > 0) {
- toBeAdded.add(entry);
- entryCountDiff.put(entry, entryCountDiff.get(entry) - 1);
- }
- });
- return toBeAdded;
- }
-
- /**
- * Finds all the items that are in the new grid which aren't in the old grid, meaning they
- * need to be removed from the new grid.
- *
- * @return an IntArray of item id's which we need to remove.
- */
- private IntArray getItemsToBeRemoved(
- @NonNull final List<DbEntry> src,
- @NonNull final List<DbEntry> dest) {
- Map<DbEntry, Integer> entryCountDiff =
- calcDiff(src, dest);
- IntArray toBeRemoved = new IntArray();
- dest.forEach(entry -> {
- if (entryCountDiff.get(entry) < 0) {
- toBeRemoved.add(entry.id);
- if (entry.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
- entry.mFolderItems.values().forEach(ids -> ids.forEach(toBeRemoved::add));
- }
- entryCountDiff.put(entry, entryCountDiff.get(entry) + 1);
- }
- });
- return toBeRemoved;
- }
-
- /**
- * Calculates the difference between the old and new grid items in terms of how many of each
- * item there are. E.g. if the old grid had 2 Calculator icons but the new grid has 0, then the
- * difference there would be 2. While if the old grid has 0 Calculator icons and the
- * new grid has 1, then the difference would be -1.
- *
- * @return a Map with each DbEntry as a key and the count of said entry as the value.
- */
- private Map<DbEntry, Integer> calcDiff(
- @NonNull final List<DbEntry> src,
- @NonNull final List<DbEntry> dest) {
- Map<DbEntry, Integer> entryCountDiff = new HashMap<>();
- src.forEach(entry ->
- entryCountDiff.put(entry, entryCountDiff.getOrDefault(entry, 0) + 1));
- dest.forEach(entry ->
- entryCountDiff.put(entry, entryCountDiff.getOrDefault(entry, 0) - 1));
- return entryCountDiff;
- }
-
- private List<DbEntry> solveHotseatPlacement(final int hotseatSize,
- @NonNull final List<DbEntry> placedHotseatItems,
- @NonNull final List<DbEntry> itemsToPlace) {
- List<DbEntry> placementSolution = new ArrayList<>();
- List<DbEntry> remainingItemsToPlace =
- new ArrayList<>(itemsToPlace);
- final boolean[] occupied = new boolean[hotseatSize];
- for (DbEntry entry : placedHotseatItems) {
- occupied[entry.screenId] = true;
- }
-
- for (int i = 0; i < occupied.length; i++) {
- if (!occupied[i] && !remainingItemsToPlace.isEmpty()) {
- DbEntry entry = remainingItemsToPlace.remove(0);
- entry.screenId = i;
- // These values does not affect the item position, but we should set them
- // to something other than -1.
- entry.cellX = i;
- entry.cellY = 0;
-
- placementSolution.add(entry);
- occupied[entry.screenId] = true;
- }
- }
- return placementSolution;
- }
-
- private WorkspaceItemsToPlace solveGridPlacement(
- Context context,
- final int screenId, final int trgX, final int trgY,
- @NonNull final List<DbEntry> sortedItemsToPlace,
- List<DbEntry> existedEntries) {
- WorkspaceItemsToPlace itemsToPlace = new WorkspaceItemsToPlace(sortedItemsToPlace);
- final GridOccupancy occupied = new GridOccupancy(trgX, trgY);
- final Point trg = new Point(trgX, trgY);
- final Point next = new Point(0, screenId == 0
- && (FeatureFlags.QSB_ON_FIRST_SCREEN
- && (!enableSmartspaceRemovalToggle() || LauncherPrefs.getPrefs(context)
- .getBoolean(SMARTSPACE_ON_HOME_SCREEN, true))
- && !SHOULD_SHOW_FIRST_PAGE_WIDGET)
- ? 1 /* smartspace */ : 0);
- if (existedEntries != null) {
- for (DbEntry entry : existedEntries) {
- occupied.markCells(entry, true);
- }
- }
- Iterator<DbEntry> iterator =
- itemsToPlace.mRemainingItemsToPlace.iterator();
- while (iterator.hasNext()) {
- final DbEntry entry = iterator.next();
- if (entry.minSpanX > trgX || entry.minSpanY > trgY) {
- iterator.remove();
- continue;
- }
- CellAndSpan placement = findPlacementForEntry(
- entry, next.x, next.y, trg, occupied);
- if (placement != null) {
- entry.screenId = screenId;
- entry.cellX = placement.cellX;
- entry.cellY = placement.cellY;
- entry.spanX = placement.spanX;
- entry.spanY = placement.spanY;
- occupied.markCells(entry, true);
- next.set(entry.cellX + entry.spanX, entry.cellY);
- itemsToPlace.mPlacementSolution.add(entry);
- iterator.remove();
- }
- }
- return itemsToPlace;
- }
-
- /**
- * Search for the next possible placement of an item. (mNextStartX, mNextStartY) serves as
- * a memoization of last placement, we can start our search for next placement from there
- * to speed up the search.
- *
- * @return NewEntryPlacement object if we found a valid placement, null if we didn't.
- */
- private CellAndSpan findPlacementForEntry(
- @NonNull final DbEntry entry,
- int startPosX, int startPosY, @NonNull final Point trg,
- @NonNull final GridOccupancy occupied) {
- for (int y = startPosY; y < trg.y; y++) {
- for (int x = startPosX; x < trg.x; x++) {
- boolean minFits = occupied.isRegionVacant(x, y, entry.minSpanX, entry.minSpanY);
- if (minFits) {
- return (new CellAndSpan(x, y, entry.minSpanX, entry.minSpanY));
- }
- }
- startPosX = 0;
- }
- return null;
- }
-
- private static class WorkspaceItemsToPlace {
- List<DbEntry> mRemainingItemsToPlace;
- List<DbEntry> mPlacementSolution;
-
- WorkspaceItemsToPlace(List<DbEntry> sortedItemsToPlace) {
- mRemainingItemsToPlace = new ArrayList<>(sortedItemsToPlace);
- mPlacementSolution = new ArrayList<>();
- }
-
- }
-}
diff --git a/src/com/android/launcher3/model/GridSizeMigrationLogic.kt b/src/com/android/launcher3/model/GridSizeMigrationLogic.kt
new file mode 100644
index 0000000..07316ef
--- /dev/null
+++ b/src/com/android/launcher3/model/GridSizeMigrationLogic.kt
@@ -0,0 +1,524 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.model
+
+import android.content.Context
+import android.database.sqlite.SQLiteDatabase
+import android.graphics.Point
+import android.util.Log
+import androidx.annotation.VisibleForTesting
+import com.android.launcher3.Flags
+import com.android.launcher3.LauncherPrefs
+import com.android.launcher3.LauncherPrefs.Companion.get
+import com.android.launcher3.LauncherPrefs.Companion.getPrefs
+import com.android.launcher3.LauncherSettings
+import com.android.launcher3.Utilities
+import com.android.launcher3.config.FeatureFlags
+import com.android.launcher3.model.GridSizeMigrationDBController.DbReader
+import com.android.launcher3.provider.LauncherDbUtils
+import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction
+import com.android.launcher3.util.CellAndSpan
+import com.android.launcher3.util.GridOccupancy
+import com.android.launcher3.util.IntArray
+
+class GridSizeMigrationLogic {
+ /**
+ * Migrates the grid size from srcDeviceState to destDeviceState and make those changes in the
+ * target DB, using the source DB to determine what to add/remove/move/resize in the destination
+ * DB.
+ */
+ fun migrateGrid(
+ context: Context,
+ srcDeviceState: DeviceGridState,
+ destDeviceState: DeviceGridState,
+ target: DatabaseHelper,
+ source: SQLiteDatabase,
+ ) {
+ if (!GridSizeMigrationDBController.needsToMigrate(srcDeviceState, destDeviceState)) {
+ return
+ }
+
+ val isFirstLoad = get(context).get(LauncherPrefs.IS_FIRST_LOAD_AFTER_RESTORE)
+ Log.d(TAG, "Begin grid migration. First load: $isFirstLoad")
+
+ // This is a special case where if the grid is the same amount of columns but a larger
+ // amount of rows we simply copy over the source grid to the destination grid, rather
+ // than undergoing the general grid migration.
+ if (shouldMigrateToStrictlyTallerGrid(isFirstLoad, srcDeviceState, destDeviceState)) {
+ GridSizeMigrationDBController.copyCurrentGridToNewGrid(
+ context,
+ destDeviceState,
+ target,
+ source,
+ )
+ return
+ }
+ LauncherDbUtils.copyTable(
+ source,
+ LauncherSettings.Favorites.TABLE_NAME,
+ target.writableDatabase,
+ LauncherSettings.Favorites.TMP_TABLE,
+ context,
+ )
+
+ val migrationStartTime = System.currentTimeMillis()
+ try {
+ SQLiteTransaction(target.writableDatabase).use { t ->
+ val srcReader = DbReader(t.db, LauncherSettings.Favorites.TMP_TABLE, context)
+ val destReader = DbReader(t.db, LauncherSettings.Favorites.TABLE_NAME, context)
+
+ val targetSize = Point(destDeviceState.columns, destDeviceState.rows)
+
+ // Here we keep all the DB ids we have in the destination DB such that we don't
+ // assign
+ // an item that we want to add to the destination DB the same id as an already
+ // existing
+ // item.
+ val idsInUse = mutableListOf<Int>()
+
+ // Migrate hotseat.
+ migrateHotseat(destDeviceState.numHotseat, srcReader, destReader, target, idsInUse)
+ // Migrate workspace.
+ migrateWorkspace(srcReader, destReader, target, targetSize, idsInUse)
+
+ LauncherDbUtils.dropTable(t.db, LauncherSettings.Favorites.TMP_TABLE)
+ t.commit()
+ }
+ } catch (e: Exception) {
+ Log.e(TAG, "Error during grid migration", e)
+ } finally {
+ Log.v(
+ TAG,
+ "Workspace migration completed in " +
+ (System.currentTimeMillis() - migrationStartTime),
+ )
+
+ // Save current configuration, so that the migration does not run again.
+ destDeviceState.writeToPrefs(context)
+ }
+ }
+
+ /** Handles hotseat migration. */
+ @VisibleForTesting
+ fun migrateHotseat(
+ destHotseatSize: Int,
+ srcReader: DbReader,
+ destReader: DbReader,
+ helper: DatabaseHelper,
+ idsInUse: MutableList<Int>,
+ ) {
+ val srcHotseatItems = srcReader.loadHotseatEntries()
+ val dstHotseatItems = destReader.loadHotseatEntries()
+
+ val hotseatToBeAdded = getItemsToBeAdded(srcHotseatItems, dstHotseatItems)
+ val toBeRemoved = IntArray()
+ toBeRemoved.addAll(getItemsToBeRemoved(srcHotseatItems, dstHotseatItems))
+
+ if (DEBUG) {
+ Log.d(
+ TAG,
+ """Start hotseat migration:
+ |Removing Hotseat Items: [${dstHotseatItems.filter { toBeRemoved.contains(it.id) }
+ .joinToString(",\n") { it.toString() }}]
+ |Adding Hotseat Items: [${hotseatToBeAdded
+ .joinToString(",\n") { it.toString() }}]
+ |"""
+ .trimMargin(),
+ )
+ }
+
+ // Removes the items that we need to remove from the destination DB.
+ if (!toBeRemoved.isEmpty) {
+ GridSizeMigrationDBController.removeEntryFromDb(
+ destReader.mDb,
+ destReader.mTableName,
+ toBeRemoved,
+ )
+ }
+
+ placeHotseatItems(
+ hotseatToBeAdded,
+ dstHotseatItems,
+ destHotseatSize,
+ helper,
+ srcReader,
+ destReader,
+ idsInUse,
+ )
+ }
+
+ private fun placeHotseatItems(
+ hotseatToBeAdded: MutableList<DbEntry>,
+ dstHotseatItems: List<DbEntry>,
+ destHotseatSize: Int,
+ helper: DatabaseHelper,
+ srcReader: DbReader,
+ destReader: DbReader,
+ idsInUse: MutableList<Int>,
+ ) {
+ if (hotseatToBeAdded.isEmpty()) {
+ return
+ }
+
+ idsInUse.addAll(dstHotseatItems.map { entry: DbEntry -> entry.id })
+
+ hotseatToBeAdded.sort()
+
+ val placementSolutionHotseat =
+ solveHotseatPlacement(destHotseatSize, dstHotseatItems, hotseatToBeAdded)
+ for (entryToPlace in placementSolutionHotseat) {
+ GridSizeMigrationDBController.insertEntryInDb(
+ helper,
+ entryToPlace,
+ srcReader.mTableName,
+ destReader.mTableName,
+ idsInUse,
+ )
+ }
+ }
+
+ @VisibleForTesting
+ fun migrateWorkspace(
+ srcReader: DbReader,
+ destReader: DbReader,
+ helper: DatabaseHelper,
+ targetSize: Point,
+ idsInUse: MutableList<Int>,
+ ) {
+ val srcWorkspaceItems = srcReader.loadAllWorkspaceEntries()
+
+ val dstWorkspaceItems = destReader.loadAllWorkspaceEntries()
+
+ val toBeRemoved = IntArray()
+
+ val workspaceToBeAdded = getItemsToBeAdded(srcWorkspaceItems, dstWorkspaceItems)
+ toBeRemoved.addAll(getItemsToBeRemoved(srcWorkspaceItems, dstWorkspaceItems))
+
+ if (DEBUG) {
+ Log.d(
+ TAG,
+ """Start workspace migration:
+ |Source Device: [${srcWorkspaceItems.joinToString(",\n") { it.toString() }}]
+ |Target Device: [${dstWorkspaceItems.joinToString(",\n") { it.toString() }}]
+ |Removing Workspace Items: [${dstWorkspaceItems.filter { toBeRemoved.contains(it.id) }
+ .joinToString(",\n") { it.toString() }}]
+ |Adding Workspace Items: [${workspaceToBeAdded
+ .joinToString(",\n") { it.toString() }}]
+ |"""
+ .trimMargin(),
+ )
+ }
+
+ // Removes the items that we need to remove from the destination DB.
+ if (!toBeRemoved.isEmpty) {
+ GridSizeMigrationDBController.removeEntryFromDb(
+ destReader.mDb,
+ destReader.mTableName,
+ toBeRemoved,
+ )
+ }
+
+ placeWorkspaceItems(
+ workspaceToBeAdded,
+ dstWorkspaceItems,
+ targetSize.x,
+ targetSize.y,
+ helper,
+ srcReader,
+ destReader,
+ idsInUse,
+ )
+ }
+
+ private fun placeWorkspaceItems(
+ workspaceToBeAdded: MutableList<DbEntry>,
+ dstWorkspaceItems: List<DbEntry>,
+ trgX: Int,
+ trgY: Int,
+ helper: DatabaseHelper,
+ srcReader: DbReader,
+ destReader: DbReader,
+ idsInUse: MutableList<Int>,
+ ) {
+ if (workspaceToBeAdded.isEmpty()) {
+ return
+ }
+
+ idsInUse.addAll(dstWorkspaceItems.map { entry: DbEntry -> entry.id })
+
+ workspaceToBeAdded.sort()
+
+ // First we create a collection of the screens
+ val screens: MutableList<Int> = ArrayList()
+ for (screenId in 0..destReader.mLastScreenId) {
+ screens.add(screenId)
+ }
+
+ // Then we place the items on the screens
+ var itemsToPlace = WorkspaceItemsToPlace(workspaceToBeAdded, mutableListOf())
+ for (screenId in screens) {
+ if (DEBUG) {
+ Log.d(TAG, "Migrating $screenId")
+ }
+ itemsToPlace =
+ solveGridPlacement(
+ destReader.mContext,
+ screenId,
+ trgX,
+ trgY,
+ itemsToPlace.mRemainingItemsToPlace,
+ destReader.mWorkspaceEntriesByScreenId[screenId],
+ )
+ placeItems(itemsToPlace, helper, srcReader, destReader, idsInUse)
+ while (itemsToPlace.mPlacementSolution.isNotEmpty()) {
+ GridSizeMigrationDBController.insertEntryInDb(
+ helper,
+ itemsToPlace.mPlacementSolution.removeAt(0),
+ srcReader.mTableName,
+ destReader.mTableName,
+ idsInUse,
+ )
+ }
+ if (itemsToPlace.mRemainingItemsToPlace.isEmpty()) {
+ break
+ }
+ }
+
+ // In case the new grid is smaller, there might be some leftover items that don't fit on
+ // any of the screens, in this case we add them to new screens until all of them are placed.
+ var screenId = destReader.mLastScreenId + 1
+ while (itemsToPlace.mRemainingItemsToPlace.isNotEmpty()) {
+ itemsToPlace =
+ solveGridPlacement(
+ destReader.mContext,
+ screenId,
+ trgX,
+ trgY,
+ itemsToPlace.mRemainingItemsToPlace,
+ destReader.mWorkspaceEntriesByScreenId[screenId],
+ )
+ placeItems(itemsToPlace, helper, srcReader, destReader, idsInUse)
+ screenId++
+ }
+ }
+
+ private fun placeItems(
+ itemsToPlace: WorkspaceItemsToPlace,
+ helper: DatabaseHelper,
+ srcReader: DbReader,
+ destReader: DbReader,
+ idsInUse: List<Int>,
+ ) {
+ while (itemsToPlace.mPlacementSolution.isNotEmpty()) {
+ GridSizeMigrationDBController.insertEntryInDb(
+ helper,
+ itemsToPlace.mPlacementSolution.removeAt(0),
+ srcReader.mTableName,
+ destReader.mTableName,
+ idsInUse,
+ )
+ }
+ }
+
+ /** Only migrate the grid in this manner if the target grid is taller and not wider. */
+ private fun shouldMigrateToStrictlyTallerGrid(
+ isFirstLoad: Boolean,
+ srcDeviceState: DeviceGridState,
+ destDeviceState: DeviceGridState,
+ ): Boolean {
+ return isFirstLoad &&
+ srcDeviceState.columns == destDeviceState.columns &&
+ srcDeviceState.rows < destDeviceState.rows
+ }
+
+ /**
+ * Finds all the items that are in the old grid which aren't in the new grid, meaning they need
+ * to be added to the new grid.
+ *
+ * @return a list of DbEntry's which we need to add.
+ */
+ private fun getItemsToBeAdded(src: List<DbEntry>, dest: List<DbEntry>): MutableList<DbEntry> {
+ val entryCountDiff = calcDiff(src, dest)
+ val toBeAdded: MutableList<DbEntry> = ArrayList()
+ src.forEach { entry ->
+ entryCountDiff[entry]?.let { entryDiff ->
+ if (entryDiff > 0) {
+ toBeAdded.add(entry)
+ entryCountDiff[entry] = entryDiff - 1
+ }
+ }
+ }
+ return toBeAdded
+ }
+
+ /**
+ * Finds all the items that are in the new grid which aren't in the old grid, meaning they need
+ * to be removed from the new grid.
+ *
+ * @return an IntArray of item id's which we need to remove.
+ */
+ private fun getItemsToBeRemoved(src: List<DbEntry>, dest: List<DbEntry>): IntArray {
+ val entryCountDiff = calcDiff(src, dest)
+ val toBeRemoved =
+ IntArray().apply {
+ dest.forEach { entry ->
+ entryCountDiff[entry]?.let { entryDiff ->
+ if (entryDiff < 0) {
+ add(entry.id)
+ if (entry.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
+ entry.mFolderItems.values.forEach { ids ->
+ ids.forEach { value -> add(value) }
+ }
+ }
+ }
+ entryCountDiff[entry] = entryDiff.plus(1)
+ }
+ }
+ }
+ return toBeRemoved
+ }
+
+ /**
+ * Calculates the difference between the old and new grid items in terms of how many of each
+ * item there are. E.g. if the old grid had 2 Calculator icons but the new grid has 0, then the
+ * difference there would be 2. While if the old grid has 0 Calculator icons and the new grid
+ * has 1, then the difference would be -1.
+ *
+ * @return a Map with each DbEntry as a key and the count of said entry as the value.
+ */
+ private fun calcDiff(src: List<DbEntry>, dest: List<DbEntry>): MutableMap<DbEntry, Int> {
+ val entryCountDiff: MutableMap<DbEntry, Int> = HashMap()
+ src.forEach { entry -> entryCountDiff[entry] = entryCountDiff.getOrDefault(entry, 0) + 1 }
+ dest.forEach { entry -> entryCountDiff[entry] = entryCountDiff.getOrDefault(entry, 0) - 1 }
+ return entryCountDiff
+ }
+
+ private fun solveHotseatPlacement(
+ hotseatSize: Int,
+ placedHotseatItems: List<DbEntry>,
+ itemsToPlace: List<DbEntry>,
+ ): List<DbEntry> {
+ val placementSolution: MutableList<DbEntry> = ArrayList()
+ val remainingItemsToPlace: MutableList<DbEntry> = ArrayList(itemsToPlace)
+ val occupied = BooleanArray(hotseatSize)
+ for (entry in placedHotseatItems) {
+ occupied[entry.screenId] = true
+ }
+
+ for (i in occupied.indices) {
+ if (!occupied[i] && remainingItemsToPlace.isNotEmpty()) {
+ val entry: DbEntry =
+ remainingItemsToPlace.removeAt(0).apply {
+ screenId = i
+ // These values does not affect the item position, but we should set them
+ // to something other than -1.
+ cellX = i
+ cellY = 0
+ }
+ placementSolution.add(entry)
+ occupied[entry.screenId] = true
+ }
+ }
+ return placementSolution
+ }
+
+ private fun solveGridPlacement(
+ context: Context,
+ screenId: Int,
+ trgX: Int,
+ trgY: Int,
+ sortedItemsToPlace: MutableList<DbEntry>,
+ existedEntries: MutableList<DbEntry>?,
+ ): WorkspaceItemsToPlace {
+ val itemsToPlace = WorkspaceItemsToPlace(sortedItemsToPlace, mutableListOf())
+ val occupied = GridOccupancy(trgX, trgY)
+ val trg = Point(trgX, trgY)
+ val next: Point =
+ if (
+ screenId == 0 &&
+ (FeatureFlags.QSB_ON_FIRST_SCREEN &&
+ (!Flags.enableSmartspaceRemovalToggle() ||
+ getPrefs(context)
+ .getBoolean(LoaderTask.SMARTSPACE_ON_HOME_SCREEN, true)) &&
+ !Utilities.SHOULD_SHOW_FIRST_PAGE_WIDGET)
+ ) {
+ Point(0, 1 /* smartspace */)
+ } else {
+ Point(0, 0)
+ }
+ if (existedEntries != null) {
+ for (entry in existedEntries) {
+ occupied.markCells(entry, true)
+ }
+ }
+ val iterator = itemsToPlace.mRemainingItemsToPlace.iterator()
+ while (iterator.hasNext()) {
+ val entry = iterator.next()
+ if (entry.minSpanX > trgX || entry.minSpanY > trgY) {
+ iterator.remove()
+ continue
+ }
+ findPlacementForEntry(entry, next.x, next.y, trg, occupied)?.let {
+ entry.screenId = screenId
+ entry.cellX = it.cellX
+ entry.cellY = it.cellY
+ entry.spanX = it.spanX
+ entry.spanY = it.spanY
+ occupied.markCells(entry, true)
+ next[entry.cellX + entry.spanX] = entry.cellY
+ itemsToPlace.mPlacementSolution.add(entry)
+ iterator.remove()
+ }
+ }
+ return itemsToPlace
+ }
+
+ /**
+ * Search for the next possible placement of an item. (mNextStartX, mNextStartY) serves as a
+ * memoization of last placement, we can start our search for next placement from there to speed
+ * up the search.
+ *
+ * @return NewEntryPlacement object if we found a valid placement, null if we didn't.
+ */
+ private fun findPlacementForEntry(
+ entry: DbEntry,
+ startPosX: Int,
+ startPosY: Int,
+ trg: Point,
+ occupied: GridOccupancy,
+ ): CellAndSpan? {
+ var newStartPosX = startPosX
+ for (y in startPosY until trg.y) {
+ for (x in newStartPosX until trg.x) {
+ if (occupied.isRegionVacant(x, y, entry.minSpanX, entry.minSpanY)) {
+ return (CellAndSpan(x, y, entry.minSpanX, entry.minSpanY))
+ }
+ }
+ newStartPosX = 0
+ }
+ return null
+ }
+
+ private data class WorkspaceItemsToPlace(
+ val mRemainingItemsToPlace: MutableList<DbEntry>,
+ val mPlacementSolution: MutableList<DbEntry>,
+ )
+
+ companion object {
+ private const val TAG = "GridSizeMigrationLogic"
+ private const val DEBUG = true
+ }
+}
diff --git a/src/com/android/launcher3/model/ItemInstallQueue.java b/src/com/android/launcher3/model/ItemInstallQueue.java
index 49f75eb..f9c6e96 100644
--- a/src/com/android/launcher3/model/ItemInstallQueue.java
+++ b/src/com/android/launcher3/model/ItemInstallQueue.java
@@ -45,16 +45,18 @@
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings.Favorites;
+import com.android.launcher3.dagger.ApplicationContext;
+import com.android.launcher3.dagger.LauncherAppSingleton;
+import com.android.launcher3.dagger.LauncherBaseAppComponent;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.shortcuts.ShortcutRequest;
-import com.android.launcher3.util.MainThreadInitializedObject;
+import com.android.launcher3.util.DaggerSingletonObject;
import com.android.launcher3.util.PersistedItemArray;
import com.android.launcher3.util.Preconditions;
-import com.android.launcher3.util.SafeCloseable;
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
import java.util.HashSet;
@@ -62,10 +64,13 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import javax.inject.Inject;
+
/**
* Class to maintain a queue of pending items to be added to the workspace.
*/
-public class ItemInstallQueue implements SafeCloseable {
+@LauncherAppSingleton
+public class ItemInstallQueue {
private static final String LOG = "ItemInstallQueue";
@@ -81,9 +86,8 @@
public static final int NEW_SHORTCUT_BOUNCE_DURATION = 450;
public static final int NEW_SHORTCUT_STAGGER_DELAY = 85;
- public static MainThreadInitializedObject<ItemInstallQueue> INSTANCE =
- new MainThreadInitializedObject<>(ItemInstallQueue::new);
-
+ public static DaggerSingletonObject<ItemInstallQueue> INSTANCE =
+ new DaggerSingletonObject<>(LauncherBaseAppComponent::getItemInstallQueue);
private final PersistedItemArray<PendingInstallShortcutInfo> mStorage =
new PersistedItemArray<>(APPS_PENDING_INSTALL);
private final Context mContext;
@@ -95,13 +99,11 @@
// Only accessed on worker thread
private List<PendingInstallShortcutInfo> mItems;
- private ItemInstallQueue(Context context) {
+ @Inject
+ public ItemInstallQueue(@ApplicationContext Context context) {
mContext = context;
}
- @Override
- public void close() {}
-
@WorkerThread
private void ensureQueueLoaded() {
Preconditions.assertWorkerThread();
diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java
index 06d8b59..a830c96 100644
--- a/src/com/android/launcher3/model/LoaderTask.java
+++ b/src/com/android/launcher3/model/LoaderTask.java
@@ -20,6 +20,7 @@
import static com.android.launcher3.Flags.enableLauncherBrMetricsFixed;
import static com.android.launcher3.Flags.enableSmartspaceAsAWidget;
import static com.android.launcher3.Flags.enableSmartspaceRemovalToggle;
+import static com.android.launcher3.Flags.enableTieredWidgetsByDefaultInPicker;
import static com.android.launcher3.LauncherPrefs.IS_FIRST_LOAD_AFTER_RESTORE;
import static com.android.launcher3.LauncherPrefs.SHOULD_SHOW_SMARTSPACE;
import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME;
@@ -142,6 +143,7 @@
private final UserManager mUserManager;
private final UserCache mUserCache;
private final PackageManagerHelper mPmHelper;
+ private final WidgetsFilterDataProvider mWidgetsFilterDataProvider;
private final InstallSessionHelper mSessionHelper;
private final IconCache mIconCache;
@@ -158,13 +160,16 @@
private String mDbName;
public LoaderTask(@NonNull LauncherAppState app, AllAppsList bgAllAppsList, BgDataModel bgModel,
- ModelDelegate modelDelegate, @NonNull BaseLauncherBinder launcherBinder) {
- this(app, bgAllAppsList, bgModel, modelDelegate, launcherBinder, new UserManagerState());
+ ModelDelegate modelDelegate, @NonNull BaseLauncherBinder launcherBinder,
+ @NonNull WidgetsFilterDataProvider widgetsFilterDataProvider) {
+ this(app, bgAllAppsList, bgModel, modelDelegate, launcherBinder, widgetsFilterDataProvider,
+ new UserManagerState());
}
@VisibleForTesting
LoaderTask(@NonNull LauncherAppState app, AllAppsList bgAllAppsList, BgDataModel bgModel,
ModelDelegate modelDelegate, @NonNull BaseLauncherBinder launcherBinder,
+ WidgetsFilterDataProvider widgetsFilterDataProvider,
UserManagerState userManagerState) {
mApp = app;
mBgAllAppsList = bgAllAppsList;
@@ -179,6 +184,7 @@
mIconCache = mApp.getIconCache();
mUserManagerState = userManagerState;
mInstallingPkgsCached = null;
+ mWidgetsFilterDataProvider = widgetsFilterDataProvider;
}
protected synchronized void waitForIdle() {
@@ -330,7 +336,15 @@
verifyNotStopped();
// fourth step
- List<CachedObject> allWidgetsList = mBgDataModel.widgetsModel.update(mApp, null);
+ WidgetsModel widgetsModel = mBgDataModel.widgetsModel;
+ if (enableTieredWidgetsByDefaultInPicker()) {
+ // Begin periodic refresh of filters
+ mWidgetsFilterDataProvider.initPeriodicDataRefresh(
+ mApp.getModel()::onWidgetFiltersLoaded);
+ // And, update model with currently cached data.
+ widgetsModel.updateWidgetFilters(mWidgetsFilterDataProvider);
+ }
+ List<CachedObject> allWidgetsList = widgetsModel.update(mApp, /*packageUser=*/null);
logASplit("load widgets");
verifyNotStopped();
diff --git a/src/com/android/launcher3/model/ModelDbController.java b/src/com/android/launcher3/model/ModelDbController.java
index 8c3e860..094798b 100644
--- a/src/com/android/launcher3/model/ModelDbController.java
+++ b/src/com/android/launcher3/model/ModelDbController.java
@@ -20,6 +20,7 @@
import static android.util.Base64.NO_WRAP;
import static com.android.launcher3.DefaultLayoutParser.RES_PARTNER_DEFAULT_LAYOUT;
+import static com.android.launcher3.LauncherPrefs.DB_FILE;
import static com.android.launcher3.LauncherPrefs.NO_DB_FILES_RESTORED;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER;
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE;
@@ -128,16 +129,20 @@
private synchronized void createDbIfNotExists() {
if (mOpenHelper == null) {
- mOpenHelper = createDatabaseHelper(false /* forMigration */);
+ String dbFile = LauncherPrefs.get(mContext).get(DB_FILE);
+ if (dbFile.isEmpty()) {
+ dbFile = InvariantDeviceProfile.INSTANCE.get(mContext).dbFile;
+ }
+ mOpenHelper = createDatabaseHelper(false /* forMigration */, dbFile);
printDBs("before: ");
RestoreDbTask.restoreIfNeeded(mContext, this);
printDBs("after: ");
}
}
- protected DatabaseHelper createDatabaseHelper(boolean forMigration) {
+ protected DatabaseHelper createDatabaseHelper(boolean forMigration, String dbFile) {
boolean isSandbox = mContext instanceof SandboxContext;
- String dbName = isSandbox ? null : InvariantDeviceProfile.INSTANCE.get(mContext).dbFile;
+ String dbName = isSandbox ? null : dbFile;
// Set the flag for empty DB
Runnable onEmptyDbCreateCallback = forMigration ? () -> { }
@@ -364,7 +369,7 @@
InvariantDeviceProfile idp = LauncherAppState.getIDP(mContext);
DatabaseHelper oldHelper = mOpenHelper;
mOpenHelper = (mContext instanceof SandboxContext) ? oldHelper
- : createDatabaseHelper(true /* forMigration */);
+ : createDatabaseHelper(true, new DeviceGridState(idp).getDbFile());
try {
// This is the current grid we have, given by the mContext
DeviceGridState srcDeviceState = new DeviceGridState(mContext);
@@ -388,7 +393,6 @@
* Migrates the DB if needed. If the migration failed, it clears the DB.
*/
public void tryMigrateDB(@Nullable LauncherRestoreEventLogger restoreEventLogger) {
-
if (!migrateGridIfNeeded()) {
if (restoreEventLogger != null) {
if (LauncherPrefs.get(mContext).get(NO_DB_FILES_RESTORED)) {
@@ -438,7 +442,7 @@
}
DatabaseHelper oldHelper = mOpenHelper;
mOpenHelper = (mContext instanceof SandboxContext) ? oldHelper
- : createDatabaseHelper(true /* forMigration */);
+ : createDatabaseHelper(true /* forMigration */, targetDbName);
try {
// This is the current grid we have, given by the mContext
DeviceGridState srcDeviceState = new DeviceGridState(mContext);
diff --git a/src/com/android/launcher3/model/ModelTaskController.kt b/src/com/android/launcher3/model/ModelTaskController.kt
index cf2cadc..fc53343 100644
--- a/src/com/android/launcher3/model/ModelTaskController.kt
+++ b/src/com/android/launcher3/model/ModelTaskController.kt
@@ -35,7 +35,7 @@
val dataModel: BgDataModel,
val allAppsList: AllAppsList,
private val model: LauncherModel,
- private val uiExecutor: Executor
+ private val uiExecutor: Executor,
) {
/** Schedules a {@param task} to be executed on the current callbacks. */
@@ -79,10 +79,19 @@
}
fun bindUpdatedWidgets(dataModel: BgDataModel) {
- val widgets =
- WidgetsListBaseEntriesBuilder(app.context)
- .build(dataModel.widgetsModel.widgetsByPackageItem)
- scheduleCallbackTask { it.bindAllWidgets(widgets) }
+ val widgetsByPackageItem = dataModel.widgetsModel.widgetsByPackageItem
+ val allWidgets = WidgetsListBaseEntriesBuilder(app.context).build(widgetsByPackageItem)
+
+ val defaultWidgetsFilter = dataModel.widgetsModel.defaultWidgetsFilter
+ val defaultWidgets =
+ if (defaultWidgetsFilter != null) {
+ WidgetsListBaseEntriesBuilder(app.context)
+ .build(widgetsByPackageItem, defaultWidgetsFilter)
+ } else {
+ emptyList()
+ }
+
+ scheduleCallbackTask { it.bindAllWidgets(allWidgets, defaultWidgets) }
}
fun deleteAndBindComponentsRemoved(matcher: Predicate<ItemInfo?>, reason: String?) {
@@ -99,7 +108,7 @@
val packageUserKeyToUidMap =
apps.associateBy(
keySelector = { PackageUserKey(it.componentName!!.packageName, it.user) },
- valueTransform = { it.uid }
+ valueTransform = { it.uid },
)
scheduleCallbackTask { it.bindAllApplications(apps, flags, packageUserKeyToUidMap) }
}
diff --git a/src/com/android/launcher3/model/WidgetsFilterDataProvider.kt b/src/com/android/launcher3/model/WidgetsFilterDataProvider.kt
new file mode 100644
index 0000000..0571de3
--- /dev/null
+++ b/src/com/android/launcher3/model/WidgetsFilterDataProvider.kt
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.model
+
+import android.content.Context
+import androidx.annotation.WorkerThread
+import com.android.launcher3.R
+import com.android.launcher3.util.ResourceBasedOverride
+import java.util.function.Predicate
+
+/** Helper for the widgets model to load the filters that can be applied to available widgets. */
+open class WidgetsFilterDataProvider(val context: Context) : ResourceBasedOverride {
+ /**
+ * Start regular periodic refresh of widget filtering data starting now (if not started
+ * already).
+ */
+ @WorkerThread
+ open fun initPeriodicDataRefresh(callback: WidgetsFilterLoadedCallback? = null) {
+ // no-op
+ }
+
+ /**
+ * Returns a filter that should be applied to the widget predictions.
+ *
+ * @return null if no filter needs to be applied
+ */
+ @WorkerThread open fun getPredictedWidgetsFilter(): Predicate<WidgetItem>? = null
+
+ /**
+ * Returns a filter that should be applied to the widgets list to see which widgets can be shown
+ * by default.
+ *
+ * @return null if no separate "default" list is supported
+ */
+ @WorkerThread open fun getDefaultWidgetsFilter(): Predicate<WidgetItem>? = null
+
+ /** Called when filter data provider is no longer needed. */
+ open fun destroy() {}
+
+ companion object {
+ /** Returns a new instance of the [WidgetsFilterDataProvider] based on resource override. */
+ fun newInstance(context: Context?): WidgetsFilterDataProvider {
+ return ResourceBasedOverride.Overrides.getObject(
+ WidgetsFilterDataProvider::class.java,
+ context,
+ R.string.widgets_filter_data_provider_class,
+ )
+ }
+ }
+}
+
+/** Interface for the model callback to be invoked when filters are loaded. */
+interface WidgetsFilterLoadedCallback {
+ /** Method called back when widget filters are loaded */
+ fun onWidgetsFilterLoaded()
+}
diff --git a/src/com/android/launcher3/model/WidgetsModel.java b/src/com/android/launcher3/model/WidgetsModel.java
index b450f46..01d4996 100644
--- a/src/com/android/launcher3/model/WidgetsModel.java
+++ b/src/com/android/launcher3/model/WidgetsModel.java
@@ -18,6 +18,8 @@
import android.util.Log;
import android.util.Pair;
+import androidx.annotation.AnyThread;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.collection.ArrayMap;
@@ -65,6 +67,8 @@
/* Map of widgets and shortcuts that are tracked per package. */
private final Map<PackageItemInfo, List<WidgetItem>> mWidgetsByPackageItem = new HashMap<>();
+ @Nullable private Predicate<WidgetItem> mDefaultWidgetsFilter = null;
+ @Nullable private Predicate<WidgetItem> mPredictedWidgetsFilter = null;
/**
* Returns all widgets keyed by their component key.
@@ -92,6 +96,37 @@
}
/**
+ * Returns widget filter that can be applied to {@link WidgetItem}s to check if they can be
+ * shown in the default widgets list.
+ * <p>Returns null if filtering isn't available</p>
+ */
+ @AnyThread
+ public @Nullable Predicate<WidgetItem> getDefaultWidgetsFilter() {
+ return mDefaultWidgetsFilter;
+ }
+
+ /**
+ * Returns widget filter that can be applied to {@link WidgetItem}s to check if they can be
+ * part of widget predictions.
+ * <p>Returns null if filter isn't available</p>
+ */
+ @AnyThread
+ public @Nullable Predicate<WidgetItem> getPredictedWidgetsFilter() {
+ return mPredictedWidgetsFilter;
+ }
+
+ /**
+ * Updates model with latest filter data in cache.
+ */
+ public void updateWidgetFilters(@NonNull WidgetsFilterDataProvider widgetsFilterDataProvider) {
+ if (!WIDGETS_ENABLED) {
+ return;
+ }
+ mDefaultWidgetsFilter = widgetsFilterDataProvider.getDefaultWidgetsFilter();
+ mPredictedWidgetsFilter = widgetsFilterDataProvider.getPredictedWidgetsFilter();
+ }
+
+ /**
* @param packageUser If null, all widgets and shortcuts are updated and returned, otherwise
* only widgets and shortcuts associated with the package/user are.
*/
@@ -299,7 +334,7 @@
if (pInfo == null) {
pInfo = new PackageItemInfo(key.mPackageName, key.mWidgetCategory, key.mUser);
pInfo.user = key.mUser;
- mMap.put(key, pInfo);
+ mMap.put(key, pInfo);
}
return pInfo;
}
diff --git a/src/com/android/launcher3/model/data/WorkspaceItemInfo.java b/src/com/android/launcher3/model/data/WorkspaceItemInfo.java
index f31bf1e..9af61f0 100644
--- a/src/com/android/launcher3/model/data/WorkspaceItemInfo.java
+++ b/src/com/android/launcher3/model/data/WorkspaceItemInfo.java
@@ -189,7 +189,13 @@
if (TextUtils.isEmpty(label)) {
label = shortcutInfo.getShortLabel();
}
- contentDescription = context.getPackageManager().getUserBadgedLabel(label, user);
+ try {
+ contentDescription = context.getPackageManager().getUserBadgedLabel(label, user);
+ } catch (SecurityException e) {
+ contentDescription = null;
+ Log.e(TAG, "Failed to get content description", e);
+ }
+
if (shortcutInfo.isEnabled()) {
runtimeStatusFlags &= ~FLAG_DISABLED_BY_PUBLISHER;
} else {
diff --git a/src/com/android/launcher3/provider/RestoreDbTask.java b/src/com/android/launcher3/provider/RestoreDbTask.java
index 775d248..8db981f 100644
--- a/src/com/android/launcher3/provider/RestoreDbTask.java
+++ b/src/com/android/launcher3/provider/RestoreDbTask.java
@@ -51,7 +51,6 @@
import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;
-import com.android.launcher3.Flags;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherFiles;
@@ -124,17 +123,14 @@
// executed again.
LauncherPrefs.get(context).removeSync(RESTORE_DEVICE);
- if (Flags.enableNarrowGridRestore()) {
- String oldPhoneFileName = idp.dbFile;
- List<String> previousDbs = existingDbs(context);
- removeOldDBs(context, oldPhoneFileName);
- // The idp before this contains data about the old phone, after this it becomes the idp
- // of the current phone.
- idp.reset(context);
- trySettingPreviousGridAsCurrent(context, idp, oldPhoneFileName, previousDbs);
- } else {
- idp.reinitializeAfterRestore(context);
- }
+ DeviceGridState deviceGridState = new DeviceGridState(context);
+ String oldPhoneFileName = deviceGridState.getDbFile();
+ List<String> previousDbs = existingDbs(context);
+ removeOldDBs(context, oldPhoneFileName);
+ // The idp before this contains data about the old phone, after this it becomes the idp
+ // of the current phone.
+ idp.reset(context);
+ trySettingPreviousGridAsCurrent(context, idp, oldPhoneFileName, previousDbs);
}
@@ -148,6 +144,7 @@
context, oldPhoneDbFileName);
// The grid option could be null if current phone doesn't support the previous db.
if (oldPhoneGridOption != null) {
+
/* If the user only used the default db on the previous phone and the new default db is
* bigger than or equal to the previous one, then keep the new default db */
if (previousDbs.size() == 1 && oldPhoneGridOption.numColumns <= idp.numColumns
diff --git a/src/com/android/launcher3/shapes/AppShapesProvider.kt b/src/com/android/launcher3/shapes/AppShapesProvider.kt
index 41bac6a..8c2f181 100644
--- a/src/com/android/launcher3/shapes/AppShapesProvider.kt
+++ b/src/com/android/launcher3/shapes/AppShapesProvider.kt
@@ -16,39 +16,43 @@
package com.android.launcher3.shapes
+import com.android.systemui.shared.Flags
+
object AppShapesProvider {
val shapes =
- listOf(
- AppShape(
- "arch",
- "arch",
- "M100 83.46C100 85.471 100 86.476 99.9 87.321 99.116 93.916 93.916 99.116 87.321 99.9 86.476 100 85.471 100 83.46 100H16.54C14.529 100 13.524 100 12.679 99.9 6.084 99.116.884 93.916.1 87.321 0 86.476 0 85.471 0 83.46L0 50C0 22.386 22.386 0 50 0 77.614 0 100 22.386 100 50V83.46Z",
- ),
- AppShape(
- "4_sided_cookie",
- "4 sided cookie",
- "M63.605 3C84.733-6.176 106.176 15.268 97 36.395L95.483 39.888C92.681 46.338 92.681 53.662 95.483 60.112L97 63.605C106.176 84.732 84.733 106.176 63.605 97L60.112 95.483C53.662 92.681 46.338 92.681 39.888 95.483L36.395 97C15.267 106.176-6.176 84.732 3 63.605L4.517 60.112C7.319 53.662 7.319 46.338 4.517 39.888L3 36.395C-6.176 15.268 15.267-6.176 36.395 3L39.888 4.517C46.338 7.319 53.662 7.319 60.112 4.517L63.605 3Z",
- ),
- AppShape(
- "seven_sided_cookie",
- "7 sided cookie",
- "M35.209 4.878C36.326 3.895 36.884 3.404 37.397 3.006 44.82-2.742 55.18-2.742 62.603 3.006 63.116 3.404 63.674 3.895 64.791 4.878 65.164 5.207 65.351 5.371 65.539 5.529 68.167 7.734 71.303 9.248 74.663 9.932 74.902 9.981 75.147 10.025 75.637 10.113 77.1 10.375 77.831 10.506 78.461 10.66 87.573 12.893 94.032 21.011 94.176 30.412 94.186 31.062 94.151 31.805 94.08 33.293 94.057 33.791 94.045 34.04 94.039 34.285 93.958 37.72 94.732 41.121 96.293 44.18 96.404 44.399 96.522 44.618 96.759 45.056 97.467 46.366 97.821 47.021 98.093 47.611 102.032 56.143 99.727 66.266 92.484 72.24 91.983 72.653 91.381 73.089 90.177 73.961 89.774 74.254 89.572 74.4 89.377 74.548 86.647 76.626 84.477 79.353 83.063 82.483 82.962 82.707 82.865 82.936 82.671 83.395 82.091 84.766 81.8 85.451 81.51 86.033 77.31 94.44 67.977 98.945 58.801 96.994 58.166 96.859 57.451 96.659 56.019 96.259 55.54 96.125 55.3 96.058 55.063 95.998 51.74 95.154 48.26 95.154 44.937 95.998 44.699 96.058 44.46 96.125 43.981 96.259 42.549 96.659 41.834 96.859 41.199 96.994 32.023 98.945 22.69 94.44 18.49 86.033 18.2 85.451 17.909 84.766 17.329 83.395 17.135 82.936 17.038 82.707 16.937 82.483 15.523 79.353 13.353 76.626 10.623 74.548 10.428 74.4 10.226 74.254 9.823 73.961 8.619 73.089 8.017 72.653 7.516 72.24.273 66.266-2.032 56.143 1.907 47.611 2.179 47.021 2.533 46.366 3.241 45.056 3.478 44.618 3.596 44.399 3.707 44.18 5.268 41.121 6.042 37.72 5.961 34.285 5.955 34.04 5.943 33.791 5.92 33.293 5.849 31.805 5.814 31.062 5.824 30.412 5.968 21.011 12.427 12.893 21.539 10.66 22.169 10.506 22.9 10.375 24.363 10.113 24.853 10.025 25.098 9.981 25.337 9.932 28.697 9.248 31.833 7.734 34.461 5.529 34.649 5.371 34.836 5.207 35.209 4.878Z",
- ),
- AppShape(
- "sunny",
- "sunny",
- "M42.846 4.873C46.084-.531 53.916-.531 57.154 4.873L60.796 10.951C62.685 14.103 66.414 15.647 69.978 14.754L76.851 13.032C82.962 11.5 88.5 17.038 86.968 23.149L85.246 30.022C84.353 33.586 85.897 37.315 89.049 39.204L95.127 42.846C100.531 46.084 100.531 53.916 95.127 57.154L89.049 60.796C85.897 62.685 84.353 66.414 85.246 69.978L86.968 76.851C88.5 82.962 82.962 88.5 76.851 86.968L69.978 85.246C66.414 84.353 62.685 85.898 60.796 89.049L57.154 95.127C53.916 100.531 46.084 100.531 42.846 95.127L39.204 89.049C37.315 85.898 33.586 84.353 30.022 85.246L23.149 86.968C17.038 88.5 11.5 82.962 13.032 76.851L14.754 69.978C15.647 66.414 14.103 62.685 10.951 60.796L4.873 57.154C-.531 53.916-.531 46.084 4.873 42.846L10.951 39.204C14.103 37.315 15.647 33.586 14.754 30.022L13.032 23.149C11.5 17.038 17.038 11.5 23.149 13.032L30.022 14.754C33.586 15.647 37.315 14.103 39.204 10.951L42.846 4.873Z",
- ),
- AppShape(
- "circle",
- "circle",
- "M99.18 50C99.18 77.162 77.162 99.18 50 99.18 22.838 99.18.82 77.162.82 50 .82 22.839 22.838.82 50 .82 77.162.82 99.18 22.839 99.18 50Z",
- ),
- AppShape(
- "square",
- "square",
- "M99.18 53.689C99.18 67.434 99.18 74.306 97.022 79.758 93.897 87.649 87.649 93.897 79.758 97.022 74.306 99.18 67.434 99.18 53.689 99.18H46.311C32.566 99.18 25.694 99.18 20.242 97.022 12.351 93.897 6.103 87.649 2.978 79.758.82 74.306.82 67.434.82 53.689L.82 46.311C.82 32.566.82 25.694 2.978 20.242 6.103 12.351 12.351 6.103 20.242 2.978 25.694.82 32.566.82 46.311.82L53.689.82C67.434.82 74.306.82 79.758 2.978 87.649 6.103 93.897 12.351 97.022 20.242 99.18 25.694 99.18 32.566 99.18 46.311V53.689Z\n",
- ),
- )
+ if (Flags.newCustomizationPickerUi())
+ listOf(
+ AppShape(
+ "arch",
+ "arch",
+ "M100 83.46C100 85.471 100 86.476 99.9 87.321 99.116 93.916 93.916 99.116 87.321 99.9 86.476 100 85.471 100 83.46 100H16.54C14.529 100 13.524 100 12.679 99.9 6.084 99.116.884 93.916.1 87.321 0 86.476 0 85.471 0 83.46L0 50C0 22.386 22.386 0 50 0 77.614 0 100 22.386 100 50V83.46Z",
+ ),
+ AppShape(
+ "4_sided_cookie",
+ "4 sided cookie",
+ "M63.605 3C84.733-6.176 106.176 15.268 97 36.395L95.483 39.888C92.681 46.338 92.681 53.662 95.483 60.112L97 63.605C106.176 84.732 84.733 106.176 63.605 97L60.112 95.483C53.662 92.681 46.338 92.681 39.888 95.483L36.395 97C15.267 106.176-6.176 84.732 3 63.605L4.517 60.112C7.319 53.662 7.319 46.338 4.517 39.888L3 36.395C-6.176 15.268 15.267-6.176 36.395 3L39.888 4.517C46.338 7.319 53.662 7.319 60.112 4.517L63.605 3Z",
+ ),
+ AppShape(
+ "seven_sided_cookie",
+ "7 sided cookie",
+ "M35.209 4.878C36.326 3.895 36.884 3.404 37.397 3.006 44.82-2.742 55.18-2.742 62.603 3.006 63.116 3.404 63.674 3.895 64.791 4.878 65.164 5.207 65.351 5.371 65.539 5.529 68.167 7.734 71.303 9.248 74.663 9.932 74.902 9.981 75.147 10.025 75.637 10.113 77.1 10.375 77.831 10.506 78.461 10.66 87.573 12.893 94.032 21.011 94.176 30.412 94.186 31.062 94.151 31.805 94.08 33.293 94.057 33.791 94.045 34.04 94.039 34.285 93.958 37.72 94.732 41.121 96.293 44.18 96.404 44.399 96.522 44.618 96.759 45.056 97.467 46.366 97.821 47.021 98.093 47.611 102.032 56.143 99.727 66.266 92.484 72.24 91.983 72.653 91.381 73.089 90.177 73.961 89.774 74.254 89.572 74.4 89.377 74.548 86.647 76.626 84.477 79.353 83.063 82.483 82.962 82.707 82.865 82.936 82.671 83.395 82.091 84.766 81.8 85.451 81.51 86.033 77.31 94.44 67.977 98.945 58.801 96.994 58.166 96.859 57.451 96.659 56.019 96.259 55.54 96.125 55.3 96.058 55.063 95.998 51.74 95.154 48.26 95.154 44.937 95.998 44.699 96.058 44.46 96.125 43.981 96.259 42.549 96.659 41.834 96.859 41.199 96.994 32.023 98.945 22.69 94.44 18.49 86.033 18.2 85.451 17.909 84.766 17.329 83.395 17.135 82.936 17.038 82.707 16.937 82.483 15.523 79.353 13.353 76.626 10.623 74.548 10.428 74.4 10.226 74.254 9.823 73.961 8.619 73.089 8.017 72.653 7.516 72.24.273 66.266-2.032 56.143 1.907 47.611 2.179 47.021 2.533 46.366 3.241 45.056 3.478 44.618 3.596 44.399 3.707 44.18 5.268 41.121 6.042 37.72 5.961 34.285 5.955 34.04 5.943 33.791 5.92 33.293 5.849 31.805 5.814 31.062 5.824 30.412 5.968 21.011 12.427 12.893 21.539 10.66 22.169 10.506 22.9 10.375 24.363 10.113 24.853 10.025 25.098 9.981 25.337 9.932 28.697 9.248 31.833 7.734 34.461 5.529 34.649 5.371 34.836 5.207 35.209 4.878Z",
+ ),
+ AppShape(
+ "sunny",
+ "sunny",
+ "M42.846 4.873C46.084-.531 53.916-.531 57.154 4.873L60.796 10.951C62.685 14.103 66.414 15.647 69.978 14.754L76.851 13.032C82.962 11.5 88.5 17.038 86.968 23.149L85.246 30.022C84.353 33.586 85.897 37.315 89.049 39.204L95.127 42.846C100.531 46.084 100.531 53.916 95.127 57.154L89.049 60.796C85.897 62.685 84.353 66.414 85.246 69.978L86.968 76.851C88.5 82.962 82.962 88.5 76.851 86.968L69.978 85.246C66.414 84.353 62.685 85.898 60.796 89.049L57.154 95.127C53.916 100.531 46.084 100.531 42.846 95.127L39.204 89.049C37.315 85.898 33.586 84.353 30.022 85.246L23.149 86.968C17.038 88.5 11.5 82.962 13.032 76.851L14.754 69.978C15.647 66.414 14.103 62.685 10.951 60.796L4.873 57.154C-.531 53.916-.531 46.084 4.873 42.846L10.951 39.204C14.103 37.315 15.647 33.586 14.754 30.022L13.032 23.149C11.5 17.038 17.038 11.5 23.149 13.032L30.022 14.754C33.586 15.647 37.315 14.103 39.204 10.951L42.846 4.873Z",
+ ),
+ AppShape(
+ "circle",
+ "circle",
+ "M99.18 50C99.18 77.162 77.162 99.18 50 99.18 22.838 99.18.82 77.162.82 50 .82 22.839 22.838.82 50 .82 77.162.82 99.18 22.839 99.18 50Z",
+ ),
+ AppShape(
+ "square",
+ "square",
+ "M99.18 53.689C99.18 67.434 99.18 74.306 97.022 79.758 93.897 87.649 87.649 93.897 79.758 97.022 74.306 99.18 67.434 99.18 53.689 99.18H46.311C32.566 99.18 25.694 99.18 20.242 97.022 12.351 93.897 6.103 87.649 2.978 79.758.82 74.306.82 67.434.82 53.689L.82 46.311C.82 32.566.82 25.694 2.978 20.242 6.103 12.351 12.351 6.103 20.242 2.978 25.694.82 32.566.82 46.311.82L53.689.82C67.434.82 74.306.82 79.758 2.978 87.649 6.103 93.897 12.351 97.022 20.242 99.18 25.694 99.18 32.566 99.18 46.311V53.689Z\n",
+ ),
+ )
+ else emptyList()
}
diff --git a/src/com/android/launcher3/util/DisplayController.java b/src/com/android/launcher3/util/DisplayController.java
index 0b45118..26912eb 100644
--- a/src/com/android/launcher3/util/DisplayController.java
+++ b/src/com/android/launcher3/util/DisplayController.java
@@ -255,7 +255,9 @@
|| config.fontScale != mInfo.fontScale
|| !mInfo.mScreenSizeDp.equals(
new PortraitSize(config.screenHeightDp, config.screenWidthDp))
- || mWindowContext.getDisplay().getRotation() != mInfo.rotation) {
+ || mWindowContext.getDisplay().getRotation() != mInfo.rotation
+ || WindowManagerProxy.INSTANCE.get(mContext).showLockedTaskbarOnHome(mWindowContext)
+ != mInfo.showLockedTaskbarOnHome()) {
notifyConfigChange();
}
}
diff --git a/src/com/android/launcher3/util/LogConfig.java b/src/com/android/launcher3/util/LogConfig.java
index f183f18..72e3e79 100644
--- a/src/com/android/launcher3/util/LogConfig.java
+++ b/src/com/android/launcher3/util/LogConfig.java
@@ -52,9 +52,9 @@
public static final String WEB_APP_SEARCH_LOGGING = "WebAppSearchLogging";
/**
- * When turned on, we enable quick launch v2 related logging.
+ * When turned on, we enable quick launch related logging.
*/
- public static final String QUICK_LAUNCH_V2 = "QuickLaunchV2";
+ public static final String QUICK_LAUNCH = "QuickLaunch";
/**
* When turned on, we enable Gms Play related logging.
diff --git a/src/com/android/launcher3/util/PackageManagerHelper.java b/src/com/android/launcher3/util/PackageManagerHelper.java
index e51609a..4b60d98 100644
--- a/src/com/android/launcher3/util/PackageManagerHelper.java
+++ b/src/com/android/launcher3/util/PackageManagerHelper.java
@@ -42,6 +42,9 @@
import com.android.launcher3.PendingAddItemInfo;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
+import com.android.launcher3.dagger.ApplicationContext;
+import com.android.launcher3.dagger.LauncherAppSingleton;
+import com.android.launcher3.dagger.LauncherBaseAppComponent;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.ItemInfoWithIcon;
@@ -51,16 +54,19 @@
import java.util.List;
import java.util.Objects;
+import javax.inject.Inject;
+
/**
* Utility methods using package manager
*/
-public class PackageManagerHelper implements SafeCloseable{
+@LauncherAppSingleton
+public class PackageManagerHelper {
private static final String TAG = "PackageManagerHelper";
@NonNull
- public static final MainThreadInitializedObject<PackageManagerHelper> INSTANCE =
- new MainThreadInitializedObject<>(PackageManagerHelper::new);
+ public static DaggerSingletonObject<PackageManagerHelper> INSTANCE =
+ new DaggerSingletonObject<>(LauncherBaseAppComponent::getPackageManagerHelper);
@NonNull
private final Context mContext;
@@ -73,17 +79,15 @@
private final String[] mLegacyMultiInstanceSupportedApps;
- public PackageManagerHelper(@NonNull final Context context) {
+ @Inject
+ public PackageManagerHelper(@ApplicationContext final Context context) {
mContext = context;
mPm = context.getPackageManager();
mLauncherApps = Objects.requireNonNull(context.getSystemService(LauncherApps.class));
mLegacyMultiInstanceSupportedApps = mContext.getResources().getStringArray(
- R.array.config_appsSupportMultiInstancesSplit);
+ R.array.config_appsSupportMultiInstancesSplit);
}
- @Override
- public void close() { }
-
/**
* Returns the installing app package for the given package
*/
diff --git a/src/com/android/launcher3/util/SettingsCache.java b/src/com/android/launcher3/util/SettingsCache.java
index 29d5032..8fe6e93 100644
--- a/src/com/android/launcher3/util/SettingsCache.java
+++ b/src/com/android/launcher3/util/SettingsCache.java
@@ -28,6 +28,8 @@
import android.os.Looper;
import android.provider.Settings;
+import androidx.annotation.UiThread;
+
import com.android.launcher3.dagger.ApplicationContext;
import com.android.launcher3.dagger.LauncherAppSingleton;
import com.android.launcher3.dagger.LauncherBaseAppComponent;
@@ -140,7 +142,9 @@
* 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) {
+ Preconditions.assertUIThread();
if (mListenerMap.containsKey(uri)) {
mListenerMap.get(uri).add(changeListener);
} else {
diff --git a/src/com/android/launcher3/util/VibratorWrapper.java b/src/com/android/launcher3/util/VibratorWrapper.java
index adb8f9d..39c9c42 100644
--- a/src/com/android/launcher3/util/VibratorWrapper.java
+++ b/src/com/android/launcher3/util/VibratorWrapper.java
@@ -19,6 +19,7 @@
import static android.os.VibrationEffect.createPredefined;
import static android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED;
+import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import android.annotation.SuppressLint;
@@ -31,13 +32,20 @@
import androidx.annotation.VisibleForTesting;
+import com.android.launcher3.dagger.ApplicationContext;
+import com.android.launcher3.dagger.LauncherAppSingleton;
+import com.android.launcher3.dagger.LauncherBaseAppComponent;
+
+import javax.inject.Inject;
+
/**
* Wrapper around {@link Vibrator} to easily perform haptic feedback where necessary.
*/
-public class VibratorWrapper implements SafeCloseable {
+@LauncherAppSingleton
+public class VibratorWrapper {
- public static final MainThreadInitializedObject<VibratorWrapper> INSTANCE =
- new MainThreadInitializedObject<>(VibratorWrapper::new);
+ public static final DaggerSingletonObject<VibratorWrapper> INSTANCE =
+ new DaggerSingletonObject<>(LauncherBaseAppComponent::getVibratorWrapper);
public static final AudioAttributes VIBRATION_ATTRS = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
@@ -59,38 +67,29 @@
private final Vibrator mVibrator;
private final boolean mHasVibrator;
- private final SettingsCache mSettingsCache;
-
@VisibleForTesting
final SettingsCache.OnChangeListener mHapticChangeListener =
isEnabled -> mIsHapticFeedbackEnabled = isEnabled;
private boolean mIsHapticFeedbackEnabled;
- private VibratorWrapper(Context context) {
- this(context.getSystemService(Vibrator.class), SettingsCache.INSTANCE.get(context));
- }
+ @Inject
+ public VibratorWrapper(@ApplicationContext Context context, SettingsCache settingsCache,
+ DaggerSingletonTracker tracker) {
- @VisibleForTesting
- VibratorWrapper(Vibrator vibrator, SettingsCache settingsCache) {
- mVibrator = vibrator;
+ mVibrator = context.getSystemService(Vibrator.class);
mHasVibrator = mVibrator.hasVibrator();
- mSettingsCache = settingsCache;
if (mHasVibrator) {
- mSettingsCache.register(HAPTIC_FEEDBACK_URI, mHapticChangeListener);
- mIsHapticFeedbackEnabled = mSettingsCache.getValue(HAPTIC_FEEDBACK_URI, 0);
+ MAIN_EXECUTOR.execute(
+ () -> settingsCache.register(HAPTIC_FEEDBACK_URI, mHapticChangeListener));
+ mIsHapticFeedbackEnabled = settingsCache.getValue(HAPTIC_FEEDBACK_URI, 0);
+ tracker.addCloseable(
+ () -> settingsCache.unregister(HAPTIC_FEEDBACK_URI, mHapticChangeListener));
} else {
mIsHapticFeedbackEnabled = false;
}
}
- @Override
- public void close() {
- if (mHasVibrator) {
- mSettingsCache.unregister(HAPTIC_FEEDBACK_URI, mHapticChangeListener);
- }
- }
-
/**
* This should be used to cancel a haptic in case where the haptic shouldn't be vibrating. For
* example, when no animation is happening but a vibrator happens to be vibrating still.
diff --git a/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt b/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt
index 8770859..55a028b 100644
--- a/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt
+++ b/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt
@@ -79,7 +79,7 @@
val statusBarNaturalPx: Int,
val statusBarRotatedPx: Int,
val gesturePx: Int,
- val cutoutPx: Int
+ val cutoutPx: Int,
)
open val deviceSpecs =
@@ -91,7 +91,7 @@
statusBarNaturalPx = 118,
statusBarRotatedPx = 74,
gesturePx = 63,
- cutoutPx = 118
+ cutoutPx = 118,
),
"tablet" to
DeviceSpec(
@@ -100,7 +100,7 @@
statusBarNaturalPx = 104,
statusBarRotatedPx = 104,
gesturePx = 0,
- cutoutPx = 0
+ cutoutPx = 0,
),
"twopanel-phone" to
DeviceSpec(
@@ -109,7 +109,7 @@
statusBarNaturalPx = 133,
statusBarRotatedPx = 110,
gesturePx = 63,
- cutoutPx = 133
+ cutoutPx = 133,
),
"twopanel-tablet" to
DeviceSpec(
@@ -118,14 +118,14 @@
statusBarNaturalPx = 110,
statusBarRotatedPx = 133,
gesturePx = 0,
- cutoutPx = 0
- )
+ cutoutPx = 0,
+ ),
)
protected fun initializeVarsForPhone(
deviceSpec: DeviceSpec,
isGestureMode: Boolean = true,
- isVerticalBar: Boolean = false
+ isVerticalBar: Boolean = false,
) {
val (naturalX, naturalY) = deviceSpec.naturalSize
val windowsBounds = phoneWindowsBounds(deviceSpec, isGestureMode, naturalX, naturalY)
@@ -137,14 +137,14 @@
displayInfo,
rotation = if (isVerticalBar) Surface.ROTATION_90 else Surface.ROTATION_0,
isGestureMode,
- densityDpi = deviceSpec.densityDpi
+ densityDpi = deviceSpec.densityDpi,
)
}
protected fun initializeVarsForTablet(
deviceSpec: DeviceSpec,
isLandscape: Boolean = false,
- isGestureMode: Boolean = true
+ isGestureMode: Boolean = true,
) {
val (naturalX, naturalY) = deviceSpec.naturalSize
val windowsBounds = tabletWindowsBounds(deviceSpec, naturalX, naturalY)
@@ -156,7 +156,7 @@
displayInfo,
rotation = if (isLandscape) Surface.ROTATION_0 else Surface.ROTATION_90,
isGestureMode,
- densityDpi = deviceSpec.densityDpi
+ densityDpi = deviceSpec.densityDpi,
)
}
@@ -165,7 +165,7 @@
deviceSpecFolded: DeviceSpec,
isLandscape: Boolean = false,
isGestureMode: Boolean = true,
- isFolded: Boolean = false
+ isFolded: Boolean = false,
) {
val (unfoldedNaturalX, unfoldedNaturalY) = deviceSpecUnfolded.naturalSize
val unfoldedWindowsBounds =
@@ -182,7 +182,7 @@
val perDisplayBoundsCache =
mapOf(
unfoldedDisplayInfo to unfoldedWindowsBounds,
- foldedDisplayInfo to foldedWindowsBounds
+ foldedDisplayInfo to foldedWindowsBounds,
)
if (isFolded) {
@@ -191,7 +191,7 @@
displayInfo = foldedDisplayInfo,
rotation = if (isLandscape) Surface.ROTATION_90 else Surface.ROTATION_0,
isGestureMode = isGestureMode,
- densityDpi = deviceSpecFolded.densityDpi
+ densityDpi = deviceSpecFolded.densityDpi,
)
} else {
initializeCommonVars(
@@ -199,7 +199,7 @@
displayInfo = unfoldedDisplayInfo,
rotation = if (isLandscape) Surface.ROTATION_0 else Surface.ROTATION_90,
isGestureMode = isGestureMode,
- densityDpi = deviceSpecUnfolded.densityDpi
+ densityDpi = deviceSpecUnfolded.densityDpi,
)
}
}
@@ -208,7 +208,7 @@
deviceSpec: DeviceSpec,
isGestureMode: Boolean,
naturalX: Int,
- naturalY: Int
+ naturalY: Int,
): List<WindowBounds> {
val buttonsNavHeight = Utilities.dpToPx(48f, deviceSpec.densityDpi)
@@ -217,14 +217,14 @@
0,
max(deviceSpec.statusBarNaturalPx, deviceSpec.cutoutPx),
0,
- if (isGestureMode) deviceSpec.gesturePx else buttonsNavHeight
+ if (isGestureMode) deviceSpec.gesturePx else buttonsNavHeight,
)
val rotation90Insets =
Rect(
deviceSpec.cutoutPx,
deviceSpec.statusBarRotatedPx,
if (isGestureMode) 0 else buttonsNavHeight,
- if (isGestureMode) deviceSpec.gesturePx else 0
+ if (isGestureMode) deviceSpec.gesturePx else 0,
)
val rotation180Insets =
Rect(
@@ -233,29 +233,29 @@
0,
max(
if (isGestureMode) deviceSpec.gesturePx else buttonsNavHeight,
- deviceSpec.cutoutPx
- )
+ deviceSpec.cutoutPx,
+ ),
)
val rotation270Insets =
Rect(
if (isGestureMode) 0 else buttonsNavHeight,
deviceSpec.statusBarRotatedPx,
deviceSpec.cutoutPx,
- if (isGestureMode) deviceSpec.gesturePx else 0
+ if (isGestureMode) deviceSpec.gesturePx else 0,
)
return listOf(
WindowBounds(Rect(0, 0, naturalX, naturalY), rotation0Insets, Surface.ROTATION_0),
WindowBounds(Rect(0, 0, naturalY, naturalX), rotation90Insets, Surface.ROTATION_90),
WindowBounds(Rect(0, 0, naturalX, naturalY), rotation180Insets, Surface.ROTATION_180),
- WindowBounds(Rect(0, 0, naturalY, naturalX), rotation270Insets, Surface.ROTATION_270)
+ WindowBounds(Rect(0, 0, naturalY, naturalX), rotation270Insets, Surface.ROTATION_270),
)
}
private fun tabletWindowsBounds(
deviceSpec: DeviceSpec,
naturalX: Int,
- naturalY: Int
+ naturalY: Int,
): List<WindowBounds> {
val naturalInsets = Rect(0, deviceSpec.statusBarNaturalPx, 0, 0)
val rotatedInsets = Rect(0, deviceSpec.statusBarRotatedPx, 0, 0)
@@ -264,7 +264,7 @@
WindowBounds(Rect(0, 0, naturalX, naturalY), naturalInsets, Surface.ROTATION_0),
WindowBounds(Rect(0, 0, naturalY, naturalX), rotatedInsets, Surface.ROTATION_90),
WindowBounds(Rect(0, 0, naturalX, naturalY), naturalInsets, Surface.ROTATION_180),
- WindowBounds(Rect(0, 0, naturalY, naturalX), rotatedInsets, Surface.ROTATION_270)
+ WindowBounds(Rect(0, 0, naturalY, naturalX), rotatedInsets, Surface.ROTATION_270),
)
}
@@ -273,7 +273,7 @@
displayInfo: CachedDisplayInfo,
rotation: Int,
isGestureMode: Boolean = true,
- densityDpi: Int
+ densityDpi: Int,
) {
setFlagsRule.setFlags(true, Flags.FLAG_ENABLE_TWOLINE_TOGGLE)
LauncherPrefs.get(testContext).put(LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE, true)
@@ -307,6 +307,10 @@
whenever(launcherPrefs.get(LauncherPrefs.TASKBAR_PINNING)).thenReturn(false)
whenever(launcherPrefs.get(LauncherPrefs.TASKBAR_PINNING_IN_DESKTOP_MODE)).thenReturn(true)
+ whenever(launcherPrefs.get(LauncherPrefs.HOTSEAT_COUNT)).thenReturn(-1)
+ whenever(launcherPrefs.get(LauncherPrefs.DEVICE_TYPE)).thenReturn(-1)
+ whenever(launcherPrefs.get(LauncherPrefs.WORKSPACE_SIZE)).thenReturn("")
+ whenever(launcherPrefs.get(LauncherPrefs.DB_FILE)).thenReturn("")
val info = spy(DisplayController.Info(context, windowManagerProxy, perDisplayBoundsCache))
whenever(displayController.info).thenReturn(info)
whenever(info.isTransientTaskbar).thenReturn(isGestureMode)
diff --git a/tests/multivalentTests/src/com/android/launcher3/model/WidgetsModelTest.kt b/tests/multivalentTests/src/com/android/launcher3/model/WidgetsModelTest.kt
index ff545fe..ae4ff04 100644
--- a/tests/multivalentTests/src/com/android/launcher3/model/WidgetsModelTest.kt
+++ b/tests/multivalentTests/src/com/android/launcher3/model/WidgetsModelTest.kt
@@ -43,6 +43,7 @@
import com.google.common.truth.Truth.assertThat
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
+import java.util.function.Predicate
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Rule
@@ -64,6 +65,7 @@
@Mock private lateinit var appWidgetManager: AppWidgetManager
@Mock private lateinit var app: LauncherAppState
@Mock private lateinit var iconCacheMock: IconCache
+ @Mock private lateinit var widgetsFilterDataProvider: WidgetsFilterDataProvider
private lateinit var context: Context
private lateinit var idp: InvariantDeviceProfile
@@ -215,6 +217,27 @@
// No exception
}
+ @Test
+ fun updateWidgetFilters_setsFiltersCorrectly() {
+ val testDefaultWidgetFilter = Predicate<WidgetItem> { w -> w.widgetInfo != null }
+ whenever(widgetsFilterDataProvider.getDefaultWidgetsFilter())
+ .thenReturn(testDefaultWidgetFilter)
+ val testPredicatedWidgetFilter = Predicate<WidgetItem> { w -> w.widgetInfo != null }
+ whenever(widgetsFilterDataProvider.getPredictedWidgetsFilter())
+ .thenReturn(testPredicatedWidgetFilter)
+
+ underTest.updateWidgetFilters(widgetsFilterDataProvider)
+
+ assertThat(underTest.defaultWidgetsFilter).isEqualTo(testDefaultWidgetFilter)
+ assertThat(underTest.predictedWidgetsFilter).isEqualTo(testPredicatedWidgetFilter)
+ }
+
+ @Test
+ fun widgetFilters_nullInitially() {
+ assertThat(underTest.defaultWidgetsFilter).isNull()
+ assertThat(underTest.predictedWidgetsFilter).isNull()
+ }
+
private fun loadWidgets() {
val latch = CountDownLatch(1)
Executors.MODEL_EXECUTOR.execute {
diff --git a/tests/multivalentTests/src/com/android/launcher3/util/DisplayControllerTest.kt b/tests/multivalentTests/src/com/android/launcher3/util/DisplayControllerTest.kt
index 308f200..a3a680e 100644
--- a/tests/multivalentTests/src/com/android/launcher3/util/DisplayControllerTest.kt
+++ b/tests/multivalentTests/src/com/android/launcher3/util/DisplayControllerTest.kt
@@ -207,4 +207,21 @@
.onDisplayInfoChanged(any(), any(), eq(CHANGE_TASKBAR_PINNING))
assertFalse(displayController.getInfo().isTransientTaskbar())
}
+
+ @Test
+ @UiThreadTest
+ fun testLockedTaskbarChangeOnConfigurationChanged() {
+ whenever(windowManagerProxy.showLockedTaskbarOnHome(any())).thenReturn(true)
+ whenever(windowManagerProxy.isHomeVisible(any())).thenReturn(true)
+ whenever(windowManagerProxy.isInDesktopMode()).thenReturn(false)
+ whenever(launcherPrefs.get(TASKBAR_PINNING)).thenReturn(false)
+ DisplayController.enableTaskbarModePreferenceForTests(true)
+ assertTrue(displayController.getInfo().isTransientTaskbar())
+
+ displayController.onConfigurationChanged(configuration)
+
+ verify(displayInfoChangeListener)
+ .onDisplayInfoChanged(any(), any(), eq(CHANGE_TASKBAR_PINNING))
+ assertFalse(displayController.getInfo().isTransientTaskbar())
+ }
}
diff --git a/tests/multivalentTests/src/com/android/launcher3/util/VibratorWrapperTest.kt b/tests/multivalentTests/src/com/android/launcher3/util/VibratorWrapperTest.kt
index d321e41..dee98e7 100644
--- a/tests/multivalentTests/src/com/android/launcher3/util/VibratorWrapperTest.kt
+++ b/tests/multivalentTests/src/com/android/launcher3/util/VibratorWrapperTest.kt
@@ -21,8 +21,8 @@
import android.os.VibrationEffect.Composition.PRIMITIVE_LOW_TICK
import android.os.VibrationEffect.Composition.PRIMITIVE_TICK
import android.os.Vibrator
-import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
+import com.android.launcher3.util.LauncherModelHelper.SandboxModelContext
import com.android.launcher3.util.VibratorWrapper.HAPTIC_FEEDBACK_URI
import com.android.launcher3.util.VibratorWrapper.OVERVIEW_HAPTIC
import com.android.launcher3.util.VibratorWrapper.VIBRATION_ATTRS
@@ -41,25 +41,27 @@
import org.mockito.kotlin.same
@SmallTest
-@RunWith(AndroidJUnit4::class)
+@RunWith(LauncherMultivalentJUnit::class)
class VibratorWrapperTest {
@Mock private lateinit var settingsCache: SettingsCache
- @Mock private lateinit var vibrator: Vibrator
+ private lateinit var vibrator: Vibrator
+ private val context: SandboxModelContext = SandboxModelContext()
@Captor private lateinit var vibrationEffectCaptor: ArgumentCaptor<VibrationEffect>
-
+ @Mock private lateinit var tracker: DaggerSingletonTracker
private lateinit var underTest: VibratorWrapper
@Before
fun setup() {
MockitoAnnotations.initMocks(this)
+ vibrator = context.spyService(Vibrator::class.java)
`when`(settingsCache.getValue(HAPTIC_FEEDBACK_URI, 0)).thenReturn(true)
`when`(vibrator.hasVibrator()).thenReturn(true)
`when`(vibrator.areAllPrimitivesSupported(PRIMITIVE_TICK)).thenReturn(true)
`when`(vibrator.areAllPrimitivesSupported(PRIMITIVE_LOW_TICK)).thenReturn(true)
`when`(vibrator.getPrimitiveDurations(PRIMITIVE_LOW_TICK)).thenReturn(intArrayOf(10))
- underTest = VibratorWrapper(vibrator, settingsCache)
+ underTest = VibratorWrapper(context, settingsCache, tracker)
}
@Test
@@ -68,13 +70,6 @@
}
@Test
- fun close_unregister_onChangeListener() {
- underTest.close()
-
- verify(settingsCache).unregister(HAPTIC_FEEDBACK_URI, underTest.mHapticChangeListener)
- }
-
- @Test
fun vibrate() {
underTest.vibrate(OVERVIEW_HAPTIC)
@@ -117,7 +112,7 @@
@Test
fun haptic_feedback_disabled_no_vibrate() {
`when`(vibrator.hasVibrator()).thenReturn(false)
- underTest = VibratorWrapper(vibrator, settingsCache)
+ underTest = VibratorWrapper(context, settingsCache, tracker)
underTest.vibrate(OVERVIEW_HAPTIC)
diff --git a/tests/src/com/android/launcher3/model/LoaderTaskTest.kt b/tests/src/com/android/launcher3/model/LoaderTaskTest.kt
index ef7242f..882061f 100644
--- a/tests/src/com/android/launcher3/model/LoaderTaskTest.kt
+++ b/tests/src/com/android/launcher3/model/LoaderTaskTest.kt
@@ -28,6 +28,7 @@
import com.android.launcher3.util.UserIconInfo
import com.google.common.truth.Truth
import java.util.concurrent.CountDownLatch
+import java.util.function.Predicate
import junit.framework.Assert.assertEquals
import org.junit.After
import org.junit.Before
@@ -76,6 +77,7 @@
@Mock private lateinit var modelDelegate: ModelDelegate
@Mock private lateinit var launcherBinder: BaseLauncherBinder
private lateinit var launcherModel: LauncherModel
+ @Mock private lateinit var widgetsFilterDataProvider: WidgetsFilterDataProvider
@Mock private lateinit var transaction: LoaderTransaction
@Mock private lateinit var iconCache: IconCache
@Mock private lateinit var idleLock: LooperIdleLock
@@ -89,6 +91,7 @@
@Before
fun setup() {
MockitoAnnotations.initMocks(this)
+ setFlagsRule.enableFlags(Flags.FLAG_ENABLE_TIERED_WIDGETS_BY_DEFAULT_IN_PICKER)
launcherModel = mock(LauncherModel::class.java)
mockitoSession =
ExtendedMockito.mockitoSession()
@@ -118,6 +121,7 @@
`when`(launcherBinder.newIdleLock(any())).thenReturn(idleLock)
`when`(idleLock.awaitLocked(1000)).thenReturn(false)
`when`(iconCache.updateHandler).thenReturn(iconCacheUpdateHandler)
+ `when`(widgetsFilterDataProvider.getDefaultWidgetsFilter()).thenReturn(Predicate { true })
context.putObject(UserCache.INSTANCE, userCache)
TestUtil.grantWriteSecurePermission()
@@ -136,17 +140,32 @@
val mockUserHandles = arrayListOf<UserHandle>(MAIN_HANDLE)
`when`(userCache.userProfiles).thenReturn(mockUserHandles)
`when`(userCache.getUserInfo(MAIN_HANDLE)).thenReturn(UserIconInfo(MAIN_HANDLE, 1))
- LoaderTask(app, bgAllAppsList, this, modelDelegate, launcherBinder)
+ LoaderTask(
+ app,
+ bgAllAppsList,
+ this,
+ modelDelegate,
+ launcherBinder,
+ widgetsFilterDataProvider,
+ )
.runSyncOnBackgroundThread()
Truth.assertThat(workspaceItems.size).isAtLeast(25)
Truth.assertThat(appWidgets.size).isAtLeast(7)
Truth.assertThat(collections.size()).isAtLeast(8)
Truth.assertThat(itemsIdMap.size()).isAtLeast(40)
+ Truth.assertThat(widgetsModel.defaultWidgetsFilter).isNotNull()
}
@Test
fun bindsLoadedDataCorrectly() {
- LoaderTask(app, bgAllAppsList, BgDataModel(), modelDelegate, launcherBinder)
+ LoaderTask(
+ app,
+ bgAllAppsList,
+ BgDataModel(),
+ modelDelegate,
+ launcherBinder,
+ widgetsFilterDataProvider,
+ )
.runSyncOnBackgroundThread()
verify(launcherBinder).bindWorkspace(true, false)
@@ -155,6 +174,7 @@
verify(launcherBinder).bindAllApps()
verify(iconCacheUpdateHandler, times(4)).updateIcons(any(), any<CachingLogic<Any>>(), any())
verify(launcherBinder).bindDeepShortcuts()
+ verify(widgetsFilterDataProvider).initPeriodicDataRefresh(any())
verify(launcherBinder).bindWidgets()
verify(modelDelegate).loadAndBindOtherItems(anyOrNull())
verify(iconCacheUpdateHandler).finish()
@@ -172,7 +192,15 @@
`when`(userManagerState?.isUserQuiet(MAIN_HANDLE)).thenReturn(true)
`when`(userCache.getUserInfo(MAIN_HANDLE)).thenReturn(UserIconInfo(MAIN_HANDLE, 1))
- LoaderTask(app, bgAllAppsList, this, modelDelegate, launcherBinder, userManagerState)
+ LoaderTask(
+ app,
+ bgAllAppsList,
+ this,
+ modelDelegate,
+ launcherBinder,
+ widgetsFilterDataProvider,
+ userManagerState,
+ )
.runSyncOnBackgroundThread()
verify(bgAllAppsList)
@@ -193,7 +221,15 @@
`when`(userManagerState?.isUserQuiet(MAIN_HANDLE)).thenReturn(true)
`when`(userCache.getUserInfo(MAIN_HANDLE)).thenReturn(UserIconInfo(MAIN_HANDLE, 3))
- LoaderTask(app, bgAllAppsList, this, modelDelegate, launcherBinder, userManagerState)
+ LoaderTask(
+ app,
+ bgAllAppsList,
+ this,
+ modelDelegate,
+ launcherBinder,
+ widgetsFilterDataProvider,
+ userManagerState,
+ )
.runSyncOnBackgroundThread()
verify(bgAllAppsList)
@@ -232,7 +268,14 @@
RestoreDbTask.setPending(spyContext)
// When
- LoaderTask(app, bgAllAppsList, BgDataModel(), modelDelegate, launcherBinder)
+ LoaderTask(
+ app,
+ bgAllAppsList,
+ BgDataModel(),
+ modelDelegate,
+ launcherBinder,
+ widgetsFilterDataProvider,
+ )
.runSyncOnBackgroundThread()
// Then
@@ -301,7 +344,14 @@
RestoreDbTask.setPending(spyContext)
// When
- LoaderTask(app, bgAllAppsList, BgDataModel(), modelDelegate, launcherBinder)
+ LoaderTask(
+ app,
+ bgAllAppsList,
+ BgDataModel(),
+ modelDelegate,
+ launcherBinder,
+ widgetsFilterDataProvider,
+ )
.runSyncOnBackgroundThread()
// Then
@@ -369,7 +419,14 @@
Settings.Secure.putInt(spyContext.contentResolver, "launcher_broadcast_installed_apps", 1)
// When
- LoaderTask(app, bgAllAppsList, BgDataModel(), modelDelegate, launcherBinder)
+ LoaderTask(
+ app,
+ bgAllAppsList,
+ BgDataModel(),
+ modelDelegate,
+ launcherBinder,
+ widgetsFilterDataProvider,
+ )
.runSyncOnBackgroundThread()
// Then
@@ -404,7 +461,14 @@
RestoreDbTask.setPending(spyContext)
// When
- LoaderTask(app, bgAllAppsList, BgDataModel(), modelDelegate, launcherBinder)
+ LoaderTask(
+ app,
+ bgAllAppsList,
+ BgDataModel(),
+ modelDelegate,
+ launcherBinder,
+ widgetsFilterDataProvider,
+ )
.runSyncOnBackgroundThread()
// Then
diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java
index e1bd686..512db39 100644
--- a/tests/tapl/com/android/launcher3/tapl/Background.java
+++ b/tests/tapl/com/android/launcher3/tapl/Background.java
@@ -29,6 +29,7 @@
import com.android.launcher3.tapl.LauncherInstrumentation.NavigationModel;
import com.android.launcher3.tapl.LauncherInstrumentation.TrackpadGestureType;
+import com.android.launcher3.tapl.OverviewTask.TaskViewType;
import com.android.launcher3.testing.shared.TestProtocol;
import java.util.List;
@@ -121,12 +122,31 @@
if (mLauncher.isTablet()) {
List<UiObject2> tasks = mLauncher.getDevice().findObjects(
TASK_SELECTOR);
+
final int centerX = mLauncher.getDevice().getDisplayWidth() / 2;
- mLauncher.assertTrue(
- "Task(s) found to the right of the swiped task",
- tasks.stream().allMatch(t ->
- t.getVisibleBounds().right < centerX
- || t.getVisibleBounds().centerX() == centerX));
+ UiObject2 centerTask = tasks.stream()
+ .filter(t -> t.getVisibleCenter().x == centerX)
+ .findFirst()
+ .orElse(null);
+
+ if (centerTask != null) {
+ mLauncher.assertTrue(
+ "Task(s) found to the right of the swiped task",
+ tasks.stream()
+ .filter(t -> t != centerTask
+ && OverviewTask.getType(t)
+ != TaskViewType.DESKTOP)
+ .allMatch(t -> t.getVisibleBounds().right
+ < centerTask.getVisibleBounds().left));
+ mLauncher.assertTrue(
+ "DesktopTask(s) found to the left of the swiped task",
+ tasks.stream()
+ .filter(t -> t != centerTask
+ && OverviewTask.getType(t)
+ == TaskViewType.DESKTOP)
+ .allMatch(t -> t.getVisibleBounds().left
+ > centerTask.getVisibleBounds().right));
+ }
}
}
diff --git a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
index 1002ca4..b15afc1 100644
--- a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
+++ b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
@@ -536,6 +536,10 @@
int focusedTaskHeight = focusTaskSize.height();
for (UiObject2 task : taskViews) {
OverviewTask overviewTask = new OverviewTask(mLauncher, task, this);
+ // Desktop tasks can't be focused tasks, but are the same size.
+ if (overviewTask.isDesktop()) {
+ continue;
+ }
if (overviewTask.getVisibleHeight() == focusedTaskHeight) {
return overviewTask;
}
diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
index 5fd4dac..8512d73 100644
--- a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
+++ b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
@@ -57,7 +57,7 @@
mLauncher.assertNotNull("task must not be null", task);
mTask = task;
mOverview = overview;
- mType = getType();
+ mType = getType(task);
verifyActiveContainer();
}
@@ -304,8 +304,12 @@
return containsContentDescription(expected, DEFAULT);
}
- private TaskViewType getType() {
- String resourceName = mTask.getResourceName();
+ /**
+ * Returns the TaskView type of the task. It will return whether the task is a single TaskView,
+ * a GroupedTaskView or a DesktopTaskView.
+ */
+ static TaskViewType getType(UiObject2 task) {
+ String resourceName = task.getResourceName();
if (resourceName.endsWith("task_view_grouped")) {
return TaskViewType.GROUPED;
} else if (resourceName.endsWith("task_view_desktop")) {
@@ -345,7 +349,7 @@
}
}
- private enum TaskViewType {
+ enum TaskViewType {
SINGLE,
GROUPED,
DESKTOP