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

Commit f5534e84 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Schedule regrouping if classification adjustment is after notification...

Merge "Schedule regrouping if classification adjustment is after notification polite_notifications_attn_update" into main
parents 6481a94c bf59faca
Loading
Loading
Loading
Loading
+42 −17
Original line number Diff line number Diff line
@@ -832,8 +832,9 @@ public class GroupHelper {
                                      FullyQualifiedGroupKey newGroup) { }

    /**
     * Called when a notification channel is updated, so that this helper can adjust
     * the aggregate groups by moving children if their section has changed.
     * Called when a notification channel is updated (channel attributes have changed),
     * so that this helper can adjust the aggregate groups by moving children
     * if their section has changed.
     * see {@link #onNotificationPostedWithDelay(NotificationRecord, List, Map)}
     * @param userId the userId of the channel
     * @param pkgName the channel's package
@@ -853,6 +854,31 @@ public class GroupHelper {
                }
            }

            regroupNotifications(userId, pkgName, notificationsToCheck);
        }
    }

    /**
     * Called when an individuial notification's channel is updated (moved to a new channel),
     * so that this helper can adjust the aggregate groups by moving children
     * if their section has changed.
     * see {@link #onNotificationPostedWithDelay(NotificationRecord, List, Map)}
     *
     * @param record the notification which had its channel updated
     */
    @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_FORCE_GROUPING)
    public void onChannelUpdated(final NotificationRecord record) {
        synchronized (mAggregatedNotifications) {
            ArrayMap<String, NotificationRecord> notificationsToCheck = new ArrayMap<>();
            notificationsToCheck.put(record.getKey(), record);
            regroupNotifications(record.getUserId(), record.getSbn().getPackageName(),
                    notificationsToCheck);
        }
    }

    @GuardedBy("mAggregatedNotifications")
    private void regroupNotifications(int userId, String pkgName,
            ArrayMap<String, NotificationRecord> notificationsToCheck) {
        // The list of notification operations required after the channel update
        final ArrayList<NotificationMoveOp> notificationsToMove = new ArrayList<>();

@@ -872,7 +898,6 @@ public class GroupHelper {
            moveNotificationsToNewSection(userId, pkgName, notificationsToMove);
        }
    }
    }

    @GuardedBy("mAggregatedNotifications")
    private List<NotificationMoveOp> getAutogroupedNotificationsMoveOps(int userId, String pkgName,
+28 −0
Original line number Diff line number Diff line
@@ -15,6 +15,9 @@
*/
package com.android.server.notification;

import static android.service.notification.Adjustment.KEY_TYPE;
import static android.service.notification.Flags.notificationForceGrouping;

import android.content.Context;
import android.util.Slog;

@@ -24,6 +27,7 @@ import android.util.Slog;
public class NotificationAdjustmentExtractor implements NotificationSignalExtractor {
    private static final String TAG = "AdjustmentExtractor";
    private static final boolean DBG = false;
    private GroupHelper mGroupHelper;


    public void initialize(Context ctx, NotificationUsageStats usageStats) {
@@ -35,8 +39,27 @@ public class NotificationAdjustmentExtractor implements NotificationSignalExtrac
            if (DBG) Slog.d(TAG, "skipping empty notification");
            return null;
        }

        final boolean hasAdjustedClassification = record.hasAdjustment(KEY_TYPE);
        record.applyAdjustments();

        if (notificationForceGrouping()
                && android.service.notification.Flags.notificationClassification()) {
            // Classification adjustments trigger regrouping
            if (mGroupHelper != null && hasAdjustedClassification) {
                return new RankingReconsideration(record.getKey(), 0) {
                    @Override
                    public void work() {
                    }

                    @Override
                    public void applyChangesLocked(NotificationRecord record) {
                        mGroupHelper.onChannelUpdated(record);
                    }
                };
            }
        }

        return null;
    }

@@ -49,4 +72,9 @@ public class NotificationAdjustmentExtractor implements NotificationSignalExtrac
    public void setZenHelper(ZenModeHelper helper) {

    }

    @Override
    public void setGroupHelper(GroupHelper groupHelper) {
        mGroupHelper = groupHelper;
    }
}
+26 −17
Original line number Diff line number Diff line
@@ -519,6 +519,7 @@ public class NotificationManagerService extends SystemService {
    private static final long DELAY_FORCE_REGROUP_TIME = 3000;
    private static final String ACTION_NOTIFICATION_TIMEOUT =
            NotificationManagerService.class.getSimpleName() + ".TIMEOUT";
    private static final int REQUEST_CODE_TIMEOUT = 1;
@@ -2583,7 +2584,7 @@ public class NotificationManagerService extends SystemService {
                mShowReviewPermissionsNotification,
                Clock.systemUTC());
        mRankingHelper = new RankingHelper(getContext(), mRankingHandler, mPreferencesHelper,
                mZenModeHelper, mUsageStats, extractorNames, mPlatformCompat);
                mZenModeHelper, mUsageStats, extractorNames, mPlatformCompat, groupHelper);
        mSnoozeHelper = snoozeHelper;
        mGroupHelper = groupHelper;
        mHistoryManager = historyManager;
@@ -6871,22 +6872,9 @@ public class NotificationManagerService extends SystemService {
            }
            if (android.service.notification.Flags.notificationClassification()
                    && adjustments.containsKey(KEY_TYPE)) {
                NotificationChannel newChannel = null;
                int type = adjustments.getInt(KEY_TYPE);
                if (TYPE_NEWS == type) {
                    newChannel = mPreferencesHelper.getNotificationChannel(
                            r.getSbn().getPackageName(), r.getUid(), NEWS_ID, false);
                } else if (TYPE_PROMOTION == type) {
                    newChannel = mPreferencesHelper.getNotificationChannel(
                            r.getSbn().getPackageName(), r.getUid(), PROMOTIONS_ID, false);
                } else if (TYPE_SOCIAL_MEDIA == type) {
                    newChannel = mPreferencesHelper.getNotificationChannel(
                            r.getSbn().getPackageName(), r.getUid(), SOCIAL_MEDIA_ID, false);
                } else if (TYPE_CONTENT_RECOMMENDATION == type) {
                    newChannel = mPreferencesHelper.getNotificationChannel(
                            r.getSbn().getPackageName(), r.getUid(), RECS_ID, false);
                }
                if (newChannel == null) {
                final NotificationChannel newChannel = getClassificationChannelLocked(r,
                        adjustments);
                if (newChannel == null || newChannel.getId().equals(r.getChannel().getId())) {
                    adjustments.remove(KEY_TYPE);
                } else {
                    // swap app provided type with the real thing
@@ -6902,6 +6890,27 @@ public class NotificationManagerService extends SystemService {
        }
    }
    @GuardedBy("mNotificationLock")
    @Nullable
    private NotificationChannel getClassificationChannelLocked(NotificationRecord r,
            Bundle adjustments) {
        int type = adjustments.getInt(KEY_TYPE);
        if (TYPE_NEWS == type) {
            return mPreferencesHelper.getNotificationChannel(
                    r.getSbn().getPackageName(), r.getUid(), NEWS_ID, false);
        } else if (TYPE_PROMOTION == type) {
            return mPreferencesHelper.getNotificationChannel(
                    r.getSbn().getPackageName(), r.getUid(), PROMOTIONS_ID, false);
        } else if (TYPE_SOCIAL_MEDIA == type) {
            return mPreferencesHelper.getNotificationChannel(
                    r.getSbn().getPackageName(), r.getUid(), SOCIAL_MEDIA_ID, false);
        } else if (TYPE_CONTENT_RECOMMENDATION == type) {
            return mPreferencesHelper.getNotificationChannel(
                    r.getSbn().getPackageName(), r.getUid(), RECS_ID, false);
        }
        return null;
    }
    @SuppressWarnings("GuardedBy")
    @GuardedBy("mNotificationLock")
    void addAutogroupKeyLocked(String key, String groupName, boolean requestSort) {
+5 −0
Original line number Diff line number Diff line
@@ -55,4 +55,9 @@ public interface NotificationSignalExtractor {
    void setZenHelper(ZenModeHelper helper);

    default void setCompatChangeLogger(IPlatformCompat platformCompat){};

    /**
     * @param groupHelper Helper for auto-grouping notifications
     */
    default void setGroupHelper(GroupHelper groupHelper){};
}
+2 −2
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.text.TextUtils.formatSimple;

import android.annotation.NonNull;
import android.app.NotificationManager;
import android.content.Context;
import android.service.notification.RankingHelperProto;
import android.util.ArrayMap;
@@ -61,7 +60,7 @@ public class RankingHelper {
            })
    public RankingHelper(Context context, RankingHandler rankingHandler, RankingConfig config,
            ZenModeHelper zenHelper, NotificationUsageStats usageStats, String[] extractorNames,
            IPlatformCompat platformCompat) {
            IPlatformCompat platformCompat, GroupHelper groupHelper) {
        mContext = context;
        mRankingHandler = rankingHandler;
        if (sortSectionByTime()) {
@@ -80,6 +79,7 @@ public class RankingHelper {
                extractor.initialize(mContext, usageStats);
                extractor.setConfig(config);
                extractor.setZenHelper(zenHelper);
                extractor.setGroupHelper(groupHelper);
                if (restrictAudioAttributesAlarm() || restrictAudioAttributesMedia()
                        || restrictAudioAttributesCall()) {
                    extractor.setCompatChangeLogger(platformCompat);
Loading