Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 592cb8d3 authored by Flavio Fiszman's avatar Flavio Fiszman
Browse files

Add Missed call People Tile

Change-Id: I76904cff9f512525dbb2bf335409ff038287802f
Test: PeopleSpaceUtilsTest
Bug: 172576156
parent 41b553c0
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ public class PeopleSpaceTile implements Parcelable {
    private boolean mIsImportantConversation;
    private String mNotificationKey;
    private CharSequence mNotificationContent;
    private String mNotificationCategory;
    private Uri mNotificationDataUri;
    private Intent mIntent;
    private long mNotificationTimestamp;
@@ -70,6 +71,7 @@ public class PeopleSpaceTile implements Parcelable {
        mIsImportantConversation = b.mIsImportantConversation;
        mNotificationKey = b.mNotificationKey;
        mNotificationContent = b.mNotificationContent;
        mNotificationCategory = b.mNotificationCategory;
        mNotificationDataUri = b.mNotificationDataUri;
        mIntent = b.mIntent;
        mNotificationTimestamp = b.mNotificationTimestamp;
@@ -129,6 +131,10 @@ public class PeopleSpaceTile implements Parcelable {
        return mNotificationContent;
    }

    public String getNotificationCategory() {
        return mNotificationCategory;
    }

    public Uri getNotificationDataUri() {
        return mNotificationDataUri;
    }
@@ -166,6 +172,7 @@ public class PeopleSpaceTile implements Parcelable {
        builder.setIsImportantConversation(mIsImportantConversation);
        builder.setNotificationKey(mNotificationKey);
        builder.setNotificationContent(mNotificationContent);
        builder.setNotificationCategory(mNotificationCategory);
        builder.setNotificationDataUri(mNotificationDataUri);
        builder.setIntent(mIntent);
        builder.setNotificationTimestamp(mNotificationTimestamp);
@@ -186,6 +193,7 @@ public class PeopleSpaceTile implements Parcelable {
        private boolean mIsImportantConversation;
        private String mNotificationKey;
        private CharSequence mNotificationContent;
        private String mNotificationCategory;
        private Uri mNotificationDataUri;
        private Intent mIntent;
        private long mNotificationTimestamp;
@@ -299,6 +307,12 @@ public class PeopleSpaceTile implements Parcelable {
            return this;
        }

        /** Sets the associated notification's category. */
        public Builder setNotificationCategory(String notificationCategory) {
            mNotificationCategory = notificationCategory;
            return this;
        }

        /** Sets the associated notification's data URI. */
        public Builder setNotificationDataUri(Uri notificationDataUri) {
            mNotificationDataUri = notificationDataUri;
@@ -342,6 +356,7 @@ public class PeopleSpaceTile implements Parcelable {
        mIsImportantConversation = in.readBoolean();
        mNotificationKey = in.readString();
        mNotificationContent = in.readCharSequence();
        mNotificationCategory = in.readString();
        mNotificationDataUri = in.readParcelable(Uri.class.getClassLoader());
        mIntent = in.readParcelable(Intent.class.getClassLoader());
        mNotificationTimestamp = in.readLong();
@@ -367,6 +382,7 @@ public class PeopleSpaceTile implements Parcelable {
        dest.writeBoolean(mIsImportantConversation);
        dest.writeString(mNotificationKey);
        dest.writeCharSequence(mNotificationContent);
        dest.writeString(mNotificationCategory);
        dest.writeParcelable(mNotificationDataUri, flags);
        dest.writeParcelable(mIntent, flags);
        dest.writeLong(mNotificationTimestamp);
+24 −0
Original line number Diff line number Diff line
<!--
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M6.5,5.5L12,11l7,-7 -1,-1 -6,6 -4.5,-4.5L11,4.5L11,3L5,3v6h1.5L6.5,5.5zM23.71,16.67C20.66,13.78 16.54,12 12,12 7.46,12 3.34,13.78 0.29,16.67c-0.18,0.18 -0.29,0.43 -0.29,0.71s0.11,0.53 0.29,0.71l2.48,2.48c0.18,0.18 0.43,0.29 0.71,0.29 0.27,0 0.52,-0.11 0.7,-0.28 0.79,-0.74 1.69,-1.36 2.66,-1.85 0.33,-0.16 0.56,-0.5 0.56,-0.9v-3.1c1.45,-0.48 3,-0.73 4.6,-0.73 1.6,0 3.15,0.25 4.6,0.72v3.1c0,0.39 0.23,0.74 0.56,0.9 0.98,0.49 1.87,1.12 2.67,1.85 0.18,0.18 0.43,0.28 0.7,0.28 0.28,0 0.53,-0.11 0.71,-0.29l2.48,-2.48c0.18,-0.18 0.29,-0.43 0.29,-0.71s-0.12,-0.52 -0.3,-0.7z" />
</vector>
+1 −1
Original line number Diff line number Diff line
@@ -15,6 +15,6 @@
  ~ limitations under the License.
  -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="?android:attr/colorControlHighlight" />
    <solid android:color="?android:attr/colorBackground" />
    <corners android:radius="@dimen/people_space_image_radius" />
</shape>
+2 −0
Original line number Diff line number Diff line
@@ -2840,6 +2840,8 @@
    <string name="empty_user_name" translatable="false">Your friend</string>
    <!-- Empty status shown before user has selected a friend [CHAR LIMIT=30] -->
    <string name="empty_status" translatable="false">Their status</string>
    <!-- Default text for missed call notifications [CHAR LIMIT=30] -->
    <string name="missed_call" translatable="false">Missed call</string>

    <!-- Title to display in a notification when ACTION_BATTERY_CHANGED.EXTRA_PRESENT field is false
    [CHAR LIMIT=NONE] -->
+49 −16
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.people;

import static android.app.Notification.CATEGORY_MISSED_CALL;
import static android.app.Notification.EXTRA_MESSAGES;
import static android.app.people.ConversationStatus.ACTIVITY_ANNIVERSARY;
import static android.app.people.ConversationStatus.ACTIVITY_BIRTHDAY;
@@ -189,7 +190,7 @@ public class PeopleSpaceUtils {
            tiles.addAll(recentTiles);
        }

        tiles = augmentTilesFromVisibleNotifications(tiles, notificationEntryManager);
        tiles = augmentTilesFromVisibleNotifications(context, tiles, notificationEntryManager);
        return tiles;
    }

@@ -357,8 +358,8 @@ public class PeopleSpaceUtils {
                && storedUserId == userId;
    }

    static List<PeopleSpaceTile> augmentTilesFromVisibleNotifications(List<PeopleSpaceTile> tiles,
            NotificationEntryManager notificationEntryManager) {
    static List<PeopleSpaceTile> augmentTilesFromVisibleNotifications(Context context,
            List<PeopleSpaceTile> tiles, NotificationEntryManager notificationEntryManager) {
        if (notificationEntryManager == null) {
            Log.w(TAG, "NotificationEntryManager is null");
            return tiles;
@@ -374,12 +375,13 @@ public class PeopleSpaceUtils {
        }
        return tiles
                .stream()
                .map(entry -> augmentTileFromVisibleNotifications(entry, visibleNotifications))
                .map(entry -> augmentTileFromVisibleNotifications(
                        context, entry, visibleNotifications))
                .collect(Collectors.toList());
    }

    static PeopleSpaceTile augmentTileFromVisibleNotifications(PeopleSpaceTile tile,
            Map<String, NotificationEntry> visibleNotifications) {
    static PeopleSpaceTile augmentTileFromVisibleNotifications(Context context,
            PeopleSpaceTile tile, Map<String, NotificationEntry> visibleNotifications) {
        String shortcutId = tile.getId();
        String packageName = tile.getPackageName();
        int userId = UserHandle.getUserHandleForUid(tile.getUid()).getIdentifier();
@@ -389,7 +391,7 @@ public class PeopleSpaceUtils {
            return tile;
        }
        if (DEBUG) Log.d(TAG, "Augmenting tile from visible notifications, key:" + key);
        return augmentTileFromNotification(tile, visibleNotifications.get(key).getSbn());
        return augmentTileFromNotification(context, tile, visibleNotifications.get(key).getSbn());
    }

    /**
@@ -408,7 +410,7 @@ public class PeopleSpaceUtils {
        }
        if (notificationAction == PeopleSpaceUtils.NotificationAction.POSTED) {
            if (DEBUG) Log.i(TAG, "Adding notification to storage, appWidgetId: " + appWidgetId);
            storedTile = augmentTileFromNotification(storedTile, sbn);
            storedTile = augmentTileFromNotification(context, storedTile, sbn);
        } else {
            if (DEBUG) {
                Log.i(TAG, "Removing notification from storage, appWidgetId: " + appWidgetId);
@@ -418,23 +420,40 @@ public class PeopleSpaceUtils {
                    .setNotificationKey(null)
                    .setNotificationContent(null)
                    .setNotificationDataUri(null)
                    .setNotificationCategory(null)
                    .build();
        }
        updateAppWidgetOptionsAndView(appWidgetManager, context, appWidgetId, storedTile);
    }

    static PeopleSpaceTile augmentTileFromNotification(PeopleSpaceTile tile,
    static PeopleSpaceTile augmentTileFromNotification(Context context, PeopleSpaceTile tile,
            StatusBarNotification sbn) {
        Notification.MessagingStyle.Message message = getLastMessagingStyleMessage(sbn);
        if (message == null) {
            if (DEBUG) Log.i(TAG, "Notification doesn't have content, skipping.");
        Notification notification = sbn.getNotification();
        if (notification == null) {
            if (DEBUG) Log.d(TAG, "Notification is null");
            return tile;
        }
        boolean isMissedCall = Objects.equals(notification.category, CATEGORY_MISSED_CALL);
        Notification.MessagingStyle.Message message = getLastMessagingStyleMessage(notification);

        if (!isMissedCall && message == null) {
            if (DEBUG) Log.d(TAG, "Notification has no content");
            return tile;
        }

        // If it's a missed call notification and it doesn't include content, use fallback value,
        // otherwise, use notification content.
        boolean hasMessageText = message != null && !TextUtils.isEmpty(message.getText());
        CharSequence content = (isMissedCall && !hasMessageText)
                ? context.getString(R.string.missed_call) : message.getText();
        Uri dataUri = message != null ? message.getDataUri() : null;

        return tile
                .toBuilder()
                .setNotificationKey(sbn.getKey())
                .setNotificationContent(message.getText())
                .setNotificationDataUri(message.getDataUri())
                .setNotificationCategory(notification.category)
                .setNotificationContent(content)
                .setNotificationDataUri(dataUri)
                .build();
    }

@@ -462,6 +481,11 @@ public class PeopleSpaceUtils {
     * content, then birthdays, then the most recent status, and finally last interaction.
     */
    private static RemoteViews getViewForTile(Context context, PeopleSpaceTile tile) {
        if (Objects.equals(tile.getNotificationCategory(), CATEGORY_MISSED_CALL)) {
            if (DEBUG) Log.d(TAG, "Create missed call view");
            return createMissedCallRemoteViews(context, tile);
        }

        if (tile.getNotificationKey() != null) {
            if (DEBUG) Log.d(TAG, "Create notification view");
            return createNotificationRemoteViews(context, tile);
@@ -630,6 +654,16 @@ public class PeopleSpaceUtils {
        return views;
    }

    private static RemoteViews createMissedCallRemoteViews(Context context,
            PeopleSpaceTile tile) {
        RemoteViews views = new RemoteViews(
                context.getPackageName(), R.layout.people_space_small_avatar_tile);
        views.setTextViewText(R.id.status, tile.getNotificationContent());
        views.setImageViewResource(R.id.status_defined_icon, R.drawable.ic_phone_missed);
        views.setBoolean(R.id.content_background, "setClipToOutline", true);
        return views;
    }

    private static RemoteViews createNotificationRemoteViews(Context context,
            PeopleSpaceTile tile) {
        RemoteViews views = new RemoteViews(
@@ -715,8 +749,7 @@ public class PeopleSpaceUtils {
    /** Gets the most recent {@link Notification.MessagingStyle.Message} from the notification. */
    @VisibleForTesting
    public static Notification.MessagingStyle.Message getLastMessagingStyleMessage(
            StatusBarNotification sbn) {
        Notification notification = sbn.getNotification();
            Notification notification) {
        if (notification == null) {
            return null;
        }
Loading