diff options
author | Ritwika Mitra <ritwikam@google.com> | 2020-05-27 08:56:07 -0700 |
---|---|---|
committer | Ritwika Mitra <ritwikam@google.com> | 2020-05-28 10:40:40 -0700 |
commit | 970b0edc4429620417bb4d080a687321c4a7a882 (patch) | |
tree | 11ae0e2275a604f255f200b30c77b909f79d1d70 | |
parent | 7bc2717326d56a6e0e4b4e774c2df301a5c0ed0b (diff) | |
download | CompanionDeviceSupport-970b0edc4429620417bb4d080a687321c4a7a882.tar.gz |
DO NOT MERGE RVC backport: Remove Msg Notifications if feature is disabled
Bug: 155220140, 157159420
Test: built app, stubbed a fake message saying feature is disabled since
phone doesn't send it currently.
Change-Id: Ia1d530520250d6aae2f5af2d95fce73219ab5733
-rw-r--r-- | src/com/android/car/companiondevicesupport/feature/notificationmsg/NotificationMsgDelegate.java | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/com/android/car/companiondevicesupport/feature/notificationmsg/NotificationMsgDelegate.java b/src/com/android/car/companiondevicesupport/feature/notificationmsg/NotificationMsgDelegate.java index f5f25f1..81e1849 100644 --- a/src/com/android/car/companiondevicesupport/feature/notificationmsg/NotificationMsgDelegate.java +++ b/src/com/android/car/companiondevicesupport/feature/notificationmsg/NotificationMsgDelegate.java @@ -33,6 +33,7 @@ import com.android.car.companiondevicesupport.api.external.CompanionDevice; import com.android.car.messenger.NotificationMsgProto.NotificationMsg; import com.android.car.messenger.NotificationMsgProto.NotificationMsg.Action; import com.android.car.messenger.NotificationMsgProto.NotificationMsg.CarToPhoneMessage; +import com.android.car.messenger.NotificationMsgProto.NotificationMsg.ClearAppDataRequest; import com.android.car.messenger.NotificationMsgProto.NotificationMsg.ConversationNotification; import com.android.car.messenger.NotificationMsgProto.NotificationMsg.MapEntry; import com.android.car.messenger.NotificationMsgProto.NotificationMsg.MessagingStyleMessage; @@ -58,12 +59,21 @@ public class NotificationMsgDelegate extends BaseNotificationDelegate { /** Key for the Reply string in a {@link MapEntry}. **/ private static final String REPLY_KEY = "REPLY"; - + /** + * Value for {@link ClearAppDataRequest#getMessagingAppPackageName()}, representing + * when all messaging applications' data should be removed. + */ + private static final String REMOVE_ALL_APP_DATA = "ALL"; private static final AudioAttributes AUDIO_ATTRIBUTES = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .build(); private Map<String, NotificationChannelWrapper> mAppNameToChannel = new HashMap<>(); + + /** + * The Bluetooth Device address of the connected device. NOTE: this is NOT the same as + * {@link CompanionDevice#getDeviceId()}. + */ private String mConnectedDeviceBluetoothAddress; /** * Maps a Bitmap of a sender's Large Icon to the sender's unique key for 1-1 conversations. @@ -101,7 +111,8 @@ public class NotificationMsgDelegate extends BaseNotificationDelegate { message.getPhoneMetadata().getBluetoothDeviceAddress(); return; case CLEAR_APP_DATA_REQUEST: - // TODO(b/150326327): implement removal behavior. + clearAppData(device.getDeviceId(), + message.getClearAppDataRequest().getMessagingAppPackageName()); return; case FEATURE_ENABLED_STATE_CHANGE: // TODO(b/150326327): implement enabled state change behavior. @@ -280,6 +291,18 @@ public class NotificationMsgDelegate extends BaseNotificationDelegate { storeIcon(convoKey, iconSync); } + private void clearAppData(String deviceId, String packageName) { + if (!packageName.equals(REMOVE_ALL_APP_DATA)) { + // Clearing data for specific package names is not supported since this use case + // is not needed right now. + logw(TAG, "clearAppData not supported for arg: " + packageName); + return; + } + cleanupMessagesAndNotifications(key -> key.matches(deviceId)); + mOneOnOneConversationAvatarMap.entrySet().removeIf( + conversationKey -> conversationKey.getKey().matches(deviceId)); + } + /** Creates notification channels per unique messaging application. **/ private class NotificationChannelWrapper { private static final String SILENT_CHANNEL_NAME_SUFFIX = "-no-hun"; |