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