blob: 4981d5c5731fc91df33bce30eb4001a5ec1b4610 [file] [log] [blame]
Chris Wren5190c0f2014-05-08 10:42:09 -04001/*
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;
Julia Reynolds85769912016-10-25 09:08:57 -040020import android.app.NotificationManager;
Chris Wren5190c0f2014-05-08 10:42:09 -040021import android.content.Context;
Julia Reynolds24450372017-05-02 15:04:34 -040022import android.net.Uri;
Julia Reynolds0421e6d2016-01-08 09:51:24 -050023import android.service.notification.NotificationListenerService;
John Spurlock1d881a12015-03-18 19:21:54 -040024import android.util.Log;
Chris Wren5190c0f2014-05-08 10:42:09 -040025import android.util.Slog;
26
Chris Wren5190c0f2014-05-08 10:42:09 -040027/**
Julia Reynolds0dbb7312016-03-03 15:10:21 -050028 * This {@link com.android.server.notification.NotificationSignalExtractor} notices noisy
Chris Wren5190c0f2014-05-08 10:42:09 -040029 * notifications and marks them to get a temporary ranking bump.
30 */
31public class NotificationIntrusivenessExtractor implements NotificationSignalExtractor {
John Spurlock1d881a12015-03-18 19:21:54 -040032 private static final String TAG = "IntrusivenessExtractor";
33 private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
Chris Wren5190c0f2014-05-08 10:42:09 -040034
35 /** Length of time (in milliseconds) that an intrusive or noisy notification will stay at
36 the top of the ranking order, before it falls back to its natural position. */
37 private static final long HANG_TIME_MS = 10000;
38
Chris Wren5eab2b72015-06-16 13:56:22 -040039 public void initialize(Context ctx, NotificationUsageStats usageStats) {
Chris Wren5190c0f2014-05-08 10:42:09 -040040 if (DBG) Slog.d(TAG, "Initializing " + getClass().getSimpleName() + ".");
41 }
42
Chris Wren470c1ac2014-05-21 15:28:10 -040043 public RankingReconsideration process(NotificationRecord record) {
Chris Wren5190c0f2014-05-08 10:42:09 -040044 if (record == null || record.getNotification() == null) {
45 if (DBG) Slog.d(TAG, "skipping empty notification");
46 return null;
47 }
48
Julia Reynolds85769912016-10-25 09:08:57 -040049 if (record.getImportance() >= NotificationManager.IMPORTANCE_DEFAULT) {
Julia Reynolds24450372017-05-02 15:04:34 -040050 if (record.getSound() != null && record.getSound() != Uri.EMPTY) {
51 record.setRecentlyIntrusive(true);
52 }
53 if (record.getVibration() != null) {
54 record.setRecentlyIntrusive(true);
55 }
56 if (record.getNotification().fullScreenIntent != null) {
Julia Reynolds0dbb7312016-03-03 15:10:21 -050057 record.setRecentlyIntrusive(true);
58 }
Chris Wren5190c0f2014-05-08 10:42:09 -040059 }
60
Chris Wren470c1ac2014-05-21 15:28:10 -040061 return new RankingReconsideration(record.getKey(), HANG_TIME_MS) {
Chris Wren5190c0f2014-05-08 10:42:09 -040062 @Override
63 public void work() {
Chris Wren470c1ac2014-05-21 15:28:10 -040064 // pass
65 }
66
67 @Override
68 public void applyChangesLocked(NotificationRecord record) {
Julia Reynolds309d1c82017-05-03 16:00:20 -040069 // there will be another reconsideration in the message queue HANG_TIME_MS
70 // from each time this record alerts, which can finally clear this flag.
71 if ((System.currentTimeMillis() - record.getLastIntrusive()) >= HANG_TIME_MS) {
72 record.setRecentlyIntrusive(false);
73 }
Chris Wren5190c0f2014-05-08 10:42:09 -040074 }
75 };
76 }
Chris Wren54bbef42014-07-09 18:37:56 -040077
78 @Override
79 public void setConfig(RankingConfig config) {
80 // ignore: config has no relevant information yet.
81 }
82}