NotificationIntrusivenessExtractor.java revision 309d1c83e9fab971dab68cb6395c3f515ba9b85b
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; 222445037bb9a98fd00bfa14c5b99b09026e8ffed7Julia Reynoldsimport android.net.Uri; 230421e6d58635f347f785ae4c78e8b2a5da327138Julia Reynoldsimport android.service.notification.NotificationListenerService; 241d881a1e986c706963c254fbe2b6296a1cd10b75John Spurlockimport android.util.Log; 255190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wrenimport android.util.Slog; 265190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren 275190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren/** 280dbb7310088fdf2845861d2dc0e271812083e273Julia Reynolds * This {@link com.android.server.notification.NotificationSignalExtractor} notices noisy 295190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren * notifications and marks them to get a temporary ranking bump. 305190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren */ 315190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wrenpublic class NotificationIntrusivenessExtractor implements NotificationSignalExtractor { 321d881a1e986c706963c254fbe2b6296a1cd10b75John Spurlock private static final String TAG = "IntrusivenessExtractor"; 331d881a1e986c706963c254fbe2b6296a1cd10b75John Spurlock private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG); 345190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren 355190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren /** Length of time (in milliseconds) that an intrusive or noisy notification will stay at 365190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren the top of the ranking order, before it falls back to its natural position. */ 375190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren private static final long HANG_TIME_MS = 10000; 385190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren 395eab2b72afe5b20dc66c237b1cceedfc09de2d52Chris Wren public void initialize(Context ctx, NotificationUsageStats usageStats) { 405190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren if (DBG) Slog.d(TAG, "Initializing " + getClass().getSimpleName() + "."); 415190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren } 425190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren 43470c1accf5a54f9844a779eafab74e63c09342b5Chris Wren public RankingReconsideration process(NotificationRecord record) { 445190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren if (record == null || record.getNotification() == null) { 455190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren if (DBG) Slog.d(TAG, "skipping empty notification"); 465190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren return null; 475190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren } 485190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren 4985769915e7ef10bef2b5338ed8f04d9b787924fbJulia Reynolds if (record.getImportance() >= NotificationManager.IMPORTANCE_DEFAULT) { 502445037bb9a98fd00bfa14c5b99b09026e8ffed7Julia Reynolds if (record.getSound() != null && record.getSound() != Uri.EMPTY) { 512445037bb9a98fd00bfa14c5b99b09026e8ffed7Julia Reynolds record.setRecentlyIntrusive(true); 522445037bb9a98fd00bfa14c5b99b09026e8ffed7Julia Reynolds } 532445037bb9a98fd00bfa14c5b99b09026e8ffed7Julia Reynolds if (record.getVibration() != null) { 542445037bb9a98fd00bfa14c5b99b09026e8ffed7Julia Reynolds record.setRecentlyIntrusive(true); 552445037bb9a98fd00bfa14c5b99b09026e8ffed7Julia Reynolds } 562445037bb9a98fd00bfa14c5b99b09026e8ffed7Julia Reynolds if (record.getNotification().fullScreenIntent != null) { 570dbb7310088fdf2845861d2dc0e271812083e273Julia Reynolds record.setRecentlyIntrusive(true); 580dbb7310088fdf2845861d2dc0e271812083e273Julia Reynolds } 595190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren } 605190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren 61470c1accf5a54f9844a779eafab74e63c09342b5Chris Wren return new RankingReconsideration(record.getKey(), HANG_TIME_MS) { 625190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren @Override 635190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren public void work() { 64470c1accf5a54f9844a779eafab74e63c09342b5Chris Wren // pass 65470c1accf5a54f9844a779eafab74e63c09342b5Chris Wren } 66470c1accf5a54f9844a779eafab74e63c09342b5Chris Wren 67470c1accf5a54f9844a779eafab74e63c09342b5Chris Wren @Override 68470c1accf5a54f9844a779eafab74e63c09342b5Chris Wren public void applyChangesLocked(NotificationRecord record) { 69309d1c83e9fab971dab68cb6395c3f515ba9b85bJulia Reynolds // there will be another reconsideration in the message queue HANG_TIME_MS 70309d1c83e9fab971dab68cb6395c3f515ba9b85bJulia Reynolds // from each time this record alerts, which can finally clear this flag. 71309d1c83e9fab971dab68cb6395c3f515ba9b85bJulia Reynolds if ((System.currentTimeMillis() - record.getLastIntrusive()) >= HANG_TIME_MS) { 72309d1c83e9fab971dab68cb6395c3f515ba9b85bJulia Reynolds record.setRecentlyIntrusive(false); 73309d1c83e9fab971dab68cb6395c3f515ba9b85bJulia Reynolds } 745190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren } 755190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren }; 765190c0fefac9923931b5c1c02cab2d00c2d6b82bChris Wren } 7754bbef435ed857fc68941672799fc8001c101119Chris Wren 7854bbef435ed857fc68941672799fc8001c101119Chris Wren @Override 7954bbef435ed857fc68941672799fc8001c101119Chris Wren public void setConfig(RankingConfig config) { 8054bbef435ed857fc68941672799fc8001c101119Chris Wren // ignore: config has no relevant information yet. 8154bbef435ed857fc68941672799fc8001c101119Chris Wren } 8254bbef435ed857fc68941672799fc8001c101119Chris Wren} 83