Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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.telephony.ims; |
| 18 | |
| 19 | import static android.provider.Telephony.RcsColumns.RcsEventTypes.ICON_CHANGED_EVENT_TYPE; |
| 20 | import static android.provider.Telephony.RcsColumns.RcsEventTypes.NAME_CHANGED_EVENT_TYPE; |
| 21 | import static android.provider.Telephony.RcsColumns.RcsEventTypes.PARTICIPANT_ALIAS_CHANGED_EVENT_TYPE; |
| 22 | import static android.provider.Telephony.RcsColumns.RcsEventTypes.PARTICIPANT_JOINED_EVENT_TYPE; |
| 23 | import static android.provider.Telephony.RcsColumns.RcsEventTypes.PARTICIPANT_LEFT_EVENT_TYPE; |
| 24 | |
| 25 | import android.annotation.CheckResult; |
| 26 | import android.annotation.IntDef; |
| 27 | import android.annotation.IntRange; |
| 28 | import android.annotation.NonNull; |
| 29 | import android.os.Parcel; |
| 30 | import android.os.Parcelable; |
| 31 | |
| 32 | import java.lang.annotation.Retention; |
| 33 | import java.lang.annotation.RetentionPolicy; |
| 34 | import java.security.InvalidParameterException; |
| 35 | |
| 36 | /** |
| 37 | * The parameters to pass into |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 38 | * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} in order to select a |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 39 | * subset of {@link RcsEvent}s present in the message store. |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 40 | */ |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 41 | public final class RcsEventQueryParams implements Parcelable { |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 42 | /** |
| 43 | * Flag to be used with {@link Builder#setEventType(int)} to make |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 44 | * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return all types of |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 45 | * {@link RcsEvent}s |
| 46 | */ |
| 47 | public static final int ALL_EVENTS = -1; |
| 48 | |
| 49 | /** |
| 50 | * Flag to be used with {@link Builder#setEventType(int)} to make |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 51 | * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return sub-types of |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 52 | * {@link RcsGroupThreadEvent}s |
| 53 | */ |
| 54 | public static final int ALL_GROUP_THREAD_EVENTS = 0; |
| 55 | |
| 56 | /** |
| 57 | * Flag to be used with {@link Builder#setEventType(int)} to make |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 58 | * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 59 | * {@link RcsParticipantAliasChangedEvent}s |
| 60 | */ |
| 61 | public static final int PARTICIPANT_ALIAS_CHANGED_EVENT = |
| 62 | PARTICIPANT_ALIAS_CHANGED_EVENT_TYPE; |
| 63 | |
| 64 | /** |
| 65 | * Flag to be used with {@link Builder#setEventType(int)} to make |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 66 | * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 67 | * {@link RcsGroupThreadParticipantJoinedEvent}s |
| 68 | */ |
| 69 | public static final int GROUP_THREAD_PARTICIPANT_JOINED_EVENT = |
| 70 | PARTICIPANT_JOINED_EVENT_TYPE; |
| 71 | |
| 72 | /** |
| 73 | * Flag to be used with {@link Builder#setEventType(int)} to make |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 74 | * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 75 | * {@link RcsGroupThreadParticipantLeftEvent}s |
| 76 | */ |
| 77 | public static final int GROUP_THREAD_PARTICIPANT_LEFT_EVENT = |
| 78 | PARTICIPANT_LEFT_EVENT_TYPE; |
| 79 | |
| 80 | /** |
| 81 | * Flag to be used with {@link Builder#setEventType(int)} to make |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 82 | * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 83 | * {@link RcsGroupThreadNameChangedEvent}s |
| 84 | */ |
| 85 | public static final int GROUP_THREAD_NAME_CHANGED_EVENT = NAME_CHANGED_EVENT_TYPE; |
| 86 | |
| 87 | /** |
| 88 | * Flag to be used with {@link Builder#setEventType(int)} to make |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 89 | * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 90 | * {@link RcsGroupThreadIconChangedEvent}s |
| 91 | */ |
| 92 | public static final int GROUP_THREAD_ICON_CHANGED_EVENT = ICON_CHANGED_EVENT_TYPE; |
| 93 | |
| 94 | @Retention(RetentionPolicy.SOURCE) |
| 95 | @IntDef({ALL_EVENTS, ALL_GROUP_THREAD_EVENTS, PARTICIPANT_ALIAS_CHANGED_EVENT, |
| 96 | GROUP_THREAD_PARTICIPANT_JOINED_EVENT, GROUP_THREAD_PARTICIPANT_LEFT_EVENT, |
| 97 | GROUP_THREAD_NAME_CHANGED_EVENT, GROUP_THREAD_ICON_CHANGED_EVENT}) |
| 98 | public @interface EventType { |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Flag to be used with {@link Builder#setSortProperty(int)} that makes the result set sorted |
| 103 | * in the order of creation for faster query results. |
| 104 | */ |
| 105 | public static final int SORT_BY_CREATION_ORDER = 0; |
| 106 | |
| 107 | /** |
| 108 | * Flag to be used with {@link Builder#setSortProperty(int)} that makes the result set sorted |
| 109 | * with respect to {@link RcsEvent#getTimestamp()} |
| 110 | */ |
| 111 | public static final int SORT_BY_TIMESTAMP = 1; |
| 112 | |
| 113 | @Retention(RetentionPolicy.SOURCE) |
| 114 | @IntDef({SORT_BY_CREATION_ORDER, SORT_BY_TIMESTAMP}) |
| 115 | public @interface SortingProperty { |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * The key to pass into a Bundle, for usage in RcsProvider.query(Bundle) |
| 120 | * @hide - not meant for public use |
| 121 | */ |
| 122 | public static final String EVENT_QUERY_PARAMETERS_KEY = "event_query_parameters"; |
| 123 | |
| 124 | // Which types of events the results should be limited to |
| 125 | private @EventType int mEventType; |
| 126 | // The property which the results should be sorted against |
| 127 | private int mSortingProperty; |
| 128 | // Whether the results should be sorted in ascending order |
| 129 | private boolean mIsAscending; |
| 130 | // The number of results that should be returned with this query |
| 131 | private int mLimit; |
| 132 | // The thread that the results are limited to |
| 133 | private int mThreadId; |
| 134 | |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 135 | RcsEventQueryParams(@EventType int eventType, int threadId, |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 136 | @SortingProperty int sortingProperty, boolean isAscending, int limit) { |
| 137 | mEventType = eventType; |
| 138 | mSortingProperty = sortingProperty; |
| 139 | mIsAscending = isAscending; |
| 140 | mLimit = limit; |
| 141 | mThreadId = threadId; |
| 142 | } |
| 143 | |
| 144 | /** |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 145 | * @return Returns the type of {@link RcsEvent}s that this {@link RcsEventQueryParams} is |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 146 | * set to query for. |
| 147 | */ |
| 148 | public @EventType int getEventType() { |
| 149 | return mEventType; |
| 150 | } |
| 151 | |
| 152 | /** |
Sahin Caliskan | 74ebff8 | 2019-02-07 14:46:21 -0800 | [diff] [blame^] | 153 | * @return Returns the number of {@link RcsEvent}s to be returned from the query. A value of |
| 154 | * 0 means there is no set limit. |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 155 | */ |
| 156 | public int getLimit() { |
| 157 | return mLimit; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * @return Returns the property where the results should be sorted against. |
| 162 | * @see SortingProperty |
| 163 | */ |
| 164 | public int getSortingProperty() { |
| 165 | return mSortingProperty; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * @return Returns {@code true} if the result set will be sorted in ascending order, |
| 170 | * {@code false} if it will be sorted in descending order. |
| 171 | */ |
| 172 | public boolean getSortDirection() { |
| 173 | return mIsAscending; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * @return Returns the ID of the {@link RcsGroupThread} that the results are limited to. As this |
| 178 | * API exposes an ID, it should stay hidden. |
| 179 | * |
| 180 | * @hide |
| 181 | */ |
| 182 | public int getThreadId() { |
| 183 | return mThreadId; |
| 184 | } |
| 185 | |
| 186 | /** |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 187 | * A helper class to build the {@link RcsEventQueryParams}. |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 188 | */ |
| 189 | public static class Builder { |
| 190 | private @EventType int mEventType; |
| 191 | private @SortingProperty int mSortingProperty; |
| 192 | private boolean mIsAscending; |
| 193 | private int mLimit = 100; |
| 194 | private int mThreadId; |
| 195 | |
| 196 | /** |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 197 | * Creates a new builder for {@link RcsEventQueryParams} to be used in |
| 198 | * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 199 | */ |
| 200 | public Builder() { |
| 201 | // empty implementation |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Desired number of events to be returned from the query. Passing in 0 will return all |
| 206 | * existing events at once. The limit defaults to 100. |
| 207 | * |
| 208 | * @param limit The number to limit the query result to. |
| 209 | * @return The same instance of the builder to chain parameters. |
| 210 | * @throws InvalidParameterException If the given limit is negative. |
| 211 | */ |
| 212 | @CheckResult |
| 213 | public Builder setResultLimit(@IntRange(from = 0) int limit) |
| 214 | throws InvalidParameterException { |
| 215 | if (limit < 0) { |
| 216 | throw new InvalidParameterException("The query limit must be non-negative"); |
| 217 | } |
| 218 | |
| 219 | mLimit = limit; |
| 220 | return this; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Sets the type of events to be returned from the query. |
| 225 | * |
| 226 | * @param eventType The type of event to be returned. |
| 227 | * @return The same instance of the builder to chain parameters. |
| 228 | */ |
| 229 | @CheckResult |
| 230 | public Builder setEventType(@EventType int eventType) { |
| 231 | mEventType = eventType; |
| 232 | return this; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Sets the property where the results should be sorted against. Defaults to |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 237 | * {@link RcsEventQueryParams.SortingProperty#SORT_BY_CREATION_ORDER} |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 238 | * |
| 239 | * @param sortingProperty against which property the results should be sorted |
| 240 | * @return The same instance of the builder to chain parameters. |
| 241 | */ |
| 242 | @CheckResult |
| 243 | public Builder setSortProperty(@SortingProperty int sortingProperty) { |
| 244 | mSortingProperty = sortingProperty; |
| 245 | return this; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Sets whether the results should be sorted ascending or descending |
| 250 | * |
| 251 | * @param isAscending whether the results should be sorted ascending |
| 252 | * @return The same instance of the builder to chain parameters. |
| 253 | */ |
| 254 | @CheckResult |
| 255 | public Builder setSortDirection(boolean isAscending) { |
| 256 | mIsAscending = isAscending; |
| 257 | return this; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Limits the results to the given {@link RcsGroupThread}. Setting this value prevents |
| 262 | * returning any instances of {@link RcsParticipantAliasChangedEvent}. |
| 263 | * |
| 264 | * @param groupThread The thread to limit the results to. |
| 265 | * @return The same instance of the builder to chain parameters. |
| 266 | */ |
| 267 | @CheckResult |
| 268 | public Builder setGroupThread(@NonNull RcsGroupThread groupThread) { |
| 269 | mThreadId = groupThread.getThreadId(); |
| 270 | return this; |
| 271 | } |
| 272 | |
| 273 | /** |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 274 | * Builds the {@link RcsEventQueryParams} to use in |
| 275 | * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 276 | * |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 277 | * @return An instance of {@link RcsEventQueryParams} to use with the event query. |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 278 | */ |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 279 | public RcsEventQueryParams build() { |
| 280 | return new RcsEventQueryParams(mEventType, mThreadId, mSortingProperty, |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 281 | mIsAscending, mLimit); |
| 282 | } |
| 283 | } |
| 284 | |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 285 | private RcsEventQueryParams(Parcel in) { |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 286 | mEventType = in.readInt(); |
| 287 | mThreadId = in.readInt(); |
| 288 | mSortingProperty = in.readInt(); |
| 289 | mIsAscending = in.readBoolean(); |
| 290 | mLimit = in.readInt(); |
| 291 | } |
| 292 | |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 293 | public static final Creator<RcsEventQueryParams> CREATOR = |
| 294 | new Creator<RcsEventQueryParams>() { |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 295 | @Override |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 296 | public RcsEventQueryParams createFromParcel(Parcel in) { |
| 297 | return new RcsEventQueryParams(in); |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | @Override |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 301 | public RcsEventQueryParams[] newArray(int size) { |
| 302 | return new RcsEventQueryParams[size]; |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 303 | } |
| 304 | }; |
| 305 | |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 306 | @Override |
| 307 | public int describeContents() { |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public void writeToParcel(Parcel dest, int flags) { |
| 313 | dest.writeInt(mEventType); |
| 314 | dest.writeInt(mThreadId); |
| 315 | dest.writeInt(mSortingProperty); |
| 316 | dest.writeBoolean(mIsAscending); |
| 317 | dest.writeInt(mLimit); |
| 318 | } |
| 319 | } |