Removing prediciton loading state

Also fixing test flakyness due to delayed prediction loading

Bug: 132993129
Bug: 131854153
Change-Id: I85f7afff0e3ee0ca9e40e92e91681f797a0bc2de
diff --git a/quickstep/recents_ui_overrides/res/layout/prediction_load_progress.xml b/quickstep/recents_ui_overrides/res/layout/prediction_load_progress.xml
deleted file mode 100644
index 20c4004..0000000
--- a/quickstep/recents_ui_overrides/res/layout/prediction_load_progress.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
-    style="?android:attr/progressBarStyleHorizontal"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:layout_gravity="center"
-    android:layout_marginLeft="20dp"
-    android:layout_marginRight="20dp"
-    android:indeterminate="true"
-    android:indeterminateOnly="true"
-    android:indeterminateTint="?workspaceTextColor" />
diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionRowView.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionRowView.java
index 55f4c98..4a486f8 100644
--- a/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionRowView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionRowView.java
@@ -28,7 +28,6 @@
 import android.util.AttributeSet;
 import android.util.IntProperty;
 import android.util.Log;
-import android.view.LayoutInflater;
 import android.view.View;
 import android.view.animation.Interpolator;
 import android.widget.LinearLayout;
@@ -115,8 +114,6 @@
     private final AnimatedFloat mOverviewScrollFactor =
             new AnimatedFloat(this::updateTranslationAndAlpha);
 
-    private View mLoadingProgress;
-
     private boolean mPredictionsEnabled = false;
 
     public PredictionRowView(@NonNull Context context) {
@@ -165,7 +162,6 @@
 
     public void setup(FloatingHeaderView parent, FloatingHeaderRow[] rows, boolean tabsHidden) {
         mParent = parent;
-        setPredictionsEnabled(mPredictionUiStateManager.arePredictionsEnabled());
     }
 
     private void setPredictionsEnabled(boolean predictionsEnabled) {
@@ -205,7 +201,7 @@
 
     @Override
     public boolean hasVisibleContent() {
-        return mPredictionUiStateManager.arePredictionsEnabled();
+        return mPredictionsEnabled;
     }
 
     /**
@@ -241,9 +237,6 @@
     }
 
     private void applyPredictionApps() {
-        if (mLoadingProgress != null) {
-            removeView(mLoadingProgress);
-        }
         if (!mPredictionsEnabled) {
             mParent.onHeightUpdated();
             return;
@@ -290,15 +283,8 @@
         }
 
         if (predictionCount == 0) {
-            if (mLoadingProgress == null) {
-                mLoadingProgress = LayoutInflater.from(getContext())
-                        .inflate(R.layout.prediction_load_progress, this, false);
-            }
-            addView(mLoadingProgress);
-        } else {
-            mLoadingProgress = null;
+            setPredictionsEnabled(false);
         }
-
         mParent.onHeightUpdated();
     }
 
@@ -342,11 +328,8 @@
     public void setTextAlpha(int alpha) {
         mIconCurrentTextAlpha = alpha;
         int iconColor = setColorAlphaBound(mIconTextColor, mIconCurrentTextAlpha);
-
-        if (mLoadingProgress == null) {
-            for (int i = 0; i < getChildCount(); i++) {
-                ((BubbleTextView) getChildAt(i)).setTextColor(iconColor);
-            }
+        for (int i = 0; i < getChildCount(); i++) {
+            ((BubbleTextView) getChildAt(i)).setTextColor(iconColor);
         }
     }
 
diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionUiStateManager.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionUiStateManager.java
index 28ecce0..64cb4b4 100644
--- a/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionUiStateManager.java
+++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionUiStateManager.java
@@ -24,7 +24,6 @@
 import android.app.prediction.AppTarget;
 import android.content.ComponentName;
 import android.content.Context;
-import android.os.Handler;
 import android.view.ViewTreeObserver.OnGlobalLayoutListener;
 
 import com.android.launcher3.AppInfo;
@@ -63,7 +62,6 @@
         OnIDPChangeListener, OnUpdateListener {
 
     public static final String LAST_PREDICTION_ENABLED_STATE = "last_prediction_enabled_state";
-    private static final long INITIAL_CALLBACK_WAIT_TIMEOUT_MS = 5000;
 
     // TODO (b/129421797): Update the client constants
     public enum Client {
@@ -110,13 +108,8 @@
         for (int i = 0; i < mPredictionServicePredictions.length; i++) {
             mPredictionServicePredictions[i] = Collections.emptyList();
         }
-
         mGettingValidPredictionResults = Utilities.getDevicePrefs(context)
                 .getBoolean(LAST_PREDICTION_ENABLED_STATE, true);
-        if (mGettingValidPredictionResults) {
-            new Handler().postDelayed(
-                    this::updatePredictionStateAfterCallback, INITIAL_CALLBACK_WAIT_TIMEOUT_MS);
-        }
 
         // Call this last
         mCurrentState = parseLastState();
@@ -197,10 +190,7 @@
         }
     }
 
-    public boolean mDebugHadStateUpdate;
-
     private void updatePredictionStateAfterCallback() {
-        mDebugHadStateUpdate = true;
         boolean validResults = false;
         for (List l : mPredictionServicePredictions) {
             validResults |= l != null && !l.isEmpty();
@@ -296,10 +286,6 @@
         dispatchOnChange(false);
     }
 
-    public boolean arePredictionsEnabled() {
-        return mCurrentState.isEnabled;
-    }
-
     private boolean canApplyPredictions(PredictionState newState) {
         if (mAppsView == null) {
             // If there is no apps view, no need to schedule.
diff --git a/quickstep/tests/src/com/android/quickstep/AppPredictionsUITests.java b/quickstep/tests/src/com/android/quickstep/AppPredictionsUITests.java
index c6f7544..d9fcf4d 100644
--- a/quickstep/tests/src/com/android/quickstep/AppPredictionsUITests.java
+++ b/quickstep/tests/src/com/android/quickstep/AppPredictionsUITests.java
@@ -68,11 +68,7 @@
 
         // Disable app tracker
         AppLaunchTracker.INSTANCE.initializeForTesting(new AppLaunchTracker());
-
         PredictionUiStateManager.INSTANCE.initializeForTesting(null);
-        waitForLauncherCondition("Prediction never had state update",
-                launcher -> PredictionUiStateManager.INSTANCE.get(
-                        mTargetContext).mDebugHadStateUpdate);
 
         mCallback = PredictionUiStateManager.INSTANCE.get(mTargetContext).appPredictorCallback(
                 Client.HOME);
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 35113d2..a59189b 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2553,8 +2553,4 @@
 
         void onLauncherResume();
     }
-
-    public boolean debugIsPredictionInitialized() {
-        return true;
-    }
 }
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
index a19857c..44401c7 100644
--- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
+++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
@@ -54,6 +54,7 @@
 import com.android.launcher3.ResourceUtils;
 import com.android.launcher3.Utilities;
 import com.android.launcher3.compat.LauncherAppsCompat;
+import com.android.launcher3.model.AppLaunchTracker;
 import com.android.launcher3.tapl.LauncherInstrumentation;
 import com.android.launcher3.tapl.TestHelpers;
 import com.android.launcher3.util.Wait;
@@ -197,6 +198,9 @@
 
     @Before
     public void setUp() throws Exception {
+        // Disable app tracker
+        AppLaunchTracker.INSTANCE.initializeForTesting(new AppLaunchTracker());
+
         mTargetContext = InstrumentationRegistry.getTargetContext();
         mTargetPackage = mTargetContext.getPackageName();
         // Unlock the phone
diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
index d0ea142..d4cfe3a 100644
--- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
+++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
@@ -64,8 +64,6 @@
             test.mDevice.pressHome();
         }
         test.waitForLauncherCondition("Launcher didn't start", launcher -> launcher != null);
-        test.waitForLauncherCondition("Prediction never had state update",
-                launcher -> launcher.debugIsPredictionInitialized());
         test.waitForState("Launcher internal state didn't switch to Home", LauncherState.NORMAL);
         test.waitForResumed("Launcher internal state is still Background");
         // Check that we switched to home.