Prevent NPE whlie leaving windowless dream service.

There might having windowless dream service like doze dream which won't
hava attached activity, so call finish() directly in onWakeUp() since
finish() itself deals with finishAndRemoveTask() as well.

Fix: b/150110220
Test: manual test, won't throw NPE while leaving doze service.
Change-Id: I982c2f6fb1859e869732ef8795b61bf96e8cff64
Merged-In: I982c2f6fb1859e869732ef8795b61bf96e8cff64
(cherry picked from commit 45f0d572c1)
This commit is contained in:
Jerry Chang
2020-02-24 18:03:33 +08:00
parent 768070530b
commit 30efde6a30

View File

@@ -883,7 +883,7 @@ public class DreamService extends Service implements Window.Callback {
* </p>
*/
public void onWakeUp() {
mActivity.finishAndRemoveTask();
finish();
}
/** {@inheritDoc} */
@@ -904,13 +904,14 @@ public class DreamService extends Service implements Window.Callback {
public final void finish() {
if (mDebug) Slog.v(TAG, "finish(): mFinished=" + mFinished);
if (mActivity == null) {
if (mActivity != null) {
if (!mActivity.isFinishing()) {
// In case the activity is not finished yet, do it now.
mActivity.finishAndRemoveTask();
return;
}
} else if (!mWindowless) {
Slog.w(TAG, "Finish was called before the dream was attached.");
} else if (!mActivity.isFinishing()) {
// In case the activity is not finished yet, do it now. This can happen if someone calls
// finish() directly, without going through wakeUp().
mActivity.finishAndRemoveTask();
return;
}
if (!mFinished) {
@@ -1010,7 +1011,7 @@ public class DreamService extends Service implements Window.Callback {
* @param started A callback that will be invoked once onDreamingStarted has completed.
*/
private void attach(IBinder dreamToken, boolean canDoze, IRemoteCallback started) {
if (mActivity != null) {
if (mDreamToken != null) {
Slog.e(TAG, "attach() called when dream with token=" + mDreamToken
+ " already attached");
return;