1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 
15 package com.android.systemui.util;
16 
17 import android.app.NotificationChannel;
18 import android.app.NotificationManager;
19 
20 import android.content.Context;
21 import android.content.pm.PackageManager;
22 import com.android.internal.annotations.VisibleForTesting;
23 import com.android.systemui.R;
24 import com.android.systemui.SystemUI;
25 
26 import java.util.Arrays;
27 
28 public class NotificationChannels extends SystemUI {
29     public static String ALERTS      = "ALR";
30     public static String SCREENSHOTS = "SCN";
31     public static String GENERAL     = "GEN";
32     public static String STORAGE     = "DSK";
33     public static String TVPIP       = "TPP";
34 
35     @VisibleForTesting
createAll(Context context)36     static void createAll(Context context) {
37 
38         final NotificationManager nm = context.getSystemService(NotificationManager.class);
39         nm.createNotificationChannels(Arrays.asList(
40                 new NotificationChannel(
41                         ALERTS,
42                         context.getString(R.string.notification_channel_alerts),
43                         NotificationManager.IMPORTANCE_HIGH),
44                 new NotificationChannel(
45                         SCREENSHOTS,
46                         context.getString(R.string.notification_channel_screenshot),
47                         NotificationManager.IMPORTANCE_LOW),
48                 new NotificationChannel(
49                         GENERAL,
50                         context.getString(R.string.notification_channel_general),
51                         NotificationManager.IMPORTANCE_MIN),
52                 new NotificationChannel(
53                         STORAGE,
54                         context.getString(R.string.notification_channel_storage),
55                         isTv(context)
56                                 ? NotificationManager.IMPORTANCE_DEFAULT
57                                 : NotificationManager.IMPORTANCE_LOW)
58                 ));
59         if (isTv(context)) {
60             // TV specific notification channel for TV PIP controls.
61             // Importance should be {@link NotificationManager#IMPORTANCE_MAX} to have the highest
62             // priority, so it can be shown in all times.
63             nm.createNotificationChannel(new NotificationChannel(
64                     TVPIP,
65                     context.getString(R.string.notification_channel_tv_pip),
66                     NotificationManager.IMPORTANCE_MAX));
67         }
68     }
69 
70     @Override
start()71     public void start() {
72         createAll(mContext);
73     }
74 
isTv(Context context)75     private static boolean isTv(Context context) {
76         PackageManager packageManager = context.getPackageManager();
77         return packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK);
78     }
79 }
80