Merge "Adding logging to People Tiles" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f98a859fc2
@@ -245,9 +245,9 @@ public class PeopleSpaceUtils {
|
||||
* {@code messagesCount}.
|
||||
*/
|
||||
public static PeopleSpaceTile augmentTileFromNotification(Context context, PeopleSpaceTile tile,
|
||||
NotificationEntry notificationEntry, int messagesCount) {
|
||||
PeopleTileKey key, NotificationEntry notificationEntry, int messagesCount) {
|
||||
if (notificationEntry == null || notificationEntry.getSbn().getNotification() == null) {
|
||||
if (DEBUG) Log.d(TAG, "Notification is null");
|
||||
if (DEBUG) Log.d(TAG, "Tile key: " + key.toString() + ". Notification is null");
|
||||
return removeNotificationFields(tile);
|
||||
}
|
||||
Notification notification = notificationEntry.getSbn().getNotification();
|
||||
@@ -256,7 +256,7 @@ public class PeopleSpaceUtils {
|
||||
getMessagingStyleMessages(notification);
|
||||
|
||||
if (!isMissedCall && ArrayUtils.isEmpty(messages)) {
|
||||
if (DEBUG) Log.d(TAG, "Notification has no content");
|
||||
if (DEBUG) Log.d(TAG, "Tile key: " + key.toString() + ". Notification has no content");
|
||||
return removeNotificationFields(tile);
|
||||
}
|
||||
|
||||
@@ -268,7 +268,10 @@ public class PeopleSpaceUtils {
|
||||
CharSequence content = (isMissedCall && !hasMessageText)
|
||||
? context.getString(R.string.missed_call) : message.getText();
|
||||
Uri dataUri = message != null ? message.getDataUri() : null;
|
||||
if (DEBUG) Log.d(TAG, "Notification message has text: " + hasMessageText);
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Tile key: " + key.toString() + ". Notification message has text: "
|
||||
+ hasMessageText);
|
||||
}
|
||||
|
||||
return tile
|
||||
.toBuilder()
|
||||
@@ -459,7 +462,7 @@ public class PeopleSpaceUtils {
|
||||
}
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Widget: " + appWidgetId + ", " + tile.getUserName() + ", "
|
||||
+ tile.getPackageName());
|
||||
+ tile.getPackageName() + ". Updating app widget view.");
|
||||
}
|
||||
RemoteViews views = new PeopleTileViewHelper(context, tile, appWidgetId,
|
||||
options).getViews();
|
||||
@@ -472,7 +475,9 @@ public class PeopleSpaceUtils {
|
||||
public static void updateAppWidgetOptionsAndView(AppWidgetManager appWidgetManager,
|
||||
Context context, int appWidgetId, PeopleSpaceTile tile) {
|
||||
if (tile == null) {
|
||||
Log.d(TAG, "Tile is null, skipping storage and update.");
|
||||
if (DEBUG) {
|
||||
Log.w(TAG, "Widget: " + appWidgetId + "Tile is null, skipping storage and update.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
Bundle options = AppWidgetOptionsHelper.setPeopleTile(appWidgetManager, appWidgetId, tile);
|
||||
@@ -483,7 +488,10 @@ public class PeopleSpaceUtils {
|
||||
public static void updateAppWidgetOptionsAndView(AppWidgetManager appWidgetManager,
|
||||
Context context, int appWidgetId, Optional<PeopleSpaceTile> optionalTile) {
|
||||
if (!optionalTile.isPresent()) {
|
||||
Log.d(TAG, "Tile is null, skipping storage and update.");
|
||||
if (DEBUG) {
|
||||
Log.w(TAG, "Widget: " + appWidgetId
|
||||
+ "Optional tile is not present, skipping storage and update.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
updateAppWidgetOptionsAndView(appWidgetManager, context, appWidgetId, optionalTile.get());
|
||||
|
||||
@@ -59,6 +59,7 @@ import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.people.widget.LaunchConversationActivity;
|
||||
import com.android.systemui.people.widget.PeopleSpaceWidgetProvider;
|
||||
import com.android.systemui.people.widget.PeopleTileKey;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.time.Duration;
|
||||
@@ -148,6 +149,8 @@ public class PeopleTileViewHelper {
|
||||
* content, then birthdays, then the most recent status, and finally last interaction.
|
||||
*/
|
||||
private RemoteViews getViewForTile() {
|
||||
PeopleTileKey key = new PeopleTileKey(mTile);
|
||||
if (DEBUG) Log.d(TAG, "Creating view for tile key: " + key.toString());
|
||||
if (Objects.equals(mTile.getNotificationCategory(), CATEGORY_MISSED_CALL)) {
|
||||
if (DEBUG) Log.d(TAG, "Create missed call view");
|
||||
return createMissedCallRemoteViews();
|
||||
|
||||
@@ -41,7 +41,7 @@ public class AppWidgetOptionsHelper {
|
||||
PeopleSpaceTile tile) {
|
||||
Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
|
||||
if (tile == null) {
|
||||
if (DEBUG) Log.d(TAG, "Requested to store null tile");
|
||||
if (DEBUG) Log.w(TAG, "Requested to store null tile");
|
||||
return options;
|
||||
}
|
||||
options.putParcelable(OPTIONS_PEOPLE_TILE, tile);
|
||||
|
||||
@@ -236,7 +236,7 @@ public class PeopleSpaceWidgetManager {
|
||||
@Nullable
|
||||
public PeopleSpaceTile getTileFromPersistentStorage(PeopleTileKey key) {
|
||||
if (!key.isValid()) {
|
||||
Log.e(TAG, "PeopleTileKey invalid: " + key);
|
||||
Log.e(TAG, "PeopleTileKey invalid: " + key.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -267,7 +267,14 @@ public class PeopleSpaceWidgetManager {
|
||||
*/
|
||||
public void updateWidgetsWithNotificationChanged(StatusBarNotification sbn,
|
||||
PeopleSpaceUtils.NotificationAction notificationAction) {
|
||||
if (DEBUG) Log.d(TAG, "updateWidgetsWithNotificationChanged called");
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "updateWidgetsWithNotificationChanged called");
|
||||
if (notificationAction == PeopleSpaceUtils.NotificationAction.POSTED) {
|
||||
Log.d(TAG, "Notification posted, key: " + sbn.getKey());
|
||||
} else {
|
||||
Log.d(TAG, "Notification removed, key: " + sbn.getKey());
|
||||
}
|
||||
}
|
||||
if (mIsForTesting) {
|
||||
updateWidgetsWithNotificationChangedInBackground(sbn, notificationAction);
|
||||
return;
|
||||
@@ -282,7 +289,7 @@ public class PeopleSpaceWidgetManager {
|
||||
PeopleTileKey key = new PeopleTileKey(
|
||||
sbn.getShortcutId(), sbn.getUser().getIdentifier(), sbn.getPackageName());
|
||||
if (!key.isValid()) {
|
||||
Log.d(TAG, "Invalid key from sbn");
|
||||
Log.d(TAG, "Sbn doesn't contain valid PeopleTileKey: " + key.toString());
|
||||
return;
|
||||
}
|
||||
int[] widgetIds = mAppWidgetManager.getAppWidgetIds(
|
||||
@@ -309,8 +316,12 @@ public class PeopleSpaceWidgetManager {
|
||||
|
||||
/** Updates {@code widgetIdsToUpdate} with {@code action}. */
|
||||
private void updateWidgetIdsBasedOnNotifications(Set<String> widgetIdsToUpdate) {
|
||||
Log.d(TAG, "Fetching grouped notifications");
|
||||
if (widgetIdsToUpdate.isEmpty()) {
|
||||
if (DEBUG) Log.d(TAG, "No widgets to update, returning.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (DEBUG) Log.d(TAG, "Fetching grouped notifications");
|
||||
Map<PeopleTileKey, Set<NotificationEntry>> groupedNotifications =
|
||||
getGroupedConversationNotifications();
|
||||
|
||||
@@ -331,14 +342,15 @@ public class PeopleSpaceWidgetManager {
|
||||
* Augments {@code tile} based on notifications returned from {@code notificationEntryManager}.
|
||||
*/
|
||||
public PeopleSpaceTile augmentTileFromNotificationEntryManager(PeopleSpaceTile tile) {
|
||||
Log.d(TAG, "Augmenting tile from NotificationEntryManager widget: " + tile.getId());
|
||||
PeopleTileKey key = new PeopleTileKey(tile);
|
||||
Log.d(TAG, "Augmenting tile from NotificationEntryManager widget: " + key.toString());
|
||||
Map<PeopleTileKey, Set<NotificationEntry>> notifications =
|
||||
getGroupedConversationNotifications();
|
||||
String contactUri = null;
|
||||
if (tile.getContactUri() != null) {
|
||||
contactUri = tile.getContactUri().toString();
|
||||
}
|
||||
return augmentTileFromNotifications(tile, contactUri, notifications);
|
||||
return augmentTileFromNotifications(tile, key, contactUri, notifications);
|
||||
}
|
||||
|
||||
/** Returns active and pending notifications grouped by {@link PeopleTileKey}. */
|
||||
@@ -367,9 +379,9 @@ public class PeopleSpaceWidgetManager {
|
||||
}
|
||||
|
||||
/** Augments {@code tile} based on {@code notifications}, matching {@code contactUri}. */
|
||||
public PeopleSpaceTile augmentTileFromNotifications(PeopleSpaceTile tile, String contactUri,
|
||||
Map<PeopleTileKey, Set<NotificationEntry>> notifications) {
|
||||
if (DEBUG) Log.d(TAG, "Augmenting tile from notifications. Tile id: " + tile.getId());
|
||||
public PeopleSpaceTile augmentTileFromNotifications(PeopleSpaceTile tile, PeopleTileKey key,
|
||||
String contactUri, Map<PeopleTileKey, Set<NotificationEntry>> notifications) {
|
||||
if (DEBUG) Log.d(TAG, "Augmenting tile from notifications. Tile key: " + key.toString());
|
||||
boolean hasReadContactsPermission = mPackageManager.checkPermission(READ_CONTACTS,
|
||||
tile.getPackageName()) == PackageManager.PERMISSION_GRANTED;
|
||||
|
||||
@@ -384,13 +396,12 @@ public class PeopleSpaceWidgetManager {
|
||||
}
|
||||
}
|
||||
|
||||
PeopleTileKey key = new PeopleTileKey(tile);
|
||||
Set<NotificationEntry> allNotifications = notifications.get(key);
|
||||
if (allNotifications == null) {
|
||||
allNotifications = new HashSet<>();
|
||||
}
|
||||
if (allNotifications.isEmpty() && notificationsByUri.isEmpty()) {
|
||||
if (DEBUG) Log.d(TAG, "No existing notifications for tile: " + key);
|
||||
if (DEBUG) Log.d(TAG, "No existing notifications for tile: " + key.toString());
|
||||
return removeNotificationFields(tile);
|
||||
}
|
||||
|
||||
@@ -402,22 +413,28 @@ public class PeopleSpaceWidgetManager {
|
||||
NotificationEntry highestPriority = getHighestPriorityNotification(allNotifications);
|
||||
|
||||
if (DEBUG) Log.d(TAG, "Augmenting tile from notification, key: " + key.toString());
|
||||
return augmentTileFromNotification(mContext, tile, highestPriority, messagesCount);
|
||||
return augmentTileFromNotification(mContext, tile, key, highestPriority, messagesCount);
|
||||
}
|
||||
|
||||
/** Returns an augmented tile for an existing widget. */
|
||||
@Nullable
|
||||
public Optional<PeopleSpaceTile> getAugmentedTileForExistingWidget(int widgetId,
|
||||
Map<PeopleTileKey, Set<NotificationEntry>> notifications) {
|
||||
Log.d(TAG, "Augmenting tile for widget: " + widgetId);
|
||||
Log.d(TAG, "Augmenting tile for existing widget: " + widgetId);
|
||||
PeopleSpaceTile tile = getTileForExistingWidget(widgetId);
|
||||
if (tile == null) {
|
||||
if (DEBUG) {
|
||||
Log.w(TAG, "Widget: " + widgetId
|
||||
+ ". Null tile for existing widget, skipping update.");
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
String contactUriString = mSharedPrefs.getString(String.valueOf(widgetId), null);
|
||||
// Should never be null, but using ofNullable for extra safety.
|
||||
PeopleTileKey key = new PeopleTileKey(tile);
|
||||
if (DEBUG) Log.d(TAG, "Existing widget: " + widgetId + ". Tile key: " + key.toString());
|
||||
return Optional.ofNullable(
|
||||
augmentTileFromNotifications(tile, contactUriString, notifications));
|
||||
augmentTileFromNotifications(tile, key, contactUriString, notifications));
|
||||
}
|
||||
|
||||
/** Returns stored widgets for the conversation specified. */
|
||||
@@ -644,12 +661,12 @@ public class PeopleSpaceWidgetManager {
|
||||
}
|
||||
|
||||
synchronized (mLock) {
|
||||
if (DEBUG) Log.d(TAG, "Add storage for : " + tile.getId());
|
||||
if (DEBUG) Log.d(TAG, "Add storage for : " + key.toString());
|
||||
PeopleSpaceUtils.setSharedPreferencesStorageForTile(mContext, key, appWidgetId,
|
||||
tile.getContactUri());
|
||||
}
|
||||
try {
|
||||
if (DEBUG) Log.d(TAG, "Caching shortcut for PeopleTile: " + tile.getId());
|
||||
if (DEBUG) Log.d(TAG, "Caching shortcut for PeopleTile: " + key.toString());
|
||||
mLauncherApps.cacheShortcuts(tile.getPackageName(),
|
||||
Collections.singletonList(tile.getId()),
|
||||
tile.getUserHandle(), LauncherApps.FLAG_CACHE_PEOPLE_TILE_SHORTCUTS);
|
||||
@@ -679,7 +696,7 @@ public class PeopleSpaceWidgetManager {
|
||||
if (DEBUG) Log.d(TAG, "Already registered listener");
|
||||
return;
|
||||
}
|
||||
if (DEBUG) Log.d(TAG, "Register listener for " + widgetId + " with " + key);
|
||||
if (DEBUG) Log.d(TAG, "Register listener for " + widgetId + " with " + key.toString());
|
||||
mListeners.put(key, newListener);
|
||||
}
|
||||
mPeopleManager.registerConversationListener(key.getPackageName(),
|
||||
@@ -750,7 +767,9 @@ public class PeopleSpaceWidgetManager {
|
||||
if (DEBUG) Log.d(TAG, "Cannot find listener to unregister");
|
||||
return;
|
||||
}
|
||||
if (DEBUG) Log.d(TAG, "Unregister listener for " + appWidgetId + " with " + key);
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Unregister listener for " + appWidgetId + " with " + key.toString());
|
||||
}
|
||||
mListeners.remove(key);
|
||||
}
|
||||
mPeopleManager.unregisterConversationListener(registeredListener);
|
||||
|
||||
@@ -59,6 +59,7 @@ import androidx.test.filters.SmallTest;
|
||||
import com.android.internal.appwidget.IAppWidgetService;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.people.widget.PeopleTileKey;
|
||||
import com.android.systemui.statusbar.NotificationListener;
|
||||
import com.android.systemui.statusbar.notification.NotificationEntryManager;
|
||||
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
|
||||
@@ -94,6 +95,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
private static final Uri URI = Uri.parse("fake_uri");
|
||||
private static final Icon ICON = Icon.createWithResource("package", R.drawable.ic_android);
|
||||
private static final String NAME = "username";
|
||||
private static final UserHandle USER = new UserHandle(0);
|
||||
private static final Person PERSON = new Person.Builder()
|
||||
.setName("name")
|
||||
.setKey("abc")
|
||||
@@ -103,6 +105,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
private static final PeopleSpaceTile PERSON_TILE =
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_1, NAME, ICON, new Intent())
|
||||
.setUserHandle(USER)
|
||||
.setLastInteractionTimestamp(123L)
|
||||
.setNotificationKey(NOTIFICATION_KEY)
|
||||
.setNotificationContent(NOTIFICATION_CONTENT)
|
||||
@@ -231,8 +234,9 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUserHandle(new UserHandle(0))
|
||||
.build();
|
||||
PeopleTileKey key = new PeopleTileKey(tile);
|
||||
PeopleSpaceTile actual = PeopleSpaceUtils
|
||||
.augmentTileFromNotification(mContext, tile, mNotificationEntry1, 0);
|
||||
.augmentTileFromNotification(mContext, tile, key, mNotificationEntry1, 0);
|
||||
|
||||
assertThat(actual.getNotificationContent().toString()).isEqualTo(NOTIFICATION_TEXT_2);
|
||||
}
|
||||
@@ -245,8 +249,9 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUserHandle(new UserHandle(0))
|
||||
.build();
|
||||
PeopleTileKey key = new PeopleTileKey(tile);
|
||||
PeopleSpaceTile actual = PeopleSpaceUtils
|
||||
.augmentTileFromNotification(mContext, tile, mNotificationEntry3, 0);
|
||||
.augmentTileFromNotification(mContext, tile, key, mNotificationEntry3, 0);
|
||||
|
||||
assertThat(actual.getNotificationContent()).isEqualTo(null);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import android.content.res.Resources;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
@@ -73,10 +74,12 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
private static final String GAME_DESCRIPTION = "Playing a game!";
|
||||
private static final CharSequence MISSED_CALL = "Custom missed call message";
|
||||
private static final String NAME = "username";
|
||||
private static final UserHandle USER = new UserHandle(0);
|
||||
private static final PeopleSpaceTile PERSON_TILE_WITHOUT_NOTIFICATION =
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_1, NAME, ICON, new Intent())
|
||||
.setLastInteractionTimestamp(0L)
|
||||
.setUserHandle(USER)
|
||||
.build();
|
||||
private static final PeopleSpaceTile PERSON_TILE =
|
||||
new PeopleSpaceTile
|
||||
@@ -85,6 +88,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
.setNotificationKey(NOTIFICATION_KEY)
|
||||
.setNotificationContent(NOTIFICATION_CONTENT)
|
||||
.setNotificationDataUri(URI)
|
||||
.setUserHandle(USER)
|
||||
.build();
|
||||
private static final ConversationStatus GAME_STATUS =
|
||||
new ConversationStatus
|
||||
|
||||
@@ -1201,7 +1201,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
|
||||
.setPackageName(TEST_PACKAGE_A)
|
||||
.setUserHandle(new UserHandle(0))
|
||||
.build();
|
||||
PeopleSpaceTile actual = mManager.augmentTileFromNotifications(tile, EMPTY_STRING,
|
||||
PeopleTileKey key = new PeopleTileKey(tile);
|
||||
PeopleSpaceTile actual = mManager.augmentTileFromNotifications(tile, key, EMPTY_STRING,
|
||||
Map.of(new PeopleTileKey(mNotificationEntry),
|
||||
new HashSet<>(Collections.singleton(mNotificationEntry))));
|
||||
|
||||
@@ -1216,8 +1217,9 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
|
||||
.setPackageName(TEST_PACKAGE_A)
|
||||
.setUserHandle(new UserHandle(0))
|
||||
.build();
|
||||
PeopleTileKey key = new PeopleTileKey(tile);
|
||||
PeopleSpaceTile actual = mManager
|
||||
.augmentTileFromNotifications(tile, EMPTY_STRING,
|
||||
.augmentTileFromNotifications(tile, key, EMPTY_STRING,
|
||||
Map.of(new PeopleTileKey(mNotificationEntry),
|
||||
new HashSet<>(Collections.singleton(mNotificationEntry))));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user