From 2e4a2330d3acbd451087a4037d7b06632527b1ae Mon Sep 17 00:00:00 2001 From: MrSluffy Date: Fri, 1 Nov 2024 10:19:35 +0800 Subject: [PATCH] fixes more error --- build.gradle | 4 +- .../app/lawnchair/DeviceProfileOverrides.kt | 6 +- lawnchair/src/app/lawnchair/FeedBridge.kt | 6 +- .../app/lawnchair/HeadlessWidgetsManager.kt | 7 +- .../src/app/lawnchair/LawnchairLauncher.kt | 5 +- .../app/lawnchair/LawnchairLayoutFactory.kt | 7 +- .../src/app/lawnchair/NotificationManager.kt | 7 +- .../app/lawnchair/SearchBarStateHandler.kt | 2 +- .../allapps/LawnchairAlphabeticalAppsList.kt | 4 +- .../src/app/lawnchair/font/FontManager.kt | 7 +- .../preferences/PreferenceManager.kt | 7 +- .../preferences2/PreferenceManager2.kt | 6 +- .../src/app/lawnchair/theme/ThemeProvider.kt | 7 +- .../wallpaper/WallpaperManagerCompat.kt | 3 +- platform_frameworks_libs_systemui | 2 +- .../launcher3/InvariantDeviceProfile.java | 320 +++++++++--------- .../android/launcher3/LauncherAppState.java | 8 + src/com/android/launcher3/Utilities.java | 4 + .../allapps/ActivityAllAppsContainerView.java | 6 +- .../launcher3/icons/LauncherIcons.java | 6 +- .../notification/NotificationListener.java | 2 +- .../util/MainThreadInitializedObject.java | 7 + .../DisableSubpixelTextTransitionListener.kt | 84 ----- .../shared/system/QuickStepContract.java | 23 +- systemUnFold/build.gradle | 6 +- 25 files changed, 264 insertions(+), 282 deletions(-) delete mode 100644 systemUIShared/src/com/android/systemui/shared/animation/DisableSubpixelTextTransitionListener.kt diff --git a/build.gradle b/build.gradle index 374f6d9763..bb9ced66e1 100644 --- a/build.gradle +++ b/build.gradle @@ -103,7 +103,7 @@ allprojects { compileOnly fileTree(dir: FRAMEWORK_PREBUILTS_DIR, include: 'SystemUI-core.jar') compileOnly fileTree(dir: FRAMEWORK_PREBUILTS_DIR, include: 'SystemUI-statsd.jar') compileOnly fileTree(dir: FRAMEWORK_PREBUILTS_DIR, include: 'WindowManager-Shell-15.jar') - compileOnly fileTree(dir: FRAMEWORK_PREBUILTS_DIR, include: 'QuickstepResLib.jar') +// compileOnly fileTree(dir: FRAMEWORK_PREBUILTS_DIR, include: 'QuickstepResLib.jar') compileOnly projects.compatLib compileOnly projects.compatLib.compatLibVQ @@ -354,7 +354,7 @@ dependencies { implementation fileTree(dir: FRAMEWORK_PREBUILTS_DIR, include: 'SystemUI-statsd-14.jar') implementation fileTree(dir: FRAMEWORK_PREBUILTS_DIR, include: 'WindowManager-Shell-15.jar') - withQuickstepCompileOnly fileTree(dir: FRAMEWORK_PREBUILTS_DIR, include: 'QuickstepResLib.jar') +// withQuickstepCompileOnly fileTree(dir: FRAMEWORK_PREBUILTS_DIR, include: 'QuickstepResLib.jar') withQuickstepCompileOnly fileTree(dir: FRAMEWORK_PREBUILTS_DIR, include: 'framework-15.jar') coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.2' diff --git a/lawnchair/src/app/lawnchair/DeviceProfileOverrides.kt b/lawnchair/src/app/lawnchair/DeviceProfileOverrides.kt index fba4259ba3..8dd18b3618 100644 --- a/lawnchair/src/app/lawnchair/DeviceProfileOverrides.kt +++ b/lawnchair/src/app/lawnchair/DeviceProfileOverrides.kt @@ -10,9 +10,10 @@ import com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE import com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE import com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT import com.android.launcher3.util.MainThreadInitializedObject +import com.android.launcher3.util.SafeCloseable import com.patrykmichalik.opto.core.firstBlocking -class DeviceProfileOverrides(context: Context) { +class DeviceProfileOverrides(context: Context) : SafeCloseable { private val prefs = PreferenceManager.getInstance(context) private val preferenceManager2 = PreferenceManager2.getInstance(context) @@ -56,6 +57,9 @@ class DeviceProfileOverrides(context: Context) { ) fun getTextFactors() = TextFactors(preferenceManager2) + override fun close() { + TODO("Not yet implemented") + } data class DBGridInfo( val numHotseatColumns: Int, diff --git a/lawnchair/src/app/lawnchair/FeedBridge.kt b/lawnchair/src/app/lawnchair/FeedBridge.kt index 81627e1994..c35bb5ed1b 100644 --- a/lawnchair/src/app/lawnchair/FeedBridge.kt +++ b/lawnchair/src/app/lawnchair/FeedBridge.kt @@ -111,12 +111,12 @@ class FeedBridge(private val context: Context) { val info = context.packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES) val signingInfo = info.signingInfo - if (signingInfo.hasMultipleSigners()) return false + if (signingInfo!!.hasMultipleSigners()) return false return signingInfo.signingCertificateHistory.any { it.hashCode() == signatureHash } } else -> { val info = context.packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES) - return if (info.signatures.any { it.hashCode() != signatureHash }) false else info.signatures.isNotEmpty() + return if (info.signatures!!.any { it.hashCode() != signatureHash }) false else info.signatures!!.isNotEmpty() } } } @@ -130,7 +130,7 @@ class FeedBridge(private val context: Context) { val info = context.packageManager .getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES) val signingInfo = info.signingInfo - if (signingInfo.hasMultipleSigners()) return false + if (signingInfo!!.hasMultipleSigners()) return false signingInfo.signingCertificateHistory.forEach { val hash = Integer.toHexString(it.hashCode()) Log.d(TAG, "Feed provider $packageName(0x$hash) isn't whitelisted") diff --git a/lawnchair/src/app/lawnchair/HeadlessWidgetsManager.kt b/lawnchair/src/app/lawnchair/HeadlessWidgetsManager.kt index b32d3adebf..b6b5ac0ed9 100644 --- a/lawnchair/src/app/lawnchair/HeadlessWidgetsManager.kt +++ b/lawnchair/src/app/lawnchair/HeadlessWidgetsManager.kt @@ -11,6 +11,7 @@ import android.widget.RemoteViews import androidx.core.content.edit import com.android.launcher3.Utilities import com.android.launcher3.util.MainThreadInitializedObject +import com.android.launcher3.util.SafeCloseable import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.MainScope import kotlinx.coroutines.channels.awaitClose @@ -22,7 +23,7 @@ import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.shareIn import kotlinx.coroutines.plus -class HeadlessWidgetsManager(private val context: Context) { +class HeadlessWidgetsManager(private val context: Context) : SafeCloseable { private val scope = MainScope() + CoroutineName("HeadlessWidgetsManager") private val prefs = Utilities.getDevicePrefs(context) @@ -50,6 +51,10 @@ class HeadlessWidgetsManager(private val context: Context) { return widget.updates } + override fun close() { + TODO("Not yet implemented") + } + private class HeadlessAppWidgetHost(context: Context) : AppWidgetHost(context, 1028) { override fun onCreateView( diff --git a/lawnchair/src/app/lawnchair/LawnchairLauncher.kt b/lawnchair/src/app/lawnchair/LawnchairLauncher.kt index 6f4ea68e13..94b19f7804 100644 --- a/lawnchair/src/app/lawnchair/LawnchairLauncher.kt +++ b/lawnchair/src/app/lawnchair/LawnchairLauncher.kt @@ -53,6 +53,7 @@ import com.android.launcher3.Utilities import com.android.launcher3.model.data.ItemInfo import com.android.launcher3.popup.SystemShortcut import com.android.launcher3.statemanager.StateManager +import com.android.launcher3.statemanager.StateManager.StateHandler import com.android.launcher3.uioverrides.QuickstepLauncher import com.android.launcher3.uioverrides.states.AllAppsState import com.android.launcher3.uioverrides.states.OverviewState @@ -121,7 +122,7 @@ class LawnchairLauncher : QuickstepLauncher() { if (prefs.autoLaunchRoot.get()) { lifecycleScope.launch { try { - RootHelperManager.INSTANCE.get(this@LawnchairLauncher).getService() + RootHelperManager.INSTANCE.get(this@LawnchairLauncher) } catch (_: RootNotAvailableException) { } } @@ -186,7 +187,7 @@ class LawnchairLauncher : QuickstepLauncher() { reloadIconsIfNeeded() } - override fun collectStateHandlers(out: MutableList>) { + override fun collectStateHandlers(out: MutableList>) { super.collectStateHandlers(out) out.add(SearchBarStateHandler(this)) } diff --git a/lawnchair/src/app/lawnchair/LawnchairLayoutFactory.kt b/lawnchair/src/app/lawnchair/LawnchairLayoutFactory.kt index a083e16ff4..b45b864de8 100644 --- a/lawnchair/src/app/lawnchair/LawnchairLayoutFactory.kt +++ b/lawnchair/src/app/lawnchair/LawnchairLayoutFactory.kt @@ -8,9 +8,10 @@ import android.widget.Button import android.widget.TextView import app.lawnchair.font.FontManager import com.android.launcher3.BubbleTextView +import com.android.launcher3.util.SafeCloseable import com.android.launcher3.views.DoubleShadowBubbleTextView -class LawnchairLayoutFactory(context: Context) : LayoutInflater.Factory2 { +class LawnchairLayoutFactory(context: Context) : LayoutInflater.Factory2, SafeCloseable { private val fontManager by lazy { FontManager.INSTANCE.get(context) } private val constructorMap = mapOf View>( @@ -36,4 +37,8 @@ class LawnchairLayoutFactory(context: Context) : LayoutInflater.Factory2 { override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? { return onCreateView(null, name, context, attrs) } + + override fun close() { + TODO("Not yet implemented") + } } diff --git a/lawnchair/src/app/lawnchair/NotificationManager.kt b/lawnchair/src/app/lawnchair/NotificationManager.kt index bfd861386c..8463cb2d1c 100644 --- a/lawnchair/src/app/lawnchair/NotificationManager.kt +++ b/lawnchair/src/app/lawnchair/NotificationManager.kt @@ -6,6 +6,7 @@ import android.service.notification.StatusBarNotification import app.lawnchair.util.checkPackagePermission import com.android.launcher3.notification.NotificationListener import com.android.launcher3.util.MainThreadInitializedObject +import com.android.launcher3.util.SafeCloseable import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.MainScope import kotlinx.coroutines.flow.Flow @@ -13,7 +14,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -class NotificationManager(@Suppress("UNUSED_PARAMETER") context: Context) { +class NotificationManager(@Suppress("UNUSED_PARAMETER") context: Context) : SafeCloseable { private val scope = MainScope() private val notificationsMap = mutableMapOf() @@ -49,6 +50,10 @@ class NotificationManager(@Suppress("UNUSED_PARAMETER") context: Context) { _notifications.value = notificationsMap.values.toList() } + override fun close() { + TODO("Not yet implemented") + } + companion object { @JvmField val INSTANCE = MainThreadInitializedObject(::NotificationManager) } diff --git a/lawnchair/src/app/lawnchair/SearchBarStateHandler.kt b/lawnchair/src/app/lawnchair/SearchBarStateHandler.kt index c15b641795..c06c58a865 100644 --- a/lawnchair/src/app/lawnchair/SearchBarStateHandler.kt +++ b/lawnchair/src/app/lawnchair/SearchBarStateHandler.kt @@ -99,6 +99,6 @@ class SearchBarStateHandler(private val launcher: LawnchairLauncher) : private fun showKeyboard() { val editText = launcher.appsView.searchUiManager.editText ?: return - editText.showKeyboard(true) + editText.showKeyboard() } } diff --git a/lawnchair/src/app/lawnchair/allapps/LawnchairAlphabeticalAppsList.kt b/lawnchair/src/app/lawnchair/allapps/LawnchairAlphabeticalAppsList.kt index 1b880539f7..c517ef3964 100644 --- a/lawnchair/src/app/lawnchair/allapps/LawnchairAlphabeticalAppsList.kt +++ b/lawnchair/src/app/lawnchair/allapps/LawnchairAlphabeticalAppsList.kt @@ -7,6 +7,7 @@ import app.lawnchair.launcher import app.lawnchair.preferences2.PreferenceManager2 import com.android.launcher3.allapps.AllAppsStore import com.android.launcher3.allapps.AlphabeticalAppsList +import com.android.launcher3.allapps.PrivateProfileManager import com.android.launcher3.allapps.WorkProfileManager import com.android.launcher3.model.data.AppInfo import com.android.launcher3.model.data.ItemInfo @@ -18,7 +19,8 @@ class LawnchairAlphabeticalAppsList( context: T, appsStore: AllAppsStore, workProfileManager: WorkProfileManager?, -) : AlphabeticalAppsList(context, appsStore, workProfileManager) + privateProfileManager: PrivateProfileManager +) : AlphabeticalAppsList(context, appsStore, workProfileManager, privateProfileManager) where T : Context, T : ActivityContext { private var hiddenApps: Set = setOf() diff --git a/lawnchair/src/app/lawnchair/font/FontManager.kt b/lawnchair/src/app/lawnchair/font/FontManager.kt index e78cc9f288..2408349daa 100644 --- a/lawnchair/src/app/lawnchair/font/FontManager.kt +++ b/lawnchair/src/app/lawnchair/font/FontManager.kt @@ -13,9 +13,10 @@ import app.lawnchair.util.lookupLifecycleOwner import app.lawnchair.util.runOnMainThread import com.android.launcher3.R import com.android.launcher3.util.MainThreadInitializedObject +import com.android.launcher3.util.SafeCloseable import kotlinx.coroutines.launch -class FontManager private constructor(private val context: Context) { +class FontManager private constructor(private val context: Context) : SafeCloseable { private val fontCache = FontCache.INSTANCE.get(context) @@ -81,6 +82,10 @@ class FontManager private constructor(private val context: Context) { } } + override fun close() { + TODO("Not yet implemented") + } + class FontSpec(val loader: () -> FontCache.Font, val fallback: Typeface) { constructor(pref: BasePreferenceManager.FontPref, fallback: Typeface) : this(pref::get, fallback) diff --git a/lawnchair/src/app/lawnchair/preferences/PreferenceManager.kt b/lawnchair/src/app/lawnchair/preferences/PreferenceManager.kt index 603be3786c..d7f4e1a0cc 100644 --- a/lawnchair/src/app/lawnchair/preferences/PreferenceManager.kt +++ b/lawnchair/src/app/lawnchair/preferences/PreferenceManager.kt @@ -26,8 +26,9 @@ import com.android.launcher3.InvariantDeviceProfile import com.android.launcher3.model.DeviceGridState import com.android.launcher3.util.ComponentKey import com.android.launcher3.util.MainThreadInitializedObject +import com.android.launcher3.util.SafeCloseable -class PreferenceManager private constructor(private val context: Context) : BasePreferenceManager(context) { +class PreferenceManager private constructor(private val context: Context) : BasePreferenceManager(context), SafeCloseable { private val idp get() = InvariantDeviceProfile.INSTANCE.get(context) private val reloadIcons = { idp.onPreferencesChanged(context) } private val reloadGrid: () -> Unit = { idp.onPreferencesChanged(context) } @@ -111,6 +112,10 @@ class PreferenceManager private constructor(private val context: Context) : Base val recentsTranslucentBackground = BoolPref("pref_recentsTranslucentBackground", false, recreate) val recentsTranslucentBackgroundAlpha = FloatPref("pref_recentTranslucentBackgroundAlpha", .8f, recreate) + override fun close() { + TODO("Not yet implemented") + } + init { sp.registerOnSharedPreferenceChangeListener(this) migratePrefs(CURRENT_VERSION) { oldVersion -> diff --git a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt index 2c97b8e932..0eadc972cf 100644 --- a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt +++ b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt @@ -50,6 +50,7 @@ import com.android.launcher3.R import com.android.launcher3.graphics.IconShape as L3IconShape import com.android.launcher3.util.DynamicResource import com.android.launcher3.util.MainThreadInitializedObject +import com.android.launcher3.util.SafeCloseable import com.patrykmichalik.opto.core.PreferenceManager import com.patrykmichalik.opto.core.firstBlocking import com.patrykmichalik.opto.core.setBlocking @@ -60,7 +61,7 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.serialization.encodeToString -class PreferenceManager2 private constructor(private val context: Context) : PreferenceManager { +class PreferenceManager2 private constructor(private val context: Context) : PreferenceManager, SafeCloseable { private val scope = MainScope() private val resourceProvider = DynamicResource.provider(context) @@ -637,6 +638,9 @@ class PreferenceManager2 private constructor(private val context: Context) : Pre CustomAdaptiveIconDrawable.sMask = shape.getMaskPath() } + override fun close() { + } + companion object { private val Context.preferencesDataStore by preferencesDataStore( name = "preferences", diff --git a/lawnchair/src/app/lawnchair/theme/ThemeProvider.kt b/lawnchair/src/app/lawnchair/theme/ThemeProvider.kt index cf00e3a9c2..c6f539fd2d 100644 --- a/lawnchair/src/app/lawnchair/theme/ThemeProvider.kt +++ b/lawnchair/src/app/lawnchair/theme/ThemeProvider.kt @@ -18,6 +18,7 @@ import app.lawnchair.ui.theme.getSystemAccent import app.lawnchair.wallpaper.WallpaperManagerCompat import com.android.launcher3.Utilities import com.android.launcher3.util.MainThreadInitializedObject +import com.android.launcher3.util.SafeCloseable import com.android.systemui.monet.Style import com.patrykmichalik.opto.core.firstBlocking import com.patrykmichalik.opto.core.onEach @@ -28,7 +29,7 @@ import dev.kdrag0n.monet.theme.ColorScheme import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -class ThemeProvider(private val context: Context) { +class ThemeProvider(private val context: Context) : SafeCloseable { private val preferenceManager2 = PreferenceManager2.getInstance(context) private val wallpaperManager = WallpaperManagerCompat.INSTANCE.get(context) private val coroutineScope = CoroutineScope(Dispatchers.Default) @@ -121,6 +122,10 @@ class ThemeProvider(private val context: Context) { .forEach(ColorSchemeChangeListener::onColorSchemeChanged) } + override fun close() { + TODO("Not yet implemented") + } + companion object { @JvmField val INSTANCE = MainThreadInitializedObject(::ThemeProvider) diff --git a/lawnchair/src/app/lawnchair/wallpaper/WallpaperManagerCompat.kt b/lawnchair/src/app/lawnchair/wallpaper/WallpaperManagerCompat.kt index 56403240c7..0f75358a94 100644 --- a/lawnchair/src/app/lawnchair/wallpaper/WallpaperManagerCompat.kt +++ b/lawnchair/src/app/lawnchair/wallpaper/WallpaperManagerCompat.kt @@ -6,8 +6,9 @@ import app.lawnchair.util.requireSystemService import app.lawnchair.wallpaper.WallpaperColorsCompat.Companion.HINT_SUPPORTS_DARK_THEME import com.android.launcher3.Utilities import com.android.launcher3.util.MainThreadInitializedObject +import com.android.launcher3.util.SafeCloseable -sealed class WallpaperManagerCompat(val context: Context) { +sealed class WallpaperManagerCompat(val context: Context) : SafeCloseable { private val listeners = mutableListOf() private val colorHints: Int get() = wallpaperColors?.colorHints ?: 0 diff --git a/platform_frameworks_libs_systemui b/platform_frameworks_libs_systemui index a389d87583..2a60fa6381 160000 --- a/platform_frameworks_libs_systemui +++ b/platform_frameworks_libs_systemui @@ -1 +1 @@ -Subproject commit a389d8758325ad7ab87a7121446de9e8a820042c +Subproject commit 2a60fa638116b3aab60f914236f8d3301ed6df67 diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index 25b97a4441..dcb1ae9083 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -16,18 +16,18 @@ package com.android.launcher3; -import static com.android.launcher3.LauncherPrefs.GRID_NAME; import static com.android.launcher3.Utilities.dpiFromPx; import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE; import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY; -import static com.android.launcher3.util.DisplayController.CHANGE_DESKTOP_MODE; import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE; import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS; -import static com.android.launcher3.util.DisplayController.CHANGE_TASKBAR_PINNING; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import android.annotation.TargetApi; +import android.appwidget.AppWidgetHostView; +import android.content.ComponentName; import android.content.Context; +import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; @@ -63,7 +63,6 @@ import com.android.launcher3.util.Partner; import com.android.launcher3.util.SafeCloseable; import com.android.launcher3.util.WindowBounds; import com.android.launcher3.util.window.WindowManagerProxy; - import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -74,9 +73,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.stream.Collectors; +import app.lawnchair.DeviceProfileOverrides; + public class InvariantDeviceProfile implements SafeCloseable { public static final String TAG = "IDP"; @@ -84,6 +84,11 @@ public class InvariantDeviceProfile implements SafeCloseable { public static final MainThreadInitializedObject INSTANCE = new MainThreadInitializedObject<>(InvariantDeviceProfile::new); + @Override + public void close() { + + } + @Retention(RetentionPolicy.SOURCE) @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET}) public @interface DeviceType {} @@ -105,15 +110,17 @@ public class InvariantDeviceProfile implements SafeCloseable { // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different // constraints static final int COUNT_SIZES = 4; - static final int INDEX_DEFAULT = 0; - static final int INDEX_LANDSCAPE = 1; - static final int INDEX_TWO_PANEL_PORTRAIT = 2; - static final int INDEX_TWO_PANEL_LANDSCAPE = 3; + public static final int INDEX_DEFAULT = 0; + public static final int INDEX_LANDSCAPE = 1; + public static final int INDEX_TWO_PANEL_PORTRAIT = 2; + public static final int INDEX_TWO_PANEL_LANDSCAPE = 3; - /** These resources are used to override the device profile */ - private static final String RES_GRID_NUM_ROWS = "grid_num_rows"; - private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns"; - private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp"; + /** These resources are used to override the device profile */ + public static final String RES_GRID_NUM_ROWS = "grid_num_rows"; + public static final String RES_GRID_NUM_COLUMNS = "grid_num_columns"; + public static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp"; + + private static final String KEY_IDP_GRID_NAME = "idp_grid_name"; /** * Number of icons per row and column in the workspace. @@ -122,16 +129,21 @@ public class InvariantDeviceProfile implements SafeCloseable { public int numColumns; public int numSearchContainerColumns; + /** + * Original profile before preference overrides + */ + public GridOption closestProfile; + /** * Number of icons per row and column in the folder. */ - public int[] numFolderRows; - public int[] numFolderColumns; + public int numFolderRows; + public int numFolderColumns; public float[] iconSize; public float[] iconTextSize; public int iconBitmapSize; public int fillResIconDpi; - public @DeviceType int deviceType; + public static @DeviceType int deviceType; public PointF[] minCellSize; @@ -165,6 +177,7 @@ public class InvariantDeviceProfile implements SafeCloseable { */ public int numDatabaseHotseatIcons; + public int[] hotseatColumnSpan; public float[] hotseatBarBottomSpace; public float[] hotseatQsbSpace; @@ -172,7 +185,6 @@ public class InvariantDeviceProfile implements SafeCloseable { * Number of columns in the all apps list. */ public int numAllAppsColumns; - public int numAllAppsRowsForCellHeightCalculation; public int numDatabaseAllAppsColumns; public @StyleRes int allAppsStyle; @@ -182,10 +194,16 @@ public class InvariantDeviceProfile implements SafeCloseable { protected boolean isScalable; @XmlRes public int devicePaddingId = INVALID_RESOURCE_HANDLE; + + public String dbFile; + public int defaultLayoutId; + @XmlRes public int workspaceSpecsId = INVALID_RESOURCE_HANDLE; + @XmlRes public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; + @XmlRes public int allAppsSpecsId = INVALID_RESOURCE_HANDLE; @XmlRes @@ -198,6 +216,7 @@ public class InvariantDeviceProfile implements SafeCloseable { public int hotseatSpecsId = INVALID_RESOURCE_HANDLE; @XmlRes public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; + @XmlRes public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE; @XmlRes @@ -206,9 +225,6 @@ public class InvariantDeviceProfile implements SafeCloseable { public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE; @XmlRes public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; - - public String dbFile; - public int defaultLayoutId; public int demoModeLayoutId; public boolean[] inlineQsb = new boolean[COUNT_SIZES]; @@ -218,6 +234,7 @@ public class InvariantDeviceProfile implements SafeCloseable { public List supportedProfiles = Collections.EMPTY_LIST; public Point defaultWallpaperSize; + public Rect defaultWidgetPadding; private final ArrayList mChangeListeners = new ArrayList<>(); @@ -229,16 +246,16 @@ public class InvariantDeviceProfile implements SafeCloseable { String gridName = getCurrentGridName(context); String newGridName = initGrid(context, gridName); if (!newGridName.equals(gridName)) { - LauncherPrefs.get(context).put(GRID_NAME, newGridName); + Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply(); } - LockedUserState.get(context).runOnUserUnlocked(() -> - new DeviceGridState(this).writeToPrefs(context)); + LockedUserState.get(context).runOnUserUnlocked(() -> { + new DeviceGridState(this).writeToPrefs(context); + }); DisplayController.INSTANCE.get(context).setPriorityListener( (displayContext, info, flags) -> { if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS - | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING - | CHANGE_DESKTOP_MODE)) != 0) { + | CHANGE_NAVIGATION_MODE)) != 0) { onConfigChanged(displayContext); } }); @@ -248,10 +265,12 @@ public class InvariantDeviceProfile implements SafeCloseable { * This constructor should NOT have any monitors by design. */ public InvariantDeviceProfile(Context context, String gridName) { - String newName = initGrid(context, gridName); - if (newName == null || !newName.equals(gridName)) { - throw new IllegalArgumentException("Unknown grid name: " + gridName); - } + this(context, DeviceProfileOverrides.INSTANCE.get(context).getGridInfo(gridName)); + } + + public InvariantDeviceProfile(Context context, DeviceProfileOverrides.DBGridInfo dbGridInfo) { + String gridName = DeviceProfileOverrides.INSTANCE.get(context).getGridName(dbGridInfo); + initGrid(context, gridName, dbGridInfo); } /** @@ -264,7 +283,7 @@ public class InvariantDeviceProfile implements SafeCloseable { // Get the display info based on default display and interpolate it to existing display Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo(); - @DeviceType int defaultDeviceType = defaultInfo.getDeviceType(); + @DeviceType int defaultDeviceType = getDeviceType(defaultInfo); DisplayOption defaultDisplayOption = invDistWeightedInterpolate( defaultInfo, getPredefinedDeviceProfiles(context, gridName, defaultDeviceType, @@ -273,7 +292,7 @@ public class InvariantDeviceProfile implements SafeCloseable { Context displayContext = context.createDisplayContext(display); Info myInfo = new Info(displayContext); - @DeviceType int deviceType = myInfo.getDeviceType(); + @DeviceType int deviceType = getDeviceType(myInfo); DisplayOption myDisplayOption = invDistWeightedInterpolate( myInfo, getPredefinedDeviceProfiles(context, gridName, deviceType, @@ -297,11 +316,6 @@ public class InvariantDeviceProfile implements SafeCloseable { initGrid(context, myInfo, result, deviceType); } - @Override - public void close() { - DisplayController.INSTANCE.executeIfCreated(dc -> dc.setPriorityListener(null)); - } - /** * Reinitialize the current grid after a restore, where some grids might now be disabled. */ @@ -310,13 +324,8 @@ public class InvariantDeviceProfile implements SafeCloseable { 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 + Log.d(TAG, "Restored grid is disabled : " + currentGridName + ", migrating to: " + newGridName + ", removing all other grid db files"); for (String gridDbFile : LauncherFiles.GRID_DB_FILES) { @@ -324,37 +333,58 @@ public class InvariantDeviceProfile implements SafeCloseable { continue; } if (context.getDatabasePath(gridDbFile).delete()) { - FileLog.d(TAG, "Removed old grid db file: " + gridDbFile); + Log.d(TAG, "Removed old grid db file: " + gridDbFile); } } setCurrentGrid(context, newGridName); } } - public static String getCurrentGridName(Context context) { - return LauncherPrefs.get(context).get(GRID_NAME); + public static @DeviceType int getDeviceType(Info displayInfo) { + int flagPhone = 1 << 0; + int flagTablet = 1 << 1; + + int type = displayInfo.supportedBounds.stream() + .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone) + .reduce(0, (a, b) -> a | b); + if ((type == (flagPhone | flagTablet))) { + // device has profiles supporting both phone and table modes + return TYPE_MULTI_DISPLAY; + } else if (type == flagTablet) { + return TYPE_TABLET; + } else { + return TYPE_PHONE; + } } - private String initGrid(Context context, String gridName) { + public static String getCurrentGridName(Context context) { + return DeviceProfileOverrides.INSTANCE.get(context).getCurrentGridName(); + } + + private String initGrid(Context context, String gridName, DeviceProfileOverrides.DBGridInfo dbGridInfo) { Info displayInfo = DisplayController.INSTANCE.get(context).getInfo(); - @DeviceType int deviceType = displayInfo.getDeviceType(); + @DeviceType int deviceType = getDeviceType(displayInfo); ArrayList allOptions = getPredefinedDeviceProfiles(context, gridName, deviceType, RestoreDbTask.isPending(context)); DisplayOption displayOption = invDistWeightedInterpolate(displayInfo, allOptions, deviceType); - initGrid(context, displayInfo, displayOption, deviceType); + initGrid(context, displayInfo, displayOption, deviceType, dbGridInfo); return displayOption.grid.name; } - /** - * @deprecated This is a temporary solution because on the backup and restore case we modify the - * IDP, this resets it. b/332974074 - */ - @Deprecated - public void reset(Context context) { - initGrid(context, getCurrentGridName(context)); + private void initGrid(Context context, Info displayInfo, DisplayOption displayOption, + @DeviceType int deviceType) { + DeviceProfileOverrides.DBGridInfo dbGridInfo = DeviceProfileOverrides.INSTANCE.get(context) + .getGridInfo(); + initGrid(context, displayInfo, displayOption, deviceType, dbGridInfo); + } + + private String initGrid(Context context, String gridName) { + DeviceProfileOverrides.DBGridInfo dbGridInfo = DeviceProfileOverrides.INSTANCE.get(context) + .getGridInfo(); + return initGrid(context, gridName, dbGridInfo); } @VisibleForTesting @@ -363,13 +393,15 @@ public class InvariantDeviceProfile implements SafeCloseable { } private void initGrid(Context context, Info displayInfo, DisplayOption displayOption, - @DeviceType int deviceType) { + @DeviceType int deviceType, DeviceProfileOverrides.DBGridInfo dbGridInfo) { + DeviceProfileOverrides.Options overrideOptions = DeviceProfileOverrides.INSTANCE.get(context) + .getOverrides(displayOption.grid); DisplayMetrics metrics = context.getResources().getDisplayMetrics(); - GridOption closestProfile = displayOption.grid; - numRows = closestProfile.numRows; - numColumns = closestProfile.numColumns; + closestProfile = displayOption.grid; + numRows = dbGridInfo.getNumRows(); + numColumns = dbGridInfo.getNumColumns(); numSearchContainerColumns = closestProfile.numSearchContainerColumns; - dbFile = closestProfile.dbFile; + dbFile = dbGridInfo.getDbFile(); defaultLayoutId = closestProfile.defaultLayoutId; demoModeLayoutId = closestProfile.demoModeLayoutId; @@ -393,8 +425,7 @@ public class InvariantDeviceProfile implements SafeCloseable { workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId; allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId; allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId; - numAllAppsRowsForCellHeightCalculation = - closestProfile.mNumAllAppsRowsForCellHeightCalculation; + this.deviceType = deviceType; inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing; @@ -415,16 +446,17 @@ public class InvariantDeviceProfile implements SafeCloseable { horizontalMargin = displayOption.horizontalMargin; - numShownHotseatIcons = closestProfile.numHotseatIcons; + numShownHotseatIcons = deviceType == TYPE_MULTI_DISPLAY + ? closestProfile.numHotseatIcons : dbGridInfo.getNumHotseatColumns(); numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY - ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons; + ? closestProfile.numDatabaseHotseatIcons : numShownHotseatIcons; + hotseatColumnSpan = closestProfile.hotseatColumnSpan; hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace; hotseatQsbSpace = displayOption.hotseatQsbSpace; allAppsStyle = closestProfile.allAppsStyle; numAllAppsColumns = closestProfile.numAllAppsColumns; - numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns; @@ -443,6 +475,9 @@ public class InvariantDeviceProfile implements SafeCloseable { // Supported overrides: numRows, numColumns, iconSize applyPartnerDeviceProfileOverrides(context, metrics); + // Lawnchair ignores partner overrides and allows the user to customize the grid themselves + overrideOptions.applyUi(this); + final List localSupportedProfiles = new ArrayList<>(); defaultWallpaperSize = new Point(displayInfo.currentSize); SparseArray dotRendererCache = new SparseArray<>(); @@ -494,10 +529,15 @@ public class InvariantDeviceProfile implements SafeCloseable { mChangeListeners.remove(listener); } + public void onPreferencesChanged(Context context) { + Context appContext = context.getApplicationContext(); + MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext)); + } public void setCurrentGrid(Context context, String gridName) { - LauncherPrefs.get(context).put(GRID_NAME, gridName); - MAIN_EXECUTOR.execute(() -> onConfigChanged(context.getApplicationContext())); + DeviceProfileOverrides.INSTANCE.get(context).setCurrentGrid(gridName); + Context appContext = context.getApplicationContext(); + MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext)); } private Object[] toModelState() { @@ -506,9 +546,7 @@ public class InvariantDeviceProfile implements SafeCloseable { iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile}; } - /** Updates IDP using the provided context. Notifies listeners of change. */ - @VisibleForTesting - public void onConfigChanged(Context context) { + private void onConfigChanged(Context context) { Object[] oldState = toModelState(); // Re-init grid @@ -575,49 +613,10 @@ public class InvariantDeviceProfile implements SafeCloseable { return filteredProfiles; } - /** - * 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" - */ - public GridOption getGridOptionFromFileName(Context context, String fileName) { - return parseAllGridOptions(context).stream() - .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName)) - .findFirst() - .orElse(null); - } - - /** - * Returns the name of the given size on the current device or empty string if the size is not - * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc. - * (Note: the name of the grid can be different for the same grid size depending of - * the values of the InvariantDeviceProfile) - * - */ - public String getGridNameFromSize(Context context, Point size) { - return parseAllGridOptions(context).stream() - .filter(gridOption -> gridOption.numColumns == size.x - && gridOption.numRows == size.y) - .map(gridOption -> gridOption.name) - .findFirst() - .orElse(""); - } - - /** - * Returns the grid option for the given gridName on the current device (Note: the gridOption - * be different for the same gridName depending on the values of the InvariantDeviceProfile). - */ - public GridOption getGridOptionFromName(Context context, String gridName) { - return parseAllGridOptions(context).stream() - .filter(gridOption -> Objects.equals(gridOption.name, gridName)) - .findFirst() - .orElse(null); - } - /** * @return all the grid options that can be shown on the device */ - public List parseAllGridOptions(Context context) { + public static List parseAllGridOptions(Context context) { return parseAllDefinedGridOptions(context) .stream() .filter(go -> go.isEnabled(deviceType)) @@ -759,11 +758,14 @@ public class InvariantDeviceProfile implements SafeCloseable { } public DeviceProfile getDeviceProfile(Context context) { - WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context); - Rect bounds = windowManagerProxy.getCurrentBounds(context); - int rotation = windowManagerProxy.getRotation(context); + Resources res = context.getResources(); + Configuration config = context.getResources().getConfiguration(); - return getBestMatch(bounds.width(), bounds.height(), rotation); + float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density; + float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density; + int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context); + + return getBestMatch(screenWidth, screenHeight, rotation); } /** @@ -855,29 +857,28 @@ public class InvariantDeviceProfile implements SafeCloseable { public final int numSearchContainerColumns; public final int deviceCategory; - private final int[] numFolderRows = new int[COUNT_SIZES]; - private final int[] numFolderColumns = new int[COUNT_SIZES]; + public final int numFolderRows; + public final int numFolderColumns; private final @StyleRes int folderStyle; private final @StyleRes int cellStyle; private final @StyleRes int allAppsStyle; - private final int numAllAppsColumns; - private final int mNumAllAppsRowsForCellHeightCalculation; - private final int numDatabaseAllAppsColumns; - private final int numHotseatIcons; - private final int numDatabaseHotseatIcons; + public final int numAllAppsColumns; + public final int numDatabaseAllAppsColumns; + public final int numHotseatIcons; + public final int numDatabaseHotseatIcons; + + private final int[] hotseatColumnSpan = new int[COUNT_SIZES]; private final boolean[] inlineQsb = new boolean[COUNT_SIZES]; private @DimenRes int inlineNavButtonsEndSpacing; - private final String dbFile; + public final String dbFile; private final int defaultLayoutId; private final int demoModeLayoutId; - - private final boolean isScalable; - private final int devicePaddingId; private final int mWorkspaceSpecsId; + private final int mWorkspaceSpecsTwoPanelId; private final int mAllAppsSpecsId; private final int mAllAppsSpecsTwoPanelId; @@ -890,12 +891,15 @@ public class InvariantDeviceProfile implements SafeCloseable { private final int mAllAppsCellSpecsId; private final int mAllAppsCellSpecsTwoPanelId; + private final boolean isScalable; + private final int devicePaddingId; + 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); - numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0); + numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 4); numSearchContainerColumns = a.getInt( R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns); @@ -910,50 +914,33 @@ public class InvariantDeviceProfile implements SafeCloseable { numAllAppsColumns = a.getInt( R.styleable.GridDisplayOption_numAllAppsColumns, numColumns); numDatabaseAllAppsColumns = a.getInt( - R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns); + R.styleable.GridDisplayOption_numExtendedAllAppsColumns, numAllAppsColumns); numHotseatIcons = a.getInt( R.styleable.GridDisplayOption_numHotseatIcons, numColumns); numDatabaseHotseatIcons = a.getInt( R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons); + hotseatColumnSpan[INDEX_DEFAULT] = a.getInt( + R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns); + hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt( + R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns); + hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt( + R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape, + numColumns); + hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt( + R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait, + numColumns); + inlineNavButtonsEndSpacing = a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing, R.dimen.taskbar_button_margin_default); - numFolderRows[INDEX_DEFAULT] = a.getInt( + numFolderRows = a.getInt( R.styleable.GridDisplayOption_numFolderRows, numRows); - numFolderColumns[INDEX_DEFAULT] = a.getInt( + numFolderColumns = a.getInt( R.styleable.GridDisplayOption_numFolderColumns, numColumns); - if (FeatureFlags.enableResponsiveWorkspace()) { - numFolderRows[INDEX_LANDSCAPE] = a.getInt( - R.styleable.GridDisplayOption_numFolderRowsLandscape, - numFolderRows[INDEX_DEFAULT]); - numFolderColumns[INDEX_LANDSCAPE] = a.getInt( - R.styleable.GridDisplayOption_numFolderColumnsLandscape, - numFolderColumns[INDEX_DEFAULT]); - numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt( - R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait, - numFolderRows[INDEX_DEFAULT]); - numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt( - R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait, - numFolderColumns[INDEX_DEFAULT]); - numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt( - R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape, - numFolderRows[INDEX_DEFAULT]); - numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt( - R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape, - numFolderColumns[INDEX_DEFAULT]); - } else { - numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT]; - numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT]; - numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT]; - numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT]; - numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT]; - numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT]; - } - folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle, INVALID_RESOURCE_HANDLE); @@ -967,42 +954,39 @@ public class InvariantDeviceProfile implements SafeCloseable { deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory, DEVICE_CATEGORY_ALL); - if (FeatureFlags.enableResponsiveWorkspace()) { + if (FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE.get()) { mWorkspaceSpecsId = a.getResourceId( R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE); mWorkspaceSpecsTwoPanelId = a.getResourceId( R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId, - mWorkspaceSpecsId); + INVALID_RESOURCE_HANDLE); mAllAppsSpecsId = a.getResourceId( R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE); mAllAppsSpecsTwoPanelId = a.getResourceId( R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId, - mAllAppsSpecsId); + INVALID_RESOURCE_HANDLE); mFolderSpecsId = a.getResourceId( R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE); mFolderSpecsTwoPanelId = a.getResourceId( R.styleable.GridDisplayOption_folderSpecsTwoPanelId, - mFolderSpecsId); + INVALID_RESOURCE_HANDLE); mHotseatSpecsId = a.getResourceId( R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE); mHotseatSpecsTwoPanelId = a.getResourceId( R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId, - mHotseatSpecsId); + INVALID_RESOURCE_HANDLE); mWorkspaceCellSpecsId = a.getResourceId( R.styleable.GridDisplayOption_workspaceCellSpecsId, INVALID_RESOURCE_HANDLE); mWorkspaceCellSpecsTwoPanelId = a.getResourceId( R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId, - mWorkspaceCellSpecsId); + INVALID_RESOURCE_HANDLE); mAllAppsCellSpecsId = a.getResourceId( R.styleable.GridDisplayOption_allAppsCellSpecsId, INVALID_RESOURCE_HANDLE); mAllAppsCellSpecsTwoPanelId = a.getResourceId( R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId, - mAllAppsCellSpecsId); - mNumAllAppsRowsForCellHeightCalculation = a.getInt( - R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation, - numRows); + INVALID_RESOURCE_HANDLE); } else { mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE; mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; @@ -1016,7 +1000,6 @@ public class InvariantDeviceProfile implements SafeCloseable { mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE; mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; - mNumAllAppsRowsForCellHeightCalculation = numRows; } int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb, @@ -1031,7 +1014,6 @@ public class InvariantDeviceProfile implements SafeCloseable { inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] = (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE) == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE; - a.recycle(); } diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java index 513c39b6e0..e0a4283456 100644 --- a/src/com/android/launcher3/LauncherAppState.java +++ b/src/com/android/launcher3/LauncherAppState.java @@ -96,6 +96,10 @@ public class LauncherAppState implements SafeCloseable { return INSTANCE.get(context); } + public static LauncherAppState getInstanceNoCreate() { + return INSTANCE.getNoCreate(); + } + public Context getContext() { return mContext; } @@ -212,6 +216,10 @@ public class LauncherAppState implements SafeCloseable { mModel.forceReload(); } + public void reloadIcons() { + refreshAndReloadLauncher(); + } + private void refreshAndReloadLauncher() { LauncherIcons.clearPool(mContext); mIconCache.updateIconParams( diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index a0cd6de6f7..9d6bb5f64b 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -136,6 +136,10 @@ public final class Utilities { public static final boolean ATLEAST_O_MR1 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1; + public static final boolean ATLEAST_P = Build.VERSION.SDK_INT >= VERSION_CODES.P; + + public static final boolean ATLEAST_Q = Build.VERSION.SDK_INT >= VERSION_CODES.Q; + @ChecksSdkIntAtLeast(api = VERSION_CODES.R) public static final boolean ATLEAST_R = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R; diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java index 6807429db2..a570f5420c 100644 --- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java @@ -286,11 +286,11 @@ public class ActivityAllAppsContainerView mMainAdapterProvider = mSearchUiDelegate.createMainAdapterProvider(); mAH.set(AdapterHolder.MAIN, new AdapterHolder(AdapterHolder.MAIN, - new LawnchairAlphabeticalAppsList<>(mActivityContext, mAllAppsStore, null))); + new LawnchairAlphabeticalAppsList<>(mActivityContext, mAllAppsStore, null, mPrivateProfileManager))); mAH.set(AdapterHolder.WORK, new AdapterHolder(AdapterHolder.WORK, - new LawnchairAlphabeticalAppsList<>(mActivityContext, mAllAppsStore, mWorkManager))); + new LawnchairAlphabeticalAppsList<>(mActivityContext, mAllAppsStore, mWorkManager, mPrivateProfileManager))); mAH.set(SEARCH, new AdapterHolder(SEARCH, - new LawnchairAlphabeticalAppsList<>(mActivityContext, mAllAppsStore, null))); + new LawnchairAlphabeticalAppsList<>(mActivityContext, mAllAppsStore, null, mPrivateProfileManager))); getLayoutInflater().inflate(R.layout.all_apps_content, this); mHeader = findViewById(R.id.all_apps_header); diff --git a/src/com/android/launcher3/icons/LauncherIcons.java b/src/com/android/launcher3/icons/LauncherIcons.java index ddba3398f4..542f9100da 100644 --- a/src/com/android/launcher3/icons/LauncherIcons.java +++ b/src/com/android/launcher3/icons/LauncherIcons.java @@ -44,10 +44,6 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable { private static final MainThreadInitializedObject POOL = new MainThreadInitializedObject<>(Pool::new); - public static LauncherIcons obtain(Context context) { - return obtain(context, IconShape.getShape().enableShapeDetection()); - } - /** * Return a new Message instance from the global pool. Allows us to * avoid allocating new objects in many cases. @@ -64,6 +60,8 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable { private MonochromeIconFactory mMonochromeIconFactory; + public boolean mMonoIconEnabled = false; + protected LauncherIcons(Context context, int fillResIconDpi, int iconBitmapSize, ConcurrentLinkedQueue pool) { super(context, fillResIconDpi, iconBitmapSize, diff --git a/src/com/android/launcher3/notification/NotificationListener.java b/src/com/android/launcher3/notification/NotificationListener.java index a6c2c8a262..d96745eb21 100644 --- a/src/com/android/launcher3/notification/NotificationListener.java +++ b/src/com/android/launcher3/notification/NotificationListener.java @@ -92,7 +92,7 @@ public class NotificationListener extends NotificationListenerService { sNotificationListenerInstance = this; } - private static @Nullable NotificationListener getInstanceIfConnected() { + public static @Nullable NotificationListener getInstanceIfConnected() { return sIsConnected ? sNotificationListenerInstance : null; } diff --git a/src/com/android/launcher3/util/MainThreadInitializedObject.java b/src/com/android/launcher3/util/MainThreadInitializedObject.java index 187a972c91..84dcb739df 100644 --- a/src/com/android/launcher3/util/MainThreadInitializedObject.java +++ b/src/com/android/launcher3/util/MainThreadInitializedObject.java @@ -87,6 +87,13 @@ public class MainThreadInitializedObject { mValue = value; } + protected void onPostInit(Context context) { + } + + public T getNoCreate() { + return mValue; + } + /** * Initializes a provider based on resource overrides */ diff --git a/systemUIShared/src/com/android/systemui/shared/animation/DisableSubpixelTextTransitionListener.kt b/systemUIShared/src/com/android/systemui/shared/animation/DisableSubpixelTextTransitionListener.kt deleted file mode 100644 index 637ce5f68d..0000000000 --- a/systemUIShared/src/com/android/systemui/shared/animation/DisableSubpixelTextTransitionListener.kt +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2023 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.systemui.shared.animation - -import android.graphics.Paint -import android.view.ViewGroup -import android.widget.TextView -import androidx.core.view.forEach -import com.android.app.tracing.traceSection -import com.android.systemui.unfold.UnfoldTransitionProgressProvider.TransitionProgressListener -import java.lang.ref.WeakReference - -/** - * A listener which disables subpixel flag for all TextView children of a given parent ViewGroup - * during fold/unfold transitions. - */ -class DisableSubpixelTextTransitionListener(private val rootView: ViewGroup?) : - TransitionProgressListener { - private val childrenTextViews: MutableList> = mutableListOf() - private var isTransitionInProgress: Boolean = false - - override fun onTransitionStarted() { - isTransitionInProgress = true - traceSection("subpixelFlagSetForTextView") { - traceSection("subpixelFlagTraverseHierarchy") { - getAllChildTextView(rootView, childrenTextViews) - } - traceSection("subpixelFlagDisableForTextView") { - childrenTextViews.forEach { child -> - val childTextView = child.get() ?: return@forEach - childTextView.paintFlags = childTextView.paintFlags or Paint.SUBPIXEL_TEXT_FLAG - } - } - } - } - - override fun onTransitionFinished() { - if (!isTransitionInProgress) return - isTransitionInProgress = false - traceSection("subpixelFlagEnableForTextView") { - childrenTextViews.forEach { child -> - val childTextView = child.get() ?: return@forEach - childTextView.paintFlags = - childTextView.paintFlags and Paint.SUBPIXEL_TEXT_FLAG.inv() - } - childrenTextViews.clear() - } - } - - /** - * Populates a list of all TextView children of a given parent ViewGroup - * - * @param parent the root ViewGroup for which to retrieve TextView children - * @param childrenTextViews the list to store the retrieved TextView children - */ - private fun getAllChildTextView( - parent: ViewGroup?, - childrenTextViews: MutableList> - ) { - parent?.forEach { child -> - when (child) { - is ViewGroup -> getAllChildTextView(child, childrenTextViews) - is TextView -> { - if ((child.paintFlags and Paint.SUBPIXEL_TEXT_FLAG) <= 0) { - childrenTextViews.add(WeakReference(child)) - } - } - } - } - } -} diff --git a/systemUIShared/src/com/android/systemui/shared/system/QuickStepContract.java b/systemUIShared/src/com/android/systemui/shared/system/QuickStepContract.java index c0c8b75510..08e26b4c0f 100644 --- a/systemUIShared/src/com/android/systemui/shared/system/QuickStepContract.java +++ b/systemUIShared/src/com/android/systemui/shared/system/QuickStepContract.java @@ -34,6 +34,8 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.StringJoiner; +import app.lawnchair.compat.LawnchairQuickstepCompat; + /** * Various shared constants between Launcher and SysUI as part of quickstep */ @@ -381,8 +383,27 @@ public class QuickStepContract { * These values are expressed in pixels because they should not respect display or font * scaling. The corner radius may change when folding/unfolding the device. */ + public static boolean sRecentsDisabled = false; + public static boolean sHasCustomCornerRadius = false; + public static float sCustomCornerRadius = 0f; + + /** + * Corner radius that should be used on windows in order to cover the display. + * These values are expressed in pixels because they should not respect display or font + * scaling, this means that we don't have to reload them on config changes. + */ public static float getWindowCornerRadius(Context context) { - return ScreenDecorationsUtils.getWindowCornerRadius(context); + if (sRecentsDisabled || !LawnchairQuickstepCompat.ATLEAST_S) { + return 0; + } + if (sHasCustomCornerRadius) { + return sCustomCornerRadius; + } + try { + return ScreenDecorationsUtils.getWindowCornerRadius(context); + } catch (Throwable t) { + return 0; + } } /** diff --git a/systemUnFold/build.gradle b/systemUnFold/build.gradle index 5ab933ae02..2a4a5a3aa8 100644 --- a/systemUnFold/build.gradle +++ b/systemUnFold/build.gradle @@ -1,6 +1,7 @@ plugins { id 'com.android.library' id 'org.jetbrains.kotlin.android' + id 'com.google.devtools.ksp' } android { @@ -14,6 +15,9 @@ android { aidl.srcDirs = ['src'] } } + ksp { + arg("dagger.hilt.disableModulesHaveInstallInCheck", "true") + } } addFrameworkJar('framework-15.jar') @@ -21,7 +25,7 @@ compileOnlyCommonJars() dependencies { implementation "com.google.dagger:hilt-android:$daggerVersion" - annotationProcessor "com.google.dagger:hilt-compiler:$daggerVersion" + ksp "com.google.dagger:hilt-compiler:$daggerVersion" implementation "androidx.concurrent:concurrent-futures:1.2.0" implementation "androidx.lifecycle:lifecycle-common:2.8.6"