1 /*
2  * Copyright 2023 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;
18 
19 import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
20 
21 import android.app.ActivityManager;
22 import android.content.Context;
23 import android.content.res.Resources;
24 import android.provider.Settings;
25 
26 /**
27  * Helper class for configuring notification bubbles.
28  */
29 public class BubbleHelper {
30 
31     /**
32      * {@link Settings.Secure.NOTIFICATION_BUBBLES} is enabled.
33      */
34     public static final int SYSTEM_WIDE_ON = 1;
35 
36     /**
37      * {@link Settings.Secure.NOTIFICATION_BUBBLES} is disabled.
38      */
39     public static final int SYSTEM_WIDE_OFF = 0;
40 
41     /**
42      * Returns true if the device supports bubbles.
43      */
isSupportedByDevice(Context context)44     public static boolean isSupportedByDevice(Context context) {
45         ActivityManager am = context.getSystemService(ActivityManager.class);
46         if (am.isLowRamDevice()) {
47             return false;
48         }
49         if (!Resources.getSystem().getBoolean(com.android.internal.R.bool.config_supportsBubble)) {
50             return false;
51         }
52         return true;
53     }
54 
55     /**
56      * Returns true if the device supports bubbles and the global settings is enabled.
57      */
isEnabledSystemWide(Context context)58     public static boolean isEnabledSystemWide(Context context) {
59         if (!isSupportedByDevice(context)) {
60             return false;
61         }
62         return Settings.Secure.getInt(context.getContentResolver(), NOTIFICATION_BUBBLES,
63                 SYSTEM_WIDE_ON) == SYSTEM_WIDE_ON;
64     }
65 }
66