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.provider.Settings.Secure.NOTIFICATION_BUBBLES; 20 21 import android.content.Context; 22 import android.content.Intent; 23 import android.provider.Settings; 24 25 import androidx.annotation.VisibleForTesting; 26 import androidx.preference.Preference; 27 28 public class BubbleLinkPreferenceController extends NotificationPreferenceController { 29 30 private static final String KEY = "notification_bubbles"; 31 @VisibleForTesting 32 static final int ON = 1; 33 BubbleLinkPreferenceController(Context context)34 public BubbleLinkPreferenceController(Context context) { 35 super(context, null); 36 } 37 38 @Override isAvailable()39 public boolean isAvailable() { 40 if (!super.isAvailable()) { 41 return false; 42 } 43 return areBubblesEnabled(); 44 } 45 46 @Override isIncludedInFilter()47 boolean isIncludedInFilter() { 48 return false; 49 } 50 51 @Override getPreferenceKey()52 public String getPreferenceKey() { 53 return KEY; 54 } 55 56 @Override updateState(Preference preference)57 public void updateState(Preference preference) { 58 super.updateState(preference); 59 60 if (mAppRow != null) { 61 final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_BUBBLE_SETTINGS); 62 intent.putExtra(Settings.EXTRA_APP_PACKAGE, mAppRow.pkg); 63 intent.putExtra(Settings.EXTRA_APP_UID, mAppRow.uid); 64 preference.setIntent(intent); 65 } 66 } 67 68 areBubblesEnabled()69 private boolean areBubblesEnabled() { 70 return Settings.Secure.getInt(mContext.getContentResolver(), 71 NOTIFICATION_BUBBLES, ON) == ON; 72 } 73 } 74