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

Commit 7c267526 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Addressing conversation info todos

- Linking the conversation notification to the newly created
channel and triggering a ranking update
- Incorporating the flag for whether notifications/channels with
invalid shortcut ids should be allowed

Test: atest
Bug: 137397357
Change-Id: Ice1d545f2405a6c9b9eefaf1fd5481622ad72d7b
parent c3e922b0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ interface INotificationManager
    void updateNotificationChannelForPackage(String pkg, int uid, in NotificationChannel channel);
    NotificationChannel getNotificationChannel(String callingPkg, int userId, String pkg, String channelId);
    NotificationChannel getConversationNotificationChannel(String callingPkg, int userId, String pkg, String channelId, boolean returnParentIfNoConversationChannel, String conversationId);
    void createConversationNotificationChannelForPackage(String pkg, int uid, in NotificationChannel parentChannel, String conversationId);
    void createConversationNotificationChannelForPackage(String pkg, int uid, String triggeringKey, in NotificationChannel parentChannel, String conversationId);
    NotificationChannel getNotificationChannelForPackage(String pkg, int uid, String channelId, boolean includeDeleted);
    void deleteNotificationChannel(String pkg, String channelId);
    void deleteConversationNotificationChannels(String pkg, int uid, String conversationId);
+18 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package android.service.notification;

import static android.app.NotificationChannel.PLACEHOLDER_CONVERSATION_ID;
import static android.util.FeatureFlagUtils.*;

import android.annotation.NonNull;
import android.app.Notification;
import android.app.NotificationManager;
@@ -29,6 +32,8 @@ import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.FeatureFlagUtils;

import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -436,6 +441,19 @@ public class StatusBarNotification implements Parcelable {
        return logMaker;
    }

    /**
     * @hide
     */
    public String getShortcutId(Context context) {
        String conversationId = getNotification().getShortcutId();
        if (isEnabled(context,  NOTIF_CONVO_BYPASS_SHORTCUT_REQ)
                && getNotification().getNotificationStyle() == Notification.MessagingStyle.class
                && TextUtils.isEmpty(conversationId)) {
            conversationId = getId() + getTag() + PLACEHOLDER_CONVERSATION_ID;
        }
        return conversationId;
    }

    private String getGroupLogTag() {
        return shortenTag(getGroup());
    }
+4 −10
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.systemui.statusbar.notification.row;

import static android.app.Notification.EXTRA_IS_GROUP_CONVERSATION;
import static android.app.NotificationChannel.PLACEHOLDER_CONVERSATION_ID;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
@@ -103,7 +102,6 @@ public class NotificationConversationInfo extends LinearLayout implements
    private NotificationEntry mEntry;
    private StatusBarNotification mSbn;
    private boolean mIsDeviceProvisioned;

    private int mStartingChannelImportance;
    private boolean mStartedAsBubble;
    private boolean mIsBubbleable;
@@ -212,11 +210,10 @@ public class NotificationConversationInfo extends LinearLayout implements
        mLauncherApps = launcherApps;
        mConversationId = mNotificationChannel.getConversationId();
        if (TextUtils.isEmpty(mNotificationChannel.getConversationId())) {
            mConversationId = mSbn.getNotification().getShortcutId();
            mConversationId = mSbn.getShortcutId(mContext);
        }
        // TODO: flag this when flag exists
        if (TextUtils.isEmpty(mConversationId)) {
            mConversationId = mSbn.getId() + mSbn.getTag() + PLACEHOLDER_CONVERSATION_ID;
            throw new IllegalArgumentException("Does not have required information");
        }
        // TODO: consider querying this earlier in the notification pipeline and passing it in
        LauncherApps.ShortcutQuery query = new LauncherApps.ShortcutQuery()
@@ -243,10 +240,9 @@ public class NotificationConversationInfo extends LinearLayout implements
        // a custom channel
        if (TextUtils.isEmpty(mNotificationChannel.getConversationId())) {
            try {
                // TODO: associate this key with this channel service side so the customization
                // isn't forgotten on the next update
                mINotificationManager.createConversationNotificationChannelForPackage(
                        mPackageName, mAppUid, mNotificationChannel, mConversationId);
                        mPackageName, mAppUid, mSbn.getKey(), mNotificationChannel,
                        mConversationId);
                mNotificationChannel = mINotificationManager.getConversationNotificationChannel(
                        mContext.getOpPackageName(), UserHandle.getUserId(mAppUid), mPackageName,
                        mNotificationChannel.getId(), false, mConversationId);
@@ -363,7 +359,6 @@ public class NotificationConversationInfo extends LinearLayout implements
            image.setImageDrawable(mLauncherApps.getShortcutBadgedIconDrawable(mShortcutInfo,
                    mContext.getResources().getDisplayMetrics().densityDpi));
        } else {
            // TODO: flag this behavior
            if (mSbn.getNotification().extras.getBoolean(EXTRA_IS_GROUP_CONVERSATION, false)) {
                // TODO: maybe use a generic group icon, or a composite of recent senders
                image.setImageDrawable(mPm.getDefaultActivityIcon());
@@ -391,7 +386,6 @@ public class NotificationConversationInfo extends LinearLayout implements
        if (mShortcutInfo != null) {
            name.setText(mShortcutInfo.getShortLabel());
        } else {
            // TODO: flag this behavior
            Bundle extras = mSbn.getNotification().extras;
            String nameString = extras.getString(Notification.EXTRA_CONVERSATION_TITLE);
            if (TextUtils.isEmpty(nameString)) {
+2 −2
Original line number Diff line number Diff line
@@ -797,7 +797,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase {
                null,
                true);
        verify(mMockINotificationManager, times(1)).createConversationNotificationChannelForPackage(
                anyString(), anyInt(), any(), eq(CONVERSATION_ID));
                anyString(), anyInt(), anyString(), any(), eq(CONVERSATION_ID));
    }

    @Test
@@ -817,7 +817,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase {
                null,
                true);
        verify(mMockINotificationManager, never()).createConversationNotificationChannelForPackage(
                anyString(), anyInt(), any(), eq(CONVERSATION_ID));
                anyString(), anyInt(), anyString(), any(), eq(CONVERSATION_ID));
    }

    @Test
+8 −3
Original line number Diff line number Diff line
@@ -15,7 +15,10 @@
*/
package com.android.server.notification;

import android.app.Notification;
import android.app.NotificationChannel;
import android.content.Context;
import android.util.FeatureFlagUtils;
import android.util.Slog;

/**
@@ -26,8 +29,10 @@ public class NotificationChannelExtractor implements NotificationSignalExtractor
    private static final boolean DBG = false;

    private RankingConfig mConfig;
    private Context mContext;

    public void initialize(Context ctx, NotificationUsageStats usageStats) {
        mContext = ctx;
        if (DBG) Slog.d(TAG, "Initializing  " + getClass().getSimpleName() + ".");
    }

@@ -41,11 +46,11 @@ public class NotificationChannelExtractor implements NotificationSignalExtractor
            if (DBG) Slog.d(TAG, "missing config");
            return null;
        }

        record.updateNotificationChannel(mConfig.getConversationNotificationChannel(
        NotificationChannel updatedChannel = mConfig.getConversationNotificationChannel(
                record.sbn.getPackageName(),
                record.sbn.getUid(), record.getChannel().getId(),
                record.getNotification().getShortcutId(), true, false));
                record.sbn.getShortcutId(mContext), true, false);
        record.updateNotificationChannel(updatedChannel);

        return null;
    }
Loading