Loading core/java/android/app/people/ConversationChannel.java +36 −0 Original line number Diff line number Diff line Loading @@ -16,12 +16,16 @@ package android.app.people; import android.annotation.Nullable; import android.app.NotificationChannel; import android.app.NotificationChannelGroup; import android.content.pm.ShortcutInfo; import android.os.Parcel; import android.os.Parcelable; import java.util.ArrayList; import java.util.List; /** * The non-customized notification channel of a conversation. It contains the information to render * the conversation and allows the user to open and customize the conversation setting. Loading @@ -36,6 +40,8 @@ public final class ConversationChannel implements Parcelable { private NotificationChannelGroup mParentNotificationChannelGroup; private long mLastEventTimestamp; private boolean mHasActiveNotifications; private boolean mHasBirthdayToday; private List<ConversationStatus> mStatuses; public static final Creator<ConversationChannel> CREATOR = new Creator<ConversationChannel>() { @Override Loading @@ -61,6 +67,21 @@ public final class ConversationChannel implements Parcelable { mHasActiveNotifications = hasActiveNotifications; } public ConversationChannel(ShortcutInfo shortcutInfo, int uid, NotificationChannel parentNotificationChannel, NotificationChannelGroup parentNotificationChannelGroup, long lastEventTimestamp, boolean hasActiveNotifications, boolean hasBirthdayToday, List<ConversationStatus> statuses) { mShortcutInfo = shortcutInfo; mUid = uid; mParentNotificationChannel = parentNotificationChannel; mParentNotificationChannelGroup = parentNotificationChannelGroup; mLastEventTimestamp = lastEventTimestamp; mHasActiveNotifications = hasActiveNotifications; mHasBirthdayToday = hasBirthdayToday; mStatuses = statuses; } public ConversationChannel(Parcel in) { mShortcutInfo = in.readParcelable(ShortcutInfo.class.getClassLoader()); mUid = in.readInt(); Loading @@ -69,6 +90,9 @@ public final class ConversationChannel implements Parcelable { in.readParcelable(NotificationChannelGroup.class.getClassLoader()); mLastEventTimestamp = in.readLong(); mHasActiveNotifications = in.readBoolean(); mHasBirthdayToday = in.readBoolean(); mStatuses = new ArrayList<>(); in.readParcelableList(mStatuses, ConversationStatus.class.getClassLoader()); } @Override Loading @@ -84,6 +108,8 @@ public final class ConversationChannel implements Parcelable { dest.writeParcelable(mParentNotificationChannelGroup, flags); dest.writeLong(mLastEventTimestamp); dest.writeBoolean(mHasActiveNotifications); dest.writeBoolean(mHasBirthdayToday); dest.writeParcelableList(mStatuses, flags); } public ShortcutInfo getShortcutInfo() { Loading Loading @@ -113,4 +139,14 @@ public final class ConversationChannel implements Parcelable { public boolean hasActiveNotifications() { return mHasActiveNotifications; } /** Whether this conversation has a birthday today, as associated in the Contacts Database. */ public boolean hasBirthdayToday() { return mHasBirthdayToday; } /** Returns statuses associated with the conversation. */ public @Nullable List<ConversationStatus> getStatuses() { return mStatuses; } } packages/SystemUI/src/com/android/systemui/people/PeopleSpaceTile.java→core/java/android/app/people/PeopleSpaceTile.java +71 −38 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * 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. Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.systemui.people; package android.app.people; import android.annotation.NonNull; import android.app.Person; Loading @@ -30,6 +30,9 @@ import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; import java.util.ArrayList; import java.util.List; /** * The People Space tile contains all relevant information to render a tile in People Space: namely * the data of any visible conversation notification associated, associated statuses, and the last Loading @@ -45,16 +48,15 @@ public class PeopleSpaceTile implements Parcelable { private int mUid; private Uri mContactUri; private String mPackageName; private String mStatusText; private String mBirthdayText; private long mLastInteractionTimestamp; private boolean mIsImportantConversation; private boolean mIsHiddenConversation; private String mNotificationKey; // TODO: add mNotificationTimestamp private CharSequence mNotificationContent; private Uri mNotificationDataUri; private Intent mIntent; // TODO: add a List of the Status objects once created private long mNotificationTimestamp; private List<ConversationStatus> mStatuses; private PeopleSpaceTile(Builder b) { mId = b.mId; Loading @@ -63,14 +65,15 @@ public class PeopleSpaceTile implements Parcelable { mContactUri = b.mContactUri; mUid = b.mUid; mPackageName = b.mPackageName; mStatusText = b.mStatusText; mBirthdayText = b.mBirthdayText; mLastInteractionTimestamp = b.mLastInteractionTimestamp; mIsImportantConversation = b.mIsImportantConversation; mIsHiddenConversation = b.mIsHiddenConversation; mNotificationKey = b.mNotificationKey; mNotificationContent = b.mNotificationContent; mNotificationDataUri = b.mNotificationDataUri; mIntent = b.mIntent; mNotificationTimestamp = b.mNotificationTimestamp; mStatuses = b.mStatuses; } public String getId() { Loading Loading @@ -98,8 +101,8 @@ public class PeopleSpaceTile implements Parcelable { return mPackageName; } public String getStatusText() { return mStatusText; public String getBirthdayText() { return mBirthdayText; } /** Returns the timestamp of the last interaction. */ Loading @@ -114,13 +117,6 @@ public class PeopleSpaceTile implements Parcelable { return mIsImportantConversation; } /** * Whether the conversation should be hidden. */ public boolean isHiddenConversation() { return mIsHiddenConversation; } /** * If a notification is currently active that maps to the relevant shortcut ID, provides the * associated notification's key. Loading Loading @@ -148,20 +144,32 @@ public class PeopleSpaceTile implements Parcelable { return mIntent; } /** Returns the timestamp of the last notification. */ public long getNotificationTimestamp() { return mNotificationTimestamp; } /** Returns the statuses associated with the tile. */ public List<ConversationStatus> getStatuses() { return mStatuses; } /** Converts a {@link PeopleSpaceTile} into a {@link PeopleSpaceTile.Builder}. */ public PeopleSpaceTile.Builder toBuilder() { PeopleSpaceTile.Builder builder = new PeopleSpaceTile.Builder(mId, mUserName.toString(), mUserIcon, mIntent); public Builder toBuilder() { Builder builder = new Builder(mId, mUserName.toString(), mUserIcon, mIntent); builder.setContactUri(mContactUri); builder.setUid(mUid); builder.setPackageName(mPackageName); builder.setStatusText(mStatusText); builder.setBirthdayText(mBirthdayText); builder.setLastInteractionTimestamp(mLastInteractionTimestamp); builder.setIsImportantConversation(mIsImportantConversation); builder.setIsHiddenConversation(mIsHiddenConversation); builder.setNotificationKey(mNotificationKey); builder.setNotificationContent(mNotificationContent); builder.setNotificationDataUri(mNotificationDataUri); builder.setIntent(mIntent); builder.setNotificationTimestamp(mNotificationTimestamp); builder.setStatuses(mStatuses); return builder; } Loading @@ -173,14 +181,15 @@ public class PeopleSpaceTile implements Parcelable { private Uri mContactUri; private int mUid; private String mPackageName; private String mStatusText; private String mBirthdayText; private long mLastInteractionTimestamp; private boolean mIsImportantConversation; private boolean mIsHiddenConversation; private String mNotificationKey; private CharSequence mNotificationContent; private Uri mNotificationDataUri; private Intent mIntent; private long mNotificationTimestamp; private List<ConversationStatus> mStatuses; /** Builder for use only if a shortcut is not available for the tile. */ public Builder(String id, String userName, Icon userIcon, Intent intent) { Loading @@ -200,7 +209,22 @@ public class PeopleSpaceTile implements Parcelable { mContactUri = getContactUri(info); } private Uri getContactUri(ShortcutInfo info) { public Builder(ConversationChannel channel, LauncherApps launcherApps) { ShortcutInfo info = channel.getShortcutInfo(); mId = info.getId(); mUserName = info.getLabel(); mUserIcon = convertDrawableToIcon(launcherApps.getShortcutIconDrawable(info, 0)); mUid = info.getUserId(); mPackageName = info.getPackage(); mContactUri = getContactUri(info); mStatuses = channel.getStatuses(); mLastInteractionTimestamp = channel.getLastEventTimestamp(); mIsImportantConversation = channel.getParentNotificationChannel() != null && channel.getParentNotificationChannel().isImportantConversation(); } /** Returns the Contact's Uri if present. */ public Uri getContactUri(ShortcutInfo info) { if (info.getPersons() == null || info.getPersons().length != 1) { return null; } Loading Loading @@ -246,8 +270,8 @@ public class PeopleSpaceTile implements Parcelable { } /** Sets the status text. */ public Builder setStatusText(String statusText) { mStatusText = statusText; public Builder setBirthdayText(String birthdayText) { mBirthdayText = birthdayText; return this; } Loading @@ -263,12 +287,6 @@ public class PeopleSpaceTile implements Parcelable { return this; } /** Sets whether the conversation is hidden. */ public Builder setIsHiddenConversation(boolean isHiddenConversation) { mIsHiddenConversation = isHiddenConversation; return this; } /** Sets the associated notification's key. */ public Builder setNotificationKey(String notificationKey) { mNotificationKey = notificationKey; Loading @@ -293,6 +311,18 @@ public class PeopleSpaceTile implements Parcelable { return this; } /** Sets the notification timestamp. */ public Builder setNotificationTimestamp(long notificationTimestamp) { mNotificationTimestamp = notificationTimestamp; return this; } /** Sets the statuses. */ public Builder setStatuses(List<ConversationStatus> statuses) { mStatuses = statuses; return this; } /** Builds a {@link PeopleSpaceTile}. */ @NonNull public PeopleSpaceTile build() { Loading @@ -300,21 +330,23 @@ public class PeopleSpaceTile implements Parcelable { } } private PeopleSpaceTile(Parcel in) { public PeopleSpaceTile(Parcel in) { mId = in.readString(); mUserName = in.readCharSequence(); mUserIcon = in.readParcelable(Icon.class.getClassLoader()); mContactUri = in.readParcelable(Uri.class.getClassLoader()); mUid = in.readInt(); mPackageName = in.readString(); mStatusText = in.readString(); mBirthdayText = in.readString(); mLastInteractionTimestamp = in.readLong(); mIsImportantConversation = in.readBoolean(); mIsHiddenConversation = in.readBoolean(); mNotificationKey = in.readString(); mNotificationContent = in.readCharSequence(); mNotificationDataUri = in.readParcelable(Uri.class.getClassLoader()); mIntent = in.readParcelable(Intent.class.getClassLoader()); mNotificationTimestamp = in.readLong(); mStatuses = new ArrayList<>(); in.readParcelableList(mStatuses, ConversationStatus.class.getClassLoader()); } @Override Loading @@ -330,14 +362,15 @@ public class PeopleSpaceTile implements Parcelable { dest.writeParcelable(mContactUri, flags); dest.writeInt(mUid); dest.writeString(mPackageName); dest.writeString(mStatusText); dest.writeString(mBirthdayText); dest.writeLong(mLastInteractionTimestamp); dest.writeBoolean(mIsImportantConversation); dest.writeBoolean(mIsHiddenConversation); dest.writeString(mNotificationKey); dest.writeCharSequence(mNotificationContent); dest.writeParcelable(mNotificationDataUri, flags); dest.writeParcelable(mIntent, flags); dest.writeLong(mNotificationTimestamp); dest.writeParcelableList(mStatuses, flags); } public static final @android.annotation.NonNull Loading packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceTileTest.java→core/tests/coretests/src/android/app/people/PeopleSpaceTileTest.java +86 −11 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.systemui.people; package android.app.people; import static com.google.common.truth.Truth.assertThat; Loading @@ -25,6 +25,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.content.pm.LauncherApps; Loading @@ -34,13 +36,13 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; import android.net.Uri; import android.os.Parcel; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import com.android.systemui.SysuiTestCase; import com.android.systemui.people.PeopleSpaceTile; import com.google.common.collect.ImmutableList; import org.junit.Before; import org.junit.Test; Loading @@ -48,10 +50,13 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.util.List; @RunWith(AndroidJUnit4.class) @SmallTest public class PeopleSpaceTileTest extends SysuiTestCase { public class PeopleSpaceTileTest { private Context mContext; private final Drawable mDrawable = new ColorDrawable(Color.BLUE); private final Icon mIcon = PeopleSpaceTile.convertDrawableToIcon(mDrawable); Loading @@ -60,6 +65,7 @@ public class PeopleSpaceTileTest extends SysuiTestCase { @Before public void setUp() { mContext = InstrumentationRegistry.getContext(); MockitoAnnotations.initMocks(this); when(mLauncherApps.getShortcutIconDrawable(any(), eq(0))).thenReturn(mDrawable); } Loading Loading @@ -132,7 +138,7 @@ public class PeopleSpaceTileTest extends SysuiTestCase { PeopleSpaceTile tile = new PeopleSpaceTile.Builder( new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps).build(); // Automatically added by creating a ShortcutInfo. assertThat(tile.getPackageName()).isEqualTo("com.android.systemui.tests"); assertThat(tile.getPackageName()).isEqualTo("com.android.frameworks.coretests"); tile = new PeopleSpaceTile.Builder( new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps).setPackageName( Loading Loading @@ -171,16 +177,85 @@ public class PeopleSpaceTileTest extends SysuiTestCase { } @Test public void testHiddenConversation() { public void testStatuses() { PeopleSpaceTile tile = new PeopleSpaceTile.Builder( new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps).build(); assertFalse(tile.isHiddenConversation()); assertThat(tile.getStatuses()).isNull(); List<ConversationStatus> statusList = ImmutableList.of( new ConversationStatus.Builder("id", ConversationStatus.ACTIVITY_BIRTHDAY).build()); tile = new PeopleSpaceTile .Builder(new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps) .setIsHiddenConversation(true) .setStatuses(statusList) .build(); assertTrue(tile.isHiddenConversation()); assertThat(tile.getStatuses()).isEqualTo(statusList); } @Test public void testCreateFromConversationChannel() { ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(mContext, "123").setLongLabel( "name").build(); ConversationChannel convo = new ConversationChannel(shortcutInfo, 0, null, null, 0L, false, true, null); PeopleSpaceTile tile = new PeopleSpaceTile.Builder(convo, mLauncherApps).build(); assertThat(tile.getStatuses()).isNull(); assertThat(tile.getId()).isEqualTo("123"); assertThat(tile.getUserName()).isEqualTo("name"); assertFalse(tile.isImportantConversation()); assertThat(tile.getLastInteractionTimestamp()).isEqualTo(0L); List<ConversationStatus> statuses = ImmutableList.of( new ConversationStatus.Builder("id", ConversationStatus.ACTIVITY_BIRTHDAY).build()); NotificationChannel notificationChannel = new NotificationChannel("123", "channel", NotificationManager.IMPORTANCE_DEFAULT); notificationChannel.setImportantConversation(true); convo = new ConversationChannel(shortcutInfo, 0, notificationChannel, null, 123L, false, true, statuses); tile = new PeopleSpaceTile.Builder(convo, mLauncherApps).build(); assertThat(tile.getStatuses()).isEqualTo(statuses); assertTrue(tile.isImportantConversation()); assertThat(tile.getLastInteractionTimestamp()).isEqualTo(123L); } @Test public void testWriteThenReadFromParcel() { List<ConversationStatus> statusList = ImmutableList.of( new ConversationStatus.Builder("id", ConversationStatus.ACTIVITY_BIRTHDAY).build()); PeopleSpaceTile tile = new PeopleSpaceTile.Builder( new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps) .setUserName("name") .setUserIcon(mIcon) .setContactUri(Uri.parse("contact")) .setUid(42) .setPackageName("package.name") .setLastInteractionTimestamp(7L) .setIsImportantConversation(true) .setStatuses(statusList).setNotificationKey("key") .setNotificationContent("content") .setNotificationDataUri(Uri.parse("data")) .setIntent(new Intent()) .build(); Parcel parcel = Parcel.obtain(); tile.writeToParcel(parcel, 0); parcel.setDataPosition(0); PeopleSpaceTile readTile = PeopleSpaceTile.CREATOR.createFromParcel(parcel); assertThat(readTile.getId()).isEqualTo(tile.getId()); assertThat(readTile.getUserName()).isEqualTo(tile.getUserName()); assertThat(readTile.getUserIcon().toString()).isEqualTo(tile.getUserIcon().toString()); assertThat(readTile.getContactUri()).isEqualTo(tile.getContactUri()); assertThat(readTile.getUid()).isEqualTo(tile.getUid()); assertThat(readTile.getPackageName()).isEqualTo(tile.getPackageName()); assertThat(readTile.getLastInteractionTimestamp()).isEqualTo( tile.getLastInteractionTimestamp()); assertThat(readTile.isImportantConversation()).isEqualTo(tile.isImportantConversation()); assertThat(readTile.getStatuses()).isEqualTo(tile.getStatuses()); assertThat(readTile.getNotificationKey()).isEqualTo(tile.getNotificationKey()); assertThat(readTile.getNotificationContent()).isEqualTo(tile.getNotificationContent()); assertThat(readTile.getNotificationDataUri()).isEqualTo(tile.getNotificationDataUri()); assertThat(readTile.getIntent().toString()).isEqualTo(tile.getIntent().toString()); } @Test Loading packages/SystemUI/src/com/android/systemui/people/PeopleSpaceActivity.java +4 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import static android.appwidget.AppWidgetManager.INVALID_APPWIDGET_ID; import android.app.Activity; import android.app.INotificationManager; import android.app.people.IPeopleManager; import android.app.people.PeopleSpaceTile; import android.appwidget.AppWidgetManager; import android.content.ComponentName; import android.content.Context; Loading Loading @@ -134,8 +135,10 @@ public class PeopleSpaceActivity extends Activity { + tile.getId() + " for widget ID: " + mAppWidgetId); } // Ensure updates to app widget can be retrieved from both appWidget Id and tile ID. editor.putString(String.valueOf(mAppWidgetId), tile.getId()); editor.commit(); editor.putInt(tile.getId(), mAppWidgetId); editor.apply(); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext); Bundle options = new Bundle(); options.putParcelable(PeopleSpaceUtils.OPTIONS_PEOPLE_SPACE_TILE, tile); Loading packages/SystemUI/src/com/android/systemui/people/PeopleSpaceTileView.java +1 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.people; import android.app.people.PeopleSpaceTile; import android.content.Context; import android.content.pm.LauncherApps; import android.graphics.drawable.Drawable; Loading Loading
core/java/android/app/people/ConversationChannel.java +36 −0 Original line number Diff line number Diff line Loading @@ -16,12 +16,16 @@ package android.app.people; import android.annotation.Nullable; import android.app.NotificationChannel; import android.app.NotificationChannelGroup; import android.content.pm.ShortcutInfo; import android.os.Parcel; import android.os.Parcelable; import java.util.ArrayList; import java.util.List; /** * The non-customized notification channel of a conversation. It contains the information to render * the conversation and allows the user to open and customize the conversation setting. Loading @@ -36,6 +40,8 @@ public final class ConversationChannel implements Parcelable { private NotificationChannelGroup mParentNotificationChannelGroup; private long mLastEventTimestamp; private boolean mHasActiveNotifications; private boolean mHasBirthdayToday; private List<ConversationStatus> mStatuses; public static final Creator<ConversationChannel> CREATOR = new Creator<ConversationChannel>() { @Override Loading @@ -61,6 +67,21 @@ public final class ConversationChannel implements Parcelable { mHasActiveNotifications = hasActiveNotifications; } public ConversationChannel(ShortcutInfo shortcutInfo, int uid, NotificationChannel parentNotificationChannel, NotificationChannelGroup parentNotificationChannelGroup, long lastEventTimestamp, boolean hasActiveNotifications, boolean hasBirthdayToday, List<ConversationStatus> statuses) { mShortcutInfo = shortcutInfo; mUid = uid; mParentNotificationChannel = parentNotificationChannel; mParentNotificationChannelGroup = parentNotificationChannelGroup; mLastEventTimestamp = lastEventTimestamp; mHasActiveNotifications = hasActiveNotifications; mHasBirthdayToday = hasBirthdayToday; mStatuses = statuses; } public ConversationChannel(Parcel in) { mShortcutInfo = in.readParcelable(ShortcutInfo.class.getClassLoader()); mUid = in.readInt(); Loading @@ -69,6 +90,9 @@ public final class ConversationChannel implements Parcelable { in.readParcelable(NotificationChannelGroup.class.getClassLoader()); mLastEventTimestamp = in.readLong(); mHasActiveNotifications = in.readBoolean(); mHasBirthdayToday = in.readBoolean(); mStatuses = new ArrayList<>(); in.readParcelableList(mStatuses, ConversationStatus.class.getClassLoader()); } @Override Loading @@ -84,6 +108,8 @@ public final class ConversationChannel implements Parcelable { dest.writeParcelable(mParentNotificationChannelGroup, flags); dest.writeLong(mLastEventTimestamp); dest.writeBoolean(mHasActiveNotifications); dest.writeBoolean(mHasBirthdayToday); dest.writeParcelableList(mStatuses, flags); } public ShortcutInfo getShortcutInfo() { Loading Loading @@ -113,4 +139,14 @@ public final class ConversationChannel implements Parcelable { public boolean hasActiveNotifications() { return mHasActiveNotifications; } /** Whether this conversation has a birthday today, as associated in the Contacts Database. */ public boolean hasBirthdayToday() { return mHasBirthdayToday; } /** Returns statuses associated with the conversation. */ public @Nullable List<ConversationStatus> getStatuses() { return mStatuses; } }
packages/SystemUI/src/com/android/systemui/people/PeopleSpaceTile.java→core/java/android/app/people/PeopleSpaceTile.java +71 −38 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * 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. Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.systemui.people; package android.app.people; import android.annotation.NonNull; import android.app.Person; Loading @@ -30,6 +30,9 @@ import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; import java.util.ArrayList; import java.util.List; /** * The People Space tile contains all relevant information to render a tile in People Space: namely * the data of any visible conversation notification associated, associated statuses, and the last Loading @@ -45,16 +48,15 @@ public class PeopleSpaceTile implements Parcelable { private int mUid; private Uri mContactUri; private String mPackageName; private String mStatusText; private String mBirthdayText; private long mLastInteractionTimestamp; private boolean mIsImportantConversation; private boolean mIsHiddenConversation; private String mNotificationKey; // TODO: add mNotificationTimestamp private CharSequence mNotificationContent; private Uri mNotificationDataUri; private Intent mIntent; // TODO: add a List of the Status objects once created private long mNotificationTimestamp; private List<ConversationStatus> mStatuses; private PeopleSpaceTile(Builder b) { mId = b.mId; Loading @@ -63,14 +65,15 @@ public class PeopleSpaceTile implements Parcelable { mContactUri = b.mContactUri; mUid = b.mUid; mPackageName = b.mPackageName; mStatusText = b.mStatusText; mBirthdayText = b.mBirthdayText; mLastInteractionTimestamp = b.mLastInteractionTimestamp; mIsImportantConversation = b.mIsImportantConversation; mIsHiddenConversation = b.mIsHiddenConversation; mNotificationKey = b.mNotificationKey; mNotificationContent = b.mNotificationContent; mNotificationDataUri = b.mNotificationDataUri; mIntent = b.mIntent; mNotificationTimestamp = b.mNotificationTimestamp; mStatuses = b.mStatuses; } public String getId() { Loading Loading @@ -98,8 +101,8 @@ public class PeopleSpaceTile implements Parcelable { return mPackageName; } public String getStatusText() { return mStatusText; public String getBirthdayText() { return mBirthdayText; } /** Returns the timestamp of the last interaction. */ Loading @@ -114,13 +117,6 @@ public class PeopleSpaceTile implements Parcelable { return mIsImportantConversation; } /** * Whether the conversation should be hidden. */ public boolean isHiddenConversation() { return mIsHiddenConversation; } /** * If a notification is currently active that maps to the relevant shortcut ID, provides the * associated notification's key. Loading Loading @@ -148,20 +144,32 @@ public class PeopleSpaceTile implements Parcelable { return mIntent; } /** Returns the timestamp of the last notification. */ public long getNotificationTimestamp() { return mNotificationTimestamp; } /** Returns the statuses associated with the tile. */ public List<ConversationStatus> getStatuses() { return mStatuses; } /** Converts a {@link PeopleSpaceTile} into a {@link PeopleSpaceTile.Builder}. */ public PeopleSpaceTile.Builder toBuilder() { PeopleSpaceTile.Builder builder = new PeopleSpaceTile.Builder(mId, mUserName.toString(), mUserIcon, mIntent); public Builder toBuilder() { Builder builder = new Builder(mId, mUserName.toString(), mUserIcon, mIntent); builder.setContactUri(mContactUri); builder.setUid(mUid); builder.setPackageName(mPackageName); builder.setStatusText(mStatusText); builder.setBirthdayText(mBirthdayText); builder.setLastInteractionTimestamp(mLastInteractionTimestamp); builder.setIsImportantConversation(mIsImportantConversation); builder.setIsHiddenConversation(mIsHiddenConversation); builder.setNotificationKey(mNotificationKey); builder.setNotificationContent(mNotificationContent); builder.setNotificationDataUri(mNotificationDataUri); builder.setIntent(mIntent); builder.setNotificationTimestamp(mNotificationTimestamp); builder.setStatuses(mStatuses); return builder; } Loading @@ -173,14 +181,15 @@ public class PeopleSpaceTile implements Parcelable { private Uri mContactUri; private int mUid; private String mPackageName; private String mStatusText; private String mBirthdayText; private long mLastInteractionTimestamp; private boolean mIsImportantConversation; private boolean mIsHiddenConversation; private String mNotificationKey; private CharSequence mNotificationContent; private Uri mNotificationDataUri; private Intent mIntent; private long mNotificationTimestamp; private List<ConversationStatus> mStatuses; /** Builder for use only if a shortcut is not available for the tile. */ public Builder(String id, String userName, Icon userIcon, Intent intent) { Loading @@ -200,7 +209,22 @@ public class PeopleSpaceTile implements Parcelable { mContactUri = getContactUri(info); } private Uri getContactUri(ShortcutInfo info) { public Builder(ConversationChannel channel, LauncherApps launcherApps) { ShortcutInfo info = channel.getShortcutInfo(); mId = info.getId(); mUserName = info.getLabel(); mUserIcon = convertDrawableToIcon(launcherApps.getShortcutIconDrawable(info, 0)); mUid = info.getUserId(); mPackageName = info.getPackage(); mContactUri = getContactUri(info); mStatuses = channel.getStatuses(); mLastInteractionTimestamp = channel.getLastEventTimestamp(); mIsImportantConversation = channel.getParentNotificationChannel() != null && channel.getParentNotificationChannel().isImportantConversation(); } /** Returns the Contact's Uri if present. */ public Uri getContactUri(ShortcutInfo info) { if (info.getPersons() == null || info.getPersons().length != 1) { return null; } Loading Loading @@ -246,8 +270,8 @@ public class PeopleSpaceTile implements Parcelable { } /** Sets the status text. */ public Builder setStatusText(String statusText) { mStatusText = statusText; public Builder setBirthdayText(String birthdayText) { mBirthdayText = birthdayText; return this; } Loading @@ -263,12 +287,6 @@ public class PeopleSpaceTile implements Parcelable { return this; } /** Sets whether the conversation is hidden. */ public Builder setIsHiddenConversation(boolean isHiddenConversation) { mIsHiddenConversation = isHiddenConversation; return this; } /** Sets the associated notification's key. */ public Builder setNotificationKey(String notificationKey) { mNotificationKey = notificationKey; Loading @@ -293,6 +311,18 @@ public class PeopleSpaceTile implements Parcelable { return this; } /** Sets the notification timestamp. */ public Builder setNotificationTimestamp(long notificationTimestamp) { mNotificationTimestamp = notificationTimestamp; return this; } /** Sets the statuses. */ public Builder setStatuses(List<ConversationStatus> statuses) { mStatuses = statuses; return this; } /** Builds a {@link PeopleSpaceTile}. */ @NonNull public PeopleSpaceTile build() { Loading @@ -300,21 +330,23 @@ public class PeopleSpaceTile implements Parcelable { } } private PeopleSpaceTile(Parcel in) { public PeopleSpaceTile(Parcel in) { mId = in.readString(); mUserName = in.readCharSequence(); mUserIcon = in.readParcelable(Icon.class.getClassLoader()); mContactUri = in.readParcelable(Uri.class.getClassLoader()); mUid = in.readInt(); mPackageName = in.readString(); mStatusText = in.readString(); mBirthdayText = in.readString(); mLastInteractionTimestamp = in.readLong(); mIsImportantConversation = in.readBoolean(); mIsHiddenConversation = in.readBoolean(); mNotificationKey = in.readString(); mNotificationContent = in.readCharSequence(); mNotificationDataUri = in.readParcelable(Uri.class.getClassLoader()); mIntent = in.readParcelable(Intent.class.getClassLoader()); mNotificationTimestamp = in.readLong(); mStatuses = new ArrayList<>(); in.readParcelableList(mStatuses, ConversationStatus.class.getClassLoader()); } @Override Loading @@ -330,14 +362,15 @@ public class PeopleSpaceTile implements Parcelable { dest.writeParcelable(mContactUri, flags); dest.writeInt(mUid); dest.writeString(mPackageName); dest.writeString(mStatusText); dest.writeString(mBirthdayText); dest.writeLong(mLastInteractionTimestamp); dest.writeBoolean(mIsImportantConversation); dest.writeBoolean(mIsHiddenConversation); dest.writeString(mNotificationKey); dest.writeCharSequence(mNotificationContent); dest.writeParcelable(mNotificationDataUri, flags); dest.writeParcelable(mIntent, flags); dest.writeLong(mNotificationTimestamp); dest.writeParcelableList(mStatuses, flags); } public static final @android.annotation.NonNull Loading
packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceTileTest.java→core/tests/coretests/src/android/app/people/PeopleSpaceTileTest.java +86 −11 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.systemui.people; package android.app.people; import static com.google.common.truth.Truth.assertThat; Loading @@ -25,6 +25,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.content.pm.LauncherApps; Loading @@ -34,13 +36,13 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; import android.net.Uri; import android.os.Parcel; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import com.android.systemui.SysuiTestCase; import com.android.systemui.people.PeopleSpaceTile; import com.google.common.collect.ImmutableList; import org.junit.Before; import org.junit.Test; Loading @@ -48,10 +50,13 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.util.List; @RunWith(AndroidJUnit4.class) @SmallTest public class PeopleSpaceTileTest extends SysuiTestCase { public class PeopleSpaceTileTest { private Context mContext; private final Drawable mDrawable = new ColorDrawable(Color.BLUE); private final Icon mIcon = PeopleSpaceTile.convertDrawableToIcon(mDrawable); Loading @@ -60,6 +65,7 @@ public class PeopleSpaceTileTest extends SysuiTestCase { @Before public void setUp() { mContext = InstrumentationRegistry.getContext(); MockitoAnnotations.initMocks(this); when(mLauncherApps.getShortcutIconDrawable(any(), eq(0))).thenReturn(mDrawable); } Loading Loading @@ -132,7 +138,7 @@ public class PeopleSpaceTileTest extends SysuiTestCase { PeopleSpaceTile tile = new PeopleSpaceTile.Builder( new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps).build(); // Automatically added by creating a ShortcutInfo. assertThat(tile.getPackageName()).isEqualTo("com.android.systemui.tests"); assertThat(tile.getPackageName()).isEqualTo("com.android.frameworks.coretests"); tile = new PeopleSpaceTile.Builder( new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps).setPackageName( Loading Loading @@ -171,16 +177,85 @@ public class PeopleSpaceTileTest extends SysuiTestCase { } @Test public void testHiddenConversation() { public void testStatuses() { PeopleSpaceTile tile = new PeopleSpaceTile.Builder( new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps).build(); assertFalse(tile.isHiddenConversation()); assertThat(tile.getStatuses()).isNull(); List<ConversationStatus> statusList = ImmutableList.of( new ConversationStatus.Builder("id", ConversationStatus.ACTIVITY_BIRTHDAY).build()); tile = new PeopleSpaceTile .Builder(new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps) .setIsHiddenConversation(true) .setStatuses(statusList) .build(); assertTrue(tile.isHiddenConversation()); assertThat(tile.getStatuses()).isEqualTo(statusList); } @Test public void testCreateFromConversationChannel() { ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(mContext, "123").setLongLabel( "name").build(); ConversationChannel convo = new ConversationChannel(shortcutInfo, 0, null, null, 0L, false, true, null); PeopleSpaceTile tile = new PeopleSpaceTile.Builder(convo, mLauncherApps).build(); assertThat(tile.getStatuses()).isNull(); assertThat(tile.getId()).isEqualTo("123"); assertThat(tile.getUserName()).isEqualTo("name"); assertFalse(tile.isImportantConversation()); assertThat(tile.getLastInteractionTimestamp()).isEqualTo(0L); List<ConversationStatus> statuses = ImmutableList.of( new ConversationStatus.Builder("id", ConversationStatus.ACTIVITY_BIRTHDAY).build()); NotificationChannel notificationChannel = new NotificationChannel("123", "channel", NotificationManager.IMPORTANCE_DEFAULT); notificationChannel.setImportantConversation(true); convo = new ConversationChannel(shortcutInfo, 0, notificationChannel, null, 123L, false, true, statuses); tile = new PeopleSpaceTile.Builder(convo, mLauncherApps).build(); assertThat(tile.getStatuses()).isEqualTo(statuses); assertTrue(tile.isImportantConversation()); assertThat(tile.getLastInteractionTimestamp()).isEqualTo(123L); } @Test public void testWriteThenReadFromParcel() { List<ConversationStatus> statusList = ImmutableList.of( new ConversationStatus.Builder("id", ConversationStatus.ACTIVITY_BIRTHDAY).build()); PeopleSpaceTile tile = new PeopleSpaceTile.Builder( new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps) .setUserName("name") .setUserIcon(mIcon) .setContactUri(Uri.parse("contact")) .setUid(42) .setPackageName("package.name") .setLastInteractionTimestamp(7L) .setIsImportantConversation(true) .setStatuses(statusList).setNotificationKey("key") .setNotificationContent("content") .setNotificationDataUri(Uri.parse("data")) .setIntent(new Intent()) .build(); Parcel parcel = Parcel.obtain(); tile.writeToParcel(parcel, 0); parcel.setDataPosition(0); PeopleSpaceTile readTile = PeopleSpaceTile.CREATOR.createFromParcel(parcel); assertThat(readTile.getId()).isEqualTo(tile.getId()); assertThat(readTile.getUserName()).isEqualTo(tile.getUserName()); assertThat(readTile.getUserIcon().toString()).isEqualTo(tile.getUserIcon().toString()); assertThat(readTile.getContactUri()).isEqualTo(tile.getContactUri()); assertThat(readTile.getUid()).isEqualTo(tile.getUid()); assertThat(readTile.getPackageName()).isEqualTo(tile.getPackageName()); assertThat(readTile.getLastInteractionTimestamp()).isEqualTo( tile.getLastInteractionTimestamp()); assertThat(readTile.isImportantConversation()).isEqualTo(tile.isImportantConversation()); assertThat(readTile.getStatuses()).isEqualTo(tile.getStatuses()); assertThat(readTile.getNotificationKey()).isEqualTo(tile.getNotificationKey()); assertThat(readTile.getNotificationContent()).isEqualTo(tile.getNotificationContent()); assertThat(readTile.getNotificationDataUri()).isEqualTo(tile.getNotificationDataUri()); assertThat(readTile.getIntent().toString()).isEqualTo(tile.getIntent().toString()); } @Test Loading
packages/SystemUI/src/com/android/systemui/people/PeopleSpaceActivity.java +4 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import static android.appwidget.AppWidgetManager.INVALID_APPWIDGET_ID; import android.app.Activity; import android.app.INotificationManager; import android.app.people.IPeopleManager; import android.app.people.PeopleSpaceTile; import android.appwidget.AppWidgetManager; import android.content.ComponentName; import android.content.Context; Loading Loading @@ -134,8 +135,10 @@ public class PeopleSpaceActivity extends Activity { + tile.getId() + " for widget ID: " + mAppWidgetId); } // Ensure updates to app widget can be retrieved from both appWidget Id and tile ID. editor.putString(String.valueOf(mAppWidgetId), tile.getId()); editor.commit(); editor.putInt(tile.getId(), mAppWidgetId); editor.apply(); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext); Bundle options = new Bundle(); options.putParcelable(PeopleSpaceUtils.OPTIONS_PEOPLE_SPACE_TILE, tile); Loading
packages/SystemUI/src/com/android/systemui/people/PeopleSpaceTileView.java +1 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.people; import android.app.people.PeopleSpaceTile; import android.content.Context; import android.content.pm.LauncherApps; import android.graphics.drawable.Drawable; Loading