Merge "Prevent NPE whlie leaving windowless dream service." into rvc-dev am: 3944050acb

Change-Id: I1aea2e4d5d8eb5c083a0f1c80d53a2695a3c03fb
This commit is contained in:
Automerger Merge Worker
2020-02-26 17:26:50 +00:00

View File

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