Revert "Fixing issue with old tasks being visible in Overview"
Bug: 28908500
This reverts commit b258f6a4bd685e5efcb36c02d5817f659e10479b.
Change-Id: I9b3c04358d6ca693ed3fdcd9220af13f81eb704e
diff --git a/services/core/java/com/android/server/am/TaskPersister.java b/services/core/java/com/android/server/am/TaskPersister.java
index 6cdabaa..43eb251 100644
--- a/services/core/java/com/android/server/am/TaskPersister.java
+++ b/services/core/java/com/android/server/am/TaskPersister.java
@@ -17,7 +17,6 @@
package com.android.server.am;
import android.annotation.NonNull;
-import android.content.ContentResolver;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Debug;
@@ -25,7 +24,6 @@
import android.os.FileUtils;
import android.os.Process;
import android.os.SystemClock;
-import android.provider.Settings;
import android.util.ArraySet;
import android.util.AtomicFile;
import android.util.Slog;
@@ -82,7 +80,7 @@
private static final String PERSISTED_TASK_IDS_FILENAME = "persisted_taskIds.txt";
static final String IMAGE_EXTENSION = ".png";
- @VisibleForTesting static final String TAG_TASK = "task";
+ private static final String TAG_TASK = "task";
private final ActivityManagerService mService;
private final ActivityStackSupervisor mStackSupervisor;
@@ -409,43 +407,18 @@
return null;
}
- @VisibleForTesting
List<TaskRecord> restoreTasksForUserLocked(final int userId) {
final ArrayList<TaskRecord> tasks = new ArrayList<TaskRecord>();
ArraySet<Integer> recoveredTaskIds = new ArraySet<Integer>();
File userTasksDir = getUserTasksDir(userId);
+
File[] recentFiles = userTasksDir.listFiles();
if (recentFiles == null) {
Slog.e(TAG, "restoreTasksForUserLocked: Unable to list files from " + userTasksDir);
return tasks;
}
- // Get the last persist uptime so we know how to adjust the first/last active times for each
- // task
- ContentResolver cr = mService.mContext.getContentResolver();
- long lastPersistUptime = Settings.Secure.getLong(cr,
- Settings.Secure.TASK_PERSISTER_LAST_WRITE_UPTIME, 0);
- if (DEBUG) {
- Slog.d(TaskPersister.TAG, "restoreTasksForUserLocked: lastPersistUptime=" +
- lastPersistUptime);
- }
-
- // Adjust the overview last visible task active time as we adjust the task active times when
- // loading. See TaskRecord.restoreFromXml(). If we have not migrated yet, SystemUI will
- // migrate the old value into the system setting.
- if (lastPersistUptime > 0) {
- long overviewLastActiveTime = Settings.Secure.getLongForUser(cr,
- Settings.Secure.OVERVIEW_LAST_VISIBLE_TASK_ACTIVE_UPTIME, 0, userId);
- if (DEBUG) {
- Slog.d(TaskPersister.TAG, "restoreTasksForUserLocked: overviewLastActiveTime=" +
- overviewLastActiveTime + " lastPersistUptime=" + lastPersistUptime);
- }
- Settings.Secure.putLongForUser(cr,
- Settings.Secure.OVERVIEW_LAST_VISIBLE_TASK_ACTIVE_UPTIME,
- -lastPersistUptime + overviewLastActiveTime, userId);
- }
-
for (int taskNdx = 0; taskNdx < recentFiles.length; ++taskNdx) {
File taskFile = recentFiles[taskNdx];
if (DEBUG) {
@@ -466,11 +439,15 @@
if (event == XmlPullParser.START_TAG) {
if (DEBUG) Slog.d(TAG, "restoreTasksForUserLocked: START_TAG name=" + name);
if (TAG_TASK.equals(name)) {
- final TaskRecord task = TaskRecord.restoreFromXml(in, mService,
- mStackSupervisor, lastPersistUptime);
+ final TaskRecord task = TaskRecord.restoreFromXml(in, mStackSupervisor);
if (DEBUG) Slog.d(TAG, "restoreTasksForUserLocked: restored task="
+ task);
if (task != null) {
+ // XXX Don't add to write queue... there is no reason to write
+ // out the stuff we just read, if we don't write it we will
+ // read the same thing again.
+ // mWriteQueue.add(new TaskWriteQueueItem(task));
+
final int taskId = task.taskId;
if (mStackSupervisor.anyTaskForIdLocked(taskId,
/* restoreFromRecents= */ false, 0) != null) {
@@ -486,12 +463,6 @@
task.isPersistable = true;
tasks.add(task);
recoveredTaskIds.add(taskId);
-
- // We've shifted the first and last active times, so we need to
- // persist the new task data to disk otherwise they will not
- // have the updated values. This is only done once whenever
- // the recents are first loaded for the user.
- wakeup(task, false);
}
} else {
Slog.e(TAG, "restoreTasksForUserLocked: Unable to restore taskFile="
@@ -780,15 +751,6 @@
}
}
}
-
- // Always update the task persister uptime when updating any tasks
- if (DEBUG) {
- Slog.d(TAG, "LazyTaskWriter: Updating last write uptime=" +
- SystemClock.elapsedRealtime());
- }
- Settings.Secure.putLong(mService.mContext.getContentResolver(),
- Settings.Secure.TASK_PERSISTER_LAST_WRITE_UPTIME,
- SystemClock.elapsedRealtime());
}
}
}
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index b3d8027..3f6db99 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -39,14 +39,12 @@
import android.os.Debug;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
-import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.voice.IVoiceInteractionSession;
import android.util.DisplayMetrics;
import android.util.Slog;
-import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IVoiceInteractor;
import com.android.internal.util.XmlUtils;
@@ -152,10 +150,8 @@
ComponentName realActivity; // The actual activity component that started the task.
boolean realActivitySuspended; // True if the actual activity component that started the
// task is suspended.
- long firstActiveTime; // First time this task was active, relative to boot time. This can be
- // negative if this task was last used prior to boot.
- long lastActiveTime; // Last time this task was active, relative to boot time. This can be
- // negative if this task was last used prior to boot.
+ long firstActiveTime; // First time this task was active.
+ long lastActiveTime; // Last time this task was active, including sleep.
boolean inRecents; // Actually in the recents list?
boolean isAvailable; // Is the activity available to be launched?
boolean rootWasReset; // True if the intent at the root of the task had
@@ -381,14 +377,14 @@
}
void touchActiveTime() {
- lastActiveTime = SystemClock.elapsedRealtime();
+ lastActiveTime = System.currentTimeMillis();
if (firstActiveTime == 0) {
firstActiveTime = lastActiveTime;
}
}
long getInactiveDuration() {
- return SystemClock.elapsedRealtime() - lastActiveTime;
+ return System.currentTimeMillis() - lastActiveTime;
}
/** Sets the original intent, and the calling uid and package. */
@@ -459,9 +455,8 @@
rootWasReset = true;
}
userId = UserHandle.getUserId(info.applicationInfo.uid);
- mUserSetupComplete = mService != null &&
- Settings.Secure.getIntForUser(mService.mContext.getContentResolver(),
- USER_SETUP_COMPLETE, 0, userId) != 0;
+ mUserSetupComplete = Settings.Secure.getIntForUser(mService.mContext.getContentResolver(),
+ USER_SETUP_COMPLETE, 0, userId) != 0;
if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
// If the activity itself has requested auto-remove, then just always do it.
autoRemoveRecents = true;
@@ -1173,9 +1168,7 @@
if (lastTaskDescription != null) {
lastTaskDescription.saveToXml(out);
}
- if (mLastThumbnailInfo != null) {
- mLastThumbnailInfo.saveToXml(out);
- }
+ mLastThumbnailInfo.saveToXml(out);
out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
@@ -1197,11 +1190,9 @@
out.endTag(null, TAG_AFFINITYINTENT);
}
- if (intent != null) {
- out.startTag(null, TAG_INTENT);
- intent.saveToXml(out);
- out.endTag(null, TAG_INTENT);
- }
+ out.startTag(null, TAG_INTENT);
+ intent.saveToXml(out);
+ out.endTag(null, TAG_INTENT);
final ArrayList<ActivityRecord> activities = mActivities;
final int numActivities = activities.size();
@@ -1220,9 +1211,8 @@
}
}
- static TaskRecord restoreFromXml(XmlPullParser in, ActivityManagerService service,
- ActivityStackSupervisor stackSupervisor, long lastPersistUptime)
- throws IOException, XmlPullParserException {
+ static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
+ throws IOException, XmlPullParserException {
Intent intent = null;
Intent affinityIntent = null;
ArrayList<ActivityRecord> activities = new ArrayList<>();
@@ -1335,31 +1325,6 @@
}
}
- if (lastPersistUptime > 0) {
- if (TaskPersister.DEBUG) {
- Slog.d(TaskPersister.TAG, "TaskRecord: Adjust firstActiveTime=" + firstActiveTime +
- " lastPersistUptime=" + lastPersistUptime);
- Slog.d(TaskPersister.TAG, "TaskRecord: Migrate lastActiveTime=" + lastActiveTime +
- " lastActiveTime=" + lastPersistUptime);
- }
- // The first and last task active times are relative to the last boot time, so offset
- // them to be prior to the current boot time
- firstActiveTime = -lastPersistUptime + firstActiveTime;
- lastActiveTime = -lastPersistUptime + lastActiveTime;
- } else {
- // The first/last active times are still absolute clock times, so offset them to be
- // relative to the current boot time
- long currentTime = System.currentTimeMillis();
- if (TaskPersister.DEBUG) {
- Slog.d(TaskPersister.TAG, "TaskRecord: Migrate firstActiveTime=" + firstActiveTime +
- " currentTime=" + currentTime);
- Slog.d(TaskPersister.TAG, "TaskRecord: Migrate lastActiveTime=" + lastActiveTime +
- " currentTime=" + currentTime);
- }
- firstActiveTime = -Math.max(0, currentTime - firstActiveTime);
- lastActiveTime = -Math.max(0, currentTime - lastActiveTime);
- }
-
int event;
while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
(event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
@@ -1409,7 +1374,7 @@
+ ": effectiveUid=" + effectiveUid);
}
- final TaskRecord task = new TaskRecord(service, taskId, intent,
+ final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
@@ -1812,7 +1777,7 @@
pw.print(prefix + "hasBeenVisible=" + hasBeenVisible);
pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode));
pw.print(" isResizeable=" + isResizeable());
- pw.print(" firstActiveTime=" + firstActiveTime);
+ pw.print(" firstActiveTime=" + lastActiveTime);
pw.print(" lastActiveTime=" + lastActiveTime);
pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)");
}