Do not update lru list for dead process
There were multiple wrong states yield a no harm result: The updateLruProcessLocked only adds the given process to lru list if the process doesn't have activity. In R it was no problem because the activities are not detached from process when handling crash, updateProcessInfo is not called from ActivityRecord#setState with DESTROYED state. Commit7fce339fixed the case but introduced another bug that WindowProcessController#handleAppDied adds the inactive activity list to the active list that causes hasActivities returns true, so it is still no harm because update-lru will ignore the process with activity. And then commit8f7dd59corrects the inconsistent state accidentally by the added field mHasActivities. That corrects the return value of hasActivitiesOrRecentTasks. So updateLruProcessLocked takes effect to add the dead process into to lru list, which leads to the method getPackageProcessState gets old process state from a dead process record (pid=0). Fixes: 170487962 Test: OneTimePermissionTest#testStickyServiceMaintainsPermissionOnRestart Change-Id: I4449a5581cac678fd362cc22ad2754f0aada5482
This commit is contained in:
@@ -1460,6 +1460,12 @@ class ProcessRecord implements WindowProcessListener {
|
||||
if (updateServiceConnectionActivities) {
|
||||
mService.mServices.updateServiceConnectionActivitiesLocked(this);
|
||||
}
|
||||
if (thread == null) {
|
||||
// Only update lru and oom-adj if the process is alive. Because it may be called
|
||||
// when cleaning up the last activity from handling process died, the dead process
|
||||
// should not be added to lru list again.
|
||||
return;
|
||||
}
|
||||
mService.mProcessList.updateLruProcessLocked(this, activityChange, null /* client */);
|
||||
if (updateOomAdj) {
|
||||
mService.updateOomAdjLocked(this, OomAdjuster.OOM_ADJ_REASON_ACTIVITY);
|
||||
|
||||
@@ -1257,20 +1257,27 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
|
||||
mAtm.mStackSupervisor.removeHistoryRecords(this);
|
||||
|
||||
boolean hasVisibleActivities = false;
|
||||
if (mInactiveActivities != null && !mInactiveActivities.isEmpty()) {
|
||||
final boolean hasInactiveActivities =
|
||||
mInactiveActivities != null && !mInactiveActivities.isEmpty();
|
||||
final ArrayList<ActivityRecord> activities =
|
||||
(mHasActivities || hasInactiveActivities) ? new ArrayList<>() : mActivities;
|
||||
if (mHasActivities) {
|
||||
activities.addAll(mActivities);
|
||||
}
|
||||
if (hasInactiveActivities) {
|
||||
// Make sure that all activities in this process are handled.
|
||||
mActivities.addAll(mInactiveActivities);
|
||||
activities.addAll(mInactiveActivities);
|
||||
}
|
||||
if (isRemoved()) {
|
||||
// The package of the died process should be force-stopped, so make its activities as
|
||||
// finishing to prevent the process from being started again if the next top (or being
|
||||
// visible) activity also resides in the same process. This must be done before removal.
|
||||
for (int i = mActivities.size() - 1; i >= 0; i--) {
|
||||
mActivities.get(i).makeFinishingLocked();
|
||||
for (int i = activities.size() - 1; i >= 0; i--) {
|
||||
activities.get(i).makeFinishingLocked();
|
||||
}
|
||||
}
|
||||
for (int i = mActivities.size() - 1; i >= 0; i--) {
|
||||
final ActivityRecord r = mActivities.get(i);
|
||||
for (int i = activities.size() - 1; i >= 0; i--) {
|
||||
final ActivityRecord r = activities.get(i);
|
||||
if (r.mVisibleRequested || r.isVisible()) {
|
||||
// While an activity launches a new activity, it's possible that the old activity
|
||||
// is already requested to be hidden (mVisibleRequested=false), but this visibility
|
||||
|
||||
Reference in New Issue
Block a user