Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9820c05f authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Removing prediciton loading state

Also fixing test flakyness due to delayed prediction loading

Bug: 132993129
Bug: 131854153
Change-Id: I85f7afff0e3ee0ca9e40e92e91681f797a0bc2de
parent 571e5116
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
<?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" />
+4 −21
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.os.Build;
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 @@ public class PredictionRowView extends LinearLayout implements
    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 class PredictionRowView extends LinearLayout implements

    public void setup(FloatingHeaderView parent, FloatingHeaderRow[] rows, boolean tabsHidden) {
        mParent = parent;
        setPredictionsEnabled(mPredictionUiStateManager.arePredictionsEnabled());
    }

    private void setPredictionsEnabled(boolean predictionsEnabled) {
@@ -205,7 +201,7 @@ public class PredictionRowView extends LinearLayout implements

    @Override
    public boolean hasVisibleContent() {
        return mPredictionUiStateManager.arePredictionsEnabled();
        return mPredictionsEnabled;
    }

    /**
@@ -241,9 +237,6 @@ public class PredictionRowView extends LinearLayout implements
    }

    private void applyPredictionApps() {
        if (mLoadingProgress != null) {
            removeView(mLoadingProgress);
        }
        if (!mPredictionsEnabled) {
            mParent.onHeightUpdated();
            return;
@@ -290,15 +283,8 @@ public class PredictionRowView extends LinearLayout implements
        }

        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,13 +328,10 @@ public class PredictionRowView extends LinearLayout implements
    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);
        }
    }
    }

    @Override
    public boolean hasOverlappingRendering() {
+0 −14
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.app.prediction.AppPredictor;
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 @@ public class PredictionUiStateManager implements OnGlobalLayoutListener, ItemInf
        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 @@ public class PredictionUiStateManager implements OnGlobalLayoutListener, ItemInf
        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 class PredictionUiStateManager implements OnGlobalLayoutListener, ItemInf
        }
    }

    public boolean mDebugHadStateUpdate;

    private void updatePredictionStateAfterCallback() {
        mDebugHadStateUpdate = true;
        boolean validResults = false;
        for (List l : mPredictionServicePredictions) {
            validResults |= l != null && !l.isEmpty();
@@ -296,10 +286,6 @@ public class PredictionUiStateManager implements OnGlobalLayoutListener, ItemInf
        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.
+0 −4
Original line number Diff line number Diff line
@@ -68,11 +68,7 @@ public class AppPredictionsUITests extends AbstractQuickStepTest {

        // 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);
+0 −4
Original line number Diff line number Diff line
@@ -2553,8 +2553,4 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,

        void onLauncherResume();
    }

    public boolean debugIsPredictionInitialized() {
        return true;
    }
}
Loading