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