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

Commit 2f0d0152 authored by Tony Wickham's avatar Tony Wickham
Browse files

Adjust recents onboarding logic

- After dismissing, don't show again until 5 app launches
- Don't count the same task id towards that 5 (or the 2 before
  showing the first time)

Test: manual, launch a couple apps and verify onboarding shows;
continues showing until I dismiss it; shows again after launching
5 apps (different activities in the same app don't count)

Bug: 73392035
Bug: 70180942
Change-Id: Icff567e3418097c3503d2f322cf829a9efc195e7
parent 74cfe567
Loading
Loading
Loading
Loading
+29 −4
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;

import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -65,6 +66,8 @@ public class RecentsOnboarding {
    private static final long SHOW_HIDE_DURATION_MS = 300;
    // Don't show the onboarding until the user has launched this number of apps.
    private static final int SHOW_ON_APP_LAUNCH = 2;
    // After explicitly dismissing, show again after launching this number of apps.
    private static final int SHOW_ON_APP_LAUNCH_AFTER_DISMISS = 5;

    private final Context mContext;
    private final WindowManager mWindowManager;
@@ -84,6 +87,9 @@ public class RecentsOnboarding {
    private boolean mTaskListenerRegistered;
    private boolean mLayoutAttachedToWindow;
    private boolean mBackgroundIsLight;
    private int mLastTaskId;
    private boolean mHasDismissed;
    private int mNumAppsLaunchedSinceDismiss;

    private final SysUiTaskStackChangeListener mTaskListener = new SysUiTaskStackChangeListener() {
        @Override
@@ -94,15 +100,27 @@ public class RecentsOnboarding {
                hide(true);
                return;
            }
            if (info.id == mLastTaskId) {
                // We only count launches that go to a new task.
                return;
            }
            int activityType = info.configuration.windowConfiguration.getActivityType();
            int numAppsLaunched = Prefs.getInt(mContext, Prefs.Key.NUM_APPS_LAUNCHED, 0);
            if (activityType == ACTIVITY_TYPE_STANDARD) {
                mLastTaskId = info.id;
                int numAppsLaunched = mHasDismissed ? mNumAppsLaunchedSinceDismiss
                        : Prefs.getInt(mContext, Prefs.Key.NUM_APPS_LAUNCHED, 0);
                int showOnAppLaunch = mHasDismissed ? SHOW_ON_APP_LAUNCH_AFTER_DISMISS
                        : SHOW_ON_APP_LAUNCH;
                numAppsLaunched++;
                if (numAppsLaunched >= SHOW_ON_APP_LAUNCH) {
                if (numAppsLaunched >= showOnAppLaunch) {
                    show();
                } else {
                    if (mHasDismissed) {
                        mNumAppsLaunchedSinceDismiss = numAppsLaunched;
                    } else {
                        Prefs.putInt(mContext, Prefs.Key.NUM_APPS_LAUNCHED, numAppsLaunched);
                    }
                }
            } else {
                hide(false);
            }
@@ -115,6 +133,7 @@ public class RecentsOnboarding {
        public void onViewAttachedToWindow(View view) {
            if (view == mLayout) {
                mLayoutAttachedToWindow = true;
                mHasDismissed = false;
            }
        }

@@ -149,7 +168,11 @@ public class RecentsOnboarding {

        mLayout.addOnAttachStateChangeListener(mOnAttachStateChangeListener);
        mLayout.setBackground(mBackgroundDrawable);
        mDismissView.setOnClickListener(v -> hide(true));
        mDismissView.setOnClickListener(v -> {
            hide(true);
            mHasDismissed = true;
            mNumAppsLaunchedSinceDismiss = 0;
        });

        if (RESET_PREFS_FOR_DEBUG) {
            Prefs.putBoolean(mContext, Prefs.Key.HAS_SEEN_RECENTS_ONBOARDING, false);
@@ -180,6 +203,8 @@ public class RecentsOnboarding {
            ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskListener);
            mTaskListenerRegistered = false;
        }
        mHasDismissed = false;
        mNumAppsLaunchedSinceDismiss = 0;
        hide(false);
    }