diff options
Diffstat (limited to 'services/java/com/android/server/dreams/DreamController.java')
-rw-r--r-- | services/java/com/android/server/dreams/DreamController.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/services/java/com/android/server/dreams/DreamController.java b/services/java/com/android/server/dreams/DreamController.java index 1ab6a77..45ae2c5 100644 --- a/services/java/com/android/server/dreams/DreamController.java +++ b/services/java/com/android/server/dreams/DreamController.java @@ -44,6 +44,9 @@ import java.util.NoSuchElementException; final class DreamController { private static final String TAG = "DreamController"; + // How long we wait for a newly bound dream to create the service connection + private static final int DREAM_CONNECTION_TIMEOUT = 5 * 1000; + private final Context mContext; private final Handler mHandler; private final Listener mListener; @@ -58,6 +61,16 @@ final class DreamController { private DreamRecord mCurrentDream; + private final Runnable mStopUnconnectedDreamRunnable = new Runnable() { + @Override + public void run() { + if (mCurrentDream != null && mCurrentDream.mBound && !mCurrentDream.mConnected) { + Slog.w(TAG, "Bound dream did not connect in the time allotted"); + stopDream(); + } + } + }; + public DreamController(Context context, Handler handler, Listener listener) { mContext = context; mHandler = handler; @@ -116,6 +129,7 @@ final class DreamController { } mCurrentDream.mBound = true; + mHandler.postDelayed(mStopUnconnectedDreamRunnable, DREAM_CONNECTION_TIMEOUT); } public void stopDream() { @@ -128,6 +142,8 @@ final class DreamController { Slog.i(TAG, "Stopping dream: name=" + oldDream.mName + ", isTest=" + oldDream.mIsTest + ", userId=" + oldDream.mUserId); + mHandler.removeCallbacks(mStopUnconnectedDreamRunnable); + if (oldDream.mSentStartBroadcast) { mContext.sendBroadcastAsUser(mDreamingStoppedIntent, UserHandle.ALL); } @@ -200,6 +216,7 @@ final class DreamController { public final int mUserId; public boolean mBound; + public boolean mConnected; public IDreamService mService; public boolean mSentStartBroadcast; @@ -231,6 +248,7 @@ final class DreamController { mHandler.post(new Runnable() { @Override public void run() { + mConnected = true; if (mCurrentDream == DreamRecord.this && mService == null) { attach(IDreamService.Stub.asInterface(service)); } |