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