diff options
6 files changed, 32 insertions, 53 deletions
diff --git a/core/java/android/service/dreams/DreamOverlayConnectionHandler.java b/core/java/android/service/dreams/DreamOverlayConnectionHandler.java index 85a13c796ee2..bc034008f17c 100644 --- a/core/java/android/service/dreams/DreamOverlayConnectionHandler.java +++ b/core/java/android/service/dreams/DreamOverlayConnectionHandler.java @@ -27,7 +27,6 @@ import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.ObservableServiceConnection; -import com.android.internal.util.PersistentServiceConnection; import java.util.ArrayList; import java.util.List; @@ -48,22 +47,20 @@ public final class DreamOverlayConnectionHandler { private static final int MSG_OVERLAY_CLIENT_READY = 3; private final Handler mHandler; - private final PersistentServiceConnection<IDreamOverlay> mConnection; + private final ObservableServiceConnection<IDreamOverlay> mConnection; // Retrieved Client private IDreamOverlayClient mClient; // A list of pending requests to execute on the overlay. private final List<Consumer<IDreamOverlayClient>> mConsumers = new ArrayList<>(); private final OverlayConnectionCallback mCallback; + private final Runnable mOnDisconnected; DreamOverlayConnectionHandler( Context context, Looper looper, Intent serviceIntent, - int minConnectionDurationMs, - int maxReconnectAttempts, - int baseReconnectDelayMs) { - this(context, looper, serviceIntent, minConnectionDurationMs, maxReconnectAttempts, - baseReconnectDelayMs, new Injector()); + Runnable onDisconnected) { + this(context, looper, serviceIntent, onDisconnected, new Injector()); } @VisibleForTesting @@ -71,20 +68,15 @@ public final class DreamOverlayConnectionHandler { Context context, Looper looper, Intent serviceIntent, - int minConnectionDurationMs, - int maxReconnectAttempts, - int baseReconnectDelayMs, + Runnable onDisconnected, Injector injector) { mCallback = new OverlayConnectionCallback(); mHandler = new Handler(looper, new OverlayHandlerCallback()); + mOnDisconnected = onDisconnected; mConnection = injector.buildConnection( context, mHandler, - serviceIntent, - minConnectionDurationMs, - maxReconnectAttempts, - baseReconnectDelayMs - ); + serviceIntent); } /** @@ -201,10 +193,14 @@ public final class DreamOverlayConnectionHandler { @Override public void onDisconnected(ObservableServiceConnection<IDreamOverlay> connection, int reason) { + Log.i(TAG, "Dream overlay disconnected, reason: " + reason); mClient = null; // Cancel any pending messages about the overlay being ready, since it is no // longer ready. mHandler.removeMessages(MSG_OVERLAY_CLIENT_READY); + if (mOnDisconnected != null) { + mOnDisconnected.run(); + } } } @@ -217,25 +213,18 @@ public final class DreamOverlayConnectionHandler { * Returns milliseconds since boot, not counting time spent in deep sleep. Can be overridden * in tests with a fake clock. */ - public PersistentServiceConnection<IDreamOverlay> buildConnection( + public ObservableServiceConnection<IDreamOverlay> buildConnection( Context context, Handler handler, - Intent serviceIntent, - int minConnectionDurationMs, - int maxReconnectAttempts, - int baseReconnectDelayMs) { + Intent serviceIntent) { final Executor executor = handler::post; final int flags = Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE; - return new PersistentServiceConnection<>( + return new ObservableServiceConnection<>( context, executor, - handler, IDreamOverlay.Stub::asInterface, serviceIntent, - flags, - minConnectionDurationMs, - maxReconnectAttempts, - baseReconnectDelayMs + flags ); } } diff --git a/core/java/android/service/dreams/DreamService.java b/core/java/android/service/dreams/DreamService.java index a769643ce976..8ecb1fb4e9ad 100644 --- a/core/java/android/service/dreams/DreamService.java +++ b/core/java/android/service/dreams/DreamService.java @@ -182,6 +182,7 @@ public class DreamService extends Service implements Window.Callback { /** * The name of the dream manager service. + * * @hide */ public static final String DREAM_SERVICE = "dreams"; @@ -222,12 +223,14 @@ public class DreamService extends Service implements Window.Callback { /** * Dream category for Low Light Dream + * * @hide */ public static final int DREAM_CATEGORY_LOW_LIGHT = 1 << 0; /** * Dream category for Home Panel Dream + * * @hide */ public static final int DREAM_CATEGORY_HOME_PANEL = 1 << 1; @@ -295,7 +298,8 @@ public class DreamService extends Service implements Window.Callback { void init(Context context); /** Creates and returns the dream overlay connection */ - DreamOverlayConnectionHandler createOverlayConnection(ComponentName overlayComponent); + DreamOverlayConnectionHandler createOverlayConnection(ComponentName overlayComponent, + Runnable onDisconnected); /** Returns the {@link DreamActivity} component */ ComponentName getDreamActivityComponent(); @@ -333,16 +337,15 @@ public class DreamService extends Service implements Window.Callback { @Override public DreamOverlayConnectionHandler createOverlayConnection( - ComponentName overlayComponent) { + ComponentName overlayComponent, + Runnable onDisconnected) { final Resources resources = mContext.getResources(); return new DreamOverlayConnectionHandler( /* context= */ mContext, Looper.getMainLooper(), new Intent().setComponent(overlayComponent), - resources.getInteger(R.integer.config_minDreamOverlayDurationMs), - resources.getInteger(R.integer.config_dreamOverlayMaxReconnectAttempts), - resources.getInteger(R.integer.config_dreamOverlayReconnectTimeoutMs)); + onDisconnected); } @Override @@ -1176,7 +1179,8 @@ public class DreamService extends Service implements Window.Callback { // Connect to the overlay service if present. if (!mWindowless && overlayComponent != null) { - mOverlayConnection = mInjector.createOverlayConnection(overlayComponent); + mOverlayConnection = mInjector.createOverlayConnection(overlayComponent, + this::finish); if (!mOverlayConnection.bind()) { // Binding failed. diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index ff1f3dd2a1e1..105b09988835 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -567,14 +567,6 @@ It has been updated to affect other plug types. --> <bool name="config_keepDreamingWhenUnplugging">false</bool> - <!-- The timeout (in ms) to wait before attempting to reconnect to the dream overlay service if - it becomes disconnected --> - <integer name="config_dreamOverlayReconnectTimeoutMs">1000</integer> <!-- 1 second --> - <!-- The maximum number of times to attempt reconnecting to the dream overlay service --> - <integer name="config_dreamOverlayMaxReconnectAttempts">3</integer> - <!-- The duration after which the dream overlay connection should be considered stable --> - <integer name="config_minDreamOverlayDurationMs">10000</integer> <!-- 10 seconds --> - <!-- Auto-rotation behavior --> <!-- If true, enables auto-rotation features using the accelerometer. diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 25c356d4bf38..ae5e6e553ef1 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2299,9 +2299,6 @@ <java-symbol type="array" name="config_disabledDreamComponents" /> <java-symbol type="bool" name="config_dismissDreamOnActivityStart" /> <java-symbol type="bool" name="config_resetScreenTimeoutOnUnexpectedDreamExit" /> - <java-symbol type="integer" name="config_dreamOverlayReconnectTimeoutMs" /> - <java-symbol type="integer" name="config_dreamOverlayMaxReconnectAttempts" /> - <java-symbol type="integer" name="config_minDreamOverlayDurationMs" /> <java-symbol type="array" name="config_loggable_dream_prefixes" /> <java-symbol type="string" name="config_dozeComponent" /> <java-symbol type="string" name="enable_explore_by_touch_warning_title" /> diff --git a/services/tests/dreamservicetests/src/com/android/server/dreams/TestDreamEnvironment.java b/services/tests/dreamservicetests/src/com/android/server/dreams/TestDreamEnvironment.java index 3d03bf218557..e2b93ae3e9e7 100644 --- a/services/tests/dreamservicetests/src/com/android/server/dreams/TestDreamEnvironment.java +++ b/services/tests/dreamservicetests/src/com/android/server/dreams/TestDreamEnvironment.java @@ -205,7 +205,7 @@ public class TestDreamEnvironment { @Override public DreamOverlayConnectionHandler createOverlayConnection( - ComponentName overlayComponent) { + ComponentName overlayComponent, Runnable onDisconnected) { return mDreamOverlayConnectionHandler; } diff --git a/services/tests/mockingservicestests/src/android/service/dreams/DreamOverlayConnectionHandlerTest.java b/services/tests/mockingservicestests/src/android/service/dreams/DreamOverlayConnectionHandlerTest.java index 22d7e7300bba..3e6558532b94 100644 --- a/services/tests/mockingservicestests/src/android/service/dreams/DreamOverlayConnectionHandlerTest.java +++ b/services/tests/mockingservicestests/src/android/service/dreams/DreamOverlayConnectionHandlerTest.java @@ -49,10 +49,6 @@ import java.util.function.Consumer; @SmallTest @RunWith(AndroidJUnit4.class) public class DreamOverlayConnectionHandlerTest { - private static final int MIN_CONNECTION_DURATION_MS = 100; - private static final int MAX_RECONNECT_ATTEMPTS = 3; - private static final int BASE_RECONNECT_DELAY_MS = 50; - @Mock private Context mContext; @Mock @@ -63,6 +59,8 @@ public class DreamOverlayConnectionHandlerTest { private IDreamOverlay mOverlayService; @Mock private IDreamOverlayClient mOverlayClient; + @Mock + private Runnable mOnDisconnectRunnable; private TestLooper mTestLooper; private DreamOverlayConnectionHandler mDreamOverlayConnectionHandler; @@ -75,9 +73,7 @@ public class DreamOverlayConnectionHandlerTest { mContext, mTestLooper.getLooper(), mServiceIntent, - MIN_CONNECTION_DURATION_MS, - MAX_RECONNECT_ATTEMPTS, - BASE_RECONNECT_DELAY_MS, + mOnDisconnectRunnable, new TestInjector(mConnection)); } @@ -119,12 +115,14 @@ public class DreamOverlayConnectionHandlerTest { mTestLooper.dispatchAll(); // No client yet, so we shouldn't have executed verify(consumer, never()).accept(mOverlayClient); + verify(mOnDisconnectRunnable, never()).run(); provideClient(); // Service disconnected before looper could handle the message. disconnectService(); mTestLooper.dispatchAll(); verify(consumer, never()).accept(mOverlayClient); + verify(mOnDisconnectRunnable).run(); } @Test @@ -237,8 +235,7 @@ public class DreamOverlayConnectionHandlerTest { @Override public PersistentServiceConnection<IDreamOverlay> buildConnection(Context context, - Handler handler, Intent serviceIntent, int minConnectionDurationMs, - int maxReconnectAttempts, int baseReconnectDelayMs) { + Handler handler, Intent serviceIntent) { return mConnection; } } |