NotificationIntrusivenessExtractor.java revision 5190c0fefac9923931b5c1c02cab2d00c2d6b82b
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
23import com.android.internal.R;
24import com.android.server.notification.NotificationManagerService.NotificationRecord;
25
26/**
27 * This {@link com.android.server.notification.NotificationSignalExtractor} noticies noisy
28 * notifications and marks them to get a temporary ranking bump.
29 */
30public class NotificationIntrusivenessExtractor implements NotificationSignalExtractor {
31    private static final String TAG = "NotificationNoiseExtractor";
32    private static final boolean DBG = false;
33
34    /** Length of time (in milliseconds) that an intrusive or noisy notification will stay at
35    the top of the ranking order, before it falls back to its natural position. */
36    private static final long HANG_TIME_MS = 10000;
37
38    public void initialize(Context ctx) {
39        if (DBG) Slog.d(TAG, "Initializing  " + getClass().getSimpleName() + ".");
40    }
41
42    public RankingFuture process(NotificationRecord record) {
43        if (record == null || record.getNotification() == null) {
44            if (DBG) Slog.d(TAG, "skipping empty notification");
45            return null;
46        }
47
48        final Notification notification = record.getNotification();
49        if ((notification.defaults & Notification.DEFAULT_VIBRATE) != 0 ||
50                notification.vibrate != null ||
51                (notification.defaults & Notification.DEFAULT_SOUND) != 0 ||
52                notification.sound != null ||
53                notification.fullScreenIntent != null) {
54            record.setRecentlyIntusive(true);
55        }
56
57        return new RankingFuture(record, HANG_TIME_MS) {
58            @Override
59            public void work() {
60                mRecord.setRecentlyIntusive(false);
61            }
62        };
63    }
64}