1/*
2 * Copyright (C) 2018 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 com.android.internal.telephony.uicc.euicc.data;
18
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertFalse;
21import static org.junit.Assert.assertTrue;
22
23import android.os.Parcel;
24import android.service.carrier.CarrierIdentifier;
25import android.service.euicc.EuiccProfileInfo;
26import android.telephony.euicc.EuiccRulesAuthTable;
27
28import org.junit.Test;
29
30import java.util.Arrays;
31
32public class EuiccRulesAuthTableTest {
33    @Test
34    public void testFindIndex() {
35        CarrierIdentifier opA = new CarrierIdentifier(new byte[] {0x21, 0x63, 0x54}, null, "4");
36        CarrierIdentifier opB = new CarrierIdentifier(new byte[] {0x21, 0x69, 0x54}, "4", null);
37        EuiccRulesAuthTable rat =
38                new EuiccRulesAuthTable.Builder(4)
39                        .add(
40                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
41                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
42                                // Matches none
43                                Arrays.asList(new CarrierIdentifier[] {}),
44                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
45                        .add(
46                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE,
47                                Arrays.asList(
48                                        // Matches none
49                                        new CarrierIdentifier(
50                                                new byte[] {0x21, (byte) 0xF3, 0x54},
51                                                "4",
52                                                null),
53                                        // Matches opA
54                                        new CarrierIdentifier(
55                                                new byte[] {0x21, 0x63, 0x54}, null, "4")
56                                ),
57                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
58                        .add(
59                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
60                                Arrays.asList(
61                                        // Matches none
62                                        new CarrierIdentifier(
63                                                new byte[] {0x21, 0x63, 0x54}, null, "5"),
64                                        // Matches opA and opB
65                                        new CarrierIdentifier(
66                                                new byte[] {0x21, 0x6E, 0x54}, null, null)
67                                ),
68                                0)
69                        .add(
70                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
71                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
72                                Arrays.asList(
73                                        // Matches none
74                                        new CarrierIdentifier(
75                                                new byte[] {0x21, 0x69, 0x54}, "5", null),
76                                        // Matches opB
77                                        new CarrierIdentifier(
78                                                new byte[] {0x21, 0x6E, 0x54}, "4", null),
79                                        // Matches opA
80                                        new CarrierIdentifier(
81                                                new byte[] {0x21, 0x6E, 0x54}, null, "4")
82                                ),
83                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
84                        .build();
85
86        assertEquals(1, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE, opA));
87        assertEquals(3, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE, opB));
88        assertEquals(2, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE, opA));
89        assertEquals(2, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE, opB));
90        assertTrue(rat.hasPolicyRuleFlag(1, EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED));
91        assertFalse(rat.hasPolicyRuleFlag(
92                2, EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED));
93        assertTrue(rat.hasPolicyRuleFlag(3, EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED));
94    }
95
96    @Test
97    public void testFindIndex_AllowAllWithUserConsent() {
98        CarrierIdentifier opA = new CarrierIdentifier(new byte[] {0x21, 0x63, 0x54}, null, "4");
99        CarrierIdentifier opB = new CarrierIdentifier(
100                new byte[] {0x78, (byte) 0xF4, 0x25}, "4", null);
101        EuiccRulesAuthTable rat =
102                new EuiccRulesAuthTable.Builder(1)
103                        .add(
104                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
105                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
106                                Arrays.asList(
107                                        // Matches none
108                                        new CarrierIdentifier(
109                                                new byte[] {(byte) 0xEE, (byte) 0xEE, (byte) 0xEE},
110                                                null,
111                                                null)
112                                ),
113                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
114                        .build();
115        assertEquals(0, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE, opA));
116        assertEquals(0, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE, opB));
117        assertEquals(0, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE, opA));
118        assertEquals(0, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE, opB));
119    }
120
121    @Test
122    public void testFindIndex_DisallowAll() {
123        CarrierIdentifier opA = new CarrierIdentifier(new byte[] {0x21, 0x63, 0x54}, null, "4");
124        CarrierIdentifier opB = new CarrierIdentifier(
125                new byte[] {0x78, (byte) 0xF4, 0x25}, "4", null);
126        EuiccRulesAuthTable rat = new EuiccRulesAuthTable.Builder(1)
127                .add(0, Arrays.asList(new CarrierIdentifier[] {}), 0).build();
128        assertEquals(-1, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE, opA));
129        assertEquals(-1, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE, opB));
130        assertEquals(-1, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE, opA));
131        assertEquals(-1, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE, opB));
132    }
133
134    @Test
135    public void testFindIndex_DisallowAllWithEmptyRules() {
136        CarrierIdentifier opA = new CarrierIdentifier(new byte[] {0x21, 0x63, 0x54}, null, "4");
137        CarrierIdentifier opB = new CarrierIdentifier(new byte[] {0x78, 0x34, 0x25}, "4", null);
138        EuiccRulesAuthTable rat = new EuiccRulesAuthTable.Builder(0).build();
139        assertEquals(-1, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE, opA));
140        assertEquals(-1, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE, opB));
141        assertEquals(-1, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE, opA));
142        assertEquals(-1, rat.findIndex(EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE, opB));
143    }
144
145    @Test(expected = IllegalStateException.class)
146    public void testBuild_NotEnoughRules() {
147        new EuiccRulesAuthTable.Builder(1).build();
148    }
149
150    @Test(expected = ArrayIndexOutOfBoundsException.class)
151    public void testBuild_TooManyRules() {
152        new EuiccRulesAuthTable.Builder(0)
153                .add(0, Arrays.asList(new CarrierIdentifier[] {}), 0).build();
154    }
155
156    @Test(expected = ArrayIndexOutOfBoundsException.class)
157    public void testHasPolicyRuleFlag_OutOfBounds() {
158        EuiccRulesAuthTable rat = new EuiccRulesAuthTable.Builder(1)
159                .add(0, Arrays.asList(new CarrierIdentifier[] {}), 0).build();
160        rat.hasPolicyRuleFlag(1, EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED);
161    }
162
163    @Test
164    public void testMatch() {
165        assertTrue(EuiccRulesAuthTable.match("12", "12"));
166        assertTrue(EuiccRulesAuthTable.match("1E", "12"));
167        assertTrue(EuiccRulesAuthTable.match("12E", "12"));
168        assertTrue(EuiccRulesAuthTable.match("EEE", "12"));
169        assertTrue(EuiccRulesAuthTable.match("120", "120"));
170        assertTrue(EuiccRulesAuthTable.match("12E", "120"));
171        assertTrue(EuiccRulesAuthTable.match("EEE", "120"));
172
173        assertFalse(EuiccRulesAuthTable.match("13", "12"));
174        assertFalse(EuiccRulesAuthTable.match("2E", "12"));
175        assertFalse(EuiccRulesAuthTable.match("123", "120"));
176        assertFalse(EuiccRulesAuthTable.match("1E", "120"));
177        assertFalse(EuiccRulesAuthTable.match("EE", "120"));
178    }
179
180    @Test
181    public void testWriteToParcel() {
182        EuiccRulesAuthTable rat =
183                new EuiccRulesAuthTable.Builder(4)
184                        .add(
185                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
186                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
187                                Arrays.asList(new CarrierIdentifier[] {}),
188                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
189                        .add(
190                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE,
191                                Arrays.asList(
192                                        new CarrierIdentifier(
193                                                new byte[] {0x21, (byte) 0xF3, 0x54},
194                                                "4",
195                                                null),
196                                        new CarrierIdentifier(
197                                                new byte[] {0x21, 0x63, 0x54}, null, "4")
198                                ),
199                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
200                        .add(
201                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
202                                Arrays.asList(
203                                        new CarrierIdentifier(
204                                                new byte[] {0x21, 0x63, 0x54}, null, "5"),
205                                        new CarrierIdentifier(
206                                                new byte[] {0x21, 0x6E, 0x54}, null, null)
207                                ),
208                                0)
209                        .add(
210                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
211                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
212                                Arrays.asList(
213                                        new CarrierIdentifier(
214                                                new byte[] {0x21, 0x69, 0x54}, "5", null),
215                                        new CarrierIdentifier(
216                                                new byte[] {0x21, 0x6E, 0x54}, "4", null),
217                                        new CarrierIdentifier(
218                                                new byte[] {0x21, 0x6E, 0x54}, null, "4")
219                                ),
220                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
221                        .build();
222
223        Parcel parcel = Parcel.obtain();
224        assertTrue(parcel != null);
225        rat.writeToParcel(parcel, 0);
226
227        parcel.setDataPosition(0);
228        EuiccRulesAuthTable fromParcel = EuiccRulesAuthTable.CREATOR.createFromParcel(parcel);
229
230        assertEquals(rat, fromParcel);
231
232        // Empty rules.
233        rat = new EuiccRulesAuthTable.Builder(0).build();
234        parcel = Parcel.obtain();
235        rat.writeToParcel(parcel, 0);
236
237        parcel.setDataPosition(0);
238        fromParcel = EuiccRulesAuthTable.CREATOR.createFromParcel(parcel);
239
240        assertEquals(rat, fromParcel);
241
242        // Null carrier identifier.
243        rat =
244                new EuiccRulesAuthTable.Builder(1)
245                        .add(
246                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
247                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
248                                null,
249                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
250                        .build();
251        parcel = Parcel.obtain();
252        rat.writeToParcel(parcel, 0);
253
254        parcel.setDataPosition(0);
255        fromParcel = EuiccRulesAuthTable.CREATOR.createFromParcel(parcel);
256
257        assertEquals(rat, fromParcel);
258    }
259
260    @Test
261    public void testEquals() {
262        EuiccRulesAuthTable rat =
263                new EuiccRulesAuthTable.Builder(4)
264                        .add(
265                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
266                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
267                                Arrays.asList(new CarrierIdentifier[] {}),
268                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
269                        .add(
270                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE,
271                                Arrays.asList(
272                                        new CarrierIdentifier(
273                                                new byte[] {0x21, (byte) 0xF3, 0x54},
274                                                "4",
275                                                null),
276                                        new CarrierIdentifier(
277                                                new byte[] {0x21, 0x63, 0x54}, null, "4")
278                                ),
279                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
280                        .add(
281                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
282                                Arrays.asList(
283                                        new CarrierIdentifier(
284                                                new byte[] {0x21, 0x63, 0x54}, null, "5"),
285                                        new CarrierIdentifier(
286                                                new byte[] {0x21, 0x6E, 0x54}, null, null)
287                                ),
288                                0)
289                        .add(
290                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
291                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
292                                Arrays.asList(
293                                        new CarrierIdentifier(
294                                                new byte[] {0x21, 0x69, 0x54}, "5", null),
295                                        new CarrierIdentifier(
296                                                new byte[] {0x21, 0x6E, 0x54}, "4", null),
297                                        new CarrierIdentifier(
298                                                new byte[] {0x21, 0x6E, 0x54}, null, "4")
299                                ),
300                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
301                        .build();
302
303        // Same object.
304        EuiccRulesAuthTable that = rat;
305        assertTrue(rat.equals(that));
306
307        // Same values with rat.
308        that =
309                new EuiccRulesAuthTable.Builder(4)
310                        .add(
311                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
312                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
313                                Arrays.asList(new CarrierIdentifier[] {}),
314                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
315                        .add(
316                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE,
317                                Arrays.asList(
318                                        new CarrierIdentifier(
319                                                new byte[] {0x21, (byte) 0xF3, 0x54},
320                                                "4",
321                                                null),
322                                        new CarrierIdentifier(
323                                                new byte[] {0x21, 0x63, 0x54}, null, "4")
324                                ),
325                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
326                        .add(
327                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
328                                Arrays.asList(
329                                        new CarrierIdentifier(
330                                                new byte[] {0x21, 0x63, 0x54}, null, "5"),
331                                        new CarrierIdentifier(
332                                                new byte[] {0x21, 0x6E, 0x54}, null, null)
333                                ),
334                                0)
335                        .add(
336                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
337                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
338                                Arrays.asList(
339                                        new CarrierIdentifier(
340                                                new byte[] {0x21, 0x69, 0x54}, "5", null),
341                                        new CarrierIdentifier(
342                                                new byte[] {0x21, 0x6E, 0x54}, "4", null),
343                                        new CarrierIdentifier(
344                                                new byte[] {0x21, 0x6E, 0x54}, null, "4")
345                                ),
346                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
347                        .build();
348        assertTrue(rat.equals(that));
349
350        // Null object.
351        that = null;
352        assertFalse(rat.equals(that));
353
354        that =
355                new EuiccRulesAuthTable.Builder(3)
356                        // One less RAT.
357                        .add(
358                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
359                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
360                                Arrays.asList(new CarrierIdentifier[] {}),
361                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
362                        .add(
363                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE,
364                                Arrays.asList(
365                                        new CarrierIdentifier(
366                                                new byte[] {0x21, (byte) 0xF3, 0x54},
367                                                "4",
368                                                null),
369                                        new CarrierIdentifier(
370                                                new byte[] {0x21, 0x63, 0x54}, null, "4")
371                                ),
372                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
373                        .add(
374                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
375                                Arrays.asList(
376                                        new CarrierIdentifier(
377                                                new byte[] {0x21, 0x63, 0x54}, null, "5"),
378                                        new CarrierIdentifier(
379                                                new byte[] {0x21, 0x6E, 0x54}, null, null)
380                                ),
381                                0)
382                        .build();
383        assertFalse(rat.equals(that));
384
385        that =
386                new EuiccRulesAuthTable.Builder(4)
387                        .add(
388                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
389                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
390                                Arrays.asList(new CarrierIdentifier[] {}),
391                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
392                        .add(
393                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE,
394                                Arrays.asList(
395                                        // Only one item
396                                        new CarrierIdentifier(
397                                                new byte[] {0x21, (byte) 0xF3, 0x54},
398                                                "4",
399                                                null)
400                                ),
401                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
402                        .add(
403                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
404                                Arrays.asList(
405                                        new CarrierIdentifier(
406                                                new byte[] {0x21, 0x63, 0x54}, null, "5"),
407                                        new CarrierIdentifier(
408                                                new byte[] {0x21, 0x6E, 0x54}, null, null)
409                                ),
410                                0)
411                        .add(
412                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
413                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
414                                Arrays.asList(
415                                        new CarrierIdentifier(
416                                                new byte[] {0x21, 0x69, 0x54}, "5", null),
417                                        new CarrierIdentifier(
418                                                new byte[] {0x21, 0x6E, 0x54}, "4", null),
419                                        new CarrierIdentifier(
420                                                new byte[] {0x21, 0x6E, 0x54}, null, "4")
421                                ),
422                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
423                        .build();
424        assertFalse(rat.equals(that));
425
426        that =
427                new EuiccRulesAuthTable.Builder(4)
428                        .add(
429                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
430                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
431                                Arrays.asList(new CarrierIdentifier[] {}),
432                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
433                        .add(
434                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE,
435                                Arrays.asList(
436                                        // Different value from rat
437                                        new CarrierIdentifier(
438                                                new byte[] {0x22, (byte) 0xF3, 0x54},
439                                                "4",
440                                                null),
441                                        new CarrierIdentifier(
442                                                new byte[] {0x21, 0x63, 0x54}, null, "4")
443                                ),
444                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
445                        .add(
446                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
447                                Arrays.asList(
448                                        new CarrierIdentifier(
449                                                new byte[] {0x21, 0x63, 0x54}, null, "5"),
450                                        new CarrierIdentifier(
451                                                new byte[] {0x21, 0x6E, 0x54}, null, null)
452                                ),
453                                0)
454                        .add(
455                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
456                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
457                                Arrays.asList(
458                                        new CarrierIdentifier(
459                                                new byte[] {0x21, 0x69, 0x54}, "5", null),
460                                        new CarrierIdentifier(
461                                                new byte[] {0x21, 0x6E, 0x54}, "4", null),
462                                        new CarrierIdentifier(
463                                                new byte[] {0x21, 0x6E, 0x54}, null, "4")
464                                ),
465                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
466                        .build();
467        assertFalse(rat.equals(that));
468
469        that =
470                new EuiccRulesAuthTable.Builder(4)
471                        .add(
472                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
473                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
474                                // Null here.
475                                null,
476                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
477                        .add(
478                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE,
479                                Arrays.asList(
480                                        new CarrierIdentifier(
481                                                new byte[] {0x21, (byte) 0xF3, 0x54},
482                                                "4",
483                                                null),
484                                        new CarrierIdentifier(
485                                                new byte[] {0x21, 0x63, 0x54}, null, "4")
486                                ),
487                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
488                        .add(
489                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
490                                Arrays.asList(
491                                        new CarrierIdentifier(
492                                                new byte[] {0x21, 0x63, 0x54}, null, "5"),
493                                        new CarrierIdentifier(
494                                                new byte[] {0x21, 0x6E, 0x54}, null, null)
495                                ),
496                                0)
497                        .add(
498                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
499                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
500                                Arrays.asList(
501                                        new CarrierIdentifier(
502                                                new byte[] {0x21, 0x69, 0x54}, "5", null),
503                                        new CarrierIdentifier(
504                                                new byte[] {0x21, 0x6E, 0x54}, "4", null),
505                                        new CarrierIdentifier(
506                                                new byte[] {0x21, 0x6E, 0x54}, null, "4")
507                                ),
508                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
509                        .build();
510        assertTrue(rat.equals(that));
511
512        that =
513                new EuiccRulesAuthTable.Builder(4)
514                        .add(
515                                // Different policy rules
516                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE,
517                                Arrays.asList(new CarrierIdentifier[] {}),
518                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
519                        .add(
520                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE,
521                                Arrays.asList(
522                                        new CarrierIdentifier(
523                                                new byte[] {0x21, (byte) 0xF3, 0x54},
524                                                "4",
525                                                null),
526                                        new CarrierIdentifier(
527                                                new byte[] {0x21, 0x63, 0x54}, null, "4")
528                                ),
529                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
530                        .add(
531                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
532                                Arrays.asList(
533                                        new CarrierIdentifier(
534                                                new byte[] {0x21, 0x63, 0x54}, null, "5"),
535                                        new CarrierIdentifier(
536                                                new byte[] {0x21, 0x6E, 0x54}, null, null)
537                                ),
538                                0)
539                        .add(
540                                EuiccProfileInfo.POLICY_RULE_DO_NOT_DELETE
541                                        | EuiccProfileInfo.POLICY_RULE_DO_NOT_DISABLE,
542                                Arrays.asList(
543                                        new CarrierIdentifier(
544                                                new byte[] {0x21, 0x69, 0x54}, "5", null),
545                                        new CarrierIdentifier(
546                                                new byte[] {0x21, 0x6E, 0x54}, "4", null),
547                                        new CarrierIdentifier(
548                                                new byte[] {0x21, 0x6E, 0x54}, null, "4")
549                                ),
550                                EuiccRulesAuthTable.POLICY_RULE_FLAG_CONSENT_REQUIRED)
551                        .build();
552        assertFalse(rat.equals(that));
553    }
554}
555