Merge "Removes complication in onMediaDataLoaded if hasActiveMedia is false." into tm-qpr-dev
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 android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -38,6 +39,9 @@ import javax.inject.Inject;
|
||||
* the media complication as appropriate
|
||||
*/
|
||||
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 boolean mAdded;
|
||||
@Override
|
||||
@@ -46,11 +50,17 @@ public class MediaDreamSentinel extends CoreStartable {
|
||||
|
||||
@Override
|
||||
public void onMediaDataRemoved(@NonNull String key) {
|
||||
final boolean hasActiveMedia = mMediaDataManager.hasActiveMedia();
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "onMediaDataRemoved(" + key + "), mAdded=" + mAdded + ", hasActiveMedia="
|
||||
+ hasActiveMedia);
|
||||
}
|
||||
|
||||
if (!mAdded) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mMediaDataManager.hasActiveMedia()) {
|
||||
if (hasActiveMedia) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -71,11 +81,24 @@ public class MediaDreamSentinel extends CoreStartable {
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mMediaDataManager.hasActiveMedia()) {
|
||||
if (!hasActiveMedia) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,13 +72,13 @@ public class MediaDreamSentinelTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComplicationAddition() {
|
||||
public void testOnMediaDataLoaded_complicationAddition() {
|
||||
final MediaDreamSentinel sentinel = new MediaDreamSentinel(mContext, mMediaDataManager,
|
||||
mDreamOverlayStateController, mMediaEntryComplication, mFeatureFlags);
|
||||
|
||||
sentinel.start();
|
||||
|
||||
final MediaDataManager.Listener listener = captureMediaDataListener();
|
||||
|
||||
when(mMediaDataManager.hasActiveMedia()).thenReturn(false);
|
||||
listener.onMediaDataLoaded(mKey, mOldKey, mData, /* immediately= */ true,
|
||||
/* receivedSmartspaceCardLatency= */ 0, /* isSsReactived= */ false);
|
||||
@@ -90,6 +90,19 @@ public class MediaDreamSentinelTest extends SysuiTestCase {
|
||||
verify(mDreamOverlayStateController).addComplication(eq(mMediaEntryComplication));
|
||||
verify(mDreamOverlayStateController, never()).addComplication(
|
||||
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);
|
||||
verify(mDreamOverlayStateController, never()).removeComplication(any());
|
||||
@@ -100,7 +113,30 @@ public class MediaDreamSentinelTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
final MediaDreamSentinel sentinel = new MediaDreamSentinel(mContext, mMediaDataManager,
|
||||
|
||||
Reference in New Issue
Block a user