From 9cdf9e52d944e99745a4fe7fb63962fb4508ed6d Mon Sep 17 00:00:00 2001 From: Daniel 2 Olofsson Date: Mon, 16 Dec 2013 13:24:25 +0100 Subject: [PATCH] Fix to NullPointerException on move back in ActivityStack. In ActivityTask.moveTaskToBackLocked NullPointerException may occur when moving back with only current Activity in stack. This due to a condition that may trigger despite a TaskRecord being null and then attempt accessing the TaskRecord.mOnTopOfHome variable. TaskRecord task may be set to null when no resumed activity remain. Resolved by assuring that flag mOnTopOfHome is instead set to false for current TaskRecord in case where there are no remaining activities above home. The above bug has already been corrected in the following commit, ada62fca51d314cefe2c5da4e007df5b9abf320d, but it does not set the cottect value to mTopOfHome for the current taks, see below. Variable mOnTopOfHome will not be set to false in situations where stack is of size 1 or less and task is null, perhaps from already having finished current activity. To avoid current TaskRecord maintaining value mOnTopOfHome to true after launching Home this variable is set to false. Impact should not be major due to correction earlier that makes sure that there is always a TaskRecord.mOnTopOfHome set to true above Home activity but if not correctly set for current task still gives a possibility of bad behavior. Change-Id: Ie86ad99c188aaa05b0de9d58eaa16c42b6fc4341 --- services/java/com/android/server/am/ActivityStack.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java index 84cedb81810ee..47593f27a77f4 100644 --- a/services/java/com/android/server/am/ActivityStack.java +++ b/services/java/com/android/server/am/ActivityStack.java @@ -3160,9 +3160,7 @@ final class ActivityStack { final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null; if (task == tr && task.mOnTopOfHome || numTasks <= 1) { - if (task != null) { - task.mOnTopOfHome = false; - } + tr.mOnTopOfHome = false; return mStackSupervisor.resumeHomeActivity(null); }