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