blob: 9dbfe439321370461d114a23372484820f772dbf [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 Caliskanf00a8762019-01-24 14:32:12 -080040 */
Sahin Caliskan2f932d72019-02-06 10:11:39 -080041public final class RcsEventQueryParams implements Parcelable {
Sahin Caliskanf00a8762019-01-24 14:32:12 -080042 /**
43 * Flag to be used with {@link Builder#setEventType(int)} to make
Sahin Caliskan2f932d72019-02-06 10:11:39 -080044 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return all types of
Sahin Caliskanf00a8762019-01-24 14:32:12 -080045 * {@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 Caliskan2f932d72019-02-06 10:11:39 -080051 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return sub-types of
Sahin Caliskanf00a8762019-01-24 14:32:12 -080052 * {@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 Caliskan2f932d72019-02-06 10:11:39 -080058 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only
Sahin Caliskanf00a8762019-01-24 14:32:12 -080059 * {@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 Caliskan2f932d72019-02-06 10:11:39 -080066 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only
Sahin Caliskanf00a8762019-01-24 14:32:12 -080067 * {@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 Caliskan2f932d72019-02-06 10:11:39 -080074 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only
Sahin Caliskanf00a8762019-01-24 14:32:12 -080075 * {@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 Caliskan2f932d72019-02-06 10:11:39 -080082 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only
Sahin Caliskanf00a8762019-01-24 14:32:12 -080083 * {@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 Caliskan2f932d72019-02-06 10:11:39 -080089 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)} return only
Sahin Caliskanf00a8762019-01-24 14:32:12 -080090 * {@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 Caliskan2f932d72019-02-06 10:11:39 -0800135 RcsEventQueryParams(@EventType int eventType, int threadId,
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800136 @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 Caliskan2f932d72019-02-06 10:11:39 -0800145 * @return Returns the type of {@link RcsEvent}s that this {@link RcsEventQueryParams} is
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800146 * set to query for.
147 */
148 public @EventType int getEventType() {
149 return mEventType;
150 }
151
152 /**
Sahin Caliskan74ebff82019-02-07 14:46:21 -0800153 * @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 Caliskanf00a8762019-01-24 14:32:12 -0800155 */
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 Caliskan2f932d72019-02-06 10:11:39 -0800187 * A helper class to build the {@link RcsEventQueryParams}.
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800188 */
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 Caliskan2f932d72019-02-06 10:11:39 -0800197 * Creates a new builder for {@link RcsEventQueryParams} to be used in
198 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)}
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800199 */
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 Caliskan2f932d72019-02-06 10:11:39 -0800237 * {@link RcsEventQueryParams.SortingProperty#SORT_BY_CREATION_ORDER}
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800238 *
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 Caliskan2f932d72019-02-06 10:11:39 -0800274 * Builds the {@link RcsEventQueryParams} to use in
275 * {@link RcsMessageStore#getRcsEvents(RcsEventQueryParams)}
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800276 *
Sahin Caliskan2f932d72019-02-06 10:11:39 -0800277 * @return An instance of {@link RcsEventQueryParams} to use with the event query.
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800278 */
Sahin Caliskan2f932d72019-02-06 10:11:39 -0800279 public RcsEventQueryParams build() {
280 return new RcsEventQueryParams(mEventType, mThreadId, mSortingProperty,
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800281 mIsAscending, mLimit);
282 }
283 }
284
Sahin Caliskan2f932d72019-02-06 10:11:39 -0800285 private RcsEventQueryParams(Parcel in) {
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800286 mEventType = in.readInt();
287 mThreadId = in.readInt();
288 mSortingProperty = in.readInt();
289 mIsAscending = in.readBoolean();
290 mLimit = in.readInt();
291 }
292
Sahin Caliskan2f932d72019-02-06 10:11:39 -0800293 public static final Creator<RcsEventQueryParams> CREATOR =
294 new Creator<RcsEventQueryParams>() {
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800295 @Override
Sahin Caliskan2f932d72019-02-06 10:11:39 -0800296 public RcsEventQueryParams createFromParcel(Parcel in) {
297 return new RcsEventQueryParams(in);
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800298 }
299
300 @Override
Sahin Caliskan2f932d72019-02-06 10:11:39 -0800301 public RcsEventQueryParams[] newArray(int size) {
302 return new RcsEventQueryParams[size];
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800303 }
304 };
305
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800306 @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}