From 3f1a2f8740cda007283245d17b5de33a7771f865 Mon Sep 17 00:00:00 2001 From: Song Hu Date: Wed, 5 May 2021 17:49:15 -0700 Subject: [PATCH] Pass Intent as additional parameter in ContentSuggestionsServiceClient#notifyAction. This allows QuickShareProcessor to report share event in notifyInteraction. SystemUI side change. Test: test on local device Bug: 185423664 Change-Id: I40d9dd159694c1e03569f77a2d1090b4b42502da --- .../systemui/screenshot/ActionProxyReceiver.java | 2 +- .../systemui/screenshot/DeleteScreenshotReceiver.java | 2 +- .../ScreenshotNotificationSmartActionsProvider.java | 4 +++- .../systemui/screenshot/ScreenshotSmartActions.java | 5 +++-- .../systemui/screenshot/SmartActionsReceiver.java | 3 ++- .../systemui/screenshot/ActionProxyReceiverTest.java | 5 +++-- .../screenshot/DeleteScreenshotReceiverTest.java | 11 ++++++----- .../systemui/screenshot/SmartActionsReceiverTest.java | 5 ++++- 8 files changed, 23 insertions(+), 14 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ActionProxyReceiver.java b/packages/SystemUI/src/com/android/systemui/screenshot/ActionProxyReceiver.java index df9fc63a33f07..17e94c4b3f69b 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ActionProxyReceiver.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ActionProxyReceiver.java @@ -88,7 +88,7 @@ public class ActionProxyReceiver extends BroadcastReceiver { ? ACTION_TYPE_EDIT : ACTION_TYPE_SHARE; mScreenshotSmartActions.notifyScreenshotAction( - context, intent.getStringExtra(EXTRA_ID), actionType, false); + context, intent.getStringExtra(EXTRA_ID), actionType, false, null); } } } diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/DeleteScreenshotReceiver.java b/packages/SystemUI/src/com/android/systemui/screenshot/DeleteScreenshotReceiver.java index 35839f39b491a..8d44205bef309 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/DeleteScreenshotReceiver.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/DeleteScreenshotReceiver.java @@ -62,7 +62,7 @@ public class DeleteScreenshotReceiver extends BroadcastReceiver { }); if (intent.getBooleanExtra(EXTRA_SMART_ACTIONS_ENABLED, false)) { mScreenshotSmartActions.notifyScreenshotAction( - context, intent.getStringExtra(EXTRA_ID), ACTION_TYPE_DELETE, false); + context, intent.getStringExtra(EXTRA_ID), ACTION_TYPE_DELETE, false, null); } } } diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotNotificationSmartActionsProvider.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotNotificationSmartActionsProvider.java index 6ebab8a608875..3eafbfbf37d7a 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotNotificationSmartActionsProvider.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotNotificationSmartActionsProvider.java @@ -21,6 +21,7 @@ import static com.android.systemui.screenshot.LogConfig.logTag; import android.app.Notification; import android.content.ComponentName; +import android.content.Intent; import android.graphics.Bitmap; import android.net.Uri; import android.os.UserHandle; @@ -107,7 +108,8 @@ public class ScreenshotNotificationSmartActionsProvider { * @param action type of notification action invoked. * @param isSmartAction whether action invoked was a smart action. */ - public void notifyAction(String screenshotId, String action, boolean isSmartAction) { + public void notifyAction(String screenshotId, String action, boolean isSmartAction, + Intent intent) { if (DEBUG_ACTIONS) { Log.d(TAG, "SmartActions: notifyAction: return without notify"); } diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotSmartActions.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotSmartActions.java index 99238cd2c2676..0527818135dd4 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotSmartActions.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotSmartActions.java @@ -26,6 +26,7 @@ import android.app.ActivityManager; import android.app.Notification; import android.content.ComponentName; import android.content.Context; +import android.content.Intent; import android.graphics.Bitmap; import android.net.Uri; import android.os.Handler; @@ -165,7 +166,7 @@ public class ScreenshotSmartActions { } void notifyScreenshotAction(Context context, String screenshotId, String action, - boolean isSmartAction) { + boolean isSmartAction, Intent intent) { try { ScreenshotNotificationSmartActionsProvider provider = SystemUIFactory.getInstance().createScreenshotNotificationSmartActionsProvider( @@ -174,7 +175,7 @@ public class ScreenshotSmartActions { Log.d(TAG, String.format("%s notifyAction: %s id=%s, isSmartAction=%b", provider.getClass(), action, screenshotId, isSmartAction)); } - provider.notifyAction(screenshotId, action, isSmartAction); + provider.notifyAction(screenshotId, action, isSmartAction, intent); } catch (Throwable e) { Log.e(TAG, "Error in notifyScreenshotAction: ", e); } diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/SmartActionsReceiver.java b/packages/SystemUI/src/com/android/systemui/screenshot/SmartActionsReceiver.java index 3ad922b57c7c2..f703058f4a0fb 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/SmartActionsReceiver.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/SmartActionsReceiver.java @@ -60,6 +60,7 @@ public class SmartActionsReceiver extends BroadcastReceiver { } mScreenshotSmartActions.notifyScreenshotAction( - context, intent.getStringExtra(EXTRA_ID), actionType, true); + context, intent.getStringExtra(EXTRA_ID), actionType, true, + pendingIntent.getIntent()); } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/screenshot/ActionProxyReceiverTest.java b/packages/SystemUI/tests/src/com/android/systemui/screenshot/ActionProxyReceiverTest.java index 9a1126f2aa3d1..bfe875ccd60d5 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/screenshot/ActionProxyReceiverTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/screenshot/ActionProxyReceiverTest.java @@ -115,7 +115,8 @@ public class ActionProxyReceiverTest extends SysuiTestCase { actionProxyReceiver.onReceive(mContext, mIntent); verify(mMockScreenshotSmartActions, never()) - .notifyScreenshotAction(any(Context.class), anyString(), anyString(), anyBoolean()); + .notifyScreenshotAction(any(Context.class), anyString(), anyString(), anyBoolean(), + any(Intent.class)); } @Test @@ -128,7 +129,7 @@ public class ActionProxyReceiverTest extends SysuiTestCase { actionProxyReceiver.onReceive(mContext, mIntent); verify(mMockScreenshotSmartActions).notifyScreenshotAction( - mContext, testId, ACTION_TYPE_SHARE, false); + mContext, testId, ACTION_TYPE_SHARE, false, null); } private ActionProxyReceiver constructActionProxyReceiver(boolean withStatusBar) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/screenshot/DeleteScreenshotReceiverTest.java b/packages/SystemUI/tests/src/com/android/systemui/screenshot/DeleteScreenshotReceiverTest.java index 14c76798e0efe..664c125533d1c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/screenshot/DeleteScreenshotReceiverTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/screenshot/DeleteScreenshotReceiverTest.java @@ -81,7 +81,8 @@ public class DeleteScreenshotReceiverTest extends SysuiTestCase { verify(mMockExecutor, never()).execute(any(Runnable.class)); verify(mMockScreenshotSmartActions, never()).notifyScreenshotAction( - any(Context.class), any(String.class), any(String.class), anyBoolean()); + any(Context.class), any(String.class), any(String.class), anyBoolean(), + any(Intent.class)); } @Test @@ -112,8 +113,8 @@ public class DeleteScreenshotReceiverTest extends SysuiTestCase { } // ensure smart actions not called by default - verify(mMockScreenshotSmartActions, never()).notifyScreenshotAction( - any(Context.class), any(String.class), any(String.class), anyBoolean()); + verify(mMockScreenshotSmartActions, never()).notifyScreenshotAction(any(Context.class), + any(String.class), any(String.class), anyBoolean(), any(Intent.class)); } @Test @@ -128,8 +129,8 @@ public class DeleteScreenshotReceiverTest extends SysuiTestCase { mDeleteScreenshotReceiver.onReceive(mContext, intent); verify(mMockExecutor).execute(any(Runnable.class)); - verify(mMockScreenshotSmartActions).notifyScreenshotAction( - mContext, testId, ACTION_TYPE_DELETE, false); + verify(mMockScreenshotSmartActions).notifyScreenshotAction(mContext, testId, + ACTION_TYPE_DELETE, false, null); } private static ContentValues getFakeContentValues() { diff --git a/packages/SystemUI/tests/src/com/android/systemui/screenshot/SmartActionsReceiverTest.java b/packages/SystemUI/tests/src/com/android/systemui/screenshot/SmartActionsReceiverTest.java index 6f3a4a17a4a59..011e6b7b1071a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/screenshot/SmartActionsReceiverTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/screenshot/SmartActionsReceiverTest.java @@ -23,6 +23,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import android.app.PendingIntent; import android.content.Intent; @@ -65,12 +66,14 @@ public class SmartActionsReceiverTest extends SysuiTestCase { String testActionType = "testActionType"; mIntent.putExtra(EXTRA_ID, testId); mIntent.putExtra(EXTRA_ACTION_TYPE, testActionType); + Intent intent = new Intent(); + when(mMockPendingIntent.getIntent()).thenReturn(intent); mSmartActionsReceiver.onReceive(mContext, mIntent); verify(mMockPendingIntent).send( eq(mContext), eq(0), isNull(), isNull(), isNull(), isNull(), any(Bundle.class)); verify(mMockScreenshotSmartActions).notifyScreenshotAction( - mContext, testId, testActionType, true); + mContext, testId, testActionType, true, intent); } }