Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | package com.android.systemui.statusbar; |
| 17 | |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 18 | import android.app.Notification; |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 19 | import android.os.RemoteException; |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 20 | import android.util.ArraySet; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 21 | |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 22 | import com.android.internal.statusbar.IStatusBarService; |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 23 | import com.android.internal.statusbar.NotificationVisibility; |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 24 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 25 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Gustav Sennton | f892fe9 | 2019-01-22 15:31:42 +0000 | [diff] [blame] | 26 | import com.android.systemui.statusbar.notification.logging.NotificationLogger; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 27 | |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 28 | import java.util.Set; |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 29 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 30 | import javax.inject.Inject; |
| 31 | import javax.inject.Singleton; |
| 32 | |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 33 | /** |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 34 | * Handles when smart replies are added to a notification |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 35 | * and clicked upon. |
| 36 | */ |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 37 | @Singleton |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 38 | public class SmartReplyController { |
Jason Monk | 752c68f | 2018-12-21 12:07:55 -0500 | [diff] [blame] | 39 | private final IStatusBarService mBarService; |
| 40 | private final NotificationEntryManager mEntryManager; |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 41 | private Set<String> mSendingKeys = new ArraySet<>(); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 42 | private Callback mCallback; |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 43 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 44 | @Inject |
Jason Monk | 752c68f | 2018-12-21 12:07:55 -0500 | [diff] [blame] | 45 | public SmartReplyController(NotificationEntryManager entryManager, |
| 46 | IStatusBarService statusBarService) { |
| 47 | mBarService = statusBarService; |
| 48 | mEntryManager = entryManager; |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 49 | } |
| 50 | |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 51 | public void setCallback(Callback callback) { |
| 52 | mCallback = callback; |
| 53 | } |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 54 | |
Tony Mak | 2999670 | 2018-11-26 16:23:34 +0000 | [diff] [blame] | 55 | /** |
| 56 | * Notifies StatusBarService a smart reply is sent. |
| 57 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 58 | public void smartReplySent(NotificationEntry entry, int replyIndex, CharSequence reply, |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 59 | int notificationLocation, boolean modifiedBeforeSending) { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 60 | mCallback.onSmartReplySent(entry, reply); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 61 | mSendingKeys.add(entry.getKey()); |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 62 | try { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 63 | mBarService.onNotificationSmartReplySent(entry.getSbn().getKey(), replyIndex, reply, |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 64 | notificationLocation, modifiedBeforeSending); |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 65 | } catch (RemoteException e) { |
| 66 | // Nothing to do, system going down |
| 67 | } |
| 68 | } |
| 69 | |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 70 | /** |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 71 | * Notifies StatusBarService a smart action is clicked. |
| 72 | */ |
| 73 | public void smartActionClicked( |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 74 | NotificationEntry entry, int actionIndex, Notification.Action action, |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 75 | boolean generatedByAssistant) { |
| 76 | final int count = mEntryManager.getNotificationData().getActiveNotifications().size(); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 77 | final int rank = mEntryManager.getNotificationData().getRank(entry.getKey()); |
Gustav Sennton | f892fe9 | 2019-01-22 15:31:42 +0000 | [diff] [blame] | 78 | NotificationVisibility.NotificationLocation location = |
| 79 | NotificationLogger.getNotificationLocation(entry); |
| 80 | final NotificationVisibility nv = NotificationVisibility.obtain( |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 81 | entry.getKey(), rank, count, true, location); |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 82 | try { |
| 83 | mBarService.onNotificationActionClick( |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 84 | entry.getKey(), actionIndex, action, nv, generatedByAssistant); |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 85 | } catch (RemoteException e) { |
| 86 | // Nothing to do, system going down |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /** |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 91 | * Have we posted an intent to an app about sending a smart reply from the |
| 92 | * notification with this key. |
| 93 | */ |
| 94 | public boolean isSendingSmartReply(String key) { |
| 95 | return mSendingKeys.contains(key); |
| 96 | } |
| 97 | |
Gustav Sennton | d25a64d | 2018-12-07 10:58:39 +0000 | [diff] [blame] | 98 | /** |
| 99 | * Smart Replies and Actions have been added to the UI. |
| 100 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 101 | public void smartSuggestionsAdded(final NotificationEntry entry, int replyCount, |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 102 | int actionCount, boolean generatedByAssistant, boolean editBeforeSending) { |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 103 | try { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 104 | mBarService.onNotificationSmartSuggestionsAdded(entry.getSbn().getKey(), replyCount, |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 105 | actionCount, generatedByAssistant, editBeforeSending); |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 106 | } catch (RemoteException e) { |
| 107 | // Nothing to do, system going down |
| 108 | } |
| 109 | } |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 110 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 111 | public void stopSending(final NotificationEntry entry) { |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 112 | if (entry != null) { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 113 | mSendingKeys.remove(entry.getSbn().getKey()); |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 114 | } |
| 115 | } |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * Callback for any class that needs to do something in response to a smart reply being sent. |
| 119 | */ |
| 120 | public interface Callback { |
| 121 | /** |
| 122 | * A smart reply has just been sent for a notification |
| 123 | * |
| 124 | * @param entry the entry for the notification |
| 125 | * @param reply the reply that was sent |
| 126 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 127 | void onSmartReplySent(NotificationEntry entry, CharSequence reply); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 128 | } |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 129 | } |