From 5c3d37b37d2faf961c2ea3697d7bf5682f4f8550 Mon Sep 17 00:00:00 2001 From: "[1;3C" Date: Fri, 29 Jan 2021 18:20:52 -0800 Subject: [PATCH 1/8] Update input-monitors to accept unrotated coordinates Inputflinger now internally always works in the orientation the display grew-up in so the coordinates of gesture-monitors no-longer rotate to match the display. For now, this adds some shims to achieve previous expected coordinates in launcher This is behind a flag: adb shell setprop persist.debug.per_window_input_rotation 1 Bug: 179274888 Test: use touch interactions on rotated display Change-Id: Iecd9d233f60b86e24070d7d9055af6b8f44f0b54 --- .../quickstep/TouchInteractionService.java | 21 +++++++++++++++++++ .../OtherActivityInputConsumer.java | 19 +++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index 8ebea33e72..c6c942ab28 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -38,18 +38,23 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.graphics.Point; import android.graphics.Rect; import android.graphics.Region; import android.graphics.drawable.Icon; +import android.hardware.display.DisplayManager; import android.os.Build; import android.os.Bundle; import android.os.IBinder; import android.os.Looper; import android.os.SystemClock; +import android.os.SystemProperties; import android.util.Log; import android.view.Choreographer; +import android.view.Display; import android.view.InputEvent; import android.view.MotionEvent; +import android.view.Surface; import android.view.accessibility.AccessibilityManager; import androidx.annotation.BinderThread; @@ -92,6 +97,7 @@ import com.android.systemui.plugins.PluginListener; import com.android.systemui.shared.recents.IOverviewProxy; import com.android.systemui.shared.recents.ISystemUiProxy; import com.android.systemui.shared.system.ActivityManagerWrapper; +import com.android.systemui.shared.system.InputChannelCompat; import com.android.systemui.shared.system.InputChannelCompat.InputEventReceiver; import com.android.systemui.shared.system.InputConsumerController; import com.android.systemui.shared.system.InputMonitorCompat; @@ -122,6 +128,9 @@ public class TouchInteractionService extends Service implements PluginListener { ActivityManagerWrapper.getInstance().cancelRecentsAnimation( @@ -172,6 +179,7 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC mPassedPilferInputSlop = mPassedWindowMoveSlop = continuingPreviousGesture; mDisableHorizontalSwipe = !mPassedPilferInputSlop && disableHorizontalSwipe; mRotationTouchHelper = mDeviceState.getRotationTouchHelper(); + mDisplayManager = getSystemService(DisplayManager.class); } @Override @@ -197,6 +205,17 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC return; } + if (TouchInteractionService.ENABLE_PER_WINDOW_INPUT_ROTATION) { + final Display display = mDisplayManager.getDisplay(mDeviceState.getDisplayId()); + final int rotation = display.getRotation(); + if (rotation != mLastRotation) { + // If rotation changes, reset tracking to avoid degenerate velocities. + mLastPos.set(ev.getX(), ev.getY()); + mVelocityTracker.clear(); + mLastRotation = rotation; + } + } + // Proxy events to recents view if (mPassedWindowMoveSlop && mInteractionHandler != null && !mRecentsViewDispatcher.hasConsumer()) { From 4bdf380625180cbe2338d0eca519366182d4c2bf Mon Sep 17 00:00:00 2001 From: Bob Badour Date: Fri, 12 Feb 2021 17:08:17 -0800 Subject: [PATCH 2/8] [LSC] Add LOCAL_LICENSE_KINDS to packages/apps/Launcher3 Added SPDX-license-identifier-Apache-2.0 to: Android.bp Android.mk robolectric_tests/Android.mk tests/Android.mk Bug: 68860345 Bug: 151177513 Bug: 151953481 Test: m all Exempt-From-Owner-Approval: janitorial work Change-Id: Ia348bba8ca075e87070ff8a605ca79ffcbea9982 Merged-in: Ia348bba8ca075e87070ff8a605ca79ffcbea9982 --- Android.bp | 17 +++++++++++++++++ Android.mk | 6 ++++++ robolectric_tests/Android.mk | 6 ++++++ tests/Android.mk | 3 +++ 4 files changed, 32 insertions(+) diff --git a/Android.bp b/Android.bp index e132854e62..50c8556dfd 100644 --- a/Android.bp +++ b/Android.bp @@ -12,6 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. +package { + default_applicable_licenses: ["packages_apps_Launcher3_license"], +} + +// Added automatically by a large-scale-change +// See: http://go/android-license-faq +license { + name: "packages_apps_Launcher3_license", + visibility: [":__subpackages__"], + license_kinds: [ + "SPDX-license-identifier-Apache-2.0", + ], + license_text: [ + "NOTICE", + ], +} + android_library { name: "launcher-aosp-tapl", static_libs: [ diff --git a/Android.mk b/Android.mk index 7805b32e8e..2c595505ff 100644 --- a/Android.mk +++ b/Android.mk @@ -50,6 +50,9 @@ LOCAL_PROTO_JAVA_OUTPUT_PARAMS := enum_style=java LOCAL_SDK_VERSION := current LOCAL_MIN_SDK_VERSION := 21 LOCAL_MODULE := Launcher3CommonDepsLib +LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 +LOCAL_LICENSE_CONDITIONS := notice +LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE LOCAL_PRIVILEGED_MODULE := true LOCAL_MANIFEST_FILE := AndroidManifest-common.xml @@ -143,6 +146,9 @@ else LOCAL_MIN_SDK_VERSION := 26 endif LOCAL_MODULE := Launcher3QuickStepLib +LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 +LOCAL_LICENSE_CONDITIONS := notice +LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE LOCAL_PRIVILEGED_MODULE := true LOCAL_STATIC_ANDROID_LIBRARIES := Launcher3CommonDepsLib diff --git a/robolectric_tests/Android.mk b/robolectric_tests/Android.mk index 3fa9b0ab63..79c26c3d89 100644 --- a/robolectric_tests/Android.mk +++ b/robolectric_tests/Android.mk @@ -19,6 +19,9 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := LauncherRoboTests +LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 +LOCAL_LICENSE_CONDITIONS := notice +LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../NOTICE LOCAL_MODULE_CLASS := JAVA_LIBRARIES LOCAL_SDK_VERSION := system_current @@ -50,6 +53,9 @@ include $(BUILD_STATIC_JAVA_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := RunLauncherRoboTests +LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 +LOCAL_LICENSE_CONDITIONS := notice +LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../NOTICE LOCAL_SDK_VERSION := system_current LOCAL_JAVA_LIBRARIES := LauncherRoboTests diff --git a/tests/Android.mk b/tests/Android.mk index 4d1bfa6067..e7e1a49cf2 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -36,6 +36,9 @@ else endif LOCAL_MODULE := ub-launcher-aosp-tapl +LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 +LOCAL_LICENSE_CONDITIONS := notice +LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../NOTICE LOCAL_SDK_VERSION := system_current include $(BUILD_STATIC_JAVA_LIBRARY) From 25992f12e520c8a74af79b3c557f5cceac2c12fa Mon Sep 17 00:00:00 2001 From: Sreyas Date: Mon, 22 Feb 2021 21:40:49 -0800 Subject: [PATCH 3/8] Fix DWB cutting off above inset when translating down. Bug: 180979788 Test: Manual Change-Id: I08577db4149b339fa217cab6401250a3fca10e65 --- .../android/quickstep/views/DigitalWellBeingToast.java | 8 +++++--- quickstep/src/com/android/quickstep/views/TaskView.java | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java b/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java index 6630aede3d..25ae055f71 100644 --- a/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java +++ b/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java @@ -71,6 +71,7 @@ public final class DigitalWellBeingToast { private ViewOutlineProvider mOldBannerOutlineProvider; private float mBannerOffsetPercentage; private float mBannerAlpha = 1f; + private float mVerticalOffset = 0f; public DigitalWellBeingToast(BaseDraggingActivity activity, TaskView taskView) { mActivity = activity; @@ -275,16 +276,17 @@ public final class DigitalWellBeingToast { @Override public void getOutline(View view, Outline outline) { mOldBannerOutlineProvider.getOutline(view, outline); - outline.offset(0, -Math.round(view.getTranslationY())); + outline.offset(0, Math.round(-view.getTranslationY() + mVerticalOffset)); } }); mBanner.setClipToOutline(true); } - void updateBannerOffset(float offsetPercentage) { + void updateBannerOffset(float offsetPercentage, float verticalOffset) { if (mBanner != null && mBannerOffsetPercentage != offsetPercentage) { + mVerticalOffset = verticalOffset; mBannerOffsetPercentage = offsetPercentage; - mBanner.setTranslationY(offsetPercentage * mBanner.getHeight()); + mBanner.setTranslationY(offsetPercentage * mBanner.getHeight() + mVerticalOffset); mBanner.invalidateOutline(); } } diff --git a/quickstep/src/com/android/quickstep/views/TaskView.java b/quickstep/src/com/android/quickstep/views/TaskView.java index e891c95a85..dfbe6cea59 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.java +++ b/quickstep/src/com/android/quickstep/views/TaskView.java @@ -48,7 +48,6 @@ import android.app.ActivityOptions; import android.content.Context; import android.content.Intent; import android.graphics.Outline; -import android.graphics.Point; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.Drawable; @@ -429,7 +428,9 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { mContextualChip.setScaleX(comp(modalness)); mContextualChip.setScaleY(comp(modalness)); } - mDigitalWellBeingToast.updateBannerOffset(modalness); + mDigitalWellBeingToast.updateBannerOffset(modalness, + mCurrentFullscreenParams.mCurrentDrawnInsets.top + + mCurrentFullscreenParams.mCurrentDrawnInsets.bottom); } public TaskMenuView getMenuView() { @@ -666,7 +667,9 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { mContextualChip.setScaleX(scale); mContextualChip.setScaleY(scale); } - mDigitalWellBeingToast.updateBannerOffset(1f - scale); + mDigitalWellBeingToast.updateBannerOffset(1f - scale, + mCurrentFullscreenParams.mCurrentDrawnInsets.top + + mCurrentFullscreenParams.mCurrentDrawnInsets.bottom); } public void setIconScaleAnimStartProgress(float startProgress) { From f480a87423e495f126c9c98b2e5884e82806ef44 Mon Sep 17 00:00:00 2001 From: Andy Wickham Date: Tue, 23 Feb 2021 18:32:58 -0800 Subject: [PATCH 4/8] Changes ENABLE_SMARTSPACE_ENHANCED to be a DeviceFlag. This lets us toggle it server-side. Bug: 181077020 Test: Manually toggled using adb shell device_config put launcher ENABLE_SMARTSPACE_ENHANCED true Change-Id: I5172bf6f977729f4c1c813b1eaba3b8b34bfc44e --- src/com/android/launcher3/config/FeatureFlags.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java index 556aff61c3..3d5920abc5 100644 --- a/src/com/android/launcher3/config/FeatureFlags.java +++ b/src/com/android/launcher3/config/FeatureFlags.java @@ -161,7 +161,7 @@ public final class FeatureFlags { "ENABLE_SMARTSPACE_UNIVERSAL", false, "Replace Smartspace with a version rendered by System UI."); - public static final BooleanFlag ENABLE_SMARTSPACE_ENHANCED = getDebugFlag( + public static final BooleanFlag ENABLE_SMARTSPACE_ENHANCED = new DeviceFlag( "ENABLE_SMARTSPACE_ENHANCED", false, "Replace Smartspace with the enhanced version. " + "Ignored if ENABLE_SMARTSPACE_UNIVERSAL is enabled."); From b2526feb244e7eac583795439705c35da864c3c8 Mon Sep 17 00:00:00 2001 From: Pierre Barbier de Reuille Date: Wed, 3 Feb 2021 22:02:43 +0000 Subject: [PATCH 5/8] Launcher changes for go/widget-size-specification Makes sure the launcher: 1 - Send the list of actual sizes the widget in all situations. 2 - Gives the current size to the framework on inflation. Also needed to guard the new border changes introduced in http://ag/13532637 with the corresponding flag. Change-Id: I2a33e9501b921f2fc393684e8ce91ee077626bf7 Test: By hand using a local widget. Bug: 179025145 --- .../launcher3/AppWidgetResizeFrame.java | 113 ++++++++++++++---- .../LauncherAccessibilityDelegate.java | 6 +- .../launcher3/qsb/QsbContainerView.java | 13 +- .../widget/LauncherAppWidgetHostView.java | 15 ++- .../widget/PendingAppWidgetHostView.java | 8 ++ .../widget/WidgetHostViewLoader.java | 33 +++-- 6 files changed, 147 insertions(+), 41 deletions(-) diff --git a/src/com/android/launcher3/AppWidgetResizeFrame.java b/src/com/android/launcher3/AppWidgetResizeFrame.java index 1330ed4edd..be92c5d133 100644 --- a/src/com/android/launcher3/AppWidgetResizeFrame.java +++ b/src/com/android/launcher3/AppWidgetResizeFrame.java @@ -2,6 +2,8 @@ package com.android.launcher3; import static com.android.launcher3.LauncherAnimUtils.LAYOUT_HEIGHT; import static com.android.launcher3.LauncherAnimUtils.LAYOUT_WIDTH; +import static com.android.launcher3.Utilities.ATLEAST_S; +import static com.android.launcher3.config.FeatureFlags.ENABLE_FOUR_COLUMNS; import static com.android.launcher3.views.BaseDragLayer.LAYOUT_X; import static com.android.launcher3.views.BaseDragLayer.LAYOUT_Y; @@ -11,14 +13,19 @@ import android.animation.PropertyValuesHolder; import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetProviderInfo; import android.content.Context; +import android.content.res.Configuration; import android.graphics.Point; +import android.graphics.PointF; import android.graphics.Rect; +import android.os.Bundle; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import androidx.annotation.Nullable; + import com.android.launcher3.accessibility.DragViewStateAnnouncer; import com.android.launcher3.dragndrop.DragLayer; import com.android.launcher3.util.FocusLogic; @@ -352,33 +359,99 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O } public static void updateWidgetSizeRanges(AppWidgetHostView widgetView, Launcher launcher, - int spanX, int spanY) { - getWidgetSizeRanges(launcher, spanX, spanY, sTmpRect); - widgetView.updateAppWidgetSize(null, sTmpRect.left, sTmpRect.top, - sTmpRect.right, sTmpRect.bottom); + int spanX, int spanY) { + List sizes = getWidgetSizes(launcher, spanX, spanY); + if (ATLEAST_S) { + widgetView.updateAppWidgetSize(new Bundle(), sizes); + } else { + Rect bounds = getMinMaxSizes(sizes, null /* outRect */); + widgetView.updateAppWidgetSize(new Bundle(), bounds.left, bounds.top, bounds.right, + bounds.bottom); + } } - public static Rect getWidgetSizeRanges(Context context, int spanX, int spanY, Rect rect) { - if (rect == null) { - rect = new Rect(); - } + private static PointF getWidgetSize(Context context, Point cellSize, int spanX, int spanY) { final float density = context.getResources().getDisplayMetrics().density; + float hBorderSpacing = 0; + float vBorderSpacing = 0; + if (ENABLE_FOUR_COLUMNS.get()) { + final int borderSpacing = context.getResources() + .getDimensionPixelSize(R.dimen.dynamic_grid_cell_border_spacing); + hBorderSpacing = (spanX - 1) * borderSpacing; + vBorderSpacing = (spanY - 1) * borderSpacing; + } + PointF widgetSize = new PointF(); + widgetSize.x = ((spanX * cellSize.x) + hBorderSpacing) / density; + widgetSize.y = ((spanY * cellSize.y) + vBorderSpacing) / density; + return widgetSize; + } + + /** Returns the actual widget size given its span. */ + public static PointF getWidgetSize(Context context, int spanX, int spanY) { + final Point[] cellSize = CELL_SIZE.get(context); + if (isLandscape(context)) { + return getWidgetSize(context, cellSize[0], spanX, spanY); + } + return getWidgetSize(context, cellSize[1], spanX, spanY); + } + + /** Returns true if the screen is in landscape mode. */ + private static boolean isLandscape(Context context) { + return context.getResources().getConfiguration().orientation + == Configuration.ORIENTATION_LANDSCAPE; + } + + /** Returns the list of sizes for a widget of given span, in dp. */ + public static ArrayList getWidgetSizes(Context context, int spanX, int spanY) { final Point[] cellSize = CELL_SIZE.get(context); - final int borderSpacing = context.getResources() - .getDimensionPixelSize(R.dimen.dynamic_grid_cell_border_spacing); - final float hBorderSpacing = (spanX - 1) * borderSpacing; - final float vBorderSpacing = (spanY - 1) * borderSpacing; + PointF landSize = getWidgetSize(context, cellSize[0], spanX, spanY); + PointF portSize = getWidgetSize(context, cellSize[1], spanX, spanY); - // Compute landscape size - int landWidth = (int) (((spanX * cellSize[0].x) + hBorderSpacing) / density); - int landHeight = (int) (((spanY * cellSize[0].y) + vBorderSpacing) / density); + ArrayList sizes = new ArrayList<>(2); + sizes.add(landSize); + sizes.add(portSize); + return sizes; + } - // Compute portrait size - int portWidth = (int) (((spanX * cellSize[1].x) + hBorderSpacing) / density); - int portHeight = (int) (((spanY * cellSize[1].y) + vBorderSpacing) / density); - rect.set(portWidth, landHeight, landWidth, portHeight); - return rect; + /** + * Returns the min and max widths and heights given a list of sizes, in dp. + * + * @param sizes List of sizes to get the min/max from. + * @param outRect Rectangle in which the result can be stored, to avoid extra allocations. If + * null, a new rectangle will be allocated. + * @return A rectangle with the left (resp. top) is used for the min width (resp. height) and + * the right (resp. bottom) for the max. The returned rectangle is set with 0s if the list is + * empty. + */ + public static Rect getMinMaxSizes(List sizes, @Nullable Rect outRect) { + if (outRect == null) { + outRect = new Rect(); + } + if (sizes.isEmpty()) { + outRect.set(0, 0, 0, 0); + } else { + PointF first = sizes.get(0); + outRect.set((int) first.x, (int) first.y, (int) first.x, (int) first.y); + for (int i = 1; i < sizes.size(); i++) { + outRect.union((int) sizes.get(i).x, (int) sizes.get(i).y); + } + } + return outRect; + } + + /** + * Returns the range of sizes a widget may be displayed, given its span. + * + * @param context Context in which the View is rendered. + * @param spanX Width of the widget, in cells. + * @param spanY Height of the widget, in cells. + * @param outRect Rectangle in which the result can be stored, to avoid extra allocations. If + * null, a new rectangle will be allocated. + */ + public static Rect getWidgetSizeRanges(Context context, int spanX, int spanY, + @Nullable Rect outRect) { + return getMinMaxSizes(getWidgetSizes(context, spanX, spanY), outRect); } @Override diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java index cd4616a967..db7fd3feca 100644 --- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java +++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java @@ -357,10 +357,8 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme } layout.markCellsAsOccupiedForView(host); - Rect sizeRange = new Rect(); - AppWidgetResizeFrame.getWidgetSizeRanges(mLauncher, info.spanX, info.spanY, sizeRange); - ((LauncherAppWidgetHostView) host).updateAppWidgetSize(null, - sizeRange.left, sizeRange.top, sizeRange.right, sizeRange.bottom); + AppWidgetResizeFrame.updateWidgetSizeRanges(((LauncherAppWidgetHostView) host), mLauncher, + info.spanX, info.spanY); host.requestLayout(); mLauncher.getModelWriter().updateItemInDatabase(info); announceConfirmation(mLauncher.getString(R.string.widget_resized, info.spanX, info.spanY)); diff --git a/src/com/android/launcher3/qsb/QsbContainerView.java b/src/com/android/launcher3/qsb/QsbContainerView.java index 289e0d84c0..459aefe2c0 100644 --- a/src/com/android/launcher3/qsb/QsbContainerView.java +++ b/src/com/android/launcher3/qsb/QsbContainerView.java @@ -20,6 +20,8 @@ import static android.appwidget.AppWidgetManager.ACTION_APPWIDGET_BIND; import static android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID; import static android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_PROVIDER; +import static com.android.launcher3.Utilities.ATLEAST_S; + import android.app.Activity; import android.app.Fragment; import android.app.SearchManager; @@ -30,6 +32,7 @@ import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.graphics.PointF; import android.graphics.Rect; import android.os.Bundle; import android.provider.Settings; @@ -50,6 +53,8 @@ import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.graphics.FragmentWithPreview; +import java.util.ArrayList; + /** * A frame layout which contains a QSB. This internally uses fragment to bind the view, which * allows it to contain the logic for {@link Fragment#startActivityForResult(Intent, int)}. @@ -294,12 +299,16 @@ public class QsbContainerView extends FrameLayout { InvariantDeviceProfile idp = LauncherAppState.getIDP(getContext()); Bundle opts = new Bundle(); - Rect size = AppWidgetResizeFrame.getWidgetSizeRanges(getContext(), - idp.numColumns, 1, null); + ArrayList sizes = AppWidgetResizeFrame + .getWidgetSizes(getContext(), idp.numColumns, 1); + Rect size = AppWidgetResizeFrame.getMinMaxSizes(sizes, null /* outRect */); opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, size.left); opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, size.top); opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, size.right); opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, size.bottom); + if (ATLEAST_S) { + opts.putParcelableArrayList(AppWidgetManager.OPTION_APPWIDGET_SIZES, sizes); + } return opts; } diff --git a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java index 780a1a18bd..41098f9f1c 100644 --- a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java +++ b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java @@ -16,9 +16,12 @@ package com.android.launcher3.widget; +import static com.android.launcher3.Utilities.ATLEAST_S; + import android.appwidget.AppWidgetProviderInfo; import android.content.Context; import android.content.res.Configuration; +import android.graphics.PointF; import android.os.Handler; import android.os.SystemClock; import android.util.SparseBooleanArray; @@ -70,8 +73,6 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView private boolean mIsAutoAdvanceRegistered; private Runnable mAutoAdvanceRunnable; - - public LauncherAppWidgetHostView(Context context) { super(context); mLauncher = Launcher.getLauncher(context); @@ -218,6 +219,16 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView mIsScrollable = checkScrollableRecursively(this); } + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + + if (ATLEAST_S) { + float density = getContext().getResources().getDisplayMetrics().density; + setCurrentSize(new PointF(w / density, h / density)); + } + } + @Override public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { super.onInitializeAccessibilityNodeInfo(info); diff --git a/src/com/android/launcher3/widget/PendingAppWidgetHostView.java b/src/com/android/launcher3/widget/PendingAppWidgetHostView.java index ca47728020..8c3206dea8 100644 --- a/src/com/android/launcher3/widget/PendingAppWidgetHostView.java +++ b/src/com/android/launcher3/widget/PendingAppWidgetHostView.java @@ -22,6 +22,7 @@ import static com.android.launcher3.graphics.PreloadIconDrawable.newPendingIcon; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.PointF; import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.drawable.Drawable; @@ -46,6 +47,8 @@ import com.android.launcher3.model.data.PackageItemInfo; import com.android.launcher3.touch.ItemClickHandler; import com.android.launcher3.util.Themes; +import java.util.List; + public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implements OnClickListener, ItemInfoUpdateReceiver { private static final float SETUP_ICON_SIZE_FACTOR = 2f / 5; @@ -108,6 +111,11 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView // No-op } + @Override + public void updateAppWidgetSize(Bundle newOptions, List sizes) { + // No-op + } + @Override protected View getDefaultView() { View defaultView = mInflater.inflate(R.layout.appwidget_not_ready, this, false); diff --git a/src/com/android/launcher3/widget/WidgetHostViewLoader.java b/src/com/android/launcher3/widget/WidgetHostViewLoader.java index c022374614..2438bdf5ab 100644 --- a/src/com/android/launcher3/widget/WidgetHostViewLoader.java +++ b/src/com/android/launcher3/widget/WidgetHostViewLoader.java @@ -3,6 +3,7 @@ package com.android.launcher3.widget; import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetManager; import android.content.Context; +import android.graphics.PointF; import android.graphics.Rect; import android.os.Bundle; import android.os.Handler; @@ -18,6 +19,8 @@ import com.android.launcher3.dragndrop.DragLayer; import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.util.Thunk; +import java.util.ArrayList; + public class WidgetHostViewLoader implements DragController.DragListener { private static final String TAG = "WidgetHostViewLoader"; private static final boolean LOGD = false; @@ -152,24 +155,28 @@ public class WidgetHostViewLoader implements DragController.DragListener { } public static Bundle getDefaultOptionsForWidget(Context context, PendingAddWidgetInfo info) { - Rect rect = new Rect(); - AppWidgetResizeFrame.getWidgetSizeRanges(context, info.spanX, info.spanY, rect); + ArrayList sizes = AppWidgetResizeFrame + .getWidgetSizes(context, info.spanX, info.spanY); + Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, info.componentName, null); - float density = context.getResources().getDisplayMetrics().density; - int xPaddingDips = (int) ((padding.left + padding.right) / density); - int yPaddingDips = (int) ((padding.top + padding.bottom) / density); + float xPaddingDips = (padding.left + padding.right) / density; + float yPaddingDips = (padding.top + padding.bottom) / density; + + for (PointF size : sizes) { + size.x = Math.max(0.f, size.x - xPaddingDips); + size.y = Math.max(0.f, size.y - yPaddingDips); + } + + Rect rect = AppWidgetResizeFrame.getMinMaxSizes(sizes, null /* outRect */); Bundle options = new Bundle(); - options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, - rect.left - xPaddingDips); - options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, - rect.top - yPaddingDips); - options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, - rect.right - xPaddingDips); - options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, - rect.bottom - yPaddingDips); + options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, rect.left); + options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, rect.top); + options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, rect.right); + options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, rect.bottom); + options.putParcelableArrayList(AppWidgetManager.OPTION_APPWIDGET_SIZES, sizes); return options; } } From fdeee141d926f578b2878861dd0635ef073316bd Mon Sep 17 00:00:00 2001 From: Steven Ng Date: Wed, 24 Feb 2021 10:16:54 +0000 Subject: [PATCH 6/8] Replace the no preview layout check with Resources.ID_NULL(0) TODO: open up the RemoteViews(ApplicationInfo) API so that Launcher can inflate a layout from a work profile app. Test: Before this CL, install tasks app in work profile. Observed crash when tapping Tasks header in the widgets picker. After this CL, no crash observed when tapping Tasks header in the widgets picker. Bug: 181061277 Change-Id: I16c2b9aec5f4cabf15da35fea09f68c10797f5fa --- .../launcher3/dragndrop/LivePreviewWidgetCell.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/dragndrop/LivePreviewWidgetCell.java b/src/com/android/launcher3/dragndrop/LivePreviewWidgetCell.java index 71e10a82b0..be6a07f004 100644 --- a/src/com/android/launcher3/dragndrop/LivePreviewWidgetCell.java +++ b/src/com/android/launcher3/dragndrop/LivePreviewWidgetCell.java @@ -1,6 +1,9 @@ package com.android.launcher3.dragndrop; +import static com.android.launcher3.Utilities.ATLEAST_S; + import android.content.Context; +import android.content.res.Resources; import android.graphics.Bitmap; import android.util.AttributeSet; import android.view.View; @@ -62,9 +65,10 @@ public class LivePreviewWidgetCell extends WidgetCell { @Override public void applyFromCellItem(WidgetItem item, WidgetPreviewLoader loader) { - if (mPreview == null + if (ATLEAST_S + && mPreview == null && item.widgetInfo != null - && item.widgetInfo.previewLayout != View.NO_ID) { + && item.widgetInfo.previewLayout != Resources.ID_NULL) { mPreview = new RemoteViews(item.widgetInfo.provider.getPackageName(), item.widgetInfo.previewLayout); } From 8e16391b49794da98c8e9a215de4778d44a959db Mon Sep 17 00:00:00 2001 From: thiruram Date: Tue, 23 Feb 2021 19:12:05 -0800 Subject: [PATCH 7/8] [AA+] Log LAUNCHER_ALLAPPS_FOCUSED_ITEM_SELECTED_WITH_IME event. Bug: 178562918 Test: Manual Change-Id: Id40f80aae652dcc6c16ad35a003c91fd97750608 --- .../launcher3/allapps/search/AllAppsSearchBarController.java | 4 ++++ src/com/android/launcher3/logging/StatsLogManager.java | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java index 198c4b2bfb..cf2e2595c4 100644 --- a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java +++ b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java @@ -15,6 +15,8 @@ */ package com.android.launcher3.allapps.search; +import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_FOCUSED_ITEM_SELECTED_WITH_IME; + import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; @@ -105,6 +107,8 @@ public class AllAppsSearchBarController public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (FeatureFlags.ENABLE_DEVICE_SEARCH.get()) { if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_GO) { + mLauncher.getStatsLogManager().logger() + .log(LAUNCHER_ALLAPPS_FOCUSED_ITEM_SELECTED_WITH_IME); // selectFocusedView should return SearchTargetEvent that is passed onto onClick if (Launcher.getLauncher(mLauncher).getAppsView().selectFocusedView(v)) { return true; diff --git a/src/com/android/launcher3/logging/StatsLogManager.java b/src/com/android/launcher3/logging/StatsLogManager.java index 7745e90d8a..431d5342d3 100644 --- a/src/com/android/launcher3/logging/StatsLogManager.java +++ b/src/com/android/launcher3/logging/StatsLogManager.java @@ -393,6 +393,9 @@ public class StatsLogManager implements ResourceBasedOverride { @UiEvent(doc = "User selected from a selection row of Slice.") LAUNCHER_SLICE_SELECTION_ACTION(707), + @UiEvent(doc = "IME is used for selecting the focused item on the AllApps screen.") + LAUNCHER_ALLAPPS_FOCUSED_ITEM_SELECTED_WITH_IME(718), + @UiEvent(doc = "Launcher entered into AllApps state with device search enabled.") LAUNCHER_ALLAPPS_ENTRY_WITH_DEVICE_SEARCH(720), ; From 0779f740498aec5a49359d1af61f13ede6450e7b Mon Sep 17 00:00:00 2001 From: Andy Wickham Date: Thu, 25 Feb 2021 20:06:08 +0000 Subject: [PATCH 8/8] Revert "Changes ENABLE_SMARTSPACE_ENHANCED to be a DeviceFlag." This reverts commit f480a87423e495f126c9c98b2e5884e82806ef44. Reason for revert: Broke tests Change-Id: I508e1db58b7973a60e350aa679b9b6f5fe4ecbd1 --- src/com/android/launcher3/config/FeatureFlags.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java index 3d5920abc5..556aff61c3 100644 --- a/src/com/android/launcher3/config/FeatureFlags.java +++ b/src/com/android/launcher3/config/FeatureFlags.java @@ -161,7 +161,7 @@ public final class FeatureFlags { "ENABLE_SMARTSPACE_UNIVERSAL", false, "Replace Smartspace with a version rendered by System UI."); - public static final BooleanFlag ENABLE_SMARTSPACE_ENHANCED = new DeviceFlag( + public static final BooleanFlag ENABLE_SMARTSPACE_ENHANCED = getDebugFlag( "ENABLE_SMARTSPACE_ENHANCED", false, "Replace Smartspace with the enhanced version. " + "Ignored if ENABLE_SMARTSPACE_UNIVERSAL is enabled.");