diff options
Diffstat (limited to 'quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionAppTracker.java')
-rw-r--r-- | quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionAppTracker.java | 47 |
1 files changed, 10 insertions, 37 deletions
diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionAppTracker.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionAppTracker.java index bd7857330..0b8c1c57f 100644 --- a/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionAppTracker.java +++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionAppTracker.java @@ -15,7 +15,7 @@ */ package com.android.launcher3.appprediction; -import static com.android.launcher3.appprediction.PredictionUiStateManager.KEY_APP_SUGGESTION; +import static com.android.launcher3.InvariantDeviceProfile.CHANGE_FLAG_GRID; import android.annotation.TargetApi; import android.app.prediction.AppPredictionContext; @@ -26,8 +26,6 @@ import android.app.prediction.AppTargetEvent; import android.app.prediction.AppTargetId; import android.content.ComponentName; import android.content.Context; -import android.content.SharedPreferences; -import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Build; import android.os.Handler; import android.os.Message; @@ -35,12 +33,10 @@ import android.os.UserHandle; import android.util.Log; import com.android.launcher3.InvariantDeviceProfile; -import com.android.launcher3.Utilities; +import com.android.launcher3.appprediction.PredictionUiStateManager.Client; import com.android.launcher3.model.AppLaunchTracker; import com.android.launcher3.util.UiThreadHelper; -import com.android.launcher3.appprediction.PredictionUiStateManager.Client; - import androidx.annotation.UiThread; import androidx.annotation.WorkerThread; @@ -48,8 +44,7 @@ import androidx.annotation.WorkerThread; * Subclass of app tracker which publishes the data to the prediction engine and gets back results. */ @TargetApi(Build.VERSION_CODES.Q) -public class PredictionAppTracker extends AppLaunchTracker - implements OnSharedPreferenceChangeListener { +public class PredictionAppTracker extends AppLaunchTracker { private static final String TAG = "PredictionAppTracker"; private static final boolean DBG = false; @@ -62,8 +57,6 @@ public class PredictionAppTracker extends AppLaunchTracker private final Context mContext; private final Handler mMessageHandler; - private boolean mEnabled; - // Accessed only on worker thread private AppPredictor mHomeAppPredictor; private AppPredictor mRecentsOverviewPredictor; @@ -71,24 +64,16 @@ public class PredictionAppTracker extends AppLaunchTracker public PredictionAppTracker(Context context) { mContext = context; mMessageHandler = new Handler(UiThreadHelper.getBackgroundLooper(), this::handleMessage); - - SharedPreferences prefs = Utilities.getPrefs(context); - setEnabled(prefs.getBoolean(KEY_APP_SUGGESTION, true)); - prefs.registerOnSharedPreferenceChangeListener(this); InvariantDeviceProfile.INSTANCE.get(mContext).addOnChangeListener(this::onIdpChanged); - } - @UiThread - private void onIdpChanged(int changeFlags, InvariantDeviceProfile profile) { - // Reinitialize everything - setEnabled(mEnabled); + mMessageHandler.sendEmptyMessage(MSG_INIT); } - @Override @UiThread - public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - if (KEY_APP_SUGGESTION.equals(key)) { - setEnabled(prefs.getBoolean(KEY_APP_SUGGESTION, true)); + private void onIdpChanged(int changeFlags, InvariantDeviceProfile profile) { + if ((changeFlags & CHANGE_FLAG_GRID) != 0) { + // Reinitialize everything + mMessageHandler.sendEmptyMessage(MSG_INIT); } } @@ -137,13 +122,13 @@ public class PredictionAppTracker extends AppLaunchTracker return true; } case MSG_LAUNCH: { - if (mEnabled && mHomeAppPredictor != null) { + if (mHomeAppPredictor != null) { mHomeAppPredictor.notifyAppTargetEvent((AppTargetEvent) msg.obj); } return true; } case MSG_PREDICT: { - if (mEnabled && mHomeAppPredictor != null) { + if (mHomeAppPredictor != null) { String client = (String) msg.obj; if (Client.HOME.id.equals(client)) { mHomeAppPredictor.requestPredictionUpdate(); @@ -168,18 +153,6 @@ public class PredictionAppTracker extends AppLaunchTracker } } - @UiThread - public void setEnabled(boolean isEnabled) { - mEnabled = isEnabled; - if (isEnabled) { - mMessageHandler.removeMessages(MSG_DESTROY); - mMessageHandler.sendEmptyMessage(MSG_INIT); - } else { - mMessageHandler.removeMessages(MSG_INIT); - mMessageHandler.sendEmptyMessage(MSG_DESTROY); - } - } - @Override @UiThread public void onStartShortcut(String packageName, String shortcutId, UserHandle user, |