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

Commit eb3dca71 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Send less ranking reconsiderations and updates

- NotificationIntrusivenessExtractor does not need to reconsider
ranking for non intrusive notifications
- All adjustments (by group helper and the assistant) have been moved to
extractors so we can selectively send ranking updates instead of always
sending them.

Fixes: 62827235
Test: runtest systemui-notification
Change-Id: I2ea746c3883049abac0752788a3f4c2fa50c8064
parent ea9009b4
Loading
Loading
Loading
Loading
+14 −1
Original line number Original line Diff line number Diff line
@@ -17,7 +17,7 @@ package android.service.notification;


import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.TestApi;
import android.app.NotificationChannel;
import android.app.Notification;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
@@ -48,6 +48,12 @@ public final class Adjustment implements Parcelable {
     * {@link NotificationAssistantService#onNotificationSnoozedUntilContext}.
     * {@link NotificationAssistantService#onNotificationSnoozedUntilContext}.
     */
     */
    public static final String KEY_SNOOZE_CRITERIA = "key_snooze_criteria";
    public static final String KEY_SNOOZE_CRITERIA = "key_snooze_criteria";
    /**
     * Data type: String. Used to change what {@link Notification#getGroup() group} a notification
     * belongs to.
     * @hide
     */
    public static final String KEY_GROUP_KEY = "key_group_key";


    /**
    /**
     * Create a notification adjustment.
     * Create a notification adjustment.
@@ -146,4 +152,11 @@ public final class Adjustment implements Parcelable {
        dest.writeBundle(mSignals);
        dest.writeBundle(mSignals);
        dest.writeInt(mUser);
        dest.writeInt(mUser);
    }
    }

    @Override
    public String toString() {
        return "Adjustment{"
                + "mSignals=" + mSignals
                + '}';
    }
}
}
+9 −1
Original line number Original line Diff line number Diff line
@@ -2226,11 +2226,19 @@
    <string-array name="config_disabledUntilUsedPreinstalledCarrierApps" translatable="false" />
    <string-array name="config_disabledUntilUsedPreinstalledCarrierApps" translatable="false" />


    <!-- The list of classes that should be added to the notification ranking pipline.
    <!-- The list of classes that should be added to the notification ranking pipline.
     See {@link com.android.server.notification.NotificationSignalExtractor} -->
     See {@link com.android.server.notification.NotificationSignalExtractor}
      If you add a new extractor to this list make sure to update
      NotificationManagerService.handleRankingSort()-->
    <string-array name="config_notificationSignalExtractors">
    <string-array name="config_notificationSignalExtractors">
        <!-- many of the following extractors depend on the notification channel, so this
        extractor must come first -->
        <item>com.android.server.notification.NotificationChannelExtractor</item>
        <item>com.android.server.notification.NotificationAdjustmentExtractor</item>
        <!-- depends on AdjustmentExtractor-->
        <item>com.android.server.notification.ValidateNotificationPeople</item>
        <item>com.android.server.notification.ValidateNotificationPeople</item>
        <item>com.android.server.notification.PriorityExtractor</item>
        <item>com.android.server.notification.PriorityExtractor</item>
        <item>com.android.server.notification.ImportanceExtractor</item>
        <item>com.android.server.notification.ImportanceExtractor</item>
        <!-- depends on ImportanceExtractor-->
        <item>com.android.server.notification.NotificationIntrusivenessExtractor</item>
        <item>com.android.server.notification.NotificationIntrusivenessExtractor</item>
        <item>com.android.server.notification.VisibilityExtractor</item>
        <item>com.android.server.notification.VisibilityExtractor</item>
        <item>com.android.server.notification.BadgeExtractor</item>
        <item>com.android.server.notification.BadgeExtractor</item>
+5 −3
Original line number Original line Diff line number Diff line
@@ -47,9 +47,11 @@ public class BadgeExtractor implements NotificationSignalExtractor {
        if (!userWantsBadges || !appCanShowBadge) {
        if (!userWantsBadges || !appCanShowBadge) {
            record.setShowBadge(false);
            record.setShowBadge(false);
        } else {
        } else {
            record.setShowBadge(mConfig.getNotificationChannel(record.sbn.getPackageName(),
            if (record.getChannel() != null) {
                    record.sbn.getUid(), record.getChannel().getId(), false).canShowBadge()
                record.setShowBadge(record.getChannel().canShowBadge() && appCanShowBadge);
                    && appCanShowBadge);
            } else {
                record.setShowBadge(appCanShowBadge);
            }
        }
        }


        return null;
        return null;
+48 −0
Original line number Original line Diff line number Diff line
/**
* Copyright (C) 2017 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.
*/
package com.android.server.notification;

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

/**
 * Applies adjustments from the group helper and notification assistant
 */
public class NotificationAdjustmentExtractor implements NotificationSignalExtractor {
    private static final String TAG = "BadgeExtractor";
    private static final boolean DBG = false;


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

    public RankingReconsideration process(NotificationRecord record) {
        if (record == null || record.getNotification() == null) {
            if (DBG) Slog.d(TAG, "skipping empty notification");
            return null;
        }

        record.applyAdjustments();

        return null;
    }

    @Override
    public void setConfig(RankingConfig config) {
        // config is not used
    }
}
+55 −0
Original line number Original line Diff line number Diff line
/**
* Copyright (C) 2017 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.
*/
package com.android.server.notification;

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

/**
 * Stores the latest notification channel information for this notification
 */
public class NotificationChannelExtractor implements NotificationSignalExtractor {
    private static final String TAG = "BadgeExtractor";
    private static final boolean DBG = false;

    private RankingConfig mConfig;

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

    public RankingReconsideration process(NotificationRecord record) {
        if (record == null || record.getNotification() == null) {
            if (DBG) Slog.d(TAG, "skipping empty notification");
            return null;
        }

        if (mConfig == null) {
            if (DBG) Slog.d(TAG, "missing config");
            return null;
        }

        record.updateNotificationChannel(mConfig.getNotificationChannel(record.sbn.getPackageName(),
                record.sbn.getUid(), record.getChannel().getId(), false));

        return null;
    }

    @Override
    public void setConfig(RankingConfig config) {
        mConfig = config;
    }
}
Loading