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.car.internal;
18 
19 import android.car.ICarResultReceiver;
20 import android.content.Context;
21 import android.os.UserHandle;
22 import android.util.SparseArray;
23 
24 /**
25  * This is a base class for implementing NotificationHelper in car service builtin.
26  *
27  * <p> This is used as an interface between builtin and updatable car service. Do not change it
28  * without compatibility check. Adding a new method is ok.
29  *
30  * @hide
31  */
32 public abstract class NotificationHelperBase {
33 
34     public static final String CAR_WATCHDOG_ACTION_DISMISS_RESOURCE_OVERUSE_NOTIFICATION =
35             "com.android.car.watchdog.ACTION_DISMISS_RESOURCE_OVERUSE_NOTIFICATION";
36 
37     public static final String CAR_WATCHDOG_ACTION_LAUNCH_APP_SETTINGS =
38             "com.android.car.watchdog.ACTION_LAUNCH_APP_SETTINGS";
39 
40     // TODO(b/244474850): Delete the intent in W release. After TM-QPR2, it is not used anymore by
41     //  the notification helper.
42     /**
43      * @deprecated - Prefer dismissing resource over notifications using the
44      * {@code ACTION_DISMISS_RESOURCE_OVERUSE_NOTIFICATION} intent action.
45      */
46     @Deprecated
47     public static final String CAR_WATCHDOG_ACTION_RESOURCE_OVERUSE_DISABLE_APP =
48             "com.android.car.watchdog.ACTION_RESOURCE_OVERUSE_DISABLE_APP";
49 
50     public static final String INTENT_EXTRA_NOTIFICATION_ID = "notification_id";
51 
52     /*
53      * NOTE: IDs in the range {@code [RESOURCE_OVERUSE_NOTIFICATION_BASE_ID,
54      * RESOURCE_OVERUSE_NOTIFICATION_BASE_ID + RESOURCE_OVERUSE_NOTIFICATION_MAX_OFFSET)} are
55      * reserved for car watchdog's resource overuse notifications.
56      */
57     /** Base notification id for car watchdog's resource overuse notifications. */
58     public static final int RESOURCE_OVERUSE_NOTIFICATION_BASE_ID = 150;
59 
60     /** Maximum notification offset for car watchdog's resource overuse notifications. */
61     public static final int RESOURCE_OVERUSE_NOTIFICATION_MAX_OFFSET = 20;
62 
63     private final Context mContext;
64 
65     /** Creates with given {@code Context} which is used to create {@code Notification}. */
NotificationHelperBase(Context context)66     public NotificationHelperBase(Context context) {
67         mContext = context;
68     }
69 
70     /** Returns {@code Cotext} to use to create {@code Notification}. */
getContext()71     public Context getContext() {
72         return mContext;
73     }
74 
75     /**
76      * Shows the user disclaimer notification. Actual impl should be done by a child class.
77      */
showUserDisclaimerNotification(UserHandle user)78     public void showUserDisclaimerNotification(UserHandle user) {};
79 
80     /**
81      * Cancels the user disclaimer notification. Actual impl should be done by a child class.
82      */
cancelUserDisclaimerNotification(UserHandle user)83     public void cancelUserDisclaimerNotification(UserHandle user) {};
84 
85     /**
86      * Shows the user car watchdog's resource overuse notifications. Actual impl should be done by
87      * a child class.
88      */
showResourceOveruseNotificationsAsUser( UserHandle user, SparseArray<String> headsUpNotificationPackagesById, SparseArray<String> notificationCenterPackagesById)89     public void showResourceOveruseNotificationsAsUser(
90             UserHandle user, SparseArray<String> headsUpNotificationPackagesById,
91             SparseArray<String> notificationCenterPackagesById) {};
92 
93     /**
94      * Sends the notification warning the user about the factory reset. Actual impl should be done
95      * by a child class.
96      */
showFactoryResetNotification(ICarResultReceiver callback)97     public void showFactoryResetNotification(ICarResultReceiver callback) {};
98 
99     /**
100      * Cancels a specific notification as a user. Actual impl should be done by a child class.
101      */
cancelNotificationAsUser(UserHandle user, int notificationId)102     public void cancelNotificationAsUser(UserHandle user, int notificationId) {};
103 }
104