blob: 0024cf7b866290c23f633cdcb09c0f18253de8f8 [file] [log] [blame]
Sahin Caliskanf00a8762019-01-24 14:32:12 -08001/*
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
17package android.telephony.ims;
18
19import static android.provider.Telephony.RcsColumns.RcsEventTypes.ICON_CHANGED_EVENT_TYPE;
20import static android.provider.Telephony.RcsColumns.RcsEventTypes.NAME_CHANGED_EVENT_TYPE;
21import static android.provider.Telephony.RcsColumns.RcsEventTypes.PARTICIPANT_ALIAS_CHANGED_EVENT_TYPE;
22import static android.provider.Telephony.RcsColumns.RcsEventTypes.PARTICIPANT_JOINED_EVENT_TYPE;
23import static android.provider.Telephony.RcsColumns.RcsEventTypes.PARTICIPANT_LEFT_EVENT_TYPE;
24
25import android.annotation.CheckResult;
26import android.annotation.IntDef;
27import android.annotation.IntRange;
28import android.annotation.NonNull;
29import android.os.Parcel;
30import android.os.Parcelable;
31
32import java.lang.annotation.Retention;
33import java.lang.annotation.RetentionPolicy;
34import java.security.InvalidParameterException;
35
36/**
37 * The parameters to pass into
Sahin Caliskan2f932d72019-02-06 10:11:39 -080038 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} in order to select a
Sahin Caliskanf00a8762019-01-24 14:32:12 -080039 * subset of {@link RcsEvent}s present in the message store.
Sahin Caliskan9a7e40e2019-02-21 15:35:44 -080040 *
41 * @hide
Sahin Caliskanf00a8762019-01-24 14:32:12 -080042 */
Sahin Caliskan2f932d72019-02-06 10:11:39 -080043public final class RcsEventQueryParams implements Parcelable {
Sahin Caliskanf00a8762019-01-24 14:32:12 -080044 /**
45 * Flag to be used with {@link Builder#setEventType(int)} to make
Sahin Caliskan2f932d72019-02-06 10:11:39 -080046 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return all types of
Sahin Caliskanf00a8762019-01-24 14:32:12 -080047 * {@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 Caliskan2f932d72019-02-06 10:11:39 -080053 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return sub-types of
Sahin Caliskanf00a8762019-01-24 14:32:12 -080054 * {@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 Caliskan2f932d72019-02-06 10:11:39 -080060 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only
Sahin Caliskanf00a8762019-01-24 14:32:12 -080061 * {@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 Caliskan2f932d72019-02-06 10:11:39 -080068 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only
Sahin Caliskanf00a8762019-01-24 14:32:12 -080069 * {@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 Caliskan2f932d72019-02-06 10:11:39 -080076 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only
Sahin Caliskanf00a8762019-01-24 14:32:12 -080077 * {@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 Caliskan2f932d72019-02-06 10:11:39 -080084 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only
Sahin Caliskanf00a8762019-01-24 14:32:12 -080085 * {@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 Caliskan2f932d72019-02-06 10:11:39 -080091 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only
Sahin Caliskanf00a8762019-01-24 14:32:12 -080092 * {@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 Caliskan2f932d72019-02-06 10:11:39 -0800137 RcsEventQueryParams(@EventType int eventType, int threadId,
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800138 @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 Caliskan2f932d72019-02-06 10:11:39 -0800147 * @return Returns the type of {@link RcsEvent}s that this {@link RcsEventQueryParams} is
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800148 * set to query for.
149 */
150 public @EventType int getEventType() {
151 return mEventType;
152 }
153
154 /**
Sahin Caliskan74ebff82019-02-07 14:46:21 -0800155 * @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 Caliskanf00a8762019-01-24 14:32:12 -0800157 */
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 Caliskan2f932d72019-02-06 10:11:39 -0800189 * A helper class to build the {@link RcsEventQueryParams}.
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800190 */
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 Caliskan2f932d72019-02-06 10:11:39 -0800199 * Creates a new builder for {@link RcsEventQueryParams} to be used in
200 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)}
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800201 */
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 Caliskan2f932d72019-02-06 10:11:39 -0800239 * {@link RcsEventQueryParams.SortingProperty#SORT_BY_CREATION_ORDER}
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800240 *
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 Caliskan2f932d72019-02-06 10:11:39 -0800276 * Builds the {@link RcsEventQueryParams} to use in
277 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)}
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800278 *
Sahin Caliskan2f932d72019-02-06 10:11:39 -0800279 * @return An instance of {@link RcsEventQueryParams} to use with the event query.
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800280 */
Sahin Caliskan2f932d72019-02-06 10:11:39 -0800281 public RcsEventQueryParams build() {
282 return new RcsEventQueryParams(mEventType, mThreadId, mSortingProperty,
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800283 mIsAscending, mLimit);
284 }
285 }
286
Sahin Caliskan2f932d72019-02-06 10:11:39 -0800287 private RcsEventQueryParams(Parcel in) {
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800288 mEventType = in.readInt();
289 mThreadId = in.readInt();
290 mSortingProperty = in.readInt();
291 mIsAscending = in.readBoolean();
292 mLimit = in.readInt();
293 }
294
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700295 public static final @android.annotation.NonNull Creator<RcsEventQueryParams> CREATOR =
Sahin Caliskan2f932d72019-02-06 10:11:39 -0800296 new Creator<RcsEventQueryParams>() {
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800297 @Override
Sahin Caliskan2f932d72019-02-06 10:11:39 -0800298 public RcsEventQueryParams createFromParcel(Parcel in) {
299 return new RcsEventQueryParams(in);
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800300 }
301
302 @Override
Sahin Caliskan2f932d72019-02-06 10:11:39 -0800303 public RcsEventQueryParams[] newArray(int size) {
304 return new RcsEventQueryParams[size];
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800305 }
306 };
307
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800308 @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}