• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.internal.telephony.ims;
17 
18 import static android.provider.Telephony.RcsColumns.RcsParticipantColumns.RCS_PARTICIPANT_ID_COLUMN;
19 import static android.provider.Telephony.RcsColumns.RcsParticipantColumns.RCS_PARTICIPANT_URI;
20 import static android.telephony.ims.RcsQueryContinuationToken.QUERY_CONTINUATION_TOKEN;
21 
22 import android.content.ContentResolver;
23 import android.database.Cursor;
24 import android.net.Uri;
25 import android.os.Bundle;
26 import android.os.RemoteException;
27 import android.telephony.ims.RcsParticipantQueryResultParcelable;
28 import android.telephony.ims.RcsQueryContinuationToken;
29 
30 import java.util.ArrayList;
31 import java.util.List;
32 
33 class RcsParticipantQueryHelper {
34     private final ContentResolver mContentResolver;
35 
RcsParticipantQueryHelper(ContentResolver contentResolver)36     RcsParticipantQueryHelper(ContentResolver contentResolver) {
37         mContentResolver = contentResolver;
38     }
39 
performParticipantQuery(Bundle bundle)40     RcsParticipantQueryResultParcelable performParticipantQuery(Bundle bundle)
41             throws RemoteException {
42         RcsQueryContinuationToken continuationToken = null;
43         List<Integer> participantList = new ArrayList<>();
44 
45         try (Cursor cursor = mContentResolver.query(RCS_PARTICIPANT_URI, null, bundle, null)) {
46             if (cursor == null) {
47                 throw new RemoteException("Could not perform participant query, bundle: " + bundle);
48             }
49 
50             while (cursor.moveToNext()) {
51                 participantList.add(
52                         cursor.getInt(cursor.getColumnIndex(RCS_PARTICIPANT_ID_COLUMN)));
53             }
54 
55             Bundle cursorExtras = cursor.getExtras();
56             if (cursorExtras != null) {
57                 continuationToken = cursorExtras.getParcelable(QUERY_CONTINUATION_TOKEN);
58             }
59         }
60 
61         return new RcsParticipantQueryResultParcelable(continuationToken, participantList);
62     }
63 
getUriForParticipant(int participantId)64     static Uri getUriForParticipant(int participantId) {
65         return Uri.withAppendedPath(RCS_PARTICIPANT_URI, Integer.toString(participantId));
66     }
67 }
68