Loading core/java/android/service/dreams/DreamOverlayConnectionHandler.java +15 −26 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 Loading @@ -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); } /** Loading Loading @@ -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(); } } } Loading @@ -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 ); } } Loading core/java/android/service/dreams/DreamService.java +10 −6 Original line number Diff line number Diff line Loading @@ -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"; Loading Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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 Loading Loading @@ -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. Loading core/res/res/values/config.xml +0 −8 Original line number Diff line number Diff line Loading @@ -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. Loading core/res/res/values/symbols.xml +0 −3 Original line number Diff line number Diff line Loading @@ -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" /> Loading services/tests/dreamservicetests/src/com/android/server/dreams/TestDreamEnvironment.java +1 −1 Original line number Diff line number Diff line Loading @@ -205,7 +205,7 @@ public class TestDreamEnvironment { @Override public DreamOverlayConnectionHandler createOverlayConnection( ComponentName overlayComponent) { ComponentName overlayComponent, Runnable onDisconnected) { return mDreamOverlayConnectionHandler; } Loading Loading
core/java/android/service/dreams/DreamOverlayConnectionHandler.java +15 −26 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 Loading @@ -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); } /** Loading Loading @@ -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(); } } } Loading @@ -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 ); } } Loading
core/java/android/service/dreams/DreamService.java +10 −6 Original line number Diff line number Diff line Loading @@ -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"; Loading Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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 Loading Loading @@ -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. Loading
core/res/res/values/config.xml +0 −8 Original line number Diff line number Diff line Loading @@ -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. Loading
core/res/res/values/symbols.xml +0 −3 Original line number Diff line number Diff line Loading @@ -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" /> Loading
services/tests/dreamservicetests/src/com/android/server/dreams/TestDreamEnvironment.java +1 −1 Original line number Diff line number Diff line Loading @@ -205,7 +205,7 @@ public class TestDreamEnvironment { @Override public DreamOverlayConnectionHandler createOverlayConnection( ComponentName overlayComponent) { ComponentName overlayComponent, Runnable onDisconnected) { return mDreamOverlayConnectionHandler; } Loading