aboutsummaryrefslogtreecommitdiff
path: root/tests/src/com/android/ims/rcs/uce/presence/publish/PublishServiceDescTrackerTest.java
blob: 52017c7a8d9adac5176370a3ff22df09fc1db110 (plain)
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
/*
 * Copyright (C) 2021 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 com.android.ims.rcs.uce.presence.publish;

import static org.junit.Assert.assertEquals;

import android.telephony.ims.RcsContactPresenceTuple;
import android.util.ArraySet;
import android.util.Log;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.ims.rcs.uce.util.FeatureTags;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

@RunWith(AndroidJUnit4.class)
public class PublishServiceDescTrackerTest {

    public static final ServiceDescription TEST_SERVICE_DESC_1 = new ServiceDescription(
            "org.test.test1", "1.0", "ABC");
    public static final ServiceDescription TEST_SERVICE_DESC_2 = new ServiceDescription(
            "org.test.test1", "2.0", "DEF");
    public static final ServiceDescription TEST_OVERRIDE_MMTEL_DESC = new ServiceDescription(
            RcsContactPresenceTuple.SERVICE_ID_MMTEL, "1.0", "ABC");

    public static final String TEST_FEATURE_TAG_1 = "+g.test.test1=\"testing\"";
    public static final String TEST_FEATURE_TAG_2A = "+g.test.test2=\"testing\"";
    public static final String TEST_FEATURE_TAG_2B = "+g.test.testAdd";

    public static final String[] TEST_OVERRIDE_CONFIG = new String[] {
            "org.test.test1|1.0|ABC|+g.test.test1=\"testing\"",
            "org.test.test1|2.0|DEF|+g.test.test2=\"testing\";+g.test.testAdd",
            "org.test.test3|1.0|ABC|+g.test.test3",
            // Modify MMTEL+video to have a different description
            "org.3gpp.urn:urn-7:3gpp-service.ims.icsi.mmtel|1.0|ABC|+g.3gpp.icsi-ref=\""
                    + "urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel\";video"
    };

    public static final String TEST_FEATURE_TAG_FT_FORMAT =
            " +g.3gpp.iari-ref =  \" urn%3AuRN-7%3A3gpp-applicatION.ims.iari.rcs.fthttp \"   ";

    public static final String TEST_FEATURE_TAG_FT_SMS_FORMAT =
            " +g.3gpp.iari-ref=\"    urn%3Aurn-7%3A3gpp-application.iMS.iari.rcs.ftsms    \"";

    public static final String TEST_FEATURE_TAG_CHATBOT_FORMAT =
            " +g.3gpp.iari-ref=  \" Urn%3Aurn-7%3A3gpp-application.ims.iari.rcs.chatbot \"";

    public static final String TEST_FEATURE_TAG_BOTVERSION_V2_FORMAT =
            "+g.gsma.rcs.botVersion =\" #=1  , #=2 \"    ";

    public static final String TEST_FEATURE_TAG_BOTVERSION_FORMAT =
            "+g.gsma.rcs.botVersion =\" #=1   \"    ";

    public static final String TEST_FEATURE_TAG_MMTEL_FORMAT =
            "  +g.3gpp.icsi-ref =    \"urn%3Aurn-7%3A3gpp-servIce.ims.icsi.mmtel \"   ";

    public static final String TEST_FEATURE_TAG_VIDEO_FORMAT = " VIDEO  ";

    public static final String[] TEST_OVERRIDE_CONFIG_FORMAT = new String[] {
            " org.test.test1 | 1.0 | ABC | +g.test.tEST1= \" testing  \"         ",
            "  org.test.test1 |2.0  |DEF | +g.teSt.test2 = \"testing\" ;  +g.test.testAdd  ",
            " org.test.test3  | 1.0   |ABC| +g.TEst.test3   ",
            // Modify MMTEL+video to have a different description
            " org.3gpp.urn:urn-7:3gpp-service.ims.icsi.mmtel |   1.0 |  ABC |  +g.3gPp.icsi-ref=\""
                    + "urn%3Aurn-7%3A3gpp-seRVice.ims.icsi.mmtel   \" ;  video   "
    };

    @SmallTest
    @Test
    public void testDefaultConfigMatch() {
        PublishServiceDescTracker t1 =
                PublishServiceDescTracker.fromCarrierConfig(new String[]{});

        Set<ServiceDescription> expectedSet = Collections.singleton(
                ServiceDescription.SERVICE_DESCRIPTION_FT);
        Set<String> imsReg = createImsRegistration(FeatureTags.FEATURE_TAG_FILE_TRANSFER);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        expectedSet = new ArraySet<>(Arrays.asList(
                ServiceDescription.SERVICE_DESCRIPTION_FT,
                ServiceDescription.SERVICE_DESCRIPTION_FT_SMS));
        imsReg = createImsRegistration(FeatureTags.FEATURE_TAG_FILE_TRANSFER,
                FeatureTags.FEATURE_TAG_FILE_TRANSFER_VIA_SMS);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        expectedSet = Collections.singleton(
                ServiceDescription.SERVICE_DESCRIPTION_CHATBOT_SESSION);
        imsReg = createImsRegistration(
                FeatureTags.FEATURE_TAG_CHATBOT_COMMUNICATION_USING_SESSION,
                FeatureTags.FEATURE_TAG_CHATBOT_VERSION_SUPPORTED);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        // Should see chatbot v1 and v2 pop up in this case (same FTs)
        expectedSet = new ArraySet<>(Arrays.asList(
                ServiceDescription.SERVICE_DESCRIPTION_CHATBOT_SESSION_V1,
                ServiceDescription.SERVICE_DESCRIPTION_CHATBOT_SESSION_V2));
        imsReg = createImsRegistration(
                FeatureTags.FEATURE_TAG_CHATBOT_COMMUNICATION_USING_SESSION,
                FeatureTags.FEATURE_TAG_CHATBOT_VERSION_V2_SUPPORTED);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        expectedSet = Collections.singleton(
                ServiceDescription.SERVICE_DESCRIPTION_MMTEL_VOICE);
        imsReg = createImsRegistration(FeatureTags.FEATURE_TAG_MMTEL);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        expectedSet = Collections.singleton(
                ServiceDescription.SERVICE_DESCRIPTION_MMTEL_VOICE_VIDEO);
        imsReg = createImsRegistration(
                FeatureTags.FEATURE_TAG_MMTEL,
                FeatureTags.FEATURE_TAG_VIDEO);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        expectedSet = Collections.singleton(
                ServiceDescription.SERVICE_DESCRIPTION_SLM);
        imsReg = createImsRegistration(
                FeatureTags.FEATURE_TAG_PAGER_MODE,
                FeatureTags.FEATURE_TAG_LARGE_MODE,
                FeatureTags.FEATURE_TAG_DEFERRED_MESSAGING,
                FeatureTags.FEATURE_TAG_LARGE_PAGER_MODE);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());


        expectedSet = Collections.singleton(
                ServiceDescription.SERVICE_DESCRIPTION_SLM_PAGER_LARGE);
        imsReg = createImsRegistration(
                FeatureTags.FEATURE_TAG_PAGER_MODE,
                FeatureTags.FEATURE_TAG_LARGE_MODE);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        // delete the feature tags for Unregistered
        expectedSet = new ArraySet<>();
        t1.updateImsRegistration(Collections.emptySet());
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());
    }

    @SmallTest
    @Test
    public void testOverrideCarrierConfigMatch() {
        PublishServiceDescTracker t1 =
                PublishServiceDescTracker.fromCarrierConfig(TEST_OVERRIDE_CONFIG);

        Set<ServiceDescription> expectedSet = Collections.singleton(
                ServiceDescription.SERVICE_DESCRIPTION_FT);
        Set<String> imsReg = createImsRegistration(FeatureTags.FEATURE_TAG_FILE_TRANSFER);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        expectedSet = new ArraySet<>(Arrays.asList(
                ServiceDescription.SERVICE_DESCRIPTION_FT, TEST_SERVICE_DESC_1));
        imsReg = createImsRegistration(FeatureTags.FEATURE_TAG_FILE_TRANSFER,
                TEST_FEATURE_TAG_1);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        // Test overrides also allow for multiple FT specifications
        expectedSet = new ArraySet<>(Arrays.asList(
                ServiceDescription.SERVICE_DESCRIPTION_CALL_COMPOSER_MMTEL, TEST_SERVICE_DESC_2));
        imsReg = createImsRegistration(
                FeatureTags.FEATURE_TAG_CALL_COMPOSER_VIA_TELEPHONY,
                TEST_FEATURE_TAG_2B, TEST_FEATURE_TAG_2A);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        // Test override does not affect mmtel voice
        expectedSet = Collections.singleton(
                ServiceDescription.SERVICE_DESCRIPTION_MMTEL_VOICE);
        imsReg = createImsRegistration(FeatureTags.FEATURE_TAG_MMTEL);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        // Test override description works for existing tags
        expectedSet =  Collections.singleton(TEST_OVERRIDE_MMTEL_DESC);
        imsReg = createImsRegistration(
                FeatureTags.FEATURE_TAG_MMTEL,
                FeatureTags.FEATURE_TAG_VIDEO);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());
    }

    @SmallTest
    @Test
    public void testNonstandardImsRegFormatMatch() {
        PublishServiceDescTracker t1 =
                PublishServiceDescTracker.fromCarrierConfig(new String[]{});

        Set<ServiceDescription> expectedSet = new ArraySet<>(Arrays.asList(
                ServiceDescription.SERVICE_DESCRIPTION_FT,
                ServiceDescription.SERVICE_DESCRIPTION_FT_SMS));
        Set<String> imsReg = createImsRegistration(TEST_FEATURE_TAG_FT_FORMAT,
                TEST_FEATURE_TAG_FT_SMS_FORMAT);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        // The registered tag is botVersion=#1,
        // so check if the service description of chatbot version 1.0 should be set.
        expectedSet = Collections.singleton(
                ServiceDescription.SERVICE_DESCRIPTION_CHATBOT_SESSION);
        imsReg = createImsRegistration(
                TEST_FEATURE_TAG_CHATBOT_FORMAT,
                TEST_FEATURE_TAG_BOTVERSION_FORMAT);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        // The registered tag is botVersion=#1,#2,
        // so check if the service description of chatbot version 1.0 and 2.0 should be set.
        expectedSet = new ArraySet<>(Arrays.asList(
                ServiceDescription.SERVICE_DESCRIPTION_CHATBOT_SESSION_V1,
                ServiceDescription.SERVICE_DESCRIPTION_CHATBOT_SESSION_V2));
        imsReg = createImsRegistration(
                TEST_FEATURE_TAG_CHATBOT_FORMAT,
                TEST_FEATURE_TAG_BOTVERSION_V2_FORMAT);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        expectedSet = Collections.singleton(
                ServiceDescription.SERVICE_DESCRIPTION_MMTEL_VOICE);
        imsReg = createImsRegistration(TEST_FEATURE_TAG_MMTEL_FORMAT);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        expectedSet = Collections.singleton(
                ServiceDescription.SERVICE_DESCRIPTION_MMTEL_VOICE_VIDEO);
        imsReg = createImsRegistration(
                TEST_FEATURE_TAG_MMTEL_FORMAT,
                TEST_FEATURE_TAG_VIDEO_FORMAT);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());
    }

    @SmallTest
    @Test
    public void testOverrideCarrierConfigNonstandardFormatMatch() {
        PublishServiceDescTracker t1 =
                PublishServiceDescTracker.fromCarrierConfig(TEST_OVERRIDE_CONFIG_FORMAT);

        Set<ServiceDescription> expectedSet = Collections.singleton(
                ServiceDescription.SERVICE_DESCRIPTION_FT);
        Set<String> imsReg = createImsRegistration(FeatureTags.FEATURE_TAG_FILE_TRANSFER);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        expectedSet = new ArraySet<>(Arrays.asList(
                ServiceDescription.SERVICE_DESCRIPTION_FT, TEST_SERVICE_DESC_1));
        imsReg = createImsRegistration(FeatureTags.FEATURE_TAG_FILE_TRANSFER,
                TEST_FEATURE_TAG_1);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        // Test overrides also allow for multiple FT specifications
        expectedSet = new ArraySet<>(Arrays.asList(
                ServiceDescription.SERVICE_DESCRIPTION_CALL_COMPOSER_MMTEL, TEST_SERVICE_DESC_2));
        imsReg = createImsRegistration(
                FeatureTags.FEATURE_TAG_CALL_COMPOSER_VIA_TELEPHONY,
                TEST_FEATURE_TAG_2B, TEST_FEATURE_TAG_2A);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        // Test override does not affect mmtel voice
        expectedSet = Collections.singleton(
                ServiceDescription.SERVICE_DESCRIPTION_MMTEL_VOICE);
        imsReg = createImsRegistration(TEST_FEATURE_TAG_MMTEL_FORMAT);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());

        // Test override description works for existing tags
        expectedSet =  Collections.singleton(TEST_OVERRIDE_MMTEL_DESC);
        imsReg = createImsRegistration(
                FeatureTags.FEATURE_TAG_MMTEL,
                FeatureTags.FEATURE_TAG_VIDEO);
        t1.updateImsRegistration(imsReg);
        assertEquals(expectedSet, t1.copyRegistrationCapabilities());
    }

    private Set<String> createImsRegistration(String... imsReg) {
        return new ArraySet<>(imsReg);
    }
}