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

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

Merge "Remove unused extractor" into main

parents d85d573d 1be1b6a6
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -3714,7 +3714,6 @@
        <item>com.android.server.notification.ZenModeExtractor</item>
        <item>com.android.server.notification.ImportanceExtractor</item>
        <!-- depends on ImportanceExtractor-->
        <item>com.android.server.notification.NotificationIntrusivenessExtractor</item>
        <item>com.android.server.notification.VisibilityExtractor</item>
        <!-- Depends on ZenModeExtractor -->
        <item>com.android.server.notification.BadgeExtractor</item>
+0 −93
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.NotificationManager;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;

/**
 * This {@link com.android.server.notification.NotificationSignalExtractor} notices noisy
 * notifications and marks them to get a temporary ranking bump.
 */
public class NotificationIntrusivenessExtractor implements NotificationSignalExtractor {
    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. */
    @VisibleForTesting
    static final long HANG_TIME_MS = 10000;

    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 (record.getFreshnessMs(System.currentTimeMillis()) < HANG_TIME_MS
                && record.getImportance() >= NotificationManager.IMPORTANCE_DEFAULT) {
            if (record.getSound() != null && record.getSound() != Uri.EMPTY) {
                record.setRecentlyIntrusive(true);
            }
            if (record.getVibration() != null) {
                record.setRecentlyIntrusive(true);
            }
            if (record.getNotification().fullScreenIntent != null) {
                record.setRecentlyIntrusive(true);
            }
        }

        if (!record.isRecentlyIntrusive()) {
            return null;
        }

        return new RankingReconsideration(record.getKey(), HANG_TIME_MS) {
            @Override
            public void work() {
                // pass
            }

            @Override
            public void applyChangesLocked(NotificationRecord record) {
                // there will be another reconsideration in the message queue HANG_TIME_MS
                // from each time this record alerts, which can finally clear this flag.
                if ((System.currentTimeMillis() - record.getLastIntrusive()) >= HANG_TIME_MS) {
                    record.setRecentlyIntrusive(false);
                }
            }
        };
    }

    @Override
    public void setConfig(RankingConfig config) {
        // ignore: config has no relevant information yet.
    }

    @Override
    public void setZenHelper(ZenModeHelper helper) {

    }
}
+0 −19
Original line number Diff line number Diff line
@@ -111,8 +111,6 @@ public final class NotificationRecord {
    // These members are used by NotificationSignalExtractors
    // to communicate with the ranking module.
    private float mContactAffinity;
    private boolean mRecentlyIntrusive;
    private long mLastIntrusive;

    // is this notification currently being intercepted by Zen Mode?
    private boolean mIntercept;
@@ -462,7 +460,6 @@ public final class NotificationRecord {
    // copy any notes that the ranking system may have made before the update
    public void copyRankingInformation(NotificationRecord previous) {
        mContactAffinity = previous.mContactAffinity;
        mRecentlyIntrusive = previous.mRecentlyIntrusive;
        mPackagePriority = previous.mPackagePriority;
        mPackageVisibility = previous.mPackageVisibility;
        mIntercept = previous.mIntercept;
@@ -542,7 +539,6 @@ public final class NotificationRecord {
        dumpNotification(pw, prefix + prefix, notification.publicVersion, redact);
        pw.println(prefix + "stats=" + stats.toString());
        pw.println(prefix + "mContactAffinity=" + mContactAffinity);
        pw.println(prefix + "mRecentlyIntrusive=" + mRecentlyIntrusive);
        pw.println(prefix + "mPackagePriority=" + mPackagePriority);
        pw.println(prefix + "mPackageVisibility=" + mPackageVisibility);
        pw.println(prefix + "mSystemImportance="
@@ -873,21 +869,6 @@ public final class NotificationRecord {
        return mContactAffinity;
    }

    public void setRecentlyIntrusive(boolean recentlyIntrusive) {
        mRecentlyIntrusive = recentlyIntrusive;
        if (recentlyIntrusive) {
            mLastIntrusive = System.currentTimeMillis();
        }
    }

    public boolean isRecentlyIntrusive() {
        return mRecentlyIntrusive;
    }

    public long getLastIntrusive() {
        return mLastIntrusive;
    }

    public void setPackagePriority(int packagePriority) {
        mPackagePriority = packagePriority;
    }
+0 −94
Original line number 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 static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_LOW;

import static com.android.server.notification.NotificationIntrusivenessExtractor.HANG_TIME_MS;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;

import com.android.server.UiServiceTestCase;

import org.junit.Test;

public class NotificationIntrusivenessExtractorTest extends UiServiceTestCase {

    @Test
    public void testNonIntrusive() {
        NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
        final Notification.Builder builder = new Notification.Builder(getContext())
                .setContentTitle("foo")
                .setSmallIcon(android.R.drawable.sym_def_app_icon);

        Notification n = builder.build();
        StatusBarNotification sbn = new StatusBarNotification("", "", 0, "", 0,
                0, n, UserHandle.ALL, null, System.currentTimeMillis());
        NotificationRecord r = new NotificationRecord(getContext(), sbn, channel);

        assertNull(new NotificationIntrusivenessExtractor().process(r));
    }

    @Test
    public void testIntrusive_fillScreen() {
        NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_DEFAULT);
        final Notification.Builder builder = new Notification.Builder(getContext())
                .setContentTitle("foo")
                .setFullScreenIntent(PendingIntent.getActivity(
                        getContext(), 0, new Intent(""), PendingIntent.FLAG_IMMUTABLE),
                        true)
                .setSmallIcon(android.R.drawable.sym_def_app_icon);

        Notification n = builder.build();
        StatusBarNotification sbn = new StatusBarNotification("", "", 0, "", 0,
                0, n, UserHandle.ALL, null,
                System.currentTimeMillis());
        NotificationRecord r = new NotificationRecord(getContext(), sbn, channel);

        assertNotNull(new NotificationIntrusivenessExtractor().process(r));
    }

    @Test
    public void testOldNotificationsNotIntrusive() {
        NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_DEFAULT);
        final Notification.Builder builder = new Notification.Builder(getContext())
                .setContentTitle("foo")
                .setFullScreenIntent(PendingIntent.getActivity(
                        getContext(), 0, new Intent(""), PendingIntent.FLAG_IMMUTABLE),
                        true)
                .setSmallIcon(android.R.drawable.sym_def_app_icon);

        Notification n = builder.build();
        StatusBarNotification sbn = new StatusBarNotification("", "", 0, "", 0,
                0, n, UserHandle.ALL, null,
                System.currentTimeMillis() - HANG_TIME_MS);

        NotificationRecord r = new NotificationRecord(getContext(), sbn, channel);
        assertNull(new NotificationIntrusivenessExtractor().process(r));
        assertFalse(r.isRecentlyIntrusive());
    }
}
+0 −20
Original line number Diff line number Diff line
@@ -103,7 +103,6 @@ public class RankingHelperTest extends UiServiceTestCase {
    private NotificationRecord mRecordNoGroup;
    private NotificationRecord mRecordNoGroup2;
    private NotificationRecord mRecordNoGroupSortA;
    private NotificationRecord mRecentlyIntrusive;
    private NotificationRecord mNewest;
    private RankingHelper mHelper;

@@ -206,11 +205,6 @@ public class RankingHelperTest extends UiServiceTestCase {
        Notification n = new Notification.Builder(mContext, TEST_CHANNEL_ID)
                .setContentTitle("D")
                .build();
        mRecentlyIntrusive = new NotificationRecord(mContext, new StatusBarNotification(
                mPkg, mPkg, 1, null, 0, 0, n, mUser,
                null, 100), getDefaultChannel());
        mRecentlyIntrusive.setRecentlyIntrusive(true);

        mNewest = new NotificationRecord(mContext, new StatusBarNotification(
                mPkg, mPkg, 2, null, 0, 0, n, mUser,
                null, 10000), getDefaultChannel());
@@ -346,20 +340,6 @@ public class RankingHelperTest extends UiServiceTestCase {
        assertEquals(low, notificationList.get(2));
    }

    @Test
    public void testSortByRecencyNotIntrusiveness() {
        ArrayList<NotificationRecord> expected = new ArrayList<>();
        expected.add(mNewest);
        expected.add(mRecentlyIntrusive);

        ArrayList<NotificationRecord> actual = new ArrayList<>();
        actual.addAll(expected);
        Collections.shuffle(actual);

        mHelper.sort(actual);
        assertThat(actual).containsExactlyElementsIn(expected).inOrder();
    }

    @Test
    public void testSort_oldWhenChildren_unspecifiedSummary() {
        NotificationRecord child1 = new NotificationRecord(mContext,