Cleanup dream preview complication.

Fixed: 229089441
Bug: 226986434
Test: locally on device
Change-Id: I5f42fff23826505ca18f7b365371b433e32d2d20
This commit is contained in:
Lucas Silva
2022-04-13 10:42:44 -04:00
parent ff5064e713
commit 0b0ff3ddd9
12 changed files with 2 additions and 413 deletions

View File

@@ -2403,8 +2403,6 @@ package android.service.dreams {
public abstract class DreamOverlayService extends android.app.Service {
ctor public DreamOverlayService();
method @Nullable public final CharSequence getDreamLabel();
method public final boolean isPreviewMode();
method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent);
method public abstract void onStartDream(@NonNull android.view.WindowManager.LayoutParams);
method public final void requestExit();

View File

@@ -36,9 +36,6 @@ public abstract class DreamOverlayService extends Service {
private static final String TAG = "DreamOverlayService";
private static final boolean DEBUG = false;
private boolean mShowComplications;
private boolean mIsPreviewMode;
@Nullable
private CharSequence mDreamLabel;
private IDreamOverlay mDreamOverlay = new IDreamOverlay.Stub() {
@Override
@@ -59,8 +56,6 @@ public abstract class DreamOverlayService extends Service {
public final IBinder onBind(@NonNull Intent intent) {
mShowComplications = intent.getBooleanExtra(DreamService.EXTRA_SHOW_COMPLICATIONS,
DreamService.DEFAULT_SHOW_COMPLICATIONS);
mIsPreviewMode = intent.getBooleanExtra(DreamService.EXTRA_IS_PREVIEW, false);
mDreamLabel = intent.getCharSequenceExtra(DreamService.EXTRA_DREAM_LABEL);
return mDreamOverlay.asBinder();
}
@@ -89,19 +84,4 @@ public abstract class DreamOverlayService extends Service {
public final boolean shouldShowComplications() {
return mShowComplications;
}
/**
* Returns whether the dream is running in preview mode.
*/
public final boolean isPreviewMode() {
return mIsPreviewMode;
}
/**
* Returns the user-facing label of the currently running dream.
*/
@Nullable
public final CharSequence getDreamLabel() {
return mDreamLabel;
}
}

View File

@@ -215,18 +215,6 @@ public class DreamService extends Service implements Window.Callback {
public static final String EXTRA_SHOW_COMPLICATIONS =
"android.service.dreams.SHOW_COMPLICATIONS";
/**
* Extra containing a boolean for whether we are showing this dream in preview mode.
* @hide
*/
public static final String EXTRA_IS_PREVIEW = "android.service.dreams.IS_PREVIEW";
/**
* The user-facing label of the current dream service.
* @hide
*/
public static final String EXTRA_DREAM_LABEL = "android.service.dreams.DREAM_LABEL";
/**
* The default value for whether to show complications on the overlay.
* @hide
@@ -270,7 +258,7 @@ public class DreamService extends Service implements Window.Callback {
}
public void bind(Context context, @Nullable ComponentName overlayService,
ComponentName dreamService, boolean isPreviewMode) {
ComponentName dreamService) {
if (overlayService == null) {
return;
}
@@ -281,8 +269,6 @@ public class DreamService extends Service implements Window.Callback {
overlayIntent.setComponent(overlayService);
overlayIntent.putExtra(EXTRA_SHOW_COMPLICATIONS,
fetchShouldShowComplications(context, serviceInfo));
overlayIntent.putExtra(EXTRA_DREAM_LABEL, fetchDreamLabel(context, serviceInfo));
overlayIntent.putExtra(EXTRA_IS_PREVIEW, isPreviewMode);
context.bindService(overlayIntent,
this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE);
@@ -1007,8 +993,7 @@ public class DreamService extends Service implements Window.Callback {
mOverlayConnection.bind(
/* context= */ this,
intent.getParcelableExtra(EXTRA_DREAM_OVERLAY_COMPONENT),
new ComponentName(this, getClass()),
intent.getBooleanExtra(EXTRA_IS_PREVIEW, /* defaultValue= */ false));
new ComponentName(this, getClass()));
}
return mDreamServiceWrapper;

View File

@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2022 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dream_preview_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/dream_overlay_complication_preview_text_size"
android:textColor="@android:color/white"
android:shadowColor="@color/keyguard_shadow_color"
android:shadowRadius="?attr/shadowRadius"
android:gravity="center_vertical"
android:drawableStart="@drawable/dream_preview_back_arrow"
android:drawablePadding="@dimen/dream_overlay_complication_preview_icon_padding"/>

View File

@@ -38,7 +38,6 @@ import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dreams.complication.Complication;
import com.android.systemui.dreams.complication.DreamPreviewComplication;
import com.android.systemui.dreams.dagger.DreamOverlayComponent;
import com.android.systemui.dreams.touch.DreamOverlayTouchMonitor;
@@ -63,7 +62,6 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
// content area).
private final DreamOverlayContainerViewController mDreamOverlayContainerViewController;
private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private final DreamPreviewComplication mPreviewComplication;
private final UiEventLogger mUiEventLogger;
// A reference to the {@link Window} used to hold the dream overlay.
@@ -127,14 +125,12 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
DreamOverlayComponent.Factory dreamOverlayComponentFactory,
DreamOverlayStateController stateController,
KeyguardUpdateMonitor keyguardUpdateMonitor,
DreamPreviewComplication previewComplication,
UiEventLogger uiEventLogger) {
mContext = context;
mExecutor = executor;
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
mKeyguardUpdateMonitor.registerCallback(mKeyguardCallback);
mStateController = stateController;
mPreviewComplication = previewComplication;
mUiEventLogger = uiEventLogger;
final DreamOverlayComponent component =
@@ -159,9 +155,6 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
windowManager.removeView(mWindow.getDecorView());
}
mStateController.setOverlayActive(false);
mPreviewComplication.setDreamLabel(null);
mStateController.removeComplication(mPreviewComplication);
mStateController.setPreviewMode(false);
mDestroyed = true;
super.onDestroy();
}
@@ -177,11 +170,6 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
return;
}
mStateController.setShouldShowComplications(shouldShowComplications());
mStateController.setPreviewMode(isPreviewMode());
if (isPreviewMode()) {
mPreviewComplication.setDreamLabel(getDreamLabel());
mStateController.addComplication(mPreviewComplication);
}
addOverlayWindowLocked(layoutParams);
setCurrentState(Lifecycle.State.RESUMED);
mStateController.setOverlayActive(true);

View File

@@ -50,7 +50,6 @@ public class DreamOverlayStateController implements
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
public static final int STATE_DREAM_OVERLAY_ACTIVE = 1 << 0;
public static final int STATE_PREVIEW_MODE = 1 << 1;
private static final int OP_CLEAR_STATE = 1;
private static final int OP_SET_STATE = 2;
@@ -250,18 +249,4 @@ public class DreamOverlayStateController implements
mCallbacks.forEach(Callback::onAvailableComplicationTypesChanged);
});
}
/**
* Sets whether the dream is running in preview mode.
*/
public void setPreviewMode(boolean isPreviewMode) {
modifyState(isPreviewMode ? OP_SET_STATE : OP_CLEAR_STATE, STATE_PREVIEW_MODE);
}
/**
* Returns whether the dream is running in preview mode.
*/
public boolean isPreviewMode() {
return containsState(STATE_PREVIEW_MODE);
}
}

View File

@@ -1,137 +0,0 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.dreams.complication;
import static com.android.systemui.dreams.complication.dagger.DreamPreviewComplicationComponent.DREAM_LABEL;
import static com.android.systemui.dreams.complication.dagger.DreamPreviewComplicationComponent.DreamPreviewComplicationModule.DREAM_PREVIEW_COMPLICATION_LAYOUT_PARAMS;
import static com.android.systemui.dreams.complication.dagger.DreamPreviewComplicationComponent.DreamPreviewComplicationModule.DREAM_PREVIEW_COMPLICATION_VIEW;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.android.systemui.dreams.complication.dagger.DreamPreviewComplicationComponent;
import com.android.systemui.util.ViewController;
import javax.inject.Inject;
import javax.inject.Named;
/**
* Preview complication shown when user is previewing a dream.
*/
public class DreamPreviewComplication implements Complication {
DreamPreviewComplicationComponent.Factory mComponentFactory;
@Nullable
private CharSequence mDreamLabel;
/**
* Default constructor for {@link DreamPreviewComplication}.
*/
@Inject
public DreamPreviewComplication(
DreamPreviewComplicationComponent.Factory componentFactory) {
mComponentFactory = componentFactory;
}
/**
* Create {@link DreamPreviewViewHolder}.
*/
@Override
public ViewHolder createView(ComplicationViewModel model) {
return mComponentFactory.create(model, mDreamLabel).getViewHolder();
}
/**
* Sets the user-facing label for the current dream.
*/
public void setDreamLabel(@Nullable CharSequence dreamLabel) {
mDreamLabel = dreamLabel;
}
/**
* ViewHolder to contain value/logic associated with a Preview Complication View.
*/
public static class DreamPreviewViewHolder implements ViewHolder {
private final TextView mView;
private final ComplicationLayoutParams mLayoutParams;
private final DreamPreviewViewController mViewController;
@Inject
DreamPreviewViewHolder(@Named(DREAM_PREVIEW_COMPLICATION_VIEW) TextView view,
DreamPreviewViewController controller,
@Named(DREAM_PREVIEW_COMPLICATION_LAYOUT_PARAMS)
ComplicationLayoutParams layoutParams,
@Named(DREAM_LABEL) @Nullable CharSequence dreamLabel) {
mView = view;
mLayoutParams = layoutParams;
mViewController = controller;
mViewController.init();
if (!TextUtils.isEmpty(dreamLabel)) {
mView.setText(dreamLabel);
}
for (Drawable drawable : mView.getCompoundDrawablesRelative()) {
if (drawable instanceof BitmapDrawable) {
drawable.setAutoMirrored(true);
}
}
}
@Override
public View getView() {
return mView;
}
@Override
public ComplicationLayoutParams getLayoutParams() {
return mLayoutParams;
}
@Override
public int getCategory() {
return CATEGORY_SYSTEM;
}
}
/**
* ViewController to contain value/logic associated with a Preview Complication View.
*/
static class DreamPreviewViewController extends ViewController<TextView> {
private final ComplicationViewModel mViewModel;
@Inject
DreamPreviewViewController(@Named(DREAM_PREVIEW_COMPLICATION_VIEW) TextView view,
ComplicationViewModel viewModel) {
super(view);
mViewModel = viewModel;
}
@Override
protected void onViewAttached() {
mView.setOnClickListener(v -> mViewModel.exitDream());
}
@Override
protected void onViewDetached() {
mView.setOnClickListener(null);
}
}
}

View File

@@ -1,117 +0,0 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.dreams.complication.dagger;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.android.internal.util.Preconditions;
import com.android.systemui.R;
import com.android.systemui.dreams.complication.ComplicationLayoutParams;
import com.android.systemui.dreams.complication.ComplicationViewModel;
import com.android.systemui.dreams.complication.DreamPreviewComplication.DreamPreviewViewHolder;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import javax.inject.Named;
import javax.inject.Scope;
import dagger.BindsInstance;
import dagger.Module;
import dagger.Provides;
import dagger.Subcomponent;
/**
* {@link DreamPreviewComplicationComponent} is responsible for generating dependencies
* surrounding the
* Preview {@link com.android.systemui.dreams.complication.Complication}, such as the layout
* details.
*/
@Subcomponent(modules = {
DreamPreviewComplicationComponent.DreamPreviewComplicationModule.class,
})
@DreamPreviewComplicationComponent.DreamPreviewComplicationScope
public interface DreamPreviewComplicationComponent {
String DREAM_LABEL = "dream_label";
/**
* Creates {@link DreamPreviewViewHolder}.
*/
DreamPreviewViewHolder getViewHolder();
@Documented
@Retention(RUNTIME)
@Scope
@interface DreamPreviewComplicationScope {
}
/**
* Generates {@link DreamPreviewComplicationComponent}.
*/
@Subcomponent.Factory
interface Factory {
DreamPreviewComplicationComponent create(
@BindsInstance ComplicationViewModel viewModel,
@Named(DREAM_LABEL) @BindsInstance @Nullable CharSequence dreamLabel);
}
/**
* Scoped values for {@link DreamPreviewComplicationComponent}.
*/
@Module
interface DreamPreviewComplicationModule {
String DREAM_PREVIEW_COMPLICATION_VIEW = "preview_complication_view";
String DREAM_PREVIEW_COMPLICATION_LAYOUT_PARAMS = "preview_complication_layout_params";
// Order weight of insert into parent container
int INSERT_ORDER_WEIGHT = 1000;
/**
* Provides the complication view.
*/
@Provides
@DreamPreviewComplicationScope
@Named(DREAM_PREVIEW_COMPLICATION_VIEW)
static TextView provideComplicationView(LayoutInflater layoutInflater) {
return Preconditions.checkNotNull((TextView)
layoutInflater.inflate(R.layout.dream_overlay_complication_preview,
null, false),
"R.layout.dream_overlay_complication_preview did not properly inflated");
}
/**
* Provides the layout parameters for the complication view.
*/
@Provides
@DreamPreviewComplicationScope
@Named(DREAM_PREVIEW_COMPLICATION_LAYOUT_PARAMS)
static ComplicationLayoutParams provideLayoutParams() {
return new ComplicationLayoutParams(0,
ViewGroup.LayoutParams.WRAP_CONTENT,
ComplicationLayoutParams.POSITION_TOP
| ComplicationLayoutParams.POSITION_START,
ComplicationLayoutParams.DIRECTION_DOWN,
INSERT_ORDER_WEIGHT, /* snapToGuide= */ true);
}
}
}

View File

@@ -19,7 +19,6 @@ package com.android.systemui.dreams.dagger;
import android.content.Context;
import com.android.settingslib.dream.DreamBackend;
import com.android.systemui.dreams.complication.dagger.DreamPreviewComplicationComponent;
import com.android.systemui.dreams.complication.dagger.RegisteredComplicationsModule;
import dagger.Module;
@@ -33,7 +32,6 @@ import dagger.Provides;
},
subcomponents = {
DreamOverlayComponent.class,
DreamPreviewComplicationComponent.class,
})
public interface DreamModule {
/**

View File

@@ -41,7 +41,6 @@ import androidx.test.filters.SmallTest;
import com.android.internal.logging.UiEventLogger;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.dreams.complication.DreamPreviewComplication;
import com.android.systemui.dreams.dagger.DreamOverlayComponent;
import com.android.systemui.dreams.touch.DreamOverlayTouchMonitor;
import com.android.systemui.util.concurrency.FakeExecutor;
@@ -99,9 +98,6 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
@Mock
DreamOverlayStateController mStateController;
@Mock
DreamPreviewComplication mPreviewComplication;
@Mock
ViewGroup mDreamOverlayContainerViewParent;
@@ -133,7 +129,6 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
mDreamOverlayComponentFactory,
mStateController,
mKeyguardUpdateMonitor,
mPreviewComplication,
mUiEventLogger);
}
@@ -208,31 +203,6 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
assertThat(mService.shouldShowComplications()).isTrue();
}
@Test
public void testPreviewModeFalseByDefault() {
mService.onBind(new Intent());
assertThat(mService.isPreviewMode()).isFalse();
}
@Test
public void testPreviewModeSetByIntentExtra() {
final Intent intent = new Intent();
intent.putExtra(DreamService.EXTRA_IS_PREVIEW, true);
mService.onBind(intent);
assertThat(mService.isPreviewMode()).isTrue();
}
@Test
public void testDreamLabel() {
final Intent intent = new Intent();
intent.putExtra(DreamService.EXTRA_DREAM_LABEL, "TestDream");
mService.onBind(intent);
assertThat(mService.getDreamLabel()).isEqualTo("TestDream");
}
@Test
public void testDestroy() {
mService.onDestroy();

View File

@@ -82,38 +82,6 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
assertThat(stateController.isOverlayActive()).isFalse();
}
@Test
public void testStateChange_isPreviewMode() {
final DreamOverlayStateController stateController = new DreamOverlayStateController(
mExecutor);
stateController.addCallback(mCallback);
stateController.setPreviewMode(true);
mExecutor.runAllReady();
verify(mCallback).onStateChanged();
assertThat(stateController.isPreviewMode()).isTrue();
Mockito.clearInvocations(mCallback);
stateController.setPreviewMode(true);
mExecutor.runAllReady();
verify(mCallback, never()).onStateChanged();
}
@Test
public void testPreviewModeFalseByDefault() {
final DreamOverlayStateController stateController = new DreamOverlayStateController(
mExecutor);
assertThat(stateController.isPreviewMode()).isFalse();
}
@Test
public void testPreviewModeSetToTrue() {
final DreamOverlayStateController stateController = new DreamOverlayStateController(
mExecutor);
stateController.setPreviewMode(true);
assertThat(stateController.isPreviewMode()).isTrue();
}
@Test
public void testCallback() {
final DreamOverlayStateController stateController = new DreamOverlayStateController(

View File

@@ -140,7 +140,6 @@ final class DreamController {
intent.setComponent(name);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.putExtra(DreamService.EXTRA_DREAM_OVERLAY_COMPONENT, overlayComponentName);
intent.putExtra(DreamService.EXTRA_IS_PREVIEW, isPreviewMode);
try {
if (!mContext.bindServiceAsUser(intent, mCurrentDream,
Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE,