diff options
| author | 2021-03-18 14:22:15 +0000 | |
|---|---|---|
| committer | 2021-03-18 14:22:15 +0000 | |
| commit | 4d37598cbcef9a0496aede81ac9ba3d16dbd2bf8 (patch) | |
| tree | b2bc4ed67f376ac140818b219256e8aa24d04925 | |
| parent | 291a7046306f2771190c6adcc11f9aabb13aefca (diff) | |
| parent | d5a379653b024aaabe62974ba542ea280abc4455 (diff) | |
Merge "Prompt People tile on marking as priority" into sc-dev
20 files changed, 743 insertions, 246 deletions
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index e0097df62078..d3d7a95dd32c 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -602,6 +602,9 @@ android:resource="@xml/people_space_widget_info" /> </receiver> + <receiver android:name=".people.widget.PeopleSpaceWidgetPinnedReceiver" + android:enabled="true"/> + <!-- Widget service --> <service android:name=".people.widget.PeopleSpaceWidgetService" android:permission="android.permission.BIND_REMOTEVIEWS" diff --git a/packages/SystemUI/src/com/android/systemui/Prefs.java b/packages/SystemUI/src/com/android/systemui/Prefs.java index f210d508907c..f28d1137f3e7 100644 --- a/packages/SystemUI/src/com/android/systemui/Prefs.java +++ b/packages/SystemUI/src/com/android/systemui/Prefs.java @@ -74,7 +74,7 @@ public final class Prefs { Key.HAS_SEEN_ODI_CAPTIONS_TOOLTIP, Key.HAS_SEEN_REVERSE_BOTTOM_SHEET, Key.CONTROLS_STRUCTURE_SWIPE_TOOLTIP_COUNT, - Key.HAS_SEEN_PRIORITY_ONBOARDING + Key.HAS_SEEN_PRIORITY_ONBOARDING_IN_S }) // TODO: annotate these with their types so {@link PrefsCommandLine} can know how to set them public @interface Key { @@ -124,7 +124,7 @@ public final class Prefs { String HAS_SEEN_REVERSE_BOTTOM_SHEET = "HasSeenReverseBottomSheet"; String CONTROLS_STRUCTURE_SWIPE_TOOLTIP_COUNT = "ControlsStructureSwipeTooltipCount"; /** Tracks whether the user has seen the onboarding screen for priority conversations */ - String HAS_SEEN_PRIORITY_ONBOARDING = "HasUserSeenPriorityOnboarding"; + String HAS_SEEN_PRIORITY_ONBOARDING_IN_S = "HasUserSeenPriorityOnboardingInS"; } public static boolean getBoolean(Context context, @Key String key, boolean defaultValue) { diff --git a/packages/SystemUI/src/com/android/systemui/dagger/DefaultBroadcastReceiverBinder.java b/packages/SystemUI/src/com/android/systemui/dagger/DefaultBroadcastReceiverBinder.java index 25d02a66d56d..2a7023a58637 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/DefaultBroadcastReceiverBinder.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/DefaultBroadcastReceiverBinder.java @@ -19,6 +19,7 @@ package com.android.systemui.dagger; import android.content.BroadcastReceiver; import com.android.systemui.media.dialog.MediaOutputDialogReceiver; +import com.android.systemui.people.widget.PeopleSpaceWidgetPinnedReceiver; import com.android.systemui.screenshot.ActionProxyReceiver; import com.android.systemui.screenshot.DeleteScreenshotReceiver; import com.android.systemui.screenshot.SmartActionsReceiver; @@ -69,4 +70,13 @@ public abstract class DefaultBroadcastReceiverBinder { public abstract BroadcastReceiver bindMediaOutputDialogReceiver( MediaOutputDialogReceiver broadcastReceiver); + /** + * + */ + @Binds + @IntoMap + @ClassKey(PeopleSpaceWidgetPinnedReceiver.class) + public abstract BroadcastReceiver bindPeopleSpaceWidgetPinnedReceiver( + PeopleSpaceWidgetPinnedReceiver broadcastReceiver); + } diff --git a/packages/SystemUI/src/com/android/systemui/people/PeopleProvider.java b/packages/SystemUI/src/com/android/systemui/people/PeopleProvider.java index 6295692c788c..59329d1b091f 100644 --- a/packages/SystemUI/src/com/android/systemui/people/PeopleProvider.java +++ b/packages/SystemUI/src/com/android/systemui/people/PeopleProvider.java @@ -16,9 +16,7 @@ package com.android.systemui.people; -import android.app.people.ConversationChannel; import android.app.people.IPeopleManager; -import android.app.people.PeopleSpaceTile; import android.content.ContentProvider; import android.content.ContentValues; import android.content.Context; @@ -33,13 +31,16 @@ import android.os.UserHandle; import android.util.Log; import android.widget.RemoteViews; +import com.android.systemui.Dependency; import com.android.systemui.shared.system.PeopleProviderUtils; +import com.android.systemui.statusbar.notification.NotificationEntryManager; /** API that returns a People Tile preview. */ public class PeopleProvider extends ContentProvider { LauncherApps mLauncherApps; IPeopleManager mPeopleManager; + NotificationEntryManager mNotificationEntryManager; private static final String TAG = "PeopleProvider"; private static final boolean DEBUG = PeopleSpaceUtils.DEBUG; @@ -57,18 +58,6 @@ public class PeopleProvider extends ContentProvider { throw new IllegalArgumentException("Invalid method"); } - // If services are not set as mocks in tests, fetch them now. - mPeopleManager = mPeopleManager != null ? mPeopleManager - : IPeopleManager.Stub.asInterface( - ServiceManager.getService(Context.PEOPLE_SERVICE)); - mLauncherApps = mLauncherApps != null ? mLauncherApps - : getContext().getSystemService(LauncherApps.class); - - if (mPeopleManager == null || mLauncherApps == null) { - Log.w(TAG, "Null system managers"); - return null; - } - if (extras == null) { Log.w(TAG, "Extras can't be null"); throw new IllegalArgumentException("Extras can't be null"); @@ -94,24 +83,22 @@ public class PeopleProvider extends ContentProvider { throw new IllegalArgumentException("Null user handle"); } - ConversationChannel channel; - try { - channel = mPeopleManager.getConversation( - packageName, userHandle.getIdentifier(), shortcutId); - } catch (Exception e) { - Log.w(TAG, "Exception getting tiles: " + e); - return null; - } - PeopleSpaceTile tile = PeopleSpaceUtils.getTile(channel, mLauncherApps); + // If services are not set as mocks in tests, fetch them now. + mPeopleManager = mPeopleManager != null ? mPeopleManager + : IPeopleManager.Stub.asInterface( + ServiceManager.getService(Context.PEOPLE_SERVICE)); + mLauncherApps = mLauncherApps != null ? mLauncherApps + : getContext().getSystemService(LauncherApps.class); + mNotificationEntryManager = mNotificationEntryManager != null ? mNotificationEntryManager + : Dependency.get(NotificationEntryManager.class); - if (tile == null) { - if (DEBUG) Log.i(TAG, "No tile was returned"); + RemoteViews view = PeopleSpaceUtils.getPreview(getContext(), mPeopleManager, mLauncherApps, + mNotificationEntryManager, shortcutId, userHandle, packageName); + if (view == null) { + if (DEBUG) Log.d(TAG, "No preview available for shortcutId: " + shortcutId); return null; } - - if (DEBUG) Log.i(TAG, "Returning tile preview for shortcutId: " + shortcutId); final Bundle bundle = new Bundle(); - RemoteViews view = PeopleSpaceUtils.createRemoteViews(getContext(), tile, 0, bundle); bundle.putParcelable(PeopleProviderUtils.RESPONSE_KEY_REMOTE_VIEWS, view); return bundle; } diff --git a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceActivity.java b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceActivity.java index 378e49deb699..09461c36a27b 100644 --- a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceActivity.java +++ b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceActivity.java @@ -35,7 +35,6 @@ import android.view.ViewGroup; import com.android.systemui.R; import com.android.systemui.people.widget.PeopleSpaceWidgetManager; -import com.android.systemui.people.widget.PeopleTileKey; import com.android.systemui.statusbar.notification.NotificationEntryManager; import java.util.List; @@ -62,9 +61,12 @@ public class PeopleSpaceActivity extends Activity { private boolean mShowSingleConversation; @Inject - public PeopleSpaceActivity(NotificationEntryManager notificationEntryManager) { + public PeopleSpaceActivity(NotificationEntryManager notificationEntryManager, + PeopleSpaceWidgetManager peopleSpaceWidgetManager) { super(); mNotificationEntryManager = notificationEntryManager; + mPeopleSpaceWidgetManager = peopleSpaceWidgetManager; + } @Override @@ -78,7 +80,6 @@ public class PeopleSpaceActivity extends Activity { mPackageManager = getPackageManager(); mPeopleManager = IPeopleManager.Stub.asInterface( ServiceManager.getService(Context.PEOPLE_SERVICE)); - mPeopleSpaceWidgetManager = new PeopleSpaceWidgetManager(mContext); mLauncherApps = mContext.getSystemService(LauncherApps.class); setTileViewsWithPriorityConversations(); mAppWidgetId = getIntent().getIntExtra(EXTRA_APPWIDGET_ID, @@ -139,9 +140,7 @@ public class PeopleSpaceActivity extends Activity { + mAppWidgetId); } } - PeopleTileKey key = new PeopleTileKey( - tile.getId(), tile.getUserHandle().getIdentifier(), tile.getPackageName()); - mPeopleSpaceWidgetManager.addNewWidget(mAppWidgetId, key); + mPeopleSpaceWidgetManager.addNewWidget(mAppWidgetId, tile); finishActivity(); } diff --git a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java index e07e9cff4e7d..51638798277f 100644 --- a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java +++ b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java @@ -59,6 +59,8 @@ import android.icu.util.MeasureUnit; import android.net.Uri; import android.os.Bundle; import android.os.Parcelable; +import android.os.ServiceManager; +import android.os.UserHandle; import android.provider.ContactsContract; import android.provider.Settings; import android.service.notification.ConversationChannelWrapper; @@ -92,7 +94,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Date; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -207,92 +208,6 @@ public class PeopleSpaceUtils { return tiles; } - /** - * Updates {@code appWidgetIds} with their associated conversation stored, handling a - * notification being posted or removed. - */ - public static void updateSingleConversationWidgets(Context context, int[] appWidgetIds, - AppWidgetManager appWidgetManager, IPeopleManager peopleManager) { - Map<Integer, PeopleSpaceTile> widgetIdToTile = new HashMap<>(); - for (int appWidgetId : appWidgetIds) { - PeopleSpaceTile tile = getPeopleSpaceTile( - context, appWidgetId, appWidgetManager, peopleManager); - if (tile == null) { - if (DEBUG) Log.d(TAG, "Matching conversation not found for shortcut ID"); - //TODO: Delete app widget id when crash is fixed (b/172932636) - continue; - } - Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId); - updateAppWidgetViews(appWidgetManager, context, appWidgetId, tile, options); - widgetIdToTile.put(appWidgetId, tile); - } - getBirthdaysOnBackgroundThread(context, appWidgetManager, widgetIdToTile, appWidgetIds); - } - - /** - * Returns a {@link PeopleSpaceTile} based on the {@code appWidgetId}. If the PeopleSpaceTile - * isn't cached, store it in AppWidgetOptions. - */ - @Nullable - public static PeopleSpaceTile getPeopleSpaceTile(Context context, int appWidgetId, - AppWidgetManager appWidgetManager, IPeopleManager peopleManager) { - // First, check if tile is cached in AppWidgetOptions. - PeopleSpaceTile tile = AppWidgetOptionsHelper.getPeopleTile(appWidgetManager, appWidgetId); - if (tile != null) { - if (DEBUG) Log.d(TAG, "People Tile is cached for widget: " + appWidgetId); - return tile; - } - - // If not, we get the PeopleTileKey from SharedPreferences, retrieve the Conversation from - // persisted storage, and cache it in AppWidgetOptions. - SharedPreferences widgetSp = context.getSharedPreferences( - String.valueOf(appWidgetId), - Context.MODE_PRIVATE); - PeopleTileKey sharedPreferencesKey = new PeopleTileKey( - widgetSp.getString(SHORTCUT_ID, EMPTY_STRING), - widgetSp.getInt(USER_ID, INVALID_USER_ID), - widgetSp.getString(PACKAGE_NAME, EMPTY_STRING)); - - if (!sharedPreferencesKey.isValid()) { - Log.e(TAG, "Cannot find shortcut info for widgetId: " + appWidgetId); - return null; - } - - if (DEBUG) Log.d(TAG, "PeopleTile key is present in sharedPreferences: " + appWidgetId); - // If tile is null, we need to retrieve from persisted storage. - return getPeopleTileFromPersistentStorage(context, sharedPreferencesKey, peopleManager); - } - - /** - * Returns a {@link PeopleSpaceTile} based on {@link ConversationChannel} returned by - * {@link IPeopleManager}. - */ - public static PeopleSpaceTile getPeopleTileFromPersistentStorage(Context context, - PeopleTileKey peopleTileKey, IPeopleManager peopleManager) { - try { - if (DEBUG) Log.d(TAG, "Retrieving Tile from storage: " + peopleTileKey.toString()); - LauncherApps launcherApps = context.getSystemService(LauncherApps.class); - if (launcherApps == null) { - Log.d(TAG, "LauncherApps is null"); - return null; - } - - ConversationChannel channel = peopleManager.getConversation( - peopleTileKey.getPackageName(), - peopleTileKey.getUserId(), - peopleTileKey.getShortcutId()); - if (channel == null) { - Log.d(TAG, "Could not retrieve conversation from storage"); - return null; - } - - return new PeopleSpaceTile.Builder(channel, launcherApps).build(); - } catch (Exception e) { - Log.e(TAG, "Failed to retrieve conversation for tile: " + e); - return null; - } - } - /** Returns stored widgets for the conversation specified. */ public static Set<String> getStoredWidgetIds(SharedPreferences sp, PeopleTileKey key) { if (!key.isValid()) { @@ -347,6 +262,14 @@ public class PeopleSpaceUtils { widgetEditor.apply(); } + /** Augments a single {@link PeopleSpaceTile} with notification content, if one is present. */ + public static PeopleSpaceTile augmentSingleTileFromVisibleNotifications(Context context, + PeopleSpaceTile tile, NotificationEntryManager notificationEntryManager) { + List<PeopleSpaceTile> augmentedTile = augmentTilesFromVisibleNotifications( + context, Arrays.asList(tile), notificationEntryManager); + return augmentedTile.get(0); + } + static List<PeopleSpaceTile> augmentTilesFromVisibleNotifications(Context context, List<PeopleSpaceTile> tiles, NotificationEntryManager notificationEntryManager) { if (notificationEntryManager == null) { @@ -914,7 +837,7 @@ public class PeopleSpaceUtils { } /** Calls to retrieve birthdays on a background thread. */ - private static void getBirthdaysOnBackgroundThread(Context context, + public static void getBirthdaysOnBackgroundThread(Context context, AppWidgetManager appWidgetManager, Map<Integer, PeopleSpaceTile> peopleSpaceTiles, int[] appWidgetIds) { ThreadUtils.postOnBackgroundThread( @@ -992,7 +915,8 @@ public class PeopleSpaceUtils { removeBirthdayStatusIfPresent(appWidgetManager, context, storedTile, appWidgetId); } - private static void updateAppWidgetViews(AppWidgetManager appWidgetManager, + /** Updates the current widget view with provided {@link PeopleSpaceTile}. */ + public static void updateAppWidgetViews(AppWidgetManager appWidgetManager, Context context, int appWidgetId, PeopleSpaceTile tile, Bundle options) { if (DEBUG) Log.d(TAG, "Widget: " + appWidgetId + ", " + tile.getUserName()); RemoteViews views = createRemoteViews(context, tile, appWidgetId, options); @@ -1049,6 +973,43 @@ public class PeopleSpaceUtils { return lookupKeysWithBirthdaysToday; } + /** + * Returns a {@link RemoteViews} preview of a Conversation's People Tile. Returns null if one + * is not available. + */ + public static RemoteViews getPreview(Context context, IPeopleManager peopleManager, + LauncherApps launcherApps, NotificationEntryManager notificationEntryManager, + String shortcutId, UserHandle userHandle, String packageName) { + peopleManager = (peopleManager != null) ? peopleManager : IPeopleManager.Stub.asInterface( + ServiceManager.getService(Context.PEOPLE_SERVICE)); + launcherApps = (launcherApps != null) ? launcherApps + : context.getSystemService(LauncherApps.class); + if (peopleManager == null || launcherApps == null) { + return null; + } + + ConversationChannel channel; + try { + channel = peopleManager.getConversation( + packageName, userHandle.getIdentifier(), shortcutId); + } catch (Exception e) { + Log.w(TAG, "Exception getting tiles: " + e); + return null; + } + PeopleSpaceTile tile = PeopleSpaceUtils.getTile(channel, launcherApps); + + if (tile == null) { + if (DEBUG) Log.i(TAG, "No tile was returned"); + return null; + } + PeopleSpaceTile augmentedTile = augmentSingleTileFromVisibleNotifications( + context, tile, notificationEntryManager); + + if (DEBUG) Log.i(TAG, "Returning tile preview for shortcutId: " + shortcutId); + Bundle bundle = new Bundle(); + return PeopleSpaceUtils.createRemoteViews(context, augmentedTile, 0, bundle); + } + /** Returns the userId associated with a {@link PeopleSpaceTile} */ public static int getUserId(PeopleSpaceTile tile) { return tile.getUserHandle().getIdentifier(); diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java index 30eb2ac160c7..fa7b7b33dff6 100644 --- a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java +++ b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java @@ -22,11 +22,13 @@ import static com.android.systemui.people.PeopleSpaceUtils.PACKAGE_NAME; import static com.android.systemui.people.PeopleSpaceUtils.SHORTCUT_ID; import static com.android.systemui.people.PeopleSpaceUtils.USER_ID; import static com.android.systemui.people.PeopleSpaceUtils.augmentTileFromNotification; -import static com.android.systemui.people.PeopleSpaceUtils.getPeopleSpaceTile; import static com.android.systemui.people.PeopleSpaceUtils.getStoredWidgetIds; import static com.android.systemui.people.PeopleSpaceUtils.updateAppWidgetOptionsAndView; +import static com.android.systemui.people.PeopleSpaceUtils.updateAppWidgetViews; +import android.annotation.Nullable; import android.app.NotificationChannel; +import android.app.PendingIntent; import android.app.Person; import android.app.people.ConversationChannel; import android.app.people.IPeopleManager; @@ -47,14 +49,17 @@ import android.provider.Settings; import android.service.notification.NotificationListenerService; import android.service.notification.StatusBarNotification; import android.util.Log; +import android.widget.RemoteViews; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.UiEventLoggerImpl; +import com.android.systemui.Dependency; import com.android.systemui.people.PeopleSpaceUtils; import com.android.systemui.statusbar.NotificationListener; import com.android.systemui.statusbar.NotificationListener.NotificationHandler; +import com.android.systemui.statusbar.notification.NotificationEntryManager; import java.util.Collections; import java.util.HashMap; @@ -78,6 +83,7 @@ public class PeopleSpaceWidgetManager { private IPeopleManager mIPeopleManager; private SharedPreferences mSharedPrefs; private PeopleManager mPeopleManager; + private NotificationEntryManager mNotificationEntryManager; public UiEventLogger mUiEventLogger = new UiEventLoggerImpl(); @GuardedBy("mLock") public static Map<PeopleTileKey, PeopleSpaceWidgetProvider.TileConversationListener> @@ -93,6 +99,7 @@ public class PeopleSpaceWidgetManager { mLauncherApps = context.getSystemService(LauncherApps.class); mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); mPeopleManager = mContext.getSystemService(PeopleManager.class); + mNotificationEntryManager = Dependency.get(NotificationEntryManager.class); } /** @@ -101,11 +108,13 @@ public class PeopleSpaceWidgetManager { @VisibleForTesting protected void setAppWidgetManager( AppWidgetManager appWidgetManager, IPeopleManager iPeopleManager, - PeopleManager peopleManager, LauncherApps launcherApps) { + PeopleManager peopleManager, LauncherApps launcherApps, + NotificationEntryManager notificationEntryManager) { mAppWidgetManager = appWidgetManager; mIPeopleManager = iPeopleManager; mPeopleManager = peopleManager; mLauncherApps = launcherApps; + mNotificationEntryManager = notificationEntryManager; } /** @@ -124,8 +133,7 @@ public class PeopleSpaceWidgetManager { Settings.Global.PEOPLE_SPACE_CONVERSATION_TYPE, 0) == 0; if (showSingleConversation) { synchronized (mLock) { - PeopleSpaceUtils.updateSingleConversationWidgets( - mContext, widgetIds, mAppWidgetManager, mIPeopleManager); + updateSingleConversationWidgets(widgetIds); } } } catch (Exception e) { @@ -134,6 +142,85 @@ public class PeopleSpaceWidgetManager { } /** + * Updates {@code appWidgetIds} with their associated conversation stored, handling a + * notification being posted or removed. + */ + public void updateSingleConversationWidgets(int[] appWidgetIds) { + Map<Integer, PeopleSpaceTile> widgetIdToTile = new HashMap<>(); + for (int appWidgetId : appWidgetIds) { + PeopleSpaceTile tile = getTileForExistingWidget(appWidgetId); + if (tile == null) { + if (DEBUG) Log.d(TAG, "Matching conversation not found for shortcut ID"); + //TODO: Delete app widget id when crash is fixed (b/172932636) + continue; + } + Bundle options = mAppWidgetManager.getAppWidgetOptions(appWidgetId); + updateAppWidgetViews(mAppWidgetManager, mContext, appWidgetId, tile, options); + widgetIdToTile.put(appWidgetId, tile); + } + PeopleSpaceUtils.getBirthdaysOnBackgroundThread( + mContext, mAppWidgetManager, widgetIdToTile, appWidgetIds); + } + + /** + * Returns a {@link PeopleSpaceTile} based on the {@code appWidgetId}. + * Widget already exists, so fetch {@link PeopleTileKey} from {@link SharedPreferences}. + */ + @Nullable + public PeopleSpaceTile getTileForExistingWidget(int appWidgetId) { + // First, check if tile is cached in AppWidgetOptions. + PeopleSpaceTile tile = AppWidgetOptionsHelper.getPeopleTile(mAppWidgetManager, appWidgetId); + if (tile != null) { + if (DEBUG) Log.d(TAG, "People Tile is cached for widget: " + appWidgetId); + return tile; + } + + // If tile is null, we need to retrieve from persistent storage. + if (DEBUG) Log.d(TAG, "Fetching key from sharedPreferences: " + appWidgetId); + SharedPreferences widgetSp = mContext.getSharedPreferences( + String.valueOf(appWidgetId), + Context.MODE_PRIVATE); + PeopleTileKey key = new PeopleTileKey( + widgetSp.getString(SHORTCUT_ID, EMPTY_STRING), + widgetSp.getInt(USER_ID, INVALID_USER_ID), + widgetSp.getString(PACKAGE_NAME, EMPTY_STRING)); + + return getTileFromPersistentStorage(key); + } + + /** + * Returns a {@link PeopleSpaceTile} based on the {@code appWidgetId}. + * If a {@link PeopleTileKey} is not provided, fetch one from {@link SharedPreferences}. + */ + @Nullable + public PeopleSpaceTile getTileFromPersistentStorage(PeopleTileKey key) { + if (!key.isValid()) { + Log.e(TAG, "PeopleTileKey invalid: " + key); + return null; + } + + if (mIPeopleManager == null || mLauncherApps == null) { + Log.d(TAG, "System services are null"); + return null; + } + + try { + if (DEBUG) Log.d(TAG, "Retrieving Tile from storage: " + key.toString()); + ConversationChannel channel = mIPeopleManager.getConversation( + key.getPackageName(), key.getUserId(), key.getShortcutId()); + if (channel == null) { + Log.d(TAG, "Could not retrieve conversation from storage"); + return null; + } + + return new PeopleSpaceTile.Builder(channel, mLauncherApps).build(); + } catch (Exception e) { + Log.e(TAG, "Failed to retrieve conversation for tile: " + e); + return null; + } + } + + /** * Check if any existing People tiles match the incoming notification change, and store the * change in the tile if so. */ @@ -201,8 +288,7 @@ public class PeopleSpaceWidgetManager { */ private void updateStorageAndViewWithConversationData(ConversationChannel conversation, int appWidgetId) { - PeopleSpaceTile storedTile = getPeopleSpaceTile( - mContext, appWidgetId, mAppWidgetManager, mIPeopleManager); + PeopleSpaceTile storedTile = getTileForExistingWidget(appWidgetId); if (storedTile == null) { if (DEBUG) Log.d(TAG, "Could not find stored tile to add conversation to"); return; @@ -234,8 +320,7 @@ public class PeopleSpaceWidgetManager { StatusBarNotification sbn, PeopleSpaceUtils.NotificationAction notificationAction, int appWidgetId) { - PeopleSpaceTile storedTile = getPeopleSpaceTile( - mContext, appWidgetId, mAppWidgetManager, mIPeopleManager); + PeopleSpaceTile storedTile = getTileForExistingWidget(appWidgetId); if (storedTile == null) { if (DEBUG) Log.d(TAG, "Could not find stored tile to add notification to"); return; @@ -332,28 +417,51 @@ public class PeopleSpaceWidgetManager { Log.d(TAG, "PeopleTileKey was present in Options, shortcutId: " + optionsKey.getShortcutId()); } - addNewWidget(appWidgetId, optionsKey); AppWidgetOptionsHelper.removePeopleTileKey(mAppWidgetManager, appWidgetId); + addNewWidget(appWidgetId, optionsKey); } // Update views for new widget dimensions. updateWidgets(new int[]{appWidgetId}); } - /** Adds{@code tile} mapped to {@code appWidgetId}. */ + /** Adds a widget based on {@code key} mapped to {@code appWidgetId}. */ public void addNewWidget(int appWidgetId, PeopleTileKey key) { + if (DEBUG) Log.d(TAG, "addNewWidget called with key for appWidgetId: " + appWidgetId); + PeopleSpaceTile tile = getTileFromPersistentStorage(key); + tile = PeopleSpaceUtils.augmentSingleTileFromVisibleNotifications( + mContext, tile, mNotificationEntryManager); + if (tile != null) { + addNewWidget(appWidgetId, tile); + } + } + + /** + * Adds a widget based on {@code tile} mapped to {@code appWidgetId}. + * The tile provided should already be augmented. + */ + public void addNewWidget(int appWidgetId, PeopleSpaceTile tile) { + if (DEBUG) Log.d(TAG, "addNewWidget called for appWidgetId: " + appWidgetId); + if (tile == null) { + return; + } + mUiEventLogger.log(PeopleSpaceUtils.PeopleSpaceWidgetEvent.PEOPLE_SPACE_WIDGET_ADDED); synchronized (mLock) { - if (DEBUG) Log.d(TAG, "Add storage for : " + key.getShortcutId()); + if (DEBUG) Log.d(TAG, "Add storage for : " + tile.getId()); + PeopleTileKey key = new PeopleTileKey(tile); PeopleSpaceUtils.setSharedPreferencesStorageForTile(mContext, key, appWidgetId); } try { - if (DEBUG) Log.d(TAG, "Caching shortcut for PeopleTile: " + key.getShortcutId()); - mLauncherApps.cacheShortcuts(key.getPackageName(), - Collections.singletonList(key.getShortcutId()), - UserHandle.of(key.getUserId()), LauncherApps.FLAG_CACHE_PEOPLE_TILE_SHORTCUTS); + if (DEBUG) Log.d(TAG, "Caching shortcut for PeopleTile: " + tile.getId()); + mLauncherApps.cacheShortcuts(tile.getPackageName(), + Collections.singletonList(tile.getId()), + tile.getUserHandle(), LauncherApps.FLAG_CACHE_PEOPLE_TILE_SHORTCUTS); } catch (Exception e) { Log.w(TAG, "Exception caching shortcut:" + e); } + + PeopleSpaceUtils.updateAppWidgetOptionsAndView( + mAppWidgetManager, mContext, appWidgetId, tile); PeopleSpaceWidgetProvider provider = new PeopleSpaceWidgetProvider(); provider.onUpdate(mContext, mAppWidgetManager, new int[]{appWidgetId}); } @@ -452,4 +560,28 @@ public class PeopleSpaceWidgetManager { Log.d(TAG, "Exception uncaching shortcut:" + e); } } + + /** + * Builds a request to pin a People Tile app widget, with a preview and storing necessary + * information as the callback. + */ + public boolean requestPinAppWidget(ShortcutInfo shortcutInfo) { + if (DEBUG) Log.d(TAG, "Requesting pin widget, shortcutId: " + shortcutInfo.getId()); + + RemoteViews widgetPreview = PeopleSpaceUtils.getPreview(mContext, mIPeopleManager, + mLauncherApps, mNotificationEntryManager, shortcutInfo.getId(), + shortcutInfo.getUserHandle(), shortcutInfo.getPackage()); + if (widgetPreview == null) { + Log.w(TAG, "Skipping pinning widget: no tile for shortcutId: " + shortcutInfo.getId()); + return false; + } + Bundle extras = new Bundle(); + extras.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PREVIEW, widgetPreview); + + PendingIntent successCallback = + PeopleSpaceWidgetPinnedReceiver.getPendingIntent(mContext, shortcutInfo); + + ComponentName componentName = new ComponentName(mContext, PeopleSpaceWidgetProvider.class); + return mAppWidgetManager.requestPinAppWidget(componentName, extras, successCallback); + } } diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetPinnedReceiver.java b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetPinnedReceiver.java new file mode 100644 index 000000000000..a28da43a80b6 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetPinnedReceiver.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2021 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.people.widget; + +import static com.android.systemui.people.PeopleSpaceUtils.INVALID_USER_ID; + +import android.app.PendingIntent; +import android.appwidget.AppWidgetManager; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.pm.ShortcutInfo; +import android.util.Log; + +import com.android.systemui.people.PeopleSpaceUtils; + +import javax.inject.Inject; + +/** Called when a People Tile widget is added via {@link AppWidgetManager.requestPinAppWidget()}. */ +public class PeopleSpaceWidgetPinnedReceiver extends BroadcastReceiver { + private static final String TAG = "PeopleSpaceWgtPinReceiver"; + private static final int BROADCAST_ID = 0; + private static final int INVALID_WIDGET_ID = -1; + private static final boolean DEBUG = PeopleSpaceUtils.DEBUG; + + private final PeopleSpaceWidgetManager mPeopleSpaceWidgetManager; + + @Inject + public PeopleSpaceWidgetPinnedReceiver(PeopleSpaceWidgetManager peopleSpaceWidgetManager) { + mPeopleSpaceWidgetManager = peopleSpaceWidgetManager; + } + + /** Creates a {@link PendingIntent} that is passed onto this receiver when a widget is added. */ + public static PendingIntent getPendingIntent(Context context, ShortcutInfo shortcutInfo) { + Intent intent = new Intent(context, PeopleSpaceWidgetPinnedReceiver.class) + .addFlags(Intent.FLAG_RECEIVER_FOREGROUND); + intent.putExtra(Intent.EXTRA_SHORTCUT_ID, shortcutInfo.getId()); + intent.putExtra(Intent.EXTRA_USER_ID, shortcutInfo.getUserId()); + intent.putExtra(Intent.EXTRA_PACKAGE_NAME, shortcutInfo.getPackage()); + + // Intent needs to be mutable because App Widget framework populates it with app widget id. + return PendingIntent.getBroadcast(context, BROADCAST_ID, intent, + PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT); + } + + @Override + public void onReceive(Context context, Intent intent) { + if (DEBUG) Log.d(TAG, "Add widget broadcast received"); + if (context == null || intent == null) { + if (DEBUG) Log.w(TAG, "Skipping: context or intent are null"); + return; + } + + int widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, INVALID_WIDGET_ID); + if (widgetId == INVALID_WIDGET_ID) { + if (DEBUG) Log.w(TAG, "Skipping: invalid widgetId"); + return; + } + + String shortcutId = intent.getStringExtra(Intent.EXTRA_SHORTCUT_ID); + String packageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME); + int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, INVALID_USER_ID); + PeopleTileKey key = new PeopleTileKey(shortcutId, userId, packageName); + if (!key.isValid()) { + if (DEBUG) Log.w(TAG, "Skipping: key is not valid: " + key.toString()); + return; + } + + if (DEBUG) Log.d(TAG, "Adding widget: " + widgetId + ", key:" + key.toString()); + mPeopleSpaceWidgetManager.addNewWidget(widgetId, key); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleTileKey.java b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleTileKey.java index ac42cb08090a..319df85b4872 100644 --- a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleTileKey.java +++ b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleTileKey.java @@ -19,6 +19,7 @@ package com.android.systemui.people.widget; import static com.android.systemui.people.PeopleSpaceUtils.EMPTY_STRING; import static com.android.systemui.people.PeopleSpaceUtils.INVALID_USER_ID; +import android.app.people.PeopleSpaceTile; import android.text.TextUtils; import com.android.systemui.statusbar.notification.collection.NotificationEntry; @@ -37,6 +38,12 @@ public class PeopleTileKey { mPackageName = packageName; } + public PeopleTileKey(PeopleSpaceTile tile) { + mShortcutId = tile.getId(); + mUserId = tile.getUserHandle().getIdentifier(); + mPackageName = tile.getPackageName(); + } + public PeopleTileKey(NotificationEntry entry) { mShortcutId = entry.getRanking() != null && entry.getRanking().getConversationShortcutInfo() != null @@ -81,7 +88,7 @@ public class PeopleTileKey { */ @Override public String toString() { - if (!isValid()) return null; + if (!isValid()) return EMPTY_STRING; return mShortcutId + "/" + mUserId + "/" + mPackageName; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/commandline/CommandRegistry.kt b/packages/SystemUI/src/com/android/systemui/statusbar/commandline/CommandRegistry.kt index ce0a08cd4ccf..1da42a705311 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/commandline/CommandRegistry.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/commandline/CommandRegistry.kt @@ -192,9 +192,9 @@ private class PrefsCommand(val context: Context) : Command { val pref = args[0] when (pref) { - Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING -> { + Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING_IN_S -> { val value = Integer.parseInt(args[1]) - Prefs.putBoolean(context, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING, value != 0) + Prefs.putBoolean(context, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING_IN_S, value != 0) } else -> { pw.println("Cannot set pref ($pref)") diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java index 0957f7818daa..617dadb42594 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java @@ -31,6 +31,7 @@ import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.dagger.qualifiers.UiBackground; import com.android.systemui.keyguard.WakefulnessLifecycle; +import com.android.systemui.people.widget.PeopleSpaceWidgetManager; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.settings.UserContextProvider; import com.android.systemui.statusbar.FeatureFlags; @@ -71,6 +72,7 @@ import com.android.systemui.statusbar.notification.row.OnUserInteractionCallback import com.android.systemui.statusbar.notification.row.PriorityOnboardingDialogController; import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager; import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm; +import com.android.systemui.statusbar.phone.ShadeController; import com.android.systemui.statusbar.phone.StatusBar; import com.android.systemui.statusbar.policy.HeadsUpManager; import com.android.systemui.util.leak.LeakDetector; @@ -133,6 +135,8 @@ public interface NotificationsModule { AccessibilityManager accessibilityManager, HighPriorityProvider highPriorityProvider, INotificationManager notificationManager, + NotificationEntryManager notificationEntryManager, + PeopleSpaceWidgetManager peopleSpaceWidgetManager, LauncherApps launcherApps, ShortcutManager shortcutManager, ChannelEditorDialogController channelEditorDialogController, @@ -141,7 +145,8 @@ public interface NotificationsModule { AssistantFeedbackController assistantFeedbackController, Optional<BubblesManager> bubblesManagerOptional, UiEventLogger uiEventLogger, - OnUserInteractionCallback onUserInteractionCallback) { + OnUserInteractionCallback onUserInteractionCallback, + ShadeController shadeController) { return new NotificationGutsManager( context, statusBarLazy, @@ -150,6 +155,8 @@ public interface NotificationsModule { accessibilityManager, highPriorityProvider, notificationManager, + notificationEntryManager, + peopleSpaceWidgetManager, launcherApps, shortcutManager, channelEditorDialogController, @@ -158,7 +165,8 @@ public interface NotificationsModule { assistantFeedbackController, bubblesManagerOptional, uiEventLogger, - onUserInteractionCallback); + onUserInteractionCallback, + shadeController); } /** Provides an instance of {@link VisualStabilityManager} */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfo.java index adeba9078c52..b4ab8cf817dd 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfo.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfo.java @@ -69,9 +69,11 @@ import com.android.systemui.Prefs; import com.android.systemui.R; import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Main; +import com.android.systemui.people.widget.PeopleSpaceWidgetManager; import com.android.systemui.statusbar.notification.NotificationChannelHelper; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.stack.StackStateAnimator; +import com.android.systemui.statusbar.phone.ShadeController; import com.android.systemui.wmshell.BubblesManager; import java.lang.annotation.Retention; @@ -86,15 +88,16 @@ public class NotificationConversationInfo extends LinearLayout implements NotificationGuts.GutsContent { private static final String TAG = "ConversationGuts"; - private INotificationManager mINotificationManager; private ShortcutManager mShortcutManager; private PackageManager mPm; + private PeopleSpaceWidgetManager mPeopleSpaceWidgetManager; private ConversationIconFactory mIconFactory; private OnUserInteractionCallback mOnUserInteractionCallback; private Handler mMainHandler; private Handler mBgHandler; private Optional<BubblesManager> mBubblesManagerOptional; + private ShadeController mShadeController; private String mPackageName; private String mAppName; private int mAppUid; @@ -169,9 +172,16 @@ public class NotificationConversationInfo extends LinearLayout implements private OnClickListener mOnDone = v -> { mPressedApply = true; - // If the user selected Priority, maybe show the priority onboarding + + // If the user selected Priority, maybe show the priority onboarding. + // If the user selected Priority and the previous selection was not priority, show a + // People Tile add request. If showing the priority onboarding, however, delay the request + // to when the onboarding dialog closes. if (mSelectedAction == ACTION_FAVORITE && shouldShowPriorityOnboarding()) { showPriorityOnboarding(); + } else if (mSelectedAction == ACTION_FAVORITE && getPriority() != mSelectedAction) { + mShadeController.animateCollapsePanels(); + mPeopleSpaceWidgetManager.requestPinAppWidget(mShortcutInfo); } mGutsContainer.closeControls(v, true); }; @@ -209,6 +219,7 @@ public class NotificationConversationInfo extends LinearLayout implements @Action int selectedAction, ShortcutManager shortcutManager, PackageManager pm, + PeopleSpaceWidgetManager peopleSpaceWidgetManager, INotificationManager iNotificationManager, OnUserInteractionCallback onUserInteractionCallback, String pkg, @@ -224,10 +235,12 @@ public class NotificationConversationInfo extends LinearLayout implements @Main Handler mainHandler, @Background Handler bgHandler, OnConversationSettingsClickListener onConversationSettingsClickListener, - Optional<BubblesManager> bubblesManagerOptional) { + Optional<BubblesManager> bubblesManagerOptional, + ShadeController shadeController) { mPressedApply = false; mSelectedAction = selectedAction; mINotificationManager = iNotificationManager; + mPeopleSpaceWidgetManager = peopleSpaceWidgetManager; mOnUserInteractionCallback = onUserInteractionCallback; mPackageName = pkg; mEntry = entry; @@ -245,6 +258,7 @@ public class NotificationConversationInfo extends LinearLayout implements mUserContext = userContext; mBubbleMetadata = bubbleMetadata; mBubblesManagerOptional = bubblesManagerOptional; + mShadeController = shadeController; mBuilderProvider = builderProvider; mMainHandler = mainHandler; mBgHandler = bgHandler; @@ -527,7 +541,7 @@ public class NotificationConversationInfo extends LinearLayout implements } private boolean shouldShowPriorityOnboarding() { - return !Prefs.getBoolean(mUserContext, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING, false); + return !Prefs.getBoolean(mUserContext, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING_IN_S, false); } private void showPriorityOnboarding() { @@ -566,9 +580,11 @@ public class NotificationConversationInfo extends LinearLayout implements .setBadge(mIconFactory.getAppBadge( mPackageName, UserHandle.getUserId(mSbn.getUid()))) .setOnSettingsClick(mOnConversationSettingsClickListener) + .setPeopleSpaceWidgetManager(mPeopleSpaceWidgetManager) + .setShadeController(mShadeController) .build(); - controller.init(); + controller.init(mShortcutInfo); controller.show(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java index 6a873b678a93..1a7f5b0bf5af 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java @@ -21,6 +21,7 @@ import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW; import android.app.INotificationManager; import android.app.NotificationChannel; +import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; import android.content.pm.LauncherApps; @@ -49,6 +50,7 @@ import com.android.systemui.Dumpable; import com.android.systemui.R; import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Main; +import com.android.systemui.people.widget.PeopleSpaceWidgetManager; import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.settings.UserContextProvider; @@ -59,11 +61,13 @@ import com.android.systemui.statusbar.StatusBarState; import com.android.systemui.statusbar.StatusBarStateControllerImpl; import com.android.systemui.statusbar.notification.AssistantFeedbackController; import com.android.systemui.statusbar.notification.NotificationActivityStarter; +import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider; import com.android.systemui.statusbar.notification.dagger.NotificationsModule; import com.android.systemui.statusbar.notification.row.NotificationInfo.CheckSaveListener; import com.android.systemui.statusbar.notification.stack.NotificationListContainer; +import com.android.systemui.statusbar.phone.ShadeController; import com.android.systemui.statusbar.phone.StatusBar; import com.android.systemui.statusbar.policy.DeviceProvisionedController; import com.android.systemui.wmshell.BubblesManager; @@ -120,11 +124,15 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx private final Optional<BubblesManager> mBubblesManagerOptional; private Runnable mOpenRunnable; private final INotificationManager mNotificationManager; + private final NotificationEntryManager mNotificationEntryManager; + private final PeopleSpaceWidgetManager mPeopleSpaceWidgetManager; private final LauncherApps mLauncherApps; private final ShortcutManager mShortcutManager; private final UserContextProvider mContextTracker; private final Provider<PriorityOnboardingDialogController.Builder> mBuilderProvider; private final UiEventLogger mUiEventLogger; + private final ShadeController mShadeController; + private final AppWidgetManager mAppWidgetManager; /** * Injected constructor. See {@link NotificationsModule}. @@ -136,6 +144,8 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx AccessibilityManager accessibilityManager, HighPriorityProvider highPriorityProvider, INotificationManager notificationManager, + NotificationEntryManager notificationEntryManager, + PeopleSpaceWidgetManager peopleSpaceWidgetManager, LauncherApps launcherApps, ShortcutManager shortcutManager, ChannelEditorDialogController channelEditorDialogController, @@ -144,7 +154,8 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx AssistantFeedbackController assistantFeedbackController, Optional<BubblesManager> bubblesManagerOptional, UiEventLogger uiEventLogger, - OnUserInteractionCallback onUserInteractionCallback) { + OnUserInteractionCallback onUserInteractionCallback, + ShadeController shadeController) { mContext = context; mStatusBarLazy = statusBarLazy; mMainHandler = mainHandler; @@ -152,6 +163,8 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx mAccessibilityManager = accessibilityManager; mHighPriorityProvider = highPriorityProvider; mNotificationManager = notificationManager; + mNotificationEntryManager = notificationEntryManager; + mPeopleSpaceWidgetManager = peopleSpaceWidgetManager; mLauncherApps = launcherApps; mShortcutManager = shortcutManager; mContextTracker = contextTracker; @@ -161,6 +174,8 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx mBubblesManagerOptional = bubblesManagerOptional; mUiEventLogger = uiEventLogger; mOnUserInteractionCallback = onUserInteractionCallback; + mShadeController = shadeController; + mAppWidgetManager = AppWidgetManager.getInstance(context); } public void setUpWithPresenter(NotificationPresenter presenter, @@ -477,6 +492,7 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx notificationInfoView.getSelectedAction(), mShortcutManager, pmUser, + mPeopleSpaceWidgetManager, mNotificationManager, mOnUserInteractionCallback, packageName, @@ -492,7 +508,8 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx mMainHandler, mBgHandler, onConversationSettingsListener, - mBubblesManagerOptional); + mBubblesManagerOptional, + mShadeController); } /** diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PriorityOnboardingDialogController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PriorityOnboardingDialogController.kt index fab367df8fde..ae1285d3a5d7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PriorityOnboardingDialogController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PriorityOnboardingDialogController.kt @@ -22,6 +22,7 @@ import android.animation.AnimatorSet import android.animation.ValueAnimator import android.app.Dialog import android.content.Context +import android.content.pm.ShortcutInfo import android.graphics.Color import android.graphics.PixelFormat import android.graphics.drawable.ColorDrawable @@ -31,7 +32,6 @@ import android.text.SpannableStringBuilder import android.text.style.BulletSpan import android.view.Gravity import android.view.View -import android.view.ViewGroup import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.view.Window @@ -44,31 +44,36 @@ import android.widget.TextView import com.android.systemui.Interpolators.LINEAR_OUT_SLOW_IN import com.android.systemui.Prefs import com.android.systemui.R +import com.android.systemui.people.widget.PeopleSpaceWidgetManager import com.android.systemui.statusbar.notification.row.NotificationConversationInfo.OnConversationSettingsClickListener +import com.android.systemui.statusbar.phone.ShadeController import javax.inject.Inject - /** * Controller to handle presenting the priority conversations onboarding dialog */ class PriorityOnboardingDialogController @Inject constructor( - val view: View, - val context: Context, - private val ignoresDnd: Boolean, - private val showsAsBubble: Boolean, - val icon : Drawable, - private val onConversationSettingsClickListener : OnConversationSettingsClickListener, - val badge : Drawable + val view: View, + val context: Context, + private val ignoresDnd: Boolean, + private val showsAsBubble: Boolean, + val icon: Drawable, + private val onConversationSettingsClickListener: OnConversationSettingsClickListener, + val badge: Drawable, + private val peopleSpaceWidgetManager: PeopleSpaceWidgetManager, + private val shadeController: ShadeController ) { private lateinit var dialog: Dialog + private lateinit var shortcutInfo: ShortcutInfo private val OVERSHOOT: Interpolator = PathInterpolator(0.4f, 0f, 0.2f, 1.4f) private val IMPORTANCE_ANIM_DELAY = 150L private val IMPORTANCE_ANIM_GROW_DURATION = 250L private val IMPORTANCE_ANIM_SHRINK_DURATION = 200L private val IMPORTANCE_ANIM_SHRINK_DELAY = 25L - fun init() { + fun init(info: ShortcutInfo) { + shortcutInfo = info initDialog() } @@ -78,13 +83,15 @@ class PriorityOnboardingDialogController @Inject constructor( private fun done() { // Log that the user has seen the onboarding - Prefs.putBoolean(context, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING, true) + Prefs.putBoolean(context, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING_IN_S, true) dialog.dismiss() + shadeController.animateCollapsePanels() + peopleSpaceWidgetManager.requestPinAppWidget(shortcutInfo) } private fun settings() { // Log that the user has seen the onboarding - Prefs.putBoolean(context, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING, true) + Prefs.putBoolean(context, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING_IN_S, true) dialog.dismiss() onConversationSettingsClickListener?.onClick() } @@ -95,9 +102,11 @@ class PriorityOnboardingDialogController @Inject constructor( private var ignoresDnd = false private var showAsBubble = false private lateinit var icon: Drawable - private lateinit var onConversationSettingsClickListener - : OnConversationSettingsClickListener - private lateinit var badge : Drawable + private lateinit var onConversationSettingsClickListener: + OnConversationSettingsClickListener + private lateinit var badge: Drawable + private lateinit var peopleSpaceWidgetManager: PeopleSpaceWidgetManager + private lateinit var shadeController: ShadeController fun setView(v: View): Builder { view = v @@ -119,24 +128,36 @@ class PriorityOnboardingDialogController @Inject constructor( return this } - fun setIcon(draw : Drawable) : Builder { + fun setIcon(draw: Drawable): Builder { icon = draw return this } - fun setBadge(badge : Drawable) : Builder { + fun setBadge(badge: Drawable): Builder { this.badge = badge return this } - fun setOnSettingsClick(onClick : OnConversationSettingsClickListener) : Builder { + fun setOnSettingsClick(onClick: OnConversationSettingsClickListener): Builder { onConversationSettingsClickListener = onClick return this } + fun setShadeController(shadeController: ShadeController): Builder { + this.shadeController = shadeController + return this + } + + fun setPeopleSpaceWidgetManager(peopleSpaceWidgetManager: PeopleSpaceWidgetManager): + Builder { + this.peopleSpaceWidgetManager = peopleSpaceWidgetManager + return this + } + fun build(): PriorityOnboardingDialogController { val controller = PriorityOnboardingDialogController( view, context, ignoresDnd, showAsBubble, icon, - onConversationSettingsClickListener, badge) + onConversationSettingsClickListener, badge, peopleSpaceWidgetManager, + shadeController) return controller } } @@ -185,8 +206,8 @@ class PriorityOnboardingDialogController @Inject constructor( val bgSize = context.resources.getDimensionPixelSize( com.android.internal.R.dimen.conversation_icon_size_badged) - val animatorUpdateListener: ValueAnimator.AnimatorUpdateListener - = ValueAnimator.AnimatorUpdateListener { animation -> + val animatorUpdateListener: ValueAnimator.AnimatorUpdateListener = + ValueAnimator.AnimatorUpdateListener { animation -> val strokeWidth = animation.animatedValue as Int ring.setStroke(strokeWidth, ringColor) val newSize = baseSize + strokeWidth * 2 @@ -199,8 +220,8 @@ class PriorityOnboardingDialogController @Inject constructor( growAnimation.duration = IMPORTANCE_ANIM_GROW_DURATION growAnimation.addUpdateListener(animatorUpdateListener) - val shrinkAnimation: ValueAnimator - = ValueAnimator.ofInt(largeThickness, standardThickness) + val shrinkAnimation: ValueAnimator = + ValueAnimator.ofInt(largeThickness, standardThickness) shrinkAnimation.duration = IMPORTANCE_ANIM_SHRINK_DURATION shrinkAnimation.startDelay = IMPORTANCE_ANIM_SHRINK_DELAY shrinkAnimation.interpolator = OVERSHOOT @@ -208,15 +229,14 @@ class PriorityOnboardingDialogController @Inject constructor( shrinkAnimation.addListener(object : AnimatorListenerAdapter() { override fun onAnimationStart(animation: Animator?) { // Shrink the badge bg so that it doesn't peek behind the animation - bg.setSize(baseSize, baseSize); - conversationIconBadgeBg.invalidate(); + bg.setSize(baseSize, baseSize) + conversationIconBadgeBg.invalidate() } override fun onAnimationEnd(animation: Animator?) { // Reset bg back to normal size - bg.setSize(bgSize, bgSize); - conversationIconBadgeBg.invalidate(); - + bg.setSize(bgSize, bgSize) + conversationIconBadgeBg.invalidate() } }) @@ -228,20 +248,20 @@ class PriorityOnboardingDialogController @Inject constructor( R.dimen.conversation_onboarding_bullet_gap_width) val description = SpannableStringBuilder() description.append(context.getText(R.string.priority_onboarding_show_at_top_text), - BulletSpan(gapWidth), /* flags */0) + BulletSpan(gapWidth), /* flags */0) description.append(System.lineSeparator()) description.append(context.getText(R.string.priority_onboarding_show_avatar_text), - BulletSpan(gapWidth), /* flags */0) + BulletSpan(gapWidth), /* flags */0) if (showsAsBubble) { description.append(System.lineSeparator()) description.append(context.getText( R.string.priority_onboarding_appear_as_bubble_text), - BulletSpan(gapWidth), /* flags */0) + BulletSpan(gapWidth), /* flags */0) } if (ignoresDnd) { description.append(System.lineSeparator()) description.append(context.getText(R.string.priority_onboarding_ignores_dnd_text), - BulletSpan(gapWidth), /* flags */0) + BulletSpan(gapWidth), /* flags */0) } findViewById<TextView>(R.id.behaviors).setText(description) diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTest.java index b3ad6ef8da6e..24a63e7a2c73 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTest.java @@ -37,6 +37,7 @@ import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; import com.android.systemui.shared.system.PeopleProviderUtils; +import com.android.systemui.statusbar.notification.NotificationEntryManager; import junit.framework.Assert; @@ -73,6 +74,8 @@ public class PeopleProviderTest extends SysuiTestCase { private PackageManager mPackageManager; @Mock private IPeopleManager mPeopleManager; + @Mock + private NotificationEntryManager mNotificationEntryManager; @Before public void setUp() throws Exception { @@ -84,6 +87,7 @@ public class PeopleProviderTest extends SysuiTestCase { mContext, PeopleProviderUtils.PEOPLE_PROVIDER_AUTHORITY); provider.setLauncherApps(mLauncherApps); provider.setPeopleManager(mPeopleManager); + provider.setNotificationEntryManager(mNotificationEntryManager); mContext.getContentResolver().addProvider( PeopleProviderUtils.PEOPLE_PROVIDER_AUTHORITY, provider); diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTestable.java b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTestable.java index ac1893413c50..6834fa54a084 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTestable.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTestable.java @@ -21,6 +21,8 @@ import android.content.Context; import android.content.pm.LauncherApps; import android.content.pm.ProviderInfo; +import com.android.systemui.statusbar.notification.NotificationEntryManager; + public class PeopleProviderTestable extends PeopleProvider { public void initializeForTesting(Context context, String authority) { @@ -37,4 +39,8 @@ public class PeopleProviderTestable extends PeopleProvider { void setPeopleManager(IPeopleManager peopleManager) { mPeopleManager = peopleManager; } + + void setNotificationEntryManager(NotificationEntryManager notificationEntryManager) { + mNotificationEntryManager = notificationEntryManager; + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java index 410a809bd394..9185cd6426f7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java @@ -25,7 +25,6 @@ import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH; import static com.android.systemui.people.PeopleSpaceUtils.PACKAGE_NAME; import static com.android.systemui.people.PeopleSpaceUtils.REQUIRED_WIDTH_FOR_MEDIUM; -import static com.android.systemui.people.PeopleSpaceUtils.getPeopleTileFromPersistentStorage; import static com.android.systemui.people.widget.AppWidgetOptionsHelper.OPTIONS_PEOPLE_TILE; import static com.google.common.truth.Truth.assertThat; @@ -71,12 +70,13 @@ import android.provider.ContactsContract; import android.provider.Settings; import android.service.notification.ConversationChannelWrapper; import android.service.notification.StatusBarNotification; -import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; import android.view.View; import android.widget.RemoteViews; import android.widget.TextView; +import androidx.test.filters.SmallTest; + import com.android.internal.appwidget.IAppWidgetService; import com.android.systemui.R; import com.android.systemui.SysuiTestCase; @@ -98,8 +98,8 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -@SmallTest @RunWith(AndroidTestingRunner.class) +@SmallTest public class PeopleSpaceUtilsTest extends SysuiTestCase { private static final int WIDGET_ID_WITH_SHORTCUT = 1; @@ -578,6 +578,25 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase { } @Test + public void testAugmentSingleTileFromVisibleNotificationsSingleTile() { + PeopleSpaceTile tile = + new PeopleSpaceTile + .Builder(SHORTCUT_ID_1, "userName", ICON, new Intent()) + .setPackageName(PACKAGE_NAME) + .setUserHandle(new UserHandle(0)) + .build(); + PeopleSpaceTile augmentedTile = PeopleSpaceUtils + .augmentSingleTileFromVisibleNotifications( + mContext, tile, mNotificationEntryManager); + + assertThat(augmentedTile).isNotNull(); + assertThat(augmentedTile.getNotificationContent().toString()) + .isEqualTo(NOTIFICATION_TEXT_2); + + verify(mNotificationEntryManager, times(1)).getVisibleNotifications(); + } + + @Test public void testDoNotUpdateSingleConversationAppWidgetWhenNotBirthday() { int[] widgetIdsArray = {WIDGET_ID_WITH_SHORTCUT}; when(mMockCursor.moveToNext()).thenReturn(true, false); @@ -890,23 +909,6 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase { smallResult.findViewById(R.id.person_icon).getVisibility()); } - @Test - public void testGetPeopleTileFromPersistentStorageExistingConversation() - throws Exception { - when(mPeopleManager.getConversation(PACKAGE_NAME, 0, SHORTCUT_ID_1)).thenReturn( - getConversationChannelWithoutTimestamp(SHORTCUT_ID_1)); - PeopleTileKey key = new PeopleTileKey(SHORTCUT_ID_1, 0, PACKAGE_NAME); - PeopleSpaceTile tile = getPeopleTileFromPersistentStorage(mContext, key, mPeopleManager); - assertThat(tile.getId()).isEqualTo(key.getShortcutId()); - } - - @Test - public void testGetPeopleTileFromPersistentStorageNoConversation() { - PeopleTileKey key = new PeopleTileKey(SHORTCUT_ID_2, 0, PACKAGE_NAME); - PeopleSpaceTile tile = getPeopleTileFromPersistentStorage(mContext, key, mPeopleManager); - assertThat(tile).isNull(); - } - private ConversationChannelWrapper getConversationChannelWrapper(String shortcutId, boolean importantConversation, long lastInteractionTimestamp) throws Exception { ConversationChannelWrapper convo = new ConversationChannelWrapper(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java index 096e51b56263..5834aef4ba78 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java @@ -73,6 +73,7 @@ import com.android.systemui.people.PeopleSpaceUtils; import com.android.systemui.statusbar.NotificationListener; import com.android.systemui.statusbar.NotificationListener.NotificationHandler; import com.android.systemui.statusbar.SbnBuilder; +import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.collection.NoManSimulator; import com.android.systemui.statusbar.notification.collection.NoManSimulator.NotifEvent; import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder; @@ -134,6 +135,9 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { private PeopleSpaceWidgetManager mManager; @Mock + private Context mMockContext; + + @Mock private NotificationListener mListenerService; @Mock @@ -144,6 +148,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { private PeopleManager mPeopleManager; @Mock private LauncherApps mLauncherApps; + @Mock + private NotificationEntryManager mNotificationEntryManager; @Captor private ArgumentCaptor<NotificationHandler> mListenerCaptor; @@ -159,10 +165,10 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mLauncherApps = mock(LauncherApps.class); - mManager = - new PeopleSpaceWidgetManager(mContext); + mDependency.injectTestDependency(NotificationEntryManager.class, mNotificationEntryManager); + mManager = new PeopleSpaceWidgetManager(mContext); mManager.setAppWidgetManager(mAppWidgetManager, mIPeopleManager, mPeopleManager, - mLauncherApps); + mLauncherApps, mNotificationEntryManager); mManager.attach(mListenerService); mProvider = new PeopleSpaceWidgetProvider(); mProvider.setPeopleSpaceWidgetManager(mManager); @@ -668,17 +674,22 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.onAppWidgetOptionsChanged(SECOND_WIDGET_ID_WITH_SHORTCUT, newOptions); - verify(mAppWidgetManager, times(1)).updateAppWidgetOptions( + verify(mAppWidgetManager, times(2)).updateAppWidgetOptions( eq(SECOND_WIDGET_ID_WITH_SHORTCUT), mBundleArgumentCaptor.capture()); - Bundle bundle = mBundleArgumentCaptor.getValue(); - assertThat(bundle.getString(PeopleSpaceUtils.SHORTCUT_ID, EMPTY_STRING)) + List<Bundle> bundles = mBundleArgumentCaptor.getAllValues(); + Bundle first = bundles.get(0); + assertThat(first.getString(PeopleSpaceUtils.SHORTCUT_ID, EMPTY_STRING)) .isEqualTo(EMPTY_STRING); - assertThat(bundle.getInt(USER_ID, INVALID_USER_ID)).isEqualTo(INVALID_USER_ID); - assertThat(bundle.getString(PACKAGE_NAME, EMPTY_STRING)).isEqualTo(EMPTY_STRING); + assertThat(first.getInt(USER_ID, INVALID_USER_ID)).isEqualTo(INVALID_USER_ID); + assertThat(first.getString(PACKAGE_NAME, EMPTY_STRING)).isEqualTo(EMPTY_STRING); verify(mLauncherApps, times(1)).cacheShortcuts(eq(TEST_PACKAGE_A), eq(Arrays.asList(SHORTCUT_ID)), eq(UserHandle.of(0)), eq(LauncherApps.FLAG_CACHE_PEOPLE_TILE_SHORTCUTS)); + Bundle second = bundles.get(1); + PeopleSpaceTile tile = second.getParcelable(OPTIONS_PEOPLE_TILE); + assertThat(tile.getId()).isEqualTo(SHORTCUT_ID); + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); assertThat(sp.getStringSet(KEY.toString(), new HashSet<>())).contains( String.valueOf(SECOND_WIDGET_ID_WITH_SHORTCUT)); @@ -691,6 +702,52 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { assertThat(widgetSp.getInt(USER_ID, INVALID_USER_ID)).isEqualTo(0); } + @Test + public void testGetPeopleTileFromPersistentStorageExistingConversation() + throws Exception { + when(mIPeopleManager.getConversation(PACKAGE_NAME, 0, SHORTCUT_ID)).thenReturn( + getConversationWithShortcutId(SHORTCUT_ID)); + PeopleTileKey key = new PeopleTileKey(SHORTCUT_ID, 0, PACKAGE_NAME); + PeopleSpaceTile tile = mManager.getTileFromPersistentStorage(key); + assertThat(tile.getId()).isEqualTo(key.getShortcutId()); + } + + @Test + public void testGetPeopleTileFromPersistentStorageNoConversation() { + PeopleTileKey key = new PeopleTileKey(SHORTCUT_ID, 0, PACKAGE_NAME); + PeopleSpaceTile tile = mManager.getTileFromPersistentStorage(key); + assertThat(tile).isNull(); + } + + @Test + public void testRequestPinAppWidgetExistingConversation() throws Exception { + when(mMockContext.getPackageName()).thenReturn(PACKAGE_NAME); + when(mMockContext.getUserId()).thenReturn(0); + when(mIPeopleManager.getConversation(PACKAGE_NAME, 0, SHORTCUT_ID)) + .thenReturn(getConversationWithShortcutId(SHORTCUT_ID)); + when(mAppWidgetManager.requestPinAppWidget(any(), any(), any())).thenReturn(true); + + ShortcutInfo info = new ShortcutInfo.Builder(mMockContext, SHORTCUT_ID).build(); + boolean valid = mManager.requestPinAppWidget(info); + + assertThat(valid).isTrue(); + verify(mAppWidgetManager, times(1)).requestPinAppWidget( + any(), any(), any()); + } + + @Test + public void testRequestPinAppWidgetNoConversation() throws Exception { + when(mMockContext.getPackageName()).thenReturn(PACKAGE_NAME); + when(mMockContext.getUserId()).thenReturn(0); + when(mIPeopleManager.getConversation(PACKAGE_NAME, 0, SHORTCUT_ID)).thenReturn(null); + + ShortcutInfo info = new ShortcutInfo.Builder(mMockContext, SHORTCUT_ID).build(); + boolean valid = mManager.requestPinAppWidget(info); + + assertThat(valid).isFalse(); + verify(mAppWidgetManager, never()).requestPinAppWidget(any(), any(), any()); + } + /** * Adds another widget for {@code PERSON_TILE} with widget ID: {@code * SECOND_WIDGET_ID_WITH_SHORTCUT}. diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java index 5c37656d2cf1..d4b21c6f6949 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java @@ -76,6 +76,7 @@ import com.android.settingslib.notification.ConversationIconFactory; import com.android.systemui.Prefs; import com.android.systemui.R; import com.android.systemui.SysuiTestCase; +import com.android.systemui.people.widget.PeopleSpaceWidgetManager; import com.android.systemui.statusbar.SbnBuilder; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder; @@ -141,6 +142,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { @Mock private LauncherApps mLauncherApps; @Mock + private PeopleSpaceWidgetManager mPeopleSpaceWidgetManager; + @Mock private ShortcutManager mShortcutManager; @Mock private NotificationGuts mNotificationGuts; @@ -236,6 +239,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { .thenReturn(mock(NotificationManager.Policy.class)); when(mBuilder.build()).thenReturn(mock(PriorityOnboardingDialogController.class)); + + when(mPeopleSpaceWidgetManager.requestPinAppWidget(any())).thenReturn(true); } @Test @@ -244,6 +249,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -257,7 +263,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); final ImageView view = mNotificationInfo.findViewById(R.id.conversation_icon); assertEquals(mIconDrawable, view.getDrawable()); } @@ -269,6 +276,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -282,7 +290,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); final TextView textView = mNotificationInfo.findViewById(R.id.pkg_name); assertTrue(textView.getText().toString().contains("App Name")); assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); @@ -322,6 +331,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -335,7 +345,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); final TextView textView = mNotificationInfo.findViewById(R.id.group_name); assertTrue(textView.getText().toString().contains(group.getName())); assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); @@ -348,6 +359,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -361,7 +373,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); final TextView textView = mNotificationInfo.findViewById(R.id.group_name); assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); assertEquals(GONE, textView.getVisibility()); @@ -373,6 +386,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -386,7 +400,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name); assertEquals(GONE, nameView.getVisibility()); } @@ -409,6 +424,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -422,7 +438,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name); assertEquals(VISIBLE, nameView.getVisibility()); assertTrue(nameView.getText().toString().contains("Proxied")); @@ -435,6 +452,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -451,7 +469,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); final View settingsButton = mNotificationInfo.findViewById(R.id.info); settingsButton.performClick(); @@ -465,6 +484,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -478,7 +498,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); final View settingsButton = mNotificationInfo.findViewById(R.id.info); assertTrue(settingsButton.getVisibility() != View.VISIBLE); } @@ -490,6 +511,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -506,7 +528,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, false, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); final View settingsButton = mNotificationInfo.findViewById(R.id.info); assertTrue(settingsButton.getVisibility() != View.VISIBLE); } @@ -519,6 +542,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -532,7 +556,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); View view = mNotificationInfo.findViewById(R.id.silence); assertThat(view.isSelected()).isTrue(); } @@ -548,6 +573,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -561,7 +587,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); View view = mNotificationInfo.findViewById(R.id.default_behavior); assertThat(view.isSelected()).isTrue(); assertThat(((TextView) view.findViewById(R.id.default_summary)).getText()).isEqualTo( @@ -580,6 +607,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -593,7 +621,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); View view = mNotificationInfo.findViewById(R.id.default_behavior); assertThat(view.isSelected()).isTrue(); assertThat(((TextView) view.findViewById(R.id.default_summary)).getText()).isEqualTo( @@ -611,6 +640,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -624,7 +654,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); View fave = mNotificationInfo.findViewById(R.id.priority); fave.performClick(); @@ -656,6 +687,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -669,7 +701,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); mNotificationInfo.findViewById(R.id.default_behavior).performClick(); mTestableLooper.processAllMessages(); @@ -700,6 +733,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -713,7 +747,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); View silence = mNotificationInfo.findViewById(R.id.silence); @@ -745,6 +780,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -758,7 +794,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); View fave = mNotificationInfo.findViewById(R.id.priority); fave.performClick(); @@ -783,6 +820,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -796,7 +834,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); View fave = mNotificationInfo.findViewById(R.id.priority); fave.performClick(); @@ -820,6 +859,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -833,7 +873,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); View fave = mNotificationInfo.findViewById(R.id.priority); fave.performClick(); @@ -861,6 +902,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, // no action selected by default mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -874,7 +916,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); // THEN the selected action is -1, so the selected option is "Default" priority assertEquals(mNotificationInfo.getSelectedAction(), -1); @@ -892,6 +935,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { NotificationConversationInfo.ACTION_FAVORITE, // "Favorite" selected by default mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -905,7 +949,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); // THEN the selected action is "Favorite", so the selected option is "priority" priority assertEquals(mNotificationInfo.getSelectedAction(), @@ -922,6 +967,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -935,7 +981,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); mNotificationInfo.findViewById(R.id.default_behavior).performClick(); mNotificationInfo.findViewById(R.id.done).performClick(); @@ -959,6 +1006,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -972,7 +1020,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); mNotificationInfo.findViewById(R.id.default_behavior).performClick(); mNotificationInfo.findViewById(R.id.done).performClick(); @@ -996,6 +1045,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -1009,7 +1059,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); mNotificationInfo.findViewById(R.id.default_behavior).performClick(); mNotificationInfo.findViewById(R.id.done).performClick(); @@ -1032,6 +1083,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -1045,7 +1097,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); View silence = mNotificationInfo.findViewById(R.id.silence); silence.performClick(); @@ -1067,6 +1120,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -1080,7 +1134,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); verify(mMockINotificationManager, times(1)).createConversationNotificationChannelForPackage( anyString(), anyInt(), any(), eq(CONVERSATION_ID)); @@ -1093,6 +1148,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -1106,7 +1162,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mBuilderProvider, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); verify(mMockINotificationManager, never()).createConversationNotificationChannelForPackage( anyString(), anyInt(), any(), eq(CONVERSATION_ID)); @@ -1115,7 +1172,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { @Test public void testSelectPriorityPresentsOnboarding_firstTime() { // GIVEN pref is false - Prefs.putBoolean(mContext, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING, false); + Prefs.putBoolean(mContext, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING_IN_S, false); // GIVEN the priority onboarding screen is present PriorityOnboardingDialogController.Builder b = @@ -1129,6 +1186,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -1142,7 +1200,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { () -> b, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); // WHEN user clicks "priority" mNotificationInfo.setSelectedAction(NotificationConversationInfo.ACTION_FAVORITE); @@ -1158,7 +1217,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { @Test public void testSelectPriorityDoesNotShowOnboarding_secondTime() { //WHEN pref is true - Prefs.putBoolean(mContext, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING, true); + Prefs.putBoolean(mContext, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING_IN_S, true); PriorityOnboardingDialogController.Builder b = mock(PriorityOnboardingDialogController.Builder.class, Answers.RETURNS_SELF); @@ -1170,6 +1229,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { -1, mShortcutManager, mMockPackageManager, + mPeopleSpaceWidgetManager, mMockINotificationManager, mOnUserInteractionCallback, TEST_PACKAGE_NAME, @@ -1183,12 +1243,128 @@ public class NotificationConversationInfoTest extends SysuiTestCase { () -> b, true, mTestHandler, - mTestHandler, null, Optional.of(mBubblesManager)); + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); // WHEN user clicks "priority" mNotificationInfo.setSelectedAction(NotificationConversationInfo.ACTION_FAVORITE); + verify(controller, never()).show(); + + // and then done + mNotificationInfo.findViewById(R.id.done).performClick(); // THEN the user is presented with the priority onboarding screen verify(controller, never()).show(); } + + @Test + public void testSelectPriorityRequestsPinPeopleTile() { + //WHEN pref is true and channel is default importance + Prefs.putBoolean(mContext, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING_IN_S, true); + mNotificationChannel.setImportantConversation(false); + mNotificationInfo.bindNotification( + -1, + mShortcutManager, + mMockPackageManager, + mPeopleSpaceWidgetManager, + mMockINotificationManager, + mOnUserInteractionCallback, + TEST_PACKAGE_NAME, + mNotificationChannel, + mEntry, + mBubbleMetadata, + null, + null, + mIconFactory, + mContext, + mBuilderProvider, + true, + mTestHandler, + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); + + // WHEN user clicks "priority" + mNotificationInfo.setSelectedAction(NotificationConversationInfo.ACTION_FAVORITE); + + // and then done + mNotificationInfo.findViewById(R.id.done).performClick(); + + // THEN the user is presented with the People Tile pinning request + verify(mPeopleSpaceWidgetManager, times(1)).requestPinAppWidget(any()); + } + + @Test + public void testSelectDefaultDoesNotRequestPinPeopleTile() { + //WHEN pref is true + Prefs.putBoolean(mContext, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING_IN_S, true); + + mNotificationInfo.bindNotification( + -1, + mShortcutManager, + mMockPackageManager, + mPeopleSpaceWidgetManager, + mMockINotificationManager, + mOnUserInteractionCallback, + TEST_PACKAGE_NAME, + mNotificationChannel, + mEntry, + mBubbleMetadata, + null, + null, + mIconFactory, + mContext, + mBuilderProvider, + true, + mTestHandler, + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); + + // WHEN user clicks "default" + mNotificationInfo.setSelectedAction(NotificationConversationInfo.ACTION_DEFAULT); + + // and then done + mNotificationInfo.findViewById(R.id.done).performClick(); + + // THEN the user is not presented with the People Tile pinning request + verify(mPeopleSpaceWidgetManager, never()).requestPinAppWidget(mShortcutInfo); + } + + @Test + public void testSelectPriority_AlreadyPriority_DoesNotRequestPinPeopleTile() { + //WHEN pref is true and channel is priority + Prefs.putBoolean(mContext, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING_IN_S, true); + mConversationChannel.setOriginalImportance(IMPORTANCE_HIGH); + mConversationChannel.setImportance(IMPORTANCE_HIGH); + mConversationChannel.setImportantConversation(true); + + mNotificationInfo.bindNotification( + -1, + mShortcutManager, + mMockPackageManager, + mPeopleSpaceWidgetManager, + mMockINotificationManager, + mOnUserInteractionCallback, + TEST_PACKAGE_NAME, + mNotificationChannel, + mEntry, + mBubbleMetadata, + null, + null, + mIconFactory, + mContext, + mBuilderProvider, + true, + mTestHandler, + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); + + // WHEN user clicks "priority" + mNotificationInfo.setSelectedAction(NotificationConversationInfo.ACTION_FAVORITE); + + // and then done + mNotificationInfo.findViewById(R.id.done).performClick(); + + // THEN the user is not presented with the People Tile pinning request + verify(mPeopleSpaceWidgetManager, never()).requestPinAppWidget(mShortcutInfo); + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java index 458a058cc6ec..18481bca1aa6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java @@ -67,17 +67,20 @@ import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.testing.UiEventLoggerFake; import com.android.systemui.SysuiTestCase; +import com.android.systemui.people.widget.PeopleSpaceWidgetManager; import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; import com.android.systemui.settings.UserContextProvider; import com.android.systemui.statusbar.NotificationLockscreenUserManager; import com.android.systemui.statusbar.NotificationPresenter; import com.android.systemui.statusbar.notification.AssistantFeedbackController; import com.android.systemui.statusbar.notification.NotificationActivityStarter; +import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider; import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier; import com.android.systemui.statusbar.notification.row.NotificationGutsManager.OnSettingsClickListener; import com.android.systemui.statusbar.notification.stack.NotificationListContainer; +import com.android.systemui.statusbar.phone.ShadeController; import com.android.systemui.statusbar.phone.StatusBar; import com.android.systemui.statusbar.policy.DeviceProvisionedController; import com.android.systemui.wmshell.BubblesManager; @@ -126,12 +129,15 @@ public class NotificationGutsManagerTest extends SysuiTestCase { @Mock private AccessibilityManager mAccessibilityManager; @Mock private HighPriorityProvider mHighPriorityProvider; @Mock private INotificationManager mINotificationManager; + @Mock private NotificationEntryManager mNotificationEntryManager; @Mock private LauncherApps mLauncherApps; @Mock private ShortcutManager mShortcutManager; @Mock private ChannelEditorDialogController mChannelEditorDialogController; @Mock private PeopleNotificationIdentifier mPeopleNotificationIdentifier; @Mock private UserContextProvider mContextTracker; @Mock private BubblesManager mBubblesManager; + @Mock private ShadeController mShadeController; + @Mock private PeopleSpaceWidgetManager mPeopleSpaceWidgetManager; @Mock(answer = Answers.RETURNS_SELF) private PriorityOnboardingDialogController.Builder mBuilder; private Provider<PriorityOnboardingDialogController.Builder> mProvider = () -> mBuilder; @@ -154,10 +160,10 @@ public class NotificationGutsManagerTest extends SysuiTestCase { mGutsManager = new NotificationGutsManager(mContext, () -> mStatusBar, mHandler, mHandler, mAccessibilityManager, mHighPriorityProvider, - mINotificationManager, mLauncherApps, mShortcutManager, - mChannelEditorDialogController, mContextTracker, mProvider, - mAssistantFeedbackController, Optional.of(mBubblesManager), - new UiEventLoggerFake(), mOnUserInteractionCallback); + mINotificationManager, mNotificationEntryManager, mPeopleSpaceWidgetManager, + mLauncherApps, mShortcutManager, mChannelEditorDialogController, mContextTracker, + mProvider, mAssistantFeedbackController, Optional.of(mBubblesManager), + new UiEventLoggerFake(), mOnUserInteractionCallback, mShadeController); mGutsManager.setUpWithPresenter(mPresenter, mNotificationListContainer, mCheckSaveListener, mOnSettingsClickListener); mGutsManager.setNotificationActivityStarter(mNotificationActivityStarter); |