1 /* 2 * Copyright (C) 2021 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.settings.applications.specialaccess.notificationaccess; 18 19 import android.content.ComponentName; 20 import android.content.Context; 21 import android.os.Build; 22 import android.service.notification.NotificationListenerFilter; 23 24 import com.android.settings.core.BasePreferenceController; 25 import com.android.settings.notification.NotificationBackend; 26 27 public class PreUpgradePreferenceController extends BasePreferenceController { 28 29 private ComponentName mCn; 30 private int mUserId; 31 private NotificationBackend mNm; 32 private NotificationListenerFilter mNlf; 33 private int mTargetSdk; 34 PreUpgradePreferenceController(Context context, String key)35 public PreUpgradePreferenceController(Context context, String key) { 36 super(context, key); 37 } 38 setCn(ComponentName cn)39 public PreUpgradePreferenceController setCn(ComponentName cn) { 40 mCn = cn; 41 return this; 42 } 43 setUserId(int userId)44 public PreUpgradePreferenceController setUserId(int userId) { 45 mUserId = userId; 46 return this; 47 } 48 setNm(NotificationBackend nm)49 public PreUpgradePreferenceController setNm(NotificationBackend nm) { 50 mNm = nm; 51 return this; 52 } 53 setTargetSdk(int targetSdk)54 public PreUpgradePreferenceController setTargetSdk(int targetSdk) { 55 mTargetSdk = targetSdk; 56 return this; 57 } 58 59 @Override getAvailabilityStatus()60 public int getAvailabilityStatus() { 61 mNlf = mNm.getListenerFilter(mCn, mUserId); 62 63 if (mTargetSdk > Build.VERSION_CODES.S) { 64 return CONDITIONALLY_UNAVAILABLE; 65 } 66 67 if (!mNlf.areAllTypesAllowed() || !mNlf.getDisallowedPackages().isEmpty()) { 68 return CONDITIONALLY_UNAVAILABLE; 69 } 70 return AVAILABLE; 71 } 72 }