13ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren/*
23ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren* Copyright (C) 2014 The Android Open Source Project
33ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren*
43ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren* Licensed under the Apache License, Version 2.0 (the "License");
53ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren* you may not use this file except in compliance with the License.
63ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren* You may obtain a copy of the License at
73ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren*
83ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren*      http://www.apache.org/licenses/LICENSE-2.0
93ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren*
103ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren* Unless required by applicable law or agreed to in writing, software
113ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren* distributed under the License is distributed on an "AS IS" BASIS,
123ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren* See the License for the specific language governing permissions and
143ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren* limitations under the License.
153ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren*/
163ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wrenpackage com.android.server.notification;
173ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren
183ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wrenimport android.content.Context;
193ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wrenimport android.util.Slog;
203ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren
213ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wrenpublic class PackageVisibilityExtractor implements NotificationSignalExtractor {
223ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren    private static final String TAG = "PackageVisibilityExtractor";
233ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren    private static final boolean DBG = false;
243ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren
253ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren    private RankingConfig mConfig;
263ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren
273ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren    public void initialize(Context ctx) {
283ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren        if (DBG) Slog.d(TAG, "Initializing  " + getClass().getSimpleName() + ".");
293ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren    }
303ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren
313ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren    public RankingReconsideration process(NotificationRecord record) {
323ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren        if (record == null || record.getNotification() == null) {
333ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren            if (DBG) Slog.d(TAG, "skipping empty notification");
343ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren            return null;
353ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren        }
363ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren
373ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren        if (mConfig == null) {
383ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren            if (DBG) Slog.d(TAG, "missing config");
393ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren            return null;
403ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren        }
413ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren
423ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren        final int packageVisibility = mConfig.getPackageVisibilityOverride(
433ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren                record.sbn.getPackageName(), record.sbn.getUid());
443ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren        record.setPackageVisibilityOverride(packageVisibility);
453ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren
463ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren        return null;
473ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren    }
483ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren
493ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren    @Override
503ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren    public void setConfig(RankingConfig config) {
513ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren        mConfig = config;
523ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren    }
533ad4e3a45bbe44129b14c4d391431e44f1e04f0cChris Wren}
54