1 /*
2  * Copyright (C) 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.systemui.accessibility.floatingmenu;
18 
19 import android.app.Notification;
20 import android.app.PendingIntent;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.os.UserHandle;
24 
25 import com.android.systemui.res.R;
26 import com.android.systemui.util.NotificationChannels;
27 
28 class MenuNotificationFactory {
29     public static final String ACTION_UNDO =
30             "com.android.systemui.accessibility.floatingmenu.action.UNDO";
31     public static final String ACTION_DELETE =
32             "com.android.systemui.accessibility.floatingmenu.action.DELETE";
33 
34     private final Context mContext;
35 
MenuNotificationFactory(Context context)36     MenuNotificationFactory(Context context) {
37         mContext = context;
38     }
39 
createHiddenNotification()40     public Notification createHiddenNotification() {
41         final CharSequence title = mContext.getText(
42                 R.string.accessibility_floating_button_hidden_notification_title);
43         final CharSequence content = mContext.getText(
44                 R.string.accessibility_floating_button_hidden_notification_text);
45 
46         return new Notification.Builder(mContext, NotificationChannels.ALERTS)
47                 .setContentTitle(title)
48                 .setContentText(content)
49                 .setSmallIcon(R.drawable.ic_settings_24dp)
50                 .setContentIntent(buildUndoIntent())
51                 .setDeleteIntent(buildDeleteIntent())
52                 .setColor(mContext.getResources().getColor(
53                         com.android.internal.R.color.system_notification_accent_color))
54                 .setLocalOnly(true)
55                 .setCategory(Notification.CATEGORY_SYSTEM)
56                 .build();
57     }
58 
buildUndoIntent()59     private PendingIntent buildUndoIntent() {
60         final Intent intent = new Intent(ACTION_UNDO);
61 
62         return PendingIntent.getBroadcast(mContext, /* requestCode= */ 0, intent,
63                 PendingIntent.FLAG_IMMUTABLE);
64 
65     }
66 
buildDeleteIntent()67     private PendingIntent buildDeleteIntent() {
68         final Intent intent = new Intent(ACTION_DELETE);
69 
70         return PendingIntent.getBroadcastAsUser(mContext, /* requestCode= */ 0, intent,
71                 PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT
72                         | PendingIntent.FLAG_IMMUTABLE, UserHandle.CURRENT);
73 
74     }
75 }
76