NotificationIntrusivenessExtractor.java revision 85769915e7ef10bef2b5338ed8f04d9b787924fb
15190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren/* 25190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren* Copyright (C) 2014 The Android Open Source Project 35190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren* 45190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren* Licensed under the Apache License, Version 2.0 (the "License"); 55190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren* you may not use this file except in compliance with the License. 65190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren* You may obtain a copy of the License at 75190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren* 85190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren* http://www.apache.org/licenses/LICENSE-2.0 95190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren* 105190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren* Unless required by applicable law or agreed to in writing, software 115190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren* distributed under the License is distributed on an "AS IS" BASIS, 125190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren* See the License for the specific language governing permissions and 145190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren* limitations under the License. 155190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren*/ 165190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren 175190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wrenpackage com.android.server.notification; 185190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren 195190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wrenimport android.app.Notification; 2085769915e7ef10bef2b5338ed8f04d9b787924fbJulia Reynoldsimport android.app.NotificationManager; 215190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wrenimport android.content.Context; 220421e6d58635f347f785ae4c78e8b2a5da327138Julia Reynoldsimport android.service.notification.NotificationListenerService; 231d881a1e986c706963c254fbe2b6296a1cd10b75John Spurlockimport android.util.Log; 245190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wrenimport android.util.Slog; 255190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren 265190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren/** 270dbb7310088fdf2845861d2dc0e271812083e273Julia Reynolds * This {@link com.android.server.notification.NotificationSignalExtractor} notices noisy 285190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren * notifications and marks them to get a temporary ranking bump. 295190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren */ 305190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wrenpublic class NotificationIntrusivenessExtractor implements NotificationSignalExtractor { 311d881a1e986c706963c254fbe2b6296a1cd10b75John Spurlock private static final String TAG = "IntrusivenessExtractor"; 321d881a1e986c706963c254fbe2b6296a1cd10b75John Spurlock private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG); 335190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren 345190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren /** Length of time (in milliseconds) that an intrusive or noisy notification will stay at 355190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren the top of the ranking order, before it falls back to its natural position. */ 365190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren private static final long HANG_TIME_MS = 10000; 375190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren 385eab2b72afe5b20dc66c237b1cceedfc09de2d52Chris Wren public void initialize(Context ctx, NotificationUsageStats usageStats) { 395190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren if (DBG) Slog.d(TAG, "Initializing " + getClass().getSimpleName() + "."); 405190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren } 415190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren 42470c1accf5a54f9844a779eafab74e63c09342b5Chris Wren public RankingReconsideration process(NotificationRecord record) { 435190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren if (record == null || record.getNotification() == null) { 445190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren if (DBG) Slog.d(TAG, "skipping empty notification"); 455190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren return null; 465190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren } 475190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren 4885769915e7ef10bef2b5338ed8f04d9b787924fbJulia Reynolds if (record.getImportance() >= NotificationManager.IMPORTANCE_DEFAULT) { 490dbb7310088fdf2845861d2dc0e271812083e273Julia Reynolds final Notification notification = record.getNotification(); 500dbb7310088fdf2845861d2dc0e271812083e273Julia Reynolds if ((notification.defaults & Notification.DEFAULT_VIBRATE) != 0 || 510dbb7310088fdf2845861d2dc0e271812083e273Julia Reynolds notification.vibrate != null || 520dbb7310088fdf2845861d2dc0e271812083e273Julia Reynolds (notification.defaults & Notification.DEFAULT_SOUND) != 0 || 530dbb7310088fdf2845861d2dc0e271812083e273Julia Reynolds notification.sound != null || 540dbb7310088fdf2845861d2dc0e271812083e273Julia Reynolds notification.fullScreenIntent != null) { 550dbb7310088fdf2845861d2dc0e271812083e273Julia Reynolds record.setRecentlyIntrusive(true); 560dbb7310088fdf2845861d2dc0e271812083e273Julia Reynolds } 575190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren } 585190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren 59470c1accf5a54f9844a779eafab74e63c09342b5Chris Wren return new RankingReconsideration(record.getKey(), HANG_TIME_MS) { 605190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren @Override 615190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren public void work() { 62470c1accf5a54f9844a779eafab74e63c09342b5Chris Wren // pass 63470c1accf5a54f9844a779eafab74e63c09342b5Chris Wren } 64470c1accf5a54f9844a779eafab74e63c09342b5Chris Wren 65470c1accf5a54f9844a779eafab74e63c09342b5Chris Wren @Override 66470c1accf5a54f9844a779eafab74e63c09342b5Chris Wren public void applyChangesLocked(NotificationRecord record) { 671d881a1e986c706963c254fbe2b6296a1cd10b75John Spurlock record.setRecentlyIntrusive(false); 685190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren } 695190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren }; 705190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren } 7154bbef435ed857fc68941672799fc8001c101119Chris Wren 7254bbef435ed857fc68941672799fc8001c101119Chris Wren @Override 7354bbef435ed857fc68941672799fc8001c101119Chris Wren public void setConfig(RankingConfig config) { 7454bbef435ed857fc68941672799fc8001c101119Chris Wren // ignore: config has no relevant information yet. 7554bbef435ed857fc68941672799fc8001c101119Chris Wren } 7654bbef435ed857fc68941672799fc8001c101119Chris Wren} 77