fix: Conflict incoming changes from 15-dev

This commit is contained in:
Pun Butrach committed 2026-01-10 20:49:12 +07:00
1 parent 14e352c827
commit 2e76c99dad
1726 files changed
+146970 -95027

No files matched your search

@@ -16,6 +16,7 @@
package com.android.launcher3;
import static com.android.launcher3.Flags.enableScalabilityForDesktopExperience;
import static com.android.launcher3.GridType.GRID_TYPE_ANY;
import static com.android.launcher3.GridType.GRID_TYPE_NON_ONE_GRID;
import static com.android.launcher3.GridType.GRID_TYPE_ONE_GRID;
@@ -57,7 +58,6 @@ import androidx.annotation.VisibleForTesting;
import androidx.annotation.XmlRes;
import androidx.core.content.res.ResourcesCompat;
import app.lawnchair.DeviceProfileOverrides.DBGridInfo;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dagger.ApplicationContext;
import com.android.launcher3.dagger.LauncherAppComponent;
@@ -95,6 +95,7 @@ import java.util.stream.Collectors;
import javax.inject.Inject;
import app.lawnchair.DeviceProfileOverrides.DBGridInfo;
import app.lawnchair.DeviceProfileOverrides;
@LauncherAppSingleton
@@ -110,13 +111,14 @@ public class InvariantDeviceProfile {
"idp_non_fixed_landscape_grid_name";
@Retention(RetentionPolicy.SOURCE)
@IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
@IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET, TYPE_DESKTOP})
public @interface DeviceType {
}
public static final int TYPE_PHONE = 0;
public static final int TYPE_MULTI_DISPLAY = 1;
public static final int TYPE_TABLET = 2;
public static final int TYPE_DESKTOP = 3;
private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
@@ -227,7 +229,7 @@ public class InvariantDeviceProfile {
public @StyleRes int allAppsStyle;
/**
* Do not query directly. see {@link DeviceProfile#isScalableGrid}.
* Do not query directly. see {@link deviceprofile#isScalableGrid}.
*/
protected boolean isScalable;
@XmlRes
@@ -261,6 +263,11 @@ public class InvariantDeviceProfile {
private String mLocale = "";
public boolean enableTwoLinesInAllApps = false;
// If non-negative, the workspace row with which top of the all apps container is to be aligned
// with.
public int appListAlignedWithWorkspaceRow = -1;
/**
* Fixed landscape mode is the landscape on the phones.
*/
@@ -270,7 +277,6 @@ public class InvariantDeviceProfile {
public int gridType;
public String dbFile;
public int defaultLayoutId;
public int demoModeLayoutId;
public boolean[] inlineQsb = new boolean[COUNT_SIZES];
/**
@@ -413,7 +419,6 @@ public class InvariantDeviceProfile {
dbFile = dbGridInfo.getDbFile();
gridType = closestProfile.gridType;
defaultLayoutId = closestProfile.defaultLayoutId;
demoModeLayoutId = closestProfile.demoModeLayoutId;
numFolderRows = closestProfile.numFolderRows;
numFolderColumns = closestProfile.numFolderColumns;
@@ -438,6 +443,7 @@ public class InvariantDeviceProfile {
allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
numAllAppsRowsForCellHeightCalculation =
closestProfile.mNumAllAppsRowsForCellHeightCalculation;
appListAlignedWithWorkspaceRow = closestProfile.mAllAppsAlignedWithWorkspaceRow;
this.deviceType = displayInfo.getDeviceType();
this.displayInfo = displayInfo;
@@ -531,14 +537,14 @@ public class InvariantDeviceProfile {
int numMinShownHotseatIconsForTablet = supportedProfiles
.stream()
.filter(deviceProfile -> deviceProfile.isTablet)
.filter(deviceProfile -> deviceProfile.getDeviceProperties().isTablet())
.mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
.min()
.orElse(0);
supportedProfiles
.stream()
.filter(deviceProfile -> deviceProfile.isTablet)
.filter(deviceProfile -> deviceProfile.getDeviceProperties().isTablet())
.forEach(deviceProfile -> {
deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
deviceProfile.recalculateHotseatWidthAndBorderSpace();
@@ -568,7 +574,11 @@ public class InvariantDeviceProfile {
*/
@VisibleForTesting
public void setCurrentGrid(Context context, String newGridName) {
DeviceProfileOverrides.INSTANCE.get(context).setCurrentGrid(newGridName);
if (TextUtils.equals(mPrefs.get(GRID_NAME), newGridName)) return;
// pE-TODO(QPR1): Move off setCurrentGrid to Prefs
// Lawnchair-TODO: Move off setCurrentGrid to Prefs
mPrefs.put(GRID_NAME, newGridName);
//DeviceProfileOverrides.INSTANCE.get(context).setCurrentGrid(newGridName);
MAIN_EXECUTOR.execute(() -> {
onConfigChanged(context.getApplicationContext());
});
@@ -586,7 +596,7 @@ public class InvariantDeviceProfile {
Object[] oldState = toModelState();
// Re-init grid
initGrid(context, getCurrentGridName(context));
initGrid(context, mPrefs.get(GRID_NAME));
boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
for (OnIDPChangeListener listener : mChangeListeners) {
@@ -672,6 +682,19 @@ public class InvariantDeviceProfile {
Info displayInfo) {
ArrayList<GridSize> gridSizes = new ArrayList<>();
// Difference between grid sizes available for different display size breakpoints is more
// stark on desktop devices, so using grid size matched against display pixel sizes results
// in noticeable worse UI on devices with larger DPI. Compromise by matching grid size
// breakpoints against pixel size for stable device density on desktop, to ensure optimal
// grid size is selected for the default display size.
// TODO(b/420970288): Ideally, this should use the current DPI, and update grid content if
// the change in display size changes the grid size.
boolean matchAgainstDefaultDpSize = displayInfo.getDeviceType() == TYPE_DESKTOP
&& enableScalabilityForDesktopExperience();
float stableDensityScale =
matchAgainstDefaultDpSize
? displayInfo.getStableDensityScaleFactor() : 1.0f;
try (XmlResourceParser parser = resourceHelper.getXml()) {
final int depth = parser.getDepth();
int type;
@@ -679,19 +702,51 @@ public class InvariantDeviceProfile {
|| parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
if ((type == XmlPullParser.START_TAG)
&& "GridSize".equals(parser.getName())) {
gridSizes.add(new GridSize(context, Xml.asAttributeSet(parser)));
gridSizes.add(new GridSize(context, Xml.asAttributeSet(parser),
stableDensityScale));
}
}
} catch (IOException | XmlPullParserException e) {
throw new RuntimeException(e);
}
// Finds the min width and height in dp for all displays.
// Finds the min width and height in px for all displays.
int[] dimens = findMinWidthAndHeightPxForDevice(displayInfo);
return findBestGridSize(gridSizes, dimens[0], dimens[1]);
}
private static AllAppsSize getAllAppsSize(ResourceHelper resourceHelper, Context context,
Info displayInfo) {
ArrayList<AllAppsSize> allAppsSizes = new ArrayList<>();
boolean matchAgainstDefaultDpSize = displayInfo.getDeviceType() == TYPE_DESKTOP
&& enableScalabilityForDesktopExperience();
float stableDensityScale =
matchAgainstDefaultDpSize
? displayInfo.getStableDensityScaleFactor() : 1.0f;
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)
&& "AllAppsSize".equals(parser.getName())) {
allAppsSizes.add(new AllAppsSize(context, Xml.asAttributeSet(parser),
stableDensityScale));
}
}
} catch (IOException | XmlPullParserException e) {
throw new RuntimeException(e);
}
// Finds the min width and height in px for all displays.
int[] dimens = findMinWidthAndHeightPxForDevice(displayInfo);
return findBestAllAppsSize(allAppsSizes, dimens[0]);
}
/**
* @return the biggest grid size that fits the display dimensions.
* If no best grid size is found, return null.
@@ -711,6 +766,23 @@ public class InvariantDeviceProfile {
return selectedGridSize;
}
/**
* @return An `AllAppsSize` spec with min width at most `targetWidthPx`.
* If multiple specs are available, selects the one closest to the `targetWidthPx`.
*/
private static AllAppsSize findBestAllAppsSize(List<AllAppsSize> list, int targetWidthPx) {
AllAppsSize selectedGridSize = null;
for (AllAppsSize item : list) {
if (targetWidthPx >= item.mMinDeviceWidthPx) {
if (selectedGridSize == null
|| selectedGridSize.mMinDeviceWidthPx < item.mMinDeviceWidthPx) {
selectedGridSize = item;
}
}
}
return selectedGridSize;
}
private static int[] findMinWidthAndHeightPxForDevice(Info displayInfo) {
int minDisplayWidthPx = Integer.MAX_VALUE;
int minDisplayHeightPx = Integer.MAX_VALUE;
@@ -911,6 +983,7 @@ public class InvariantDeviceProfile {
.setWindowBounds(mWMProxy.getRealBounds(
displayContext, mWMProxy.getDisplayInfo(displayContext)))
.setTransposeLayoutWithOrientation(false)
.setSecondaryDisplayOptionSpec()
.build();
}
@@ -928,12 +1001,12 @@ public class InvariantDeviceProfile {
float minDiff = Float.MAX_VALUE;
for (DeviceProfile profile : supportedProfiles) {
float diff = Math.abs(profile.widthPx - screenWidth)
+ Math.abs(profile.heightPx - screenHeight);
float diff = Math.abs(profile.getDeviceProperties().getWidthPx() - screenWidth)
+ Math.abs(profile.getDeviceProperties().getHeightPx() - screenHeight);
if (diff < minDiff) {
minDiff = diff;
bestMatch = profile;
} else if (diff == minDiff && profile.rotationHint == rotation) {
} else if (diff == minDiff && profile.getDeviceProperties().getRotationHint() == rotation) {
bestMatch = profile;
}
}
@@ -986,6 +1059,73 @@ public class InvariantDeviceProfile {
void onIdpChanged(boolean modelPropertiesChanged);
}
/** Returns {@link DisplayOptionSpec} for the provided displayInfo. */
static DisplayOptionSpec createDisplayOptionSpec(Context context, Info displayInfo,
boolean isLandscape) {
// Get predefined profiles for provided displayInfo without using any main device's pref.
List<DisplayOption> allOptions = getPredefinedDeviceProfiles(context,
/* gridName= */ null, displayInfo, /* allowDisabledGrid= */ false,
/* isFixedLandscapeMode= */ false);
return new DisplayOptionSpec(
invDistWeightedInterpolate(displayInfo, new ArrayList<>(allOptions),
displayInfo.getDeviceType()), isLandscape);
}
/** Class to expose properties required for external displays to {@link deviceprofile} */
public static final class DisplayOptionSpec {
public final int typeIndex;
public final int numShownHotseatIcons;
public final int numAllAppsColumns;
@XmlRes public final int hotseatSpecsId;
@XmlRes public final int workspaceCellSpecsId;
@XmlRes public final int workspaceSpecsId;
@XmlRes public final int allAppsSpecsId;
@XmlRes public final int folderSpecsId;
@XmlRes public final int allAppsCellSpecsId;
public final boolean startAlignTaskbar;
DisplayOptionSpec(DisplayOption displayOption, boolean isLandscape) {
typeIndex = isLandscape ? INDEX_LANDSCAPE : INDEX_DEFAULT;
numShownHotseatIcons = displayOption.grid.numHotseatIcons;
numAllAppsColumns = displayOption.grid.numAllAppsColumns;
hotseatSpecsId = displayOption.grid.mHotseatSpecsId;
workspaceCellSpecsId = displayOption.grid.mWorkspaceCellSpecsId;
workspaceSpecsId = displayOption.grid.mWorkspaceSpecsId;
allAppsSpecsId = displayOption.grid.mAllAppsSpecsId;
folderSpecsId = displayOption.grid.mFolderSpecsId;
allAppsCellSpecsId = displayOption.grid.mAllAppsCellSpecsId;
startAlignTaskbar = displayOption.startAlignTaskbar[typeIndex];
}
DisplayOptionSpec(InvariantDeviceProfile inv, boolean isTwoPanels, boolean isLandscape) {
if (isTwoPanels) {
if (isLandscape) {
typeIndex = INDEX_TWO_PANEL_LANDSCAPE;
} else {
typeIndex = INDEX_TWO_PANEL_PORTRAIT;
}
} else {
if (isLandscape) {
typeIndex = INDEX_LANDSCAPE;
} else {
typeIndex = INDEX_DEFAULT;
}
}
numShownHotseatIcons =
isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
numAllAppsColumns = isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
hotseatSpecsId = isTwoPanels ? inv.hotseatSpecsTwoPanelId : inv.hotseatSpecsId;
workspaceCellSpecsId = isTwoPanels ? inv.workspaceCellSpecsTwoPanelId
: inv.workspaceCellSpecsId;
workspaceSpecsId = isTwoPanels ? inv.workspaceSpecsTwoPanelId : inv.workspaceSpecsId;
allAppsSpecsId = isTwoPanels ? inv.allAppsSpecsTwoPanelId : inv.allAppsSpecsId;
folderSpecsId = isTwoPanels ? inv.folderSpecsTwoPanelId : inv.folderSpecsId;
allAppsCellSpecsId =
isTwoPanels ? inv.allAppsCellSpecsTwoPanelId : inv.allAppsCellSpecsId;
startAlignTaskbar = inv.startAlignTaskbar[typeIndex];
}
}
public static final class GridOption {
@@ -994,8 +1134,10 @@ public class InvariantDeviceProfile {
private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
private static final int DEVICE_CATEGORY_DESKTOP = 1 << 3;
private static final int DEVICE_CATEGORY_ANY =
DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY
| DEVICE_CATEGORY_DESKTOP;
private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
@@ -1031,7 +1173,6 @@ public class InvariantDeviceProfile {
private final String dbFile;
private final int defaultLayoutId;
private final int demoModeLayoutId;
private final boolean isScalable;
private final boolean mIsDualGrid;
@@ -1049,7 +1190,11 @@ public class InvariantDeviceProfile {
private final int mAllAppsCellSpecsId;
private final int mAllAppsCellSpecsTwoPanelId;
private final int mGridSizeSpecsId;
private final int mAllAppsSizeSpecId;
private final boolean mIsFixedLandscape;
// If non-negative, the index of workspace row with which the top of the all apps container
// should be aligned with.
private final int mAllAppsAlignedWithWorkspaceRow;
public GridOption(Context context, AttributeSet attrs, Info displayInfo) {
TypedArray a = context.obtainStyledAttributes(
@@ -1062,6 +1207,10 @@ public class InvariantDeviceProfile {
DEVICE_CATEGORY_ANY);
mGridSizeSpecsId = a.getResourceId(
R.styleable.GridDisplayOption_gridSizeSpecsId, INVALID_RESOURCE_HANDLE);
mAllAppsSizeSpecId = enableScalabilityForDesktopExperience()
? a.getResourceId(R.styleable.GridDisplayOption_allAppsSizeSpecsId,
INVALID_RESOURCE_HANDLE)
: INVALID_RESOURCE_HANDLE;
mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
ResourceHelper resourceHelper = new ResourceHelper(context, mGridSizeSpecsId);
@@ -1070,15 +1219,20 @@ public class InvariantDeviceProfile {
numRows = gridSize.mNumRows;
dbFile = gridSize.mDbFile;
defaultLayoutId = gridSize.mDefaultLayoutId;
demoModeLayoutId = gridSize.mDemoModeLayoutId;
} else {
numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
defaultLayoutId = a.getResourceId(
R.styleable.GridDisplayOption_defaultLayoutId, 0);
demoModeLayoutId = a.getResourceId(
R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
defaultLayoutId = a.getResourceId(
R.styleable.GridDisplayOption_defaultLayoutId, 0);
}
if (mAllAppsSizeSpecId != INVALID_RESOURCE_HANDLE) {
ResourceHelper resourceHelper = new ResourceHelper(context, mAllAppsSizeSpecId);
AllAppsSize allAppsSize = getAllAppsSize(resourceHelper, context, displayInfo);
mAllAppsAlignedWithWorkspaceRow = allAppsSize.mAlignWithWorkspaceRow;
} else {
mAllAppsAlignedWithWorkspaceRow = -1;
}
numSearchContainerColumns = a.getInt(
@@ -1224,6 +1378,9 @@ public class InvariantDeviceProfile {
case TYPE_MULTI_DISPLAY:
return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
== DEVICE_CATEGORY_MULTI_DISPLAY;
case TYPE_DESKTOP:
return (deviceCategory & DEVICE_CATEGORY_DESKTOP)
== DEVICE_CATEGORY_DESKTOP;
default:
return false;
}
@@ -1261,21 +1418,46 @@ public class InvariantDeviceProfile {
final float mMinDeviceHeightPx;
final String mDbFile;
final int mDefaultLayoutId;
final int mDemoModeLayoutId;
GridSize(Context context, AttributeSet attrs) {
GridSize(Context context, AttributeSet attrs, float stableDensityScale) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridSize);
mNumRows = (int) a.getFloat(R.styleable.GridSize_numGridRows, 0);
mNumColumns = (int) a.getFloat(R.styleable.GridSize_numGridColumns, 0);
mMinDeviceWidthPx = a.getFloat(R.styleable.GridSize_minDeviceWidthPx, 0);
mMinDeviceHeightPx = a.getFloat(R.styleable.GridSize_minDeviceHeightPx, 0);
mMinDeviceWidthPx = a.getInt(R.styleable.GridSize_minDeviceWidthPx, 0)
* stableDensityScale;
mMinDeviceHeightPx = a.getInt(R.styleable.GridSize_minDeviceHeightPx, 0)
* stableDensityScale;
mDbFile = a.getString(R.styleable.GridSize_dbFile);
mDefaultLayoutId = a.getResourceId(
R.styleable.GridSize_defaultLayoutId, 0);
mDemoModeLayoutId = a.getResourceId(
R.styleable.GridSize_demoModeLayoutId, mDefaultLayoutId);
a.recycle();
}
}
/**
* Optional spec that configures the size of the all apps container.
*
* Allows the all apps height to be set so the top of the all apps container aligns with the
* top of a workspace row.
*/
private static final class AllAppsSize {
// The workspace row with which top of all apps container should be aligned with.
// Negative value will be ignored, and cause all apps container to fill up vertical space.
final int mAlignWithWorkspaceRow;
// The minimum device pixel width to which the spec can be applied.
final float mMinDeviceWidthPx;
AllAppsSize(Context context, AttributeSet attrs, float stableDensityScale) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AllAppsSize);
mAlignWithWorkspaceRow = a.getInt(R.styleable.AllAppsSize_alignWithWorkspaceRow, -1);
mMinDeviceWidthPx = a.getFloat(R.styleable.AllAppsSize_minDeviceWidthDp, 0)
* stableDensityScale;
a.recycle();
}