diff --git a/lawnchair/res/values/strings.xml b/lawnchair/res/values/strings.xml
index d8d043e186..69d916f609 100644
--- a/lawnchair/res/values/strings.xml
+++ b/lawnchair/res/values/strings.xml
@@ -264,6 +264,7 @@
Show suggestion features
App suggestions
Suggestions provider
+ This feature requires Android 10 or higher
System
Lawnchair
Off
diff --git a/lawnchair/src/app/lawnchair/predictions/LawnchairAppPredictor.kt b/lawnchair/src/app/lawnchair/predictions/LawnchairAppPredictor.kt
index f89756361d..0e711eca86 100644
--- a/lawnchair/src/app/lawnchair/predictions/LawnchairAppPredictor.kt
+++ b/lawnchair/src/app/lawnchair/predictions/LawnchairAppPredictor.kt
@@ -2,6 +2,8 @@ package app.lawnchair.predictions
import android.content.Context
import android.content.pm.PackageManager
+import android.os.Build
+import androidx.annotation.RequiresApi
import androidx.annotation.WorkerThread
import com.android.launcher3.InvariantDeviceProfile
import com.android.launcher3.LauncherModel
@@ -92,11 +94,13 @@ class LawnchairAppPredictor(private val context: Context) : StatsLogCompatManage
}
@WorkerThread
+ @RequiresApi(Build.VERSION_CODES.Q)
override fun consume(event: EventEnum?, atomInfo: ItemInfo?) {
MODEL_EXECUTOR.execute { handleEvent(event, atomInfo) }
}
@WorkerThread
+ @RequiresApi(Build.VERSION_CODES.Q)
private fun handleEvent(event: EventEnum?, atomInfo: ItemInfo?) {
val resolvedEvent = eventResolver.resolve(atomInfo)
@@ -122,6 +126,7 @@ class LawnchairAppPredictor(private val context: Context) : StatsLogCompatManage
}
@WorkerThread
+ @RequiresApi(Build.VERSION_CODES.Q)
fun updates(
model: LauncherModel,
dataModel: BgDataModel,
diff --git a/lawnchair/src/app/lawnchair/predictions/LawnchairModelDelegate.kt b/lawnchair/src/app/lawnchair/predictions/LawnchairModelDelegate.kt
index ae9b0b7585..94740beb19 100644
--- a/lawnchair/src/app/lawnchair/predictions/LawnchairModelDelegate.kt
+++ b/lawnchair/src/app/lawnchair/predictions/LawnchairModelDelegate.kt
@@ -1,10 +1,13 @@
package app.lawnchair.predictions
import android.content.Context
+import android.os.Build
+import androidx.annotation.RequiresApi
import androidx.annotation.WorkerThread
import app.lawnchair.preferences2.PreferenceManager2
import app.lawnchair.preferences2.firstCached
import com.android.launcher3.InvariantDeviceProfile
+import com.android.launcher3.Utilities
import com.android.launcher3.dagger.ApplicationContext
import com.android.launcher3.model.PredictedItemFactory
import com.android.launcher3.model.QuickstepModelDelegate
@@ -63,7 +66,13 @@ class LawnchairModelDelegate @Inject constructor(
lawnchairPredictor.unregister()
when (currentPredictionMode()) {
SystemPredictor -> super.recreatePredictors()
- LawnchairPredictor -> activateLawnchairPredictor()
+
+ LawnchairPredictor -> if (Utilities.ATLEAST_Q) {
+ activateLawnchairPredictor()
+ } else {
+ clearPredictions()
+ }
+
NoPredictor -> clearPredictions()
}
}
@@ -82,14 +91,19 @@ class LawnchairModelDelegate @Inject constructor(
mWidgetsRecommendationState.requestPredictionUpdate()
}
- LawnchairPredictor -> updateLawnchairPredictions()
+ LawnchairPredictor -> if (Utilities.ATLEAST_Q) {
+ updateLawnchairPredictions()
+ } else {
+ clearPredictions()
+ }
NoPredictor -> clearPredictions()
}
}
private fun currentPredictionMode(): PredictionMode {
- if (!prefs2.enableGlobalPrediction.firstCached()) {
+ // All predictor targets can't be run on device older than Q
+ if (!Utilities.ATLEAST_Q || !prefs2.enableGlobalPrediction.firstCached()) {
return NoPredictor
}
return prefs2.predictionMode.firstCached()
@@ -101,6 +115,7 @@ class LawnchairModelDelegate @Inject constructor(
mWidgetsRecommendationState.destroyPredictor()
}
+ @RequiresApi(Build.VERSION_CODES.Q)
private fun activateLawnchairPredictor() {
destroyPredictors()
if (!mActive) return
@@ -116,6 +131,7 @@ class LawnchairModelDelegate @Inject constructor(
updateLawnchairPredictions()
}
+ @RequiresApi(Build.VERSION_CODES.Q)
private fun updateLawnchairPredictions() {
lawnchairPredictor.updates(
model = mModel,
diff --git a/lawnchair/src/app/lawnchair/predictions/LawnchairPredictionEngine.kt b/lawnchair/src/app/lawnchair/predictions/LawnchairPredictionEngine.kt
index 94317481be..b4b38b3e65 100644
--- a/lawnchair/src/app/lawnchair/predictions/LawnchairPredictionEngine.kt
+++ b/lawnchair/src/app/lawnchair/predictions/LawnchairPredictionEngine.kt
@@ -6,12 +6,15 @@ import android.app.prediction.AppTargetId
import android.content.ComponentName
import android.content.Context
import android.content.pm.LauncherApps
+import android.os.Build
import android.os.Process
import android.os.UserHandle
+import androidx.annotation.RequiresApi
import app.lawnchair.preferences2.PreferenceManager2
import app.lawnchair.preferences2.firstCached
import com.android.launcher3.AppFilter
import com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT
+import com.android.launcher3.Utilities
import com.android.launcher3.model.BgDataModel
import com.android.launcher3.model.WidgetItem
import com.android.launcher3.pm.UserCache
@@ -35,6 +38,7 @@ class LawnchairPredictionEngine(
* @param count Maximum number of targets to return.
* @param excludedKeys Store keys that should be skipped (e.g. occupied hotseat slots).
*/
+ @RequiresApi(Build.VERSION_CODES.Q)
fun compileAppTargets(
ranked: List,
count: Int,
@@ -75,6 +79,7 @@ class LawnchairPredictionEngine(
* Compiles a ranked list of store keys into widget [AppTarget] entries by matching packages to
* available widget providers.
*/
+ @RequiresApi(Build.VERSION_CODES.Q)
fun compileWidgetTargets(
ranked: List,
dataModel: BgDataModel,
@@ -234,6 +239,7 @@ class LawnchairPredictionEngine(
}
}
+ @RequiresApi(Build.VERSION_CODES.Q)
private fun createAppTarget(
prefix: String,
componentName: ComponentName,
diff --git a/lawnchair/src/app/lawnchair/ui/preferences/destinations/PredictionsPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/destinations/PredictionsPreferences.kt
index cc258c88ad..14a29b8368 100644
--- a/lawnchair/src/app/lawnchair/ui/preferences/destinations/PredictionsPreferences.kt
+++ b/lawnchair/src/app/lawnchair/ui/preferences/destinations/PredictionsPreferences.kt
@@ -44,6 +44,7 @@ import app.lawnchair.ui.preferences.components.layout.PreferenceLayout
import app.lawnchair.ui.preferences.navigation.DismissedPredictionApps
import app.lawnchair.util.lifecycleState
import com.android.launcher3.R
+import com.android.launcher3.Utilities
@Composable
fun PredictionsPreferences(
@@ -100,6 +101,8 @@ private fun AppPredictionsFeature(
dismissedPredictionAppsCount,
)
+ val canUseAppPrediction = Utilities.ATLEAST_Q
+
PreferenceGroup(
heading = stringResource(R.string.app_predictions_label),
) {
@@ -107,6 +110,8 @@ private fun AppPredictionsFeature(
adapter = predictionModeAdapter,
entries = predictionModeEntries,
label = stringResource(R.string.prediction_mode_label),
+ description = if (canUseAppPrediction) null else stringResource(R.string.app_predictions_disable_reason_pre_q_description),
+ enabled = canUseAppPrediction,
)
when (predictionModeAdapter.state.value) {
SystemPredictor -> SystemSuggestionsPreference()