blob: c1ff3965239756de7670ac3de729db44034757d5 [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 android.annotation.IntDef;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23import java.lang.annotation.Retention;
24import java.lang.annotation.RetentionPolicy;
25
26/**
Sahin Caliskan2f932d72019-02-06 10:11:39 -080027 * A token for enabling continuation queries. Instances are acquired through
28 * {@code getContinuationToken} on result objects after initial query is done.
29 *
30 * @see RcsEventQueryResult#getContinuationToken()
31 * @see RcsMessageQueryResult#getContinuationToken()
32 * @see RcsParticipantQueryResult#getContinuationToken()
33 * @see RcsThreadQueryResult#getContinuationToken()
34 *
35 * @hide - TODO: make public
Sahin Caliskanf00a8762019-01-24 14:32:12 -080036 */
Sahin Caliskan2f932d72019-02-06 10:11:39 -080037public final class RcsQueryContinuationToken implements Parcelable {
Sahin Caliskanf00a8762019-01-24 14:32:12 -080038 /**
39 * Denotes that this {@link RcsQueryContinuationToken} token is meant to allow continuing
40 * {@link RcsEvent} queries
41 */
42 public static final int EVENT_QUERY_CONTINUATION_TOKEN_TYPE = 0;
43
44 /**
45 * Denotes that this {@link RcsQueryContinuationToken} token is meant to allow continuing
46 * {@link RcsMessage} queries
47 */
48 public static final int MESSAGE_QUERY_CONTINUATION_TOKEN_TYPE = 1;
49
50 /**
51 * Denotes that this {@link RcsQueryContinuationToken} token is meant to allow continuing
52 * {@link RcsParticipant} queries
53 */
54 public static final int PARTICIPANT_QUERY_CONTINUATION_TOKEN_TYPE = 2;
55
56 /**
57 * Denotes that this {@link RcsQueryContinuationToken} token is meant to allow continuing
58 * {@link RcsThread} queries
59 */
60 public static final int THREAD_QUERY_CONTINUATION_TOKEN_TYPE = 3;
61
62 /**
63 * @hide - not meant for public use
64 */
65 public static final String QUERY_CONTINUATION_TOKEN = "query_continuation_token";
66
67 @Retention(RetentionPolicy.SOURCE)
68 @IntDef({EVENT_QUERY_CONTINUATION_TOKEN_TYPE, MESSAGE_QUERY_CONTINUATION_TOKEN_TYPE,
69 PARTICIPANT_QUERY_CONTINUATION_TOKEN_TYPE, THREAD_QUERY_CONTINUATION_TOKEN_TYPE})
70 public @interface ContinuationTokenType {}
71
72 // The type of query this token should allow to continue
73 private @ContinuationTokenType int mQueryType;
74 // The raw query string for the initial query
75 private final String mRawQuery;
76 // The number of results that is returned with each query
77 private final int mLimit;
78 // The offset value that this query should start the query from
79 private int mOffset;
80
81 /**
82 * @hide
83 */
84 public RcsQueryContinuationToken(@ContinuationTokenType int queryType, String rawQuery,
85 int limit, int offset) {
86 mQueryType = queryType;
87 mRawQuery = rawQuery;
88 mLimit = limit;
89 mOffset = offset;
90 }
91
92 /**
93 * Returns the original raw query used on {@link com.android.providers.telephony.RcsProvider}
94 * @hide
95 */
96 public String getRawQuery() {
97 return mRawQuery;
98 }
99
100 /**
101 * Returns which index this continuation query should start from
102 * @hide
103 */
104 public int getOffset() {
105 return mOffset;
106 }
107
108 /**
109 * Increments the offset by the amount of result rows returned with the continuation query for
110 * the next query.
111 * @hide
112 */
113 public void incrementOffset() {
114 mOffset += mLimit;
115 }
116
117 /**
118 * Returns the type of query that this {@link RcsQueryContinuationToken} is intended to be used
119 * to continue.
120 */
121 public @ContinuationTokenType int getQueryType() {
122 return mQueryType;
123 }
124
Sahin Caliskan2f932d72019-02-06 10:11:39 -0800125 private RcsQueryContinuationToken(Parcel in) {
Sahin Caliskanf00a8762019-01-24 14:32:12 -0800126 mQueryType = in.readInt();
127 mRawQuery = in.readString();
128 mLimit = in.readInt();
129 mOffset = in.readInt();
130 }
131
132 public static final Creator<RcsQueryContinuationToken> CREATOR =
133 new Creator<RcsQueryContinuationToken>() {
134 @Override
135 public RcsQueryContinuationToken createFromParcel(Parcel in) {
136 return new RcsQueryContinuationToken(in);
137 }
138
139 @Override
140 public RcsQueryContinuationToken[] newArray(int size) {
141 return new RcsQueryContinuationToken[size];
142 }
143 };
144
145 @Override
146 public int describeContents() {
147 return 0;
148 }
149
150 @Override
151 public void writeToParcel(Parcel dest, int flags) {
152 dest.writeInt(mQueryType);
153 dest.writeString(mRawQuery);
154 dest.writeInt(mLimit);
155 dest.writeInt(mOffset);
156 }
157}