Add sliceUri in broadcast intent

Bug: 119748954
Test: robolectric
Change-Id: I24eb8d5a274be60ba3395d05d2b306e185e7dcab
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardFeatureProvider.java b/src/com/android/settings/homepage/contextualcards/ContextualCardFeatureProvider.java
index 5ebc924..b1e9d33 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardFeatureProvider.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardFeatureProvider.java
@@ -16,24 +16,21 @@
 
 package com.android.settings.homepage.contextualcards;
 
-import android.content.Context;
-
 import java.util.List;
 
 /** Feature provider for the contextual card feature. */
 public interface ContextualCardFeatureProvider {
 
     /** Homepage displays. */
-    void logHomepageDisplay(Context context, long latency);
+    void logHomepageDisplay(long latency);
 
     /** When user clicks dismiss in contextual card */
-    void logContextualCardDismiss(Context context, ContextualCard card);
+    void logContextualCardDismiss(ContextualCard card);
 
     /** After ContextualCardManager decides which cards will be displayed/hidden */
-    void logContextualCardDisplay(Context context, List<ContextualCard> showedCards,
+    void logContextualCardDisplay(List<ContextualCard> showedCards,
             List<ContextualCard> hiddenCards);
 
     /** When user clicks toggle/title area of a contextual card. */
-    void logContextualCardClick(Context context, ContextualCard card, int row,
-            int tapTarget);
+    void logContextualCardClick(ContextualCard card, int row, int tapTarget);
 }
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardFeatureProviderImpl.java b/src/com/android/settings/homepage/contextualcards/ContextualCardFeatureProviderImpl.java
index dc295fc..12590ff 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardFeatureProviderImpl.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardFeatureProviderImpl.java
@@ -51,6 +51,9 @@
     // contextual card name
     private static final String EXTRA_CONTEXTUALCARD_NAME = "name";
 
+    // contextual card uri
+    private static final String EXTRA_CONTEXTUALCARD_URI = "uri";
+
     // contextual card score
     private static final String EXTRA_CONTEXTUALCARD_SCORE = "score";
 
@@ -84,51 +87,59 @@
     // Click slider
     private static final int TARGET_SLIDER = 3;
 
+    private final Context mContext;
+
+    public ContextualCardFeatureProviderImpl(Context context) {
+        mContext = context;
+    }
+
     @Override
-    public void logHomepageDisplay(Context context, long latency) {
-        sendBroadcast(context, new Intent()
+    public void logHomepageDisplay(long latency) {
+        sendBroadcast(new Intent()
                 .putExtra(EXTRA_CONTEXTUALCARD_ACTION_TYPE, CONTEXTUAL_HOME_SHOW)
                 .putExtra(EXTRA_LATENCY, latency));
     }
 
     @Override
-    public void logContextualCardDismiss(Context context, ContextualCard card) {
+    public void logContextualCardDismiss(ContextualCard card) {
         final Intent intent = new Intent();
         intent.putExtra(EXTRA_CONTEXTUALCARD_ACTION_TYPE, CONTEXTUAL_CARD_DISMISS);
         intent.putExtra(EXTRA_CONTEXTUALCARD_NAME, card.getName());
+        intent.putExtra(EXTRA_CONTEXTUALCARD_URI, card.getSliceUri().toString());
         intent.putExtra(EXTRA_CONTEXTUALCARD_SCORE, card.getRankingScore());
-        sendBroadcast(context, intent);
+        sendBroadcast(intent);
     }
 
     @Override
-    public void logContextualCardDisplay(Context context, List<ContextualCard> visibleCards,
+    public void logContextualCardDisplay(List<ContextualCard> visibleCards,
             List<ContextualCard> hiddenCards) {
         final Intent intent = new Intent();
         intent.putExtra(EXTRA_CONTEXTUALCARD_ACTION_TYPE, CONTEXTUAL_CARD_SHOW);
         intent.putExtra(EXTRA_CONTEXTUALCARD_VISIBLE, serialize(visibleCards));
         intent.putExtra(EXTRA_CONTEXTUALCARD_HIDDEN, serialize(hiddenCards));
-        sendBroadcast(context, intent);
+        sendBroadcast(intent);
     }
 
     @Override
-    public void logContextualCardClick(Context context, ContextualCard card, int row,
+    public void logContextualCardClick(ContextualCard card, int row,
             int actionType) {
         final Intent intent = new Intent();
         intent.putExtra(EXTRA_CONTEXTUALCARD_ACTION_TYPE, CONTEXTUAL_CARD_CLICK);
         intent.putExtra(EXTRA_CONTEXTUALCARD_NAME, card.getName());
+        intent.putExtra(EXTRA_CONTEXTUALCARD_URI, card.getSliceUri().toString());
         intent.putExtra(EXTRA_CONTEXTUALCARD_SCORE, card.getRankingScore());
         intent.putExtra(EXTRA_CONTEXTUALCARD_ROW, row);
         intent.putExtra(EXTRA_CONTEXTUALCARD_TAP_TARGET, actionTypeToTapTarget(actionType));
-        sendBroadcast(context, intent);
+        sendBroadcast(intent);
     }
 
     @VisibleForTesting
-    void sendBroadcast(final Context context, final Intent intent) {
-        intent.setPackage(context.getString(R.string.config_settingsintelligence_package_name));
-        final String action = context.getString(R.string.config_settingsintelligence_log_action);
+    void sendBroadcast(final Intent intent) {
+        intent.setPackage(mContext.getString(R.string.config_settingsintelligence_package_name));
+        final String action = mContext.getString(R.string.config_settingsintelligence_log_action);
         if (!TextUtils.isEmpty(action)) {
             intent.setAction(action);
-            context.sendBroadcastAsUser(intent, UserHandle.ALL);
+            mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
         }
     }
 
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java b/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
index 71b262d..997d86b 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
@@ -149,10 +149,10 @@
             // Two large cards
             return visibleCards;
         } finally {
+            //TODO(b/121196921): Should not call this if user click dismiss
             final ContextualCardFeatureProvider contextualCardFeatureProvider =
-                    FeatureFactory.getFactory(mContext).getContextualCardFeatureProvider();
-            contextualCardFeatureProvider.logContextualCardDisplay(mContext, visibleCards,
-                    hiddenCards);
+                    FeatureFactory.getFactory(mContext).getContextualCardFeatureProvider(mContext);
+            contextualCardFeatureProvider.logContextualCardDisplay(visibleCards, hiddenCards);
         }
     }
 
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java b/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java
index 9c06beb..067de7c 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java
@@ -201,8 +201,8 @@
                     .collect(groupingBy(ContextualCard::getCardType)));
         }
         final long totalTime = System.currentTimeMillis() - mStartTime;
-        FeatureFactory.getFactory(mContext).getContextualCardFeatureProvider()
-                .logHomepageDisplay(mContext, totalTime);
+        FeatureFactory.getFactory(mContext).getContextualCardFeatureProvider(mContext)
+                .logHomepageDisplay(totalTime);
 
         mIsFirstLaunch = false;
     }
diff --git a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardController.java b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardController.java
index 8720a3c..eb062e8 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardController.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardController.java
@@ -70,8 +70,8 @@
         });
         showFeedbackDialog(card);
         final ContextualCardFeatureProvider contextualCardFeatureProvider =
-                FeatureFactory.getFactory(mContext).getContextualCardFeatureProvider();
-        contextualCardFeatureProvider.logContextualCardDismiss(mContext, card);
+                FeatureFactory.getFactory(mContext).getContextualCardFeatureProvider(mContext);
+        contextualCardFeatureProvider.logContextualCardDismiss(card);
     }
 
     @Override
diff --git a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
index 172c3b2..17e9d48 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
@@ -173,8 +173,9 @@
             if (sliceItem.getSlice().getUri().toString().startsWith(
                     card.getSliceUri().toString())) {
                 ContextualCardFeatureProvider contexualCardFeatureProvider =
-                        FeatureFactory.getFactory(mContext).getContextualCardFeatureProvider();
-                contexualCardFeatureProvider.logContextualCardClick(mContext, card,
+                        FeatureFactory.getFactory(mContext)
+                                .getContextualCardFeatureProvider(mContext);
+                contexualCardFeatureProvider.logContextualCardClick(card,
                         eventInfo.rowIndex, eventInfo.actionType);
                 break;
             }
diff --git a/src/com/android/settings/overlay/FeatureFactory.java b/src/com/android/settings/overlay/FeatureFactory.java
index 184ccc8..0320bf6 100644
--- a/src/com/android/settings/overlay/FeatureFactory.java
+++ b/src/com/android/settings/overlay/FeatureFactory.java
@@ -110,7 +110,7 @@
 
     public abstract PanelFeatureProvider getPanelFeatureProvider();
 
-    public abstract ContextualCardFeatureProvider getContextualCardFeatureProvider();
+    public abstract ContextualCardFeatureProvider getContextualCardFeatureProvider(Context context);
 
     public abstract FaceFeatureProvider getFaceFeatureProvider();
 
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.java b/src/com/android/settings/overlay/FeatureFactoryImpl.java
index 88c09d0..0232964 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.java
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.java
@@ -228,9 +228,10 @@
     }
 
     @Override
-    public ContextualCardFeatureProvider getContextualCardFeatureProvider() {
+    public ContextualCardFeatureProvider getContextualCardFeatureProvider(Context context) {
         if (mContextualCardFeatureProvider == null) {
-            mContextualCardFeatureProvider = new ContextualCardFeatureProviderImpl();
+            mContextualCardFeatureProvider = new ContextualCardFeatureProviderImpl(
+                    context.getApplicationContext());
         }
         return mContextualCardFeatureProvider;
     }
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardFeatureProviderImplTest.java
index f1bb3ed..2db7f3f 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardFeatureProviderImplTest.java
@@ -49,13 +49,13 @@
     @Before
     public void setUp() {
         mContext = spy(RuntimeEnvironment.application);
-        mImpl = new ContextualCardFeatureProviderImpl();
+        mImpl = new ContextualCardFeatureProviderImpl(mContext);
     }
 
     @Test
     public void sendBroadcast_emptyAction_notSendBroadcast() {
         final Intent intent = new Intent();
-        mImpl.sendBroadcast(mContext, intent);
+        mImpl.sendBroadcast(intent);
 
         verify(mContext, never()).sendBroadcastAsUser(intent, UserHandle.ALL);
     }
@@ -64,7 +64,7 @@
     @Config(qualifiers = "mcc999")
     public void sendBroadcast_hasAction_sendBroadcast() {
         final Intent intent = new Intent();
-        mImpl.sendBroadcast(mContext, intent);
+        mImpl.sendBroadcast(intent);
 
         verify(mContext).sendBroadcastAsUser(intent, UserHandle.ALL);
     }
@@ -72,7 +72,7 @@
     @Test
     @Config(qualifiers = "mcc999")
     public void logContextualCardDisplay_hasAction_sendBroadcast() {
-        mImpl.logContextualCardDisplay(mContext, new ArrayList<>(), new ArrayList<>());
+        mImpl.logContextualCardDisplay(new ArrayList<>(), new ArrayList<>());
 
         verify(mContext).sendBroadcastAsUser(any(Intent.class), any());
     }
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardControllerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardControllerTest.java
index 5bc3698..7e1a32c 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardControllerTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardControllerTest.java
@@ -91,8 +91,7 @@
         cr.close();
 
         assertThat(qryDismissed).isEqualTo(1);
-        verify(mFeatureFactory.mContextualCardFeatureProvider).logContextualCardDismiss(
-                mContext, card);
+        verify(mFeatureFactory.mContextualCardFeatureProvider).logContextualCardDismiss(card);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
index e0b8646..1d8e2cb 100644
--- a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
@@ -198,8 +198,7 @@
         return panelFeatureProvider;
     }
 
-    @Override
-    public ContextualCardFeatureProvider getContextualCardFeatureProvider() {
+    public ContextualCardFeatureProvider getContextualCardFeatureProvider(Context context) {
         return mContextualCardFeatureProvider;
     }