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

Commit 154f8283 authored by Chris Wren's avatar Chris Wren Committed by Android (Google) Code Review
Browse files

Merge "Add intrusiveness signal extractor."

parents 9e317da9 5190c0fe
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1394,9 +1394,10 @@
    </string-array>

    <!-- The list of classes that should be added to the notification ranking pipline.
     See {@link com.android.server.notification.NotificationSignalExtractortor} -->
     See {@link com.android.server.notification.NotificationSignalExtractor} -->
    <string-array name="config_notificationSignalExtractors">
        <item>com.android.server.notification.ValidateNotificationPeople</item>
        <item>com.android.server.notification.NotificationIntrusivenessExtractor</item>
    </string-array>

    <!-- Flag indicating that this device does not rotate and will always remain in its default
+3 −0
Original line number Diff line number Diff line
@@ -26,6 +26,9 @@ public class NotificationComparator
    @Override
    public int compare(NotificationManagerService.NotificationRecord lhs,
            NotificationManagerService.NotificationRecord rhs) {
        if (lhs.isRecentlyIntrusive() != rhs.isRecentlyIntrusive()) {
            return lhs.isRecentlyIntrusive() ? -1 : 1;
        }
        final int leftScore = lhs.sbn.getScore();
        final int rightScore = rhs.sbn.getScore();
        if (leftScore != rightScore) {
+64 −0
Original line number Diff line number Diff line
/*
* Copyright (C) 2014 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.app.Notification;
import android.content.Context;
import android.util.Slog;

import com.android.internal.R;
import com.android.server.notification.NotificationManagerService.NotificationRecord;

/**
 * This {@link com.android.server.notification.NotificationSignalExtractor} noticies noisy
 * notifications and marks them to get a temporary ranking bump.
 */
public class NotificationIntrusivenessExtractor implements NotificationSignalExtractor {
    private static final String TAG = "NotificationNoiseExtractor";
    private static final boolean DBG = false;

    /** Length of time (in milliseconds) that an intrusive or noisy notification will stay at
    the top of the ranking order, before it falls back to its natural position. */
    private static final long HANG_TIME_MS = 10000;

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

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

        final Notification notification = record.getNotification();
        if ((notification.defaults & Notification.DEFAULT_VIBRATE) != 0 ||
                notification.vibrate != null ||
                (notification.defaults & Notification.DEFAULT_SOUND) != 0 ||
                notification.sound != null ||
                notification.fullScreenIntent != null) {
            record.setRecentlyIntusive(true);
        }

        return new RankingFuture(record, HANG_TIME_MS) {
            @Override
            public void work() {
                mRecord.setRecentlyIntusive(false);
            }
        };
    }
}
 No newline at end of file
+12 −0
Original line number Diff line number Diff line
@@ -457,7 +457,11 @@ public class NotificationManagerService extends SystemService {
        final StatusBarNotification sbn;
        SingleNotificationStats stats;
        IBinder statusBarKey;

        // These members are used by NotificationSignalExtractors
        // to communicate with the ranking module.
        private float mContactAffinity;
        private boolean mRecentlyIntrusive;

        NotificationRecord(StatusBarNotification sbn)
        {
@@ -548,6 +552,14 @@ public class NotificationManagerService extends SystemService {
        public float getContactAffinity() {
            return mContactAffinity;
        }

        public boolean isRecentlyIntrusive() {
            return mRecentlyIntrusive;
        }

        public void setRecentlyIntusive(boolean recentlyIntrusive) {
            mRecentlyIntrusive = recentlyIntrusive;
        }
    }

    private static final class ToastRecord
+2 −2
Original line number Diff line number Diff line
@@ -64,8 +64,8 @@ public abstract class RankingFuture

    @Override
    public int compareTo(Delayed another) {
        return Long.compare(getDelay(TimeUnit.MICROSECONDS),
                another.getDelay(TimeUnit.MICROSECONDS));
        return Long.compare(getDelay(TimeUnit.MILLISECONDS),
                another.getDelay(TimeUnit.MILLISECONDS));
    }

    @Override