Chris Wren | 5190c0f | 2014-05-08 10:42:09 -0400 | [diff] [blame] | 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 | |
| 17 | package com.android.server.notification; |
| 18 | |
| 19 | import android.app.Notification; |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 20 | import android.app.NotificationManager; |
Chris Wren | 5190c0f | 2014-05-08 10:42:09 -0400 | [diff] [blame] | 21 | import android.content.Context; |
Julia Reynolds | 2445037 | 2017-05-02 15:04:34 -0400 | [diff] [blame] | 22 | import android.net.Uri; |
Julia Reynolds | 0421e6d | 2016-01-08 09:51:24 -0500 | [diff] [blame] | 23 | import android.service.notification.NotificationListenerService; |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 24 | import android.util.Log; |
Chris Wren | 5190c0f | 2014-05-08 10:42:09 -0400 | [diff] [blame] | 25 | import android.util.Slog; |
| 26 | |
Chris Wren | 5190c0f | 2014-05-08 10:42:09 -0400 | [diff] [blame] | 27 | /** |
Julia Reynolds | 0dbb731 | 2016-03-03 15:10:21 -0500 | [diff] [blame] | 28 | * This {@link com.android.server.notification.NotificationSignalExtractor} notices noisy |
Chris Wren | 5190c0f | 2014-05-08 10:42:09 -0400 | [diff] [blame] | 29 | * notifications and marks them to get a temporary ranking bump. |
| 30 | */ |
| 31 | public class NotificationIntrusivenessExtractor implements NotificationSignalExtractor { |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 32 | private static final String TAG = "IntrusivenessExtractor"; |
| 33 | private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG); |
Chris Wren | 5190c0f | 2014-05-08 10:42:09 -0400 | [diff] [blame] | 34 | |
| 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 Wren | 5eab2b7 | 2015-06-16 13:56:22 -0400 | [diff] [blame] | 39 | public void initialize(Context ctx, NotificationUsageStats usageStats) { |
Chris Wren | 5190c0f | 2014-05-08 10:42:09 -0400 | [diff] [blame] | 40 | if (DBG) Slog.d(TAG, "Initializing " + getClass().getSimpleName() + "."); |
| 41 | } |
| 42 | |
Chris Wren | 470c1ac | 2014-05-21 15:28:10 -0400 | [diff] [blame] | 43 | public RankingReconsideration process(NotificationRecord record) { |
Chris Wren | 5190c0f | 2014-05-08 10:42:09 -0400 | [diff] [blame] | 44 | if (record == null || record.getNotification() == null) { |
| 45 | if (DBG) Slog.d(TAG, "skipping empty notification"); |
| 46 | return null; |
| 47 | } |
| 48 | |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 49 | if (record.getImportance() >= NotificationManager.IMPORTANCE_DEFAULT) { |
Julia Reynolds | 2445037 | 2017-05-02 15:04:34 -0400 | [diff] [blame] | 50 | 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 Reynolds | 0dbb731 | 2016-03-03 15:10:21 -0500 | [diff] [blame] | 57 | record.setRecentlyIntrusive(true); |
| 58 | } |
Chris Wren | 5190c0f | 2014-05-08 10:42:09 -0400 | [diff] [blame] | 59 | } |
| 60 | |
Chris Wren | 470c1ac | 2014-05-21 15:28:10 -0400 | [diff] [blame] | 61 | return new RankingReconsideration(record.getKey(), HANG_TIME_MS) { |
Chris Wren | 5190c0f | 2014-05-08 10:42:09 -0400 | [diff] [blame] | 62 | @Override |
| 63 | public void work() { |
Chris Wren | 470c1ac | 2014-05-21 15:28:10 -0400 | [diff] [blame] | 64 | // pass |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public void applyChangesLocked(NotificationRecord record) { |
Julia Reynolds | 309d1c8 | 2017-05-03 16:00:20 -0400 | [diff] [blame] | 69 | // 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 Wren | 5190c0f | 2014-05-08 10:42:09 -0400 | [diff] [blame] | 74 | } |
| 75 | }; |
| 76 | } |
Chris Wren | 54bbef4 | 2014-07-09 18:37:56 -0400 | [diff] [blame] | 77 | |
| 78 | @Override |
| 79 | public void setConfig(RankingConfig config) { |
| 80 | // ignore: config has no relevant information yet. |
| 81 | } |
| 82 | } |