NotificationIntrusivenessExtractor.java revision 54bbef435ed857fc68941672799fc8001c101119
1/*
2* Copyright (C) 2014 The Android Open Source Project
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8*      http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17package com.android.server.notification;
18
19import android.app.Notification;
20import android.content.Context;
21import android.util.Slog;
22
23/**
24 * This {@link com.android.server.notification.NotificationSignalExtractor} noticies noisy
25 * notifications and marks them to get a temporary ranking bump.
26 */
27public class NotificationIntrusivenessExtractor implements NotificationSignalExtractor {
28    private static final String TAG = "NotificationNoiseExtractor";
29    private static final boolean DBG = false;
30
31    /** Length of time (in milliseconds) that an intrusive or noisy notification will stay at
32    the top of the ranking order, before it falls back to its natural position. */
33    private static final long HANG_TIME_MS = 10000;
34
35    public void initialize(Context ctx) {
36        if (DBG) Slog.d(TAG, "Initializing  " + getClass().getSimpleName() + ".");
37    }
38
39    public RankingReconsideration process(NotificationRecord record) {
40        if (record == null || record.getNotification() == null) {
41            if (DBG) Slog.d(TAG, "skipping empty notification");
42            return null;
43        }
44
45        final Notification notification = record.getNotification();
46        if ((notification.defaults & Notification.DEFAULT_VIBRATE) != 0 ||
47                notification.vibrate != null ||
48                (notification.defaults & Notification.DEFAULT_SOUND) != 0 ||
49                notification.sound != null ||
50                notification.fullScreenIntent != null) {
51            record.setRecentlyIntusive(true);
52        }
53
54        return new RankingReconsideration(record.getKey(), HANG_TIME_MS) {
55            @Override
56            public void work() {
57                // pass
58            }
59
60            @Override
61            public void applyChangesLocked(NotificationRecord record) {
62                record.setRecentlyIntusive(false);
63            }
64        };
65    }
66
67    @Override
68    public void setConfig(RankingConfig config) {
69        // ignore: config has no relevant information yet.
70    }
71}
72