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

Commit 1d881a1e authored by John Spurlock's avatar John Spurlock
Browse files

HUN: Implement per-package config.

- Keep track of whether or not HUNs are allowed per-package.
- No impact on ranking, purely presentational.
- Simplify RankingHelper with a package table.
- Improve RankingHelper dump.
- Fix some warnings and typos.

Bug: 19776495
Change-Id: I28d69df69b576f4eabbb528eabecb1f736f0e830
parent 11b7445f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -48,6 +48,9 @@ interface INotificationManager
    void setPackagePriority(String pkg, int uid, int priority);
    int getPackagePriority(String pkg, int uid);

    void setPackagePeekable(String pkg, int uid, boolean peekable);
    boolean getPackagePeekable(String pkg, int uid);

    void setPackageVisibilityOverride(String pkg, int uid, int visibility);
    int getPackageVisibilityOverride(String pkg, int uid);

+20 −0
Original line number Diff line number Diff line
@@ -1839,6 +1839,26 @@ public class Notification implements Parcelable
        }
    }

    /**
     * {@hide}
     */
    public static String priorityToString(@Priority int pri) {
        switch (pri) {
            case PRIORITY_MIN:
                return "MIN";
            case PRIORITY_LOW:
                return "LOW";
            case PRIORITY_DEFAULT:
                return "DEFAULT";
            case PRIORITY_HIGH:
                return "HIGH";
            case PRIORITY_MAX:
                return "MAX";
            default:
                return "UNKNOWN(" + String.valueOf(pri) + ")";
        }
    }

    /**
     * @hide
     */
+5 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.notification;

import android.app.Notification;
import android.content.Context;
import android.util.Log;
import android.util.Slog;

/**
@@ -25,8 +26,8 @@ import android.util.Slog;
 * 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;
    private static final String TAG = "IntrusivenessExtractor";
    private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);

    /** 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. */
@@ -48,7 +49,7 @@ public class NotificationIntrusivenessExtractor implements NotificationSignalExt
                (notification.defaults & Notification.DEFAULT_SOUND) != 0 ||
                notification.sound != null ||
                notification.fullScreenIntent != null) {
            record.setRecentlyIntusive(true);
            record.setRecentlyIntrusive(true);
        }

        return new RankingReconsideration(record.getKey(), HANG_TIME_MS) {
@@ -59,7 +60,7 @@ public class NotificationIntrusivenessExtractor implements NotificationSignalExt

            @Override
            public void applyChangesLocked(NotificationRecord record) {
                record.setRecentlyIntusive(false);
                record.setRecentlyIntrusive(false);
            }
        };
    }
+21 −0
Original line number Diff line number Diff line
@@ -1215,6 +1215,19 @@ public class NotificationManagerService extends SystemService {
            return mRankingHelper.getPackagePriority(pkg, uid);
        }

        @Override
        public void setPackagePeekable(String pkg, int uid, boolean peekable) {
            checkCallerIsSystem();

            mRankingHelper.setPackagePeekable(pkg, uid, peekable);
        }

        @Override
        public boolean getPackagePeekable(String pkg, int uid) {
            checkCallerIsSystem();
            return mRankingHelper.getPackagePeekable(pkg, uid);
        }

        @Override
        public void setPackageVisibilityOverride(String pkg, int uid, int visibility) {
            checkCallerIsSystem();
@@ -1845,6 +1858,14 @@ public class NotificationManagerService extends SystemService {
                            notification.priority = Notification.PRIORITY_HIGH;
                        }
                    }
                    // force no heads up per package config
                    if (!mRankingHelper.getPackagePeekable(pkg, callingUid)) {
                        if (notification.extras == null) {
                            notification.extras = new Bundle();
                        }
                        notification.extras.putInt(Notification.EXTRA_AS_HEADS_UP,
                                Notification.HEADS_UP_NEVER);
                    }

                    // 1. initial score: buckets of 10, around the app [-20..20]
                    final int score = notification.priority * NOTIFICATION_PRIORITY_MULTIPLIER;
+1 −1
Original line number Diff line number Diff line
@@ -209,7 +209,7 @@ public final class NotificationRecord {
        return mContactAffinity;
    }

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

Loading