1 /* 2 * Copyright (C) 2020 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.notification.app; 18 19 import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; 20 import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE; 21 22 import android.content.Context; 23 import android.content.Intent; 24 import android.content.res.Resources; 25 import android.provider.Settings; 26 27 import androidx.preference.Preference; 28 29 import com.android.settings.R; 30 import com.android.settings.notification.BubbleHelper; 31 import com.android.settings.notification.NotificationBackend; 32 33 /** 34 * Summary of the app setting for bubbles, available through app notification settings. 35 */ 36 public class BubbleSummaryPreferenceController extends NotificationPreferenceController { 37 private static final String KEY = "bubble_pref_link"; 38 BubbleSummaryPreferenceController(Context context, NotificationBackend backend)39 public BubbleSummaryPreferenceController(Context context, NotificationBackend backend) { 40 super(context, backend); 41 } 42 43 @Override isAvailable()44 public boolean isAvailable() { 45 if (!super.isAvailable()) { 46 return false; 47 } 48 if (mAppRow == null) { 49 return false; 50 } 51 if (mChannel != null) { 52 if (!isGloballyEnabled()) { 53 return false; 54 } 55 if (isDefaultChannel()) { 56 return true; 57 } else { 58 return mAppRow != null; 59 } 60 } 61 return isGloballyEnabled() && mBackend.hasSentValidBubble(mAppRow.pkg, mAppRow.uid); 62 } 63 64 @Override isIncludedInFilter()65 boolean isIncludedInFilter() { 66 return false; 67 } 68 69 @Override getPreferenceKey()70 public String getPreferenceKey() { 71 return KEY; 72 } 73 74 @Override updateState(Preference preference)75 public void updateState(Preference preference) { 76 super.updateState(preference); 77 78 if (mAppRow != null) { 79 final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_BUBBLE_SETTINGS); 80 intent.setPackage(mContext.getPackageName()); 81 intent.putExtra(Settings.EXTRA_APP_PACKAGE, mAppRow.pkg); 82 intent.putExtra(Settings.EXTRA_APP_UID, mAppRow.uid); 83 preference.setIntent(intent); 84 } 85 } 86 87 @Override getSummary()88 public CharSequence getSummary() { 89 if (mAppRow == null) { 90 return null; 91 } 92 int backEndPref = mAppRow.bubblePreference; 93 Resources res = mContext.getResources(); 94 if (backEndPref == BUBBLE_PREFERENCE_NONE || !isGloballyEnabled()) { 95 return res.getString(R.string.bubble_app_setting_none); 96 } else if (backEndPref == BUBBLE_PREFERENCE_ALL) { 97 return res.getString(R.string.bubble_app_setting_all); 98 } else { 99 return res.getString(R.string.bubble_app_setting_selected); 100 } 101 } 102 isGloballyEnabled()103 private boolean isGloballyEnabled() { 104 return BubbleHelper.isEnabledSystemWide(mContext); 105 } 106 } 107