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

Commit 512bbdde authored by Manu Cornet's avatar Manu Cornet
Browse files

DO NOT MERGE - Ensuring that there are per-user last stack active times.

- This fixes an issue where the last stack active time would be clobbered
  when switching between users.  With the policy in the phone/stack
  recents, this is fine, but with the grid recents, it no longer only
  applies when out of the historical window, so it is always wrong (it
  would normally be wrong if switching back from another user after the
  historical time of six hours).

  This CL will migrate the last stack active time to a per-user secure
  setting, which will be used going forward.

[This is a manual merge of change 1913535]

Bug: 35375206
Test: On the Ryu, launch some tasks, switch users, launch more tasks, and
      return to the original user

Change-Id: Idc72920240093d15f822f5d9e3ee11b12a56edae
parent 83b072c4
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -6166,6 +6166,14 @@ public final class Settings {
        public static final String LOCK_SCREEN_SHOW_NOTIFICATIONS =
                "lock_screen_show_notifications";

        /**
         * This preference stores the last stack active task time for each user, which affects what
         * tasks will be visible in Overview.
         * @hide
         */
        public static final String OVERVIEW_LAST_STACK_ACTIVE_TIME =
                "overview_last_stack_active_time";

        /**
         * List of TV inputs that are currently hidden. This is a string
         * containing the IDs of all hidden TV inputs. Each ID is encoded by
+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ public final class Prefs {
        Key.QS_WORK_ADDED,
    })
    public @interface Key {
        @Deprecated
        String OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME = "OverviewLastStackTaskActiveTime";
        String DEBUG_MODE_ENABLED = "debugModeEnabled";
        String HOTSPOT_TILE_LAST_USED = "HotspotTileLastUsed";
+10 −7
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.os.Handler;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
@@ -42,7 +43,6 @@ import android.view.WindowManager.LayoutParams;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.systemui.Interpolators;
import com.android.systemui.Prefs;
import com.android.systemui.R;
import com.android.systemui.recents.events.EventBus;
import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent;
@@ -179,8 +179,10 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
                // is still valid.  Otherwise, we need to reset the lastStackactiveTime to the
                // currentTime and remove the old tasks in between which would not be previously
                // visible, but currently would be in the new currentTime
                long oldLastStackActiveTime = Prefs.getLong(RecentsActivity.this,
                        Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, -1);
                int currentUser = SystemServicesProxy.getInstance(RecentsActivity.this)
                        .getCurrentUser();
                long oldLastStackActiveTime = Settings.Secure.getLongForUser(getContentResolver(),
                        Secure.OVERVIEW_LAST_STACK_ACTIVE_TIME, -1, currentUser);
                if (oldLastStackActiveTime != -1) {
                    long currentTime = System.currentTimeMillis();
                    if (currentTime < oldLastStackActiveTime) {
@@ -198,8 +200,8 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
                                Recents.getSystemServices().removeTask(task.persistentId);
                            }
                        }
                        Prefs.putLong(RecentsActivity.this,
                                Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, currentTime);
                        Settings.Secure.putLongForUser(RecentsActivity.this.getContentResolver(),
                                Secure.OVERVIEW_LAST_STACK_ACTIVE_TIME, currentTime, currentUser);
                    }
                }
            }
@@ -825,8 +827,9 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        Recents.getTaskLoader().dump(prefix, writer);

        String id = Integer.toHexString(System.identityHashCode(this));
        long lastStackActiveTime = Prefs.getLong(this,
                Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, -1);
        long lastStackActiveTime = Settings.Secure.getLongForUser(getContentResolver(),
                Secure.OVERVIEW_LAST_STACK_ACTIVE_TIME, -1,
                SystemServicesProxy.getInstance(this).getCurrentUser());

        writer.print(prefix); writer.print(TAG);
        writer.print(" visible="); writer.print(mIsVisible ? "Y" : "N");
+40 −4
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.util.ArraySet;
import android.util.SparseArray;
import android.util.SparseIntArray;
@@ -129,14 +131,17 @@ public class RecentsTaskLoadPlan {
            preloadRawTasks(includeFrontMostExcludedTask);
        }

        SystemServicesProxy ssp = SystemServicesProxy.getInstance(mContext);
        SparseArray<Task.TaskKey> affiliatedTasks = new SparseArray<>();
        SparseIntArray affiliatedTaskCounts = new SparseIntArray();
        String dismissDescFormat = mContext.getString(
                R.string.accessibility_recents_item_will_be_dismissed);
        String appInfoDescFormat = mContext.getString(
                R.string.accessibility_recents_item_open_app_info);
        long lastStackActiveTime = Prefs.getLong(mContext,
                Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, 0);
        int currentUserId = ssp.getCurrentUser();
        long legacyLastStackActiveTime = migrateLegacyLastStackActiveTime(currentUserId);
        long lastStackActiveTime = Settings.Secure.getLongForUser(mContext.getContentResolver(),
                Secure.OVERVIEW_LAST_STACK_ACTIVE_TIME, legacyLastStackActiveTime, currentUserId);
        if (RecentsDebugFlags.Static.EnableMockTasks) {
            lastStackActiveTime = 0;
        }
@@ -198,8 +203,8 @@ public class RecentsTaskLoadPlan {
            affiliatedTasks.put(taskKey.id, taskKey);
        }
        if (newLastStackActiveTime != -1) {
            Prefs.putLong(mContext, Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME,
                    newLastStackActiveTime);
            Settings.Secure.putLongForUser(mContext.getContentResolver(),
                    Secure.OVERVIEW_LAST_STACK_ACTIVE_TIME, newLastStackActiveTime, currentUserId);
        }

        // Initialize the stacks
@@ -278,4 +283,35 @@ public class RecentsTaskLoadPlan {
    private boolean isHistoricalTask(ActivityManager.RecentTaskInfo t) {
        return t.lastActiveTime < (System.currentTimeMillis() - SESSION_BEGIN_TIME);
    }

    /**
     * Migrate the last active time from the prefs to the secure settings.
     *
     * The first time this runs, it will:
     * 1) fetch the last stack active time from the prefs
     * 2) set the prefs to the last stack active time for all users
     * 3) clear the pref
     * 4) return the last stack active time
     *
     * Subsequent calls to this will return zero.
     */
    private long migrateLegacyLastStackActiveTime(int currentUserId) {
        long legacyLastStackActiveTime = Prefs.getLong(mContext,
                Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, -1);
        if (legacyLastStackActiveTime != -1) {
            Prefs.remove(mContext, Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME);
            UserManager userMgr = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
            List<UserInfo> users = userMgr.getUsers();
            for (int i = 0; i < users.size(); i++) {
                int userId = users.get(i).id;
                if (userId != currentUserId) {
                    Settings.Secure.putLongForUser(mContext.getContentResolver(),
                            Secure.OVERVIEW_LAST_STACK_ACTIVE_TIME, legacyLastStackActiveTime,
                            userId);
                }
            }
            return legacyLastStackActiveTime;
        }
        return 0;
    }
}