1 /* 2 * Copyright (C) 2020 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 android.app.people; 18 19 import android.annotation.Nullable; 20 import android.app.NotificationChannel; 21 import android.app.NotificationChannelGroup; 22 import android.content.pm.ShortcutInfo; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 import java.util.ArrayList; 27 import java.util.List; 28 29 /** 30 * The non-customized notification channel of a conversation. It contains the information to render 31 * the conversation and allows the user to open and customize the conversation setting. 32 * 33 * @hide 34 */ 35 public final class ConversationChannel implements Parcelable { 36 37 private ShortcutInfo mShortcutInfo; 38 private int mUid; 39 private NotificationChannel mNotificationChannel; 40 private NotificationChannelGroup mNotificationChannelGroup; 41 private long mLastEventTimestamp; 42 private boolean mHasActiveNotifications; 43 private boolean mHasBirthdayToday; 44 private List<ConversationStatus> mStatuses; 45 46 public static final Creator<ConversationChannel> CREATOR = new Creator<ConversationChannel>() { 47 @Override 48 public ConversationChannel createFromParcel(Parcel in) { 49 return new ConversationChannel(in); 50 } 51 52 @Override 53 public ConversationChannel[] newArray(int size) { 54 return new ConversationChannel[size]; 55 } 56 }; 57 ConversationChannel(ShortcutInfo shortcutInfo, int uid, NotificationChannel parentNotificationChannel, NotificationChannelGroup parentNotificationChannelGroup, long lastEventTimestamp, boolean hasActiveNotifications)58 public ConversationChannel(ShortcutInfo shortcutInfo, int uid, 59 NotificationChannel parentNotificationChannel, 60 NotificationChannelGroup parentNotificationChannelGroup, long lastEventTimestamp, 61 boolean hasActiveNotifications) { 62 mShortcutInfo = shortcutInfo; 63 mUid = uid; 64 mNotificationChannel = parentNotificationChannel; 65 mNotificationChannelGroup = parentNotificationChannelGroup; 66 mLastEventTimestamp = lastEventTimestamp; 67 mHasActiveNotifications = hasActiveNotifications; 68 } 69 ConversationChannel(ShortcutInfo shortcutInfo, int uid, NotificationChannel parentNotificationChannel, NotificationChannelGroup parentNotificationChannelGroup, long lastEventTimestamp, boolean hasActiveNotifications, boolean hasBirthdayToday, List<ConversationStatus> statuses)70 public ConversationChannel(ShortcutInfo shortcutInfo, int uid, 71 NotificationChannel parentNotificationChannel, 72 NotificationChannelGroup parentNotificationChannelGroup, long lastEventTimestamp, 73 boolean hasActiveNotifications, boolean hasBirthdayToday, 74 List<ConversationStatus> statuses) { 75 mShortcutInfo = shortcutInfo; 76 mUid = uid; 77 mNotificationChannel = parentNotificationChannel; 78 mNotificationChannelGroup = parentNotificationChannelGroup; 79 mLastEventTimestamp = lastEventTimestamp; 80 mHasActiveNotifications = hasActiveNotifications; 81 mHasBirthdayToday = hasBirthdayToday; 82 mStatuses = statuses; 83 } 84 ConversationChannel(Parcel in)85 public ConversationChannel(Parcel in) { 86 mShortcutInfo = in.readParcelable(ShortcutInfo.class.getClassLoader(), android.content.pm.ShortcutInfo.class); 87 mUid = in.readInt(); 88 mNotificationChannel = in.readParcelable(NotificationChannel.class.getClassLoader(), android.app.NotificationChannel.class); 89 mNotificationChannelGroup = 90 in.readParcelable(NotificationChannelGroup.class.getClassLoader(), android.app.NotificationChannelGroup.class); 91 mLastEventTimestamp = in.readLong(); 92 mHasActiveNotifications = in.readBoolean(); 93 mHasBirthdayToday = in.readBoolean(); 94 mStatuses = new ArrayList<>(); 95 in.readParcelableList(mStatuses, ConversationStatus.class.getClassLoader(), android.app.people.ConversationStatus.class); 96 } 97 98 @Override describeContents()99 public int describeContents() { 100 return 0; 101 } 102 103 @Override writeToParcel(Parcel dest, int flags)104 public void writeToParcel(Parcel dest, int flags) { 105 dest.writeParcelable(mShortcutInfo, flags); 106 dest.writeInt(mUid); 107 dest.writeParcelable(mNotificationChannel, flags); 108 dest.writeParcelable(mNotificationChannelGroup, flags); 109 dest.writeLong(mLastEventTimestamp); 110 dest.writeBoolean(mHasActiveNotifications); 111 dest.writeBoolean(mHasBirthdayToday); 112 dest.writeParcelableList(mStatuses, flags); 113 } 114 getShortcutInfo()115 public ShortcutInfo getShortcutInfo() { 116 return mShortcutInfo; 117 } 118 getUid()119 public int getUid() { 120 return mUid; 121 } 122 getNotificationChannel()123 public NotificationChannel getNotificationChannel() { 124 return mNotificationChannel; 125 } 126 getNotificationChannelGroup()127 public NotificationChannelGroup getNotificationChannelGroup() { 128 return mNotificationChannelGroup; 129 } 130 getLastEventTimestamp()131 public long getLastEventTimestamp() { 132 return mLastEventTimestamp; 133 } 134 135 /** 136 * Whether this conversation has any active notifications. If it's true, the shortcut for this 137 * conversation can't be uncached until all its active notifications are dismissed. 138 */ hasActiveNotifications()139 public boolean hasActiveNotifications() { 140 return mHasActiveNotifications; 141 } 142 143 /** Whether this conversation has a birthday today, as associated in the Contacts Database. */ hasBirthdayToday()144 public boolean hasBirthdayToday() { 145 return mHasBirthdayToday; 146 } 147 148 /** Returns statuses associated with the conversation. */ getStatuses()149 public @Nullable List<ConversationStatus> getStatuses() { 150 return mStatuses; 151 } 152 153 @Override toString()154 public String toString() { 155 return "ConversationChannel{" + 156 "mShortcutInfo=" + mShortcutInfo + 157 ", mUid=" + mUid + 158 ", mNotificationChannel=" + mNotificationChannel + 159 ", mNotificationChannelGroup=" + mNotificationChannelGroup + 160 ", mLastEventTimestamp=" + mLastEventTimestamp + 161 ", mHasActiveNotifications=" + mHasActiveNotifications + 162 ", mHasBirthdayToday=" + mHasBirthdayToday + 163 ", mStatuses=" + mStatuses + 164 '}'; 165 } 166 } 167