summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lucas Silva <lusilva@google.com> 2024-06-18 09:04:03 -0400
committer Lucas Silva <lusilva@google.com> 2024-06-18 15:47:09 +0000
commitd2d4f0918e77e43f4dedc63ea876d021ae698c97 (patch)
tree66c5c12df3c7f81d53b25b1026c05c5079beb886
parent671b1184e4f22f4605f703d8640d8c703cc084a4 (diff)
Tie dream lifecycle to dream overlay
Currently, when the overlay terminates, we attempt to keep the dream active and restart the overlay connection. However, WindowManager seems to now remove the dream window when the overlay process dies. Therefore there is no longer a need to try to keep the dream running, and we can tie the dream lifecycle to the overlay. With this change, the dream is finished when the overlay is disconnected. This ensures that we reset the dream state if SystemUI crashes. Fixes: 343506030 Flag: EXEMPT bugfix Test: atest DreamServiceTest Test: atest DreamOverlayConnectionHandlerTest Change-Id: Ie8c3caf80b01cb1bf9d6127fe56d94d73ed59703
-rw-r--r--core/java/android/service/dreams/DreamOverlayConnectionHandler.java41
-rw-r--r--core/java/android/service/dreams/DreamService.java16
-rw-r--r--core/res/res/values/config.xml8
-rw-r--r--core/res/res/values/symbols.xml3
-rw-r--r--services/tests/dreamservicetests/src/com/android/server/dreams/TestDreamEnvironment.java2
-rw-r--r--services/tests/mockingservicestests/src/android/service/dreams/DreamOverlayConnectionHandlerTest.java15
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 3f9c819cd62f..cab77c59bcdd 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 f43351a2e456..7caeae4b69da 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 c16bd241a860..5e7a658823d8 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2298,9 +2298,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;
}
}