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; 20 import android.content.Context; 21 import android.service.notification.NotificationListenerService; 22 import android.util.Log; 23 import android.util.Slog; 24 25 /** 26 * This {@link com.android.server.notification.NotificationSignalExtractor} notices noisy 27 * notifications and marks them to get a temporary ranking bump. 28 */ 29 public class NotificationIntrusivenessExtractor implements NotificationSignalExtractor { 30 private static final String TAG = "IntrusivenessExtractor"; 31 private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG); 32 33 /** Length of time (in milliseconds) that an intrusive or noisy notification will stay at 34 the top of the ranking order, before it falls back to its natural position. */ 35 private static final long HANG_TIME_MS = 10000; 36 37 public void initialize(Context ctx, NotificationUsageStats usageStats) { 38 if (DBG) Slog.d(TAG, "Initializing " + getClass().getSimpleName() + "."); 39 } 40 41 public RankingReconsideration process(NotificationRecord record) { 42 if (record == null || record.getNotification() == null) { 43 if (DBG) Slog.d(TAG, "skipping empty notification"); 44 return null; 45 } 46 47 if (record.getImportance() >= NotificationListenerService.Ranking.IMPORTANCE_DEFAULT) { 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.setRecentlyIntrusive(true); 55 } 56 } 57 58 return new RankingReconsideration(record.getKey(), HANG_TIME_MS) { 59 @Override 60 public void work() { 61 // pass 62 } 63 64 @Override 65 public void applyChangesLocked(NotificationRecord record) { 66 record.setRecentlyIntrusive(false); 67 } 68 }; 69 } 70 71 @Override 72 public void setConfig(RankingConfig config) { 73 // ignore: config has no relevant information yet. 74 } 75 } 76