154bbef435ed857fc68941672799fc8001c101119Chris Wren/*
254bbef435ed857fc68941672799fc8001c101119Chris Wren* Copyright (C) 2014 The Android Open Source Project
354bbef435ed857fc68941672799fc8001c101119Chris Wren*
454bbef435ed857fc68941672799fc8001c101119Chris Wren* Licensed under the Apache License, Version 2.0 (the "License");
554bbef435ed857fc68941672799fc8001c101119Chris Wren* you may not use this file except in compliance with the License.
654bbef435ed857fc68941672799fc8001c101119Chris Wren* You may obtain a copy of the License at
754bbef435ed857fc68941672799fc8001c101119Chris Wren*
854bbef435ed857fc68941672799fc8001c101119Chris Wren*      http://www.apache.org/licenses/LICENSE-2.0
954bbef435ed857fc68941672799fc8001c101119Chris Wren*
1054bbef435ed857fc68941672799fc8001c101119Chris Wren* Unless required by applicable law or agreed to in writing, software
1154bbef435ed857fc68941672799fc8001c101119Chris Wren* distributed under the License is distributed on an "AS IS" BASIS,
1254bbef435ed857fc68941672799fc8001c101119Chris Wren* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1354bbef435ed857fc68941672799fc8001c101119Chris Wren* See the License for the specific language governing permissions and
1454bbef435ed857fc68941672799fc8001c101119Chris Wren* limitations under the License.
1554bbef435ed857fc68941672799fc8001c101119Chris Wren*/
1654bbef435ed857fc68941672799fc8001c101119Chris Wrenpackage com.android.server.notification;
1754bbef435ed857fc68941672799fc8001c101119Chris Wren
1854bbef435ed857fc68941672799fc8001c101119Chris Wrenimport android.content.Context;
1954bbef435ed857fc68941672799fc8001c101119Chris Wrenimport android.util.Slog;
2054bbef435ed857fc68941672799fc8001c101119Chris Wren
21233a5f97ea7b46814747a99f584b08d4e8c70105Julia Reynolds/**
22233a5f97ea7b46814747a99f584b08d4e8c70105Julia Reynolds * Determines if the given notification can bypass Do Not Disturb.
23233a5f97ea7b46814747a99f584b08d4e8c70105Julia Reynolds */
24ef37f284364cc45c2ed91bfe04c489d2cedd32d2Julia Reynoldspublic class PriorityExtractor implements NotificationSignalExtractor {
25233a5f97ea7b46814747a99f584b08d4e8c70105Julia Reynolds    private static final String TAG = "ImportantTopicExtractor";
2654bbef435ed857fc68941672799fc8001c101119Chris Wren    private static final boolean DBG = false;
2754bbef435ed857fc68941672799fc8001c101119Chris Wren
2854bbef435ed857fc68941672799fc8001c101119Chris Wren    private RankingConfig mConfig;
2954bbef435ed857fc68941672799fc8001c101119Chris Wren
305eab2b72afe5b20dc66c237b1cceedfc09de2d52Chris Wren    public void initialize(Context ctx, NotificationUsageStats usageStats) {
3154bbef435ed857fc68941672799fc8001c101119Chris Wren        if (DBG) Slog.d(TAG, "Initializing  " + getClass().getSimpleName() + ".");
3254bbef435ed857fc68941672799fc8001c101119Chris Wren    }
3354bbef435ed857fc68941672799fc8001c101119Chris Wren
3454bbef435ed857fc68941672799fc8001c101119Chris Wren    public RankingReconsideration process(NotificationRecord record) {
3554bbef435ed857fc68941672799fc8001c101119Chris Wren        if (record == null || record.getNotification() == null) {
3654bbef435ed857fc68941672799fc8001c101119Chris Wren            if (DBG) Slog.d(TAG, "skipping empty notification");
3754bbef435ed857fc68941672799fc8001c101119Chris Wren            return null;
3854bbef435ed857fc68941672799fc8001c101119Chris Wren        }
3954bbef435ed857fc68941672799fc8001c101119Chris Wren
4054bbef435ed857fc68941672799fc8001c101119Chris Wren        if (mConfig == null) {
4154bbef435ed857fc68941672799fc8001c101119Chris Wren            if (DBG) Slog.d(TAG, "missing config");
4254bbef435ed857fc68941672799fc8001c101119Chris Wren            return null;
4354bbef435ed857fc68941672799fc8001c101119Chris Wren        }
4454bbef435ed857fc68941672799fc8001c101119Chris Wren
45ef37f284364cc45c2ed91bfe04c489d2cedd32d2Julia Reynolds        record.setPackagePriority(
46ef37f284364cc45c2ed91bfe04c489d2cedd32d2Julia Reynolds                mConfig.getPriority(record.sbn.getPackageName(), record.sbn.getUid()));
4754bbef435ed857fc68941672799fc8001c101119Chris Wren
4854bbef435ed857fc68941672799fc8001c101119Chris Wren        return null;
4954bbef435ed857fc68941672799fc8001c101119Chris Wren    }
5054bbef435ed857fc68941672799fc8001c101119Chris Wren
5154bbef435ed857fc68941672799fc8001c101119Chris Wren    @Override
5254bbef435ed857fc68941672799fc8001c101119Chris Wren    public void setConfig(RankingConfig config) {
5354bbef435ed857fc68941672799fc8001c101119Chris Wren        mConfig = config;
5454bbef435ed857fc68941672799fc8001c101119Chris Wren    }
5554bbef435ed857fc68941672799fc8001c101119Chris Wren}
56