1 /* 2 * Copyright (C) 2018 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 static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_OFF; 20 import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON; 21 22 import android.content.Context; 23 import android.util.Log; 24 import android.util.Slog; 25 26 /** 27 * This {@link ZenModeExtractor} updates intercepted and visual interruption states. 28 */ 29 public class ZenModeExtractor implements NotificationSignalExtractor { 30 private static final String TAG = "ZenModeExtractor"; 31 private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG); 32 33 private ZenModeHelper mZenModeHelper; 34 35 public void initialize(Context ctx, NotificationUsageStats usageStats) { 36 if (DBG) Slog.d(TAG, "Initializing " + getClass().getSimpleName() + "."); 37 } 38 39 public RankingReconsideration process(NotificationRecord record) { 40 if (record == null || record.getNotification() == null) { 41 if (DBG) Slog.d(TAG, "skipping empty notification"); 42 return null; 43 } 44 45 if (mZenModeHelper == null) { 46 if (DBG) Slog.d(TAG, "skipping - no zen info available"); 47 return null; 48 } 49 50 record.setIntercepted(mZenModeHelper.shouldIntercept(record)); 51 if (record.isIntercepted()) { 52 record.setSuppressedVisualEffects( 53 mZenModeHelper.getNotificationPolicy().suppressedVisualEffects); 54 } else { 55 record.setSuppressedVisualEffects(0); 56 } 57 58 return null; 59 } 60 61 @Override 62 public void setConfig(RankingConfig config) { 63 // ignore: config has no relevant information yet. 64 } 65 66 @Override 67 public void setZenHelper(ZenModeHelper helper) { 68 mZenModeHelper = helper; 69 } 70 } 71