From 0b2e23a427d5d2d29334e73f2d21f24635909cff Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Tue, 3 Jan 2017 12:13:49 -0800 Subject: [PATCH] DozeService: Fix crash if StatusBar not yet initialized Fixes a bug where a crashing SystemUI may crash again after restarting if the services restart in an unexpected order. Bug: 34044765 Test: Crash SystemUI, observe that it doesn't crash again right away. Change-Id: Id6f781ba29ff11be0850b1883ca2942f15e76324 --- .../src/com/android/systemui/doze/DozeFactory.java | 2 +- .../src/com/android/systemui/doze/DozeService.java | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeFactory.java b/packages/SystemUI/src/com/android/systemui/doze/DozeFactory.java index f0deaf06b46e3..aa226181d7136 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeFactory.java +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeFactory.java @@ -152,7 +152,7 @@ public class DozeFactory { } } - private static DozeHost getHost(DozeService service) { + public static DozeHost getHost(DozeService service) { Application appCandidate = service.getApplication(); final SystemUIApplication app = (SystemUIApplication) appCandidate; return app.getComponent(DozeHost.class); diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeService.java b/packages/SystemUI/src/com/android/systemui/doze/DozeService.java index 52f1fb4c3c65b..828728f0ae9e7 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeService.java +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeService.java @@ -42,6 +42,11 @@ public class DozeService extends DreamService implements DozeMachine.Service { setWindowless(true); + if (DozeFactory.getHost(this) == null) { + finish(); + return; + } + DozeProvider provider = PluginManager.getInstance(this) .getOneShotPlugin(DozeProvider.ACTION, DozeProvider.VERSION); mDozeMachine = new DozeFactory(provider).assembleMachine(this); @@ -62,6 +67,8 @@ public class DozeService extends DreamService implements DozeMachine.Service { @Override protected void dumpOnHandler(FileDescriptor fd, PrintWriter pw, String[] args) { - mDozeMachine.dump(pw); + if (mDozeMachine != null) { + mDozeMachine.dump(pw); + } } }