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

Commit 067a739a authored by Beverly's avatar Beverly
Browse files

Don't increase notif importance when shouldSilence

If a notification already has a silent importance, the assistant
shouldn't suggest a higher importance.

Change-Id: I304743330a1183e3730b0d0b70b38d577f3dfad3
Fixes: 116810453
Test: Notification Attention Management Test (CTS Verifier)
Test: make ExtServices && adb install -r $OUT/system/priv-app/ExtServices/ExtServices.apk && atest ExtServicesUnitTests
parent 29077124
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import static android.service.notification.NotificationListenerService.Ranking
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityThread;
import android.app.AlarmManager;
import android.app.INotificationManager;
import android.app.Notification;
import android.app.NotificationChannel;
@@ -224,8 +223,9 @@ public class Assistant extends NotificationAssistantService {
    }

    /** A convenience helper for creating an adjustment for an SBN. */
    @VisibleForTesting
    @Nullable
    private Adjustment createEnqueuedNotificationAdjustment(
    Adjustment createEnqueuedNotificationAdjustment(
            @NonNull NotificationEntry entry,
            @NonNull ArrayList<Notification.Action> smartActions,
            @NonNull ArrayList<CharSequence> smartReplies) {
@@ -237,7 +237,9 @@ public class Assistant extends NotificationAssistantService {
            signals.putCharSequenceArrayList(Adjustment.KEY_SMART_REPLIES, smartReplies);
        }
        if (mNotificationCategorizer.shouldSilence(entry)) {
            signals.putInt(KEY_IMPORTANCE, IMPORTANCE_LOW);
            final int importance = entry.getImportance() < IMPORTANCE_LOW ? entry.getImportance()
                    : IMPORTANCE_LOW;
            signals.putInt(KEY_IMPORTANCE, importance);
        }

        return new Adjustment(
+9 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;

public class AssistantTest extends ServiceTestCase<Assistant> {

@@ -466,4 +467,12 @@ public class AssistantTest extends ServiceTestCase<Assistant> {

        assertFalse(mAssistant.mLiveNotifications.containsKey(sbn.getKey()));
    }

    @Test
    public void testAssistantNeverIncreasesImportanceWhenSuggestingSilent() throws Exception {
        StatusBarNotification sbn = generateSbn(PKG1, UID1, P1C3, "min notif!", null);
        Adjustment adjust = mAssistant.createEnqueuedNotificationAdjustment(new NotificationEntry(
                mPackageManager, sbn, P1C3), new ArrayList<>(), new ArrayList<>());
        assertEquals(IMPORTANCE_MIN, adjust.getSignals().getInt(Adjustment.KEY_IMPORTANCE));
    }
}