NotificationIntrusivenessExtractor.java revision 470c1accf5a54f9844a779eafab74e63c09342b5
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.server.notification.NotificationManagerService.NotificationRecord; 24 25/** 26 * This {@link com.android.server.notification.NotificationSignalExtractor} noticies noisy 27 * notifications and marks them to get a temporary ranking bump. 28 */ 29public class NotificationIntrusivenessExtractor implements NotificationSignalExtractor { 30 private static final String TAG = "NotificationNoiseExtractor"; 31 private static final boolean DBG = false; 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) { 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 final Notification notification = record.getNotification(); 48 if ((notification.defaults & Notification.DEFAULT_VIBRATE) != 0 || 49 notification.vibrate != null || 50 (notification.defaults & Notification.DEFAULT_SOUND) != 0 || 51 notification.sound != null || 52 notification.fullScreenIntent != null) { 53 record.setRecentlyIntusive(true); 54 } 55 56 return new RankingReconsideration(record.getKey(), HANG_TIME_MS) { 57 @Override 58 public void work() { 59 // pass 60 } 61 62 @Override 63 public void applyChangesLocked(NotificationRecord record) { 64 record.setRecentlyIntusive(false); 65 } 66 }; 67 } 68}