Prevent NPEs when no focusable stack.

Fallback to home stack when no focusable stack
(e.g. launcher force stopped & enter PIP mode with no other app task),
Fix NPEs for logWindowState & getTopRunningActivity from null stack.

Change-Id: I0a0134661dfc20ff844a0bc19ce6833242f4a865
Fixes: 110078217
Test: Manual
Test: atest ActivityStackSupervisorTests ActivityStackTests ActivityStarterTests
This commit is contained in:
lumark
2018-06-15 15:43:12 +08:00
committed by Ming-Shin Lu
parent 1a61e0ea1d
commit f6c4a9868c
2 changed files with 9 additions and 0 deletions

View File

@@ -185,6 +185,10 @@ class ActivityMetricsLogger {
mWindowState = WINDOW_STATE_INVALID;
ActivityStack stack = mSupervisor.getFocusedStack();
if (stack == null) {
return;
}
if (stack.isActivityTypeAssistant()) {
mWindowState = WINDOW_STATE_ASSISTANT;
return;

View File

@@ -708,6 +708,11 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
if (!focusCandidate.isFocusable()) {
// The focus candidate isn't focusable. Move focus to the top stack that is focusable.
focusCandidate = getNextFocusableStackLocked(focusCandidate, false /* ignoreCurrent */);
if (focusCandidate == null) {
Slog.w(TAG,
"setFocusStackUnchecked: No focusable stack found, focus home as default");
focusCandidate = mHomeStack;
}
}
if (focusCandidate != mFocusedStack) {