Merge "Removes complication in onMediaDataLoaded if hasActiveMedia is false." into tm-qpr-dev am: e91c7faf4e
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19903691 Change-Id: I8e36a9cd8ed2d2bb32dae9c545a31701b7b9c721 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -19,6 +19,7 @@ package com.android.systemui.media.dream;
|
|||||||
import static com.android.systemui.flags.Flags.MEDIA_DREAM_COMPLICATION;
|
import static com.android.systemui.flags.Flags.MEDIA_DREAM_COMPLICATION;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -38,6 +39,9 @@ import javax.inject.Inject;
|
|||||||
* the media complication as appropriate
|
* the media complication as appropriate
|
||||||
*/
|
*/
|
||||||
public class MediaDreamSentinel extends CoreStartable {
|
public class MediaDreamSentinel extends CoreStartable {
|
||||||
|
private static final String TAG = "MediaDreamSentinel";
|
||||||
|
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||||
|
|
||||||
private final MediaDataManager.Listener mListener = new MediaDataManager.Listener() {
|
private final MediaDataManager.Listener mListener = new MediaDataManager.Listener() {
|
||||||
private boolean mAdded;
|
private boolean mAdded;
|
||||||
@Override
|
@Override
|
||||||
@@ -46,11 +50,17 @@ public class MediaDreamSentinel extends CoreStartable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMediaDataRemoved(@NonNull String key) {
|
public void onMediaDataRemoved(@NonNull String key) {
|
||||||
|
final boolean hasActiveMedia = mMediaDataManager.hasActiveMedia();
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "onMediaDataRemoved(" + key + "), mAdded=" + mAdded + ", hasActiveMedia="
|
||||||
|
+ hasActiveMedia);
|
||||||
|
}
|
||||||
|
|
||||||
if (!mAdded) {
|
if (!mAdded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mMediaDataManager.hasActiveMedia()) {
|
if (hasActiveMedia) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,11 +81,24 @@ public class MediaDreamSentinel extends CoreStartable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final boolean hasActiveMedia = mMediaDataManager.hasActiveMedia();
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "onMediaDataLoaded(" + key + "), mAdded=" + mAdded + ", hasActiveMedia="
|
||||||
|
+ hasActiveMedia);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Media data can become inactive without triggering onMediaDataRemoved.
|
||||||
|
if (mAdded && !hasActiveMedia) {
|
||||||
|
mAdded = false;
|
||||||
|
mDreamOverlayStateController.removeComplication(mMediaEntryComplication);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mAdded) {
|
if (mAdded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mMediaDataManager.hasActiveMedia()) {
|
if (!hasActiveMedia) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,13 +72,13 @@ public class MediaDreamSentinelTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testComplicationAddition() {
|
public void testOnMediaDataLoaded_complicationAddition() {
|
||||||
final MediaDreamSentinel sentinel = new MediaDreamSentinel(mContext, mMediaDataManager,
|
final MediaDreamSentinel sentinel = new MediaDreamSentinel(mContext, mMediaDataManager,
|
||||||
mDreamOverlayStateController, mMediaEntryComplication, mFeatureFlags);
|
mDreamOverlayStateController, mMediaEntryComplication, mFeatureFlags);
|
||||||
|
|
||||||
sentinel.start();
|
sentinel.start();
|
||||||
|
|
||||||
final MediaDataManager.Listener listener = captureMediaDataListener();
|
final MediaDataManager.Listener listener = captureMediaDataListener();
|
||||||
|
|
||||||
when(mMediaDataManager.hasActiveMedia()).thenReturn(false);
|
when(mMediaDataManager.hasActiveMedia()).thenReturn(false);
|
||||||
listener.onMediaDataLoaded(mKey, mOldKey, mData, /* immediately= */ true,
|
listener.onMediaDataLoaded(mKey, mOldKey, mData, /* immediately= */ true,
|
||||||
/* receivedSmartspaceCardLatency= */ 0, /* isSsReactived= */ false);
|
/* receivedSmartspaceCardLatency= */ 0, /* isSsReactived= */ false);
|
||||||
@@ -90,6 +90,19 @@ public class MediaDreamSentinelTest extends SysuiTestCase {
|
|||||||
verify(mDreamOverlayStateController).addComplication(eq(mMediaEntryComplication));
|
verify(mDreamOverlayStateController).addComplication(eq(mMediaEntryComplication));
|
||||||
verify(mDreamOverlayStateController, never()).addComplication(
|
verify(mDreamOverlayStateController, never()).addComplication(
|
||||||
not(eq(mMediaEntryComplication)));
|
not(eq(mMediaEntryComplication)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnMediaDataRemoved_complicationRemoval() {
|
||||||
|
final MediaDreamSentinel sentinel = new MediaDreamSentinel(mContext, mMediaDataManager,
|
||||||
|
mDreamOverlayStateController, mMediaEntryComplication, mFeatureFlags);
|
||||||
|
sentinel.start();
|
||||||
|
|
||||||
|
final MediaDataManager.Listener listener = captureMediaDataListener();
|
||||||
|
|
||||||
|
when(mMediaDataManager.hasActiveMedia()).thenReturn(true);
|
||||||
|
listener.onMediaDataLoaded(mKey, mOldKey, mData, /* immediately= */true,
|
||||||
|
/* receivedSmartspaceCardLatency= */0, /* isSsReactived= */ false);
|
||||||
|
|
||||||
listener.onMediaDataRemoved(mKey);
|
listener.onMediaDataRemoved(mKey);
|
||||||
verify(mDreamOverlayStateController, never()).removeComplication(any());
|
verify(mDreamOverlayStateController, never()).removeComplication(any());
|
||||||
@@ -100,7 +113,30 @@ public class MediaDreamSentinelTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMediaDreamSentinel_mediaComplicationDisabled_doNotAddComplication() {
|
public void testOnMediaDataLoaded_complicationRemoval() {
|
||||||
|
final MediaDreamSentinel sentinel = new MediaDreamSentinel(mContext, mMediaDataManager,
|
||||||
|
mDreamOverlayStateController, mMediaEntryComplication, mFeatureFlags);
|
||||||
|
sentinel.start();
|
||||||
|
|
||||||
|
final MediaDataManager.Listener listener = captureMediaDataListener();
|
||||||
|
|
||||||
|
when(mMediaDataManager.hasActiveMedia()).thenReturn(true);
|
||||||
|
listener.onMediaDataLoaded(mKey, mOldKey, mData, /* immediately= */true,
|
||||||
|
/* receivedSmartspaceCardLatency= */0, /* isSsReactived= */ false);
|
||||||
|
verify(mDreamOverlayStateController, never()).removeComplication(any());
|
||||||
|
|
||||||
|
listener.onMediaDataLoaded(mKey, mOldKey, mData, /* immediately= */true,
|
||||||
|
/* receivedSmartspaceCardLatency= */0, /* isSsReactived= */ false);
|
||||||
|
verify(mDreamOverlayStateController, never()).removeComplication(any());
|
||||||
|
|
||||||
|
when(mMediaDataManager.hasActiveMedia()).thenReturn(false);
|
||||||
|
listener.onMediaDataLoaded(mKey, mOldKey, mData, /* immediately= */true,
|
||||||
|
/* receivedSmartspaceCardLatency= */0, /* isSsReactived= */ false);
|
||||||
|
verify(mDreamOverlayStateController).removeComplication(eq(mMediaEntryComplication));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnMediaDataLoaded_mediaComplicationDisabled_doesNotAddComplication() {
|
||||||
when(mFeatureFlags.isEnabled(MEDIA_DREAM_COMPLICATION)).thenReturn(false);
|
when(mFeatureFlags.isEnabled(MEDIA_DREAM_COMPLICATION)).thenReturn(false);
|
||||||
|
|
||||||
final MediaDreamSentinel sentinel = new MediaDreamSentinel(mContext, mMediaDataManager,
|
final MediaDreamSentinel sentinel = new MediaDreamSentinel(mContext, mMediaDataManager,
|
||||||
|
|||||||
Reference in New Issue
Block a user